Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision f9cef58f

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID f9cef58fafc20e2a2c6b75fae4e0546de9777be3
  • Vorgänger 09b2592d
  • Nachfolger e8d1537c

wip...

Unterschiede anzeigen:

EntityManager.pro
INSTALLS += target
}
CONFIG += c++14
QMAKE_CXXFLAGS += -Wall -Wextra -Wuninitialized -Wmaybe-uninitialized -Wsuggest-final-types -Wstrict-overflow -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -Waddress
QMAKE_CXXFLAGS += -Wall -Wextra -Wmaybe-uninitialized -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -O
#QMAKE_CXXFLAGS += -Winit-self
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
samples/example/Example.pro
models/contact.cpp \
models/faker/createfakemodeldata.cpp
unix:!macx:CONFIG(debug, debug): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug -lCuteEntityManager
else:unix:!macx:CONFIG(release, release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/ -lCuteEntityManager
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug -lCuteEntityManager
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/ -lCuteEntityManager
unix:INCLUDEPATH += $$PWD/../../src
unix:DEPENDPATH += $$PWD/../../src
CONFIG += c++14
......
win32:INCLUDEPATH += $$PWD/../../build-EntityManager-Desktop_Qt_5_4_1_MinGW_32bit-Debug/debug
win32:DEPENDPATH += $$PWD/../../build-EntityManager-Desktop_Qt_5_4_1_MinGW_32bit-Debug/debug
CONFIG += c++14
QMAKE_CXXFLAGS += -Wall -Wextra -Wmaybe-uninitialized -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -O -Winit-self
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
samples/example/main.cpp
QDir::currentPath() + "/db.sqlite");
// CuteEntityManager::EntityManager("QSQLITE",
// ":memory:");
/**
* @brief EntityInstanceFactory::registerClass<EntityClass>
* You must register every EntityClass, cause Qt is not creating all meta object informations for entity manager
*/
EntityInstanceFactory::registerClass<Group>();
EntityInstanceFactory::registerClass<Person>();
EntityInstanceFactory::registerClass<Pupil>();
......
e->moveToThread(entityManager);
QStringList inits = QStringList() << "Contact" << "Address" <<
"Pupil" << "Group";
/**
* Instead of startup(version,qstringlist) you can call method createTable of EntityManager (e->create(sharedptr))
* startup will create tables inclusive relation tables for classes in QStringList inits
*/
e->startup("0.1", inits);
QSharedPointer<CuteEntityManager::Entity> p =
......
QSharedPointer<Group> gPtr = QSharedPointer<Group>(new Group());
CreateFakeModelData::fillGroup(gPtr.data());
gPtr->setName("9b");
e->createTable(gPtr);
QSharedPointer<Entity> groupPtr = gPtr.objectCast<Entity>();
QSharedPointer<Person> mainTeacher = QSharedPointer<Person>(new Person("Max",
"Mustermann", Person::Gender::MALE));
gPtr->setMainTeacher(mainTeacher);
//Persons will also persisted
e->create(groupPtr, true, true);
//e->create(groupPtr, true, true);
/** ---------------------------------
* FIND Group
* ---------------------------------
*/
// QSharedPointer<Person> foundMainTeacher = e->findById<Person*>(1).objectCast<Person>();
// qDebug() << "Founded:" << foundMainTeacher->toString();
// qDebug() << "FoundedGroupSize:" << foundMainTeacher->getMaintainedGroups().size();
qDebug() << "-----------------------------";
QSharedPointer<Entity> groupFindPtr = e->findById<Group *>(1);
QSharedPointer<Group> grp = groupFindPtr.objectCast<Group>();
qDebug()<< "Group:" << groupFindPtr->toString();
qDebug() << "Group:" << groupFindPtr->toString();
qDebug() << "PersonSize:" << grp->getPersons().size();
qDebug() << "PupilsSize:" << grp->getPupils().size();
qDebug() << "MainTeacher:" << grp->getMainTeacher()->toString();
/** ---------------------------------
* FIND Person
* ---------------------------------
*/
QSharedPointer<Entity> personFindPtr = e->findById(1,QString("Person*"));
qDebug() << "-----------------------------";
QSharedPointer<Entity> personFindPtr = e->findById(1, QString("Person*"));
e->refresh(personFindPtr);
QSharedPointer<Person> pers = personFindPtr.objectCast<Person>();
qDebug()<< "MainTeacher:" << personFindPtr->toString();
qDebug() << "MainTeacher:" << personFindPtr->toString();
qDebug() << "GroupSize:" << pers->getMaintainedGroups().size();
/**
* or you can use following syntax:
*/
qDebug() << "-----------------------------";
QSharedPointer<Person> foundMainTeacher = e->findById<Person *>
(1).objectCast<Person>();
qDebug() << "FoundMainTeacher:" << foundMainTeacher->toString();
qDebug() << "FoundMainTeacherGroupSize:" <<
foundMainTeacher->getMaintainedGroups().size();
qDebug() << "-----------------------------";
QSharedPointer<Pupil> foundPupil = e->findById<Pupil *>
(20).objectCast<Pupil>();
qDebug() << "FoundPupil:" << foundPupil->toString();
qDebug() << "FoundPupilGroupSize:" <<
foundPupil->getGroups().size();
qDebug() << "-----------------------------";
for (int var = 0; var < grp->getPupils().size(); ++var) {
qDebug() << grp->getPupils().at(var)->getGroups().size();
}
qDebug() << "Duration:" << t.elapsed();
Person *p2 = new Person();
delete p2;
return 0;
}
samples/example/models/address.cpp
const QHash<QString, CuteEntityManager::Relation> Address::getRelations()
const {
auto hash = Entity::getRelations();
hash.insert("persons", CuteEntityManager::Relation("persons",
RelationType::MANY_TO_MANY,
QString("addresses")));
// hash.insert("persons", CuteEntityManager::Relation("persons",
// RelationType::MANY_TO_MANY,
// QString("addresses")));
hash.insert("pupils", CuteEntityManager::Relation("pupils",
RelationType::MANY_TO_MANY,
QString("addresses")));
samples/example/models/contact.cpp
const QHash<QString, CuteEntityManager::Relation> Contact::getRelations()
const {
auto hash = Entity::getRelations();
hash.insert("persons", CuteEntityManager::Relation("persons",
RelationType::MANY_TO_MANY,
QString("contacts")));
// hash.insert("persons", CuteEntityManager::Relation("persons",
// RelationType::MANY_TO_MANY,
// QString("contacts")));
hash.insert("pupils", CuteEntityManager::Relation("pupils",
RelationType::MANY_TO_MANY,
QString("contacts")));
samples/example/models/person.cpp
hash.insert("maintainedGroups", CuteEntityManager::Relation("maintainedGroups",
RelationType::ONE_TO_MANY,
QString("mainTeacher")));
hash.insert("contacts", CuteEntityManager::Relation("contacts",
RelationType::MANY_TO_MANY));
hash.insert("addresses", CuteEntityManager::Relation("addresses",
RelationType::MANY_TO_MANY));
// hash.insert("contacts", CuteEntityManager::Relation("contacts",
// RelationType::MANY_TO_MANY));
// hash.insert("addresses", CuteEntityManager::Relation("addresses",
// RelationType::MANY_TO_MANY));
return hash;
}
samples/example/models/person.h
Q_PROPERTY(QList<QSharedPointer<Group>> groups READ getGroups WRITE setGroups)
Q_PROPERTY(QList<QSharedPointer<Group>> maintainedGroups READ
getMaintainedGroups WRITE setMaintainedGroups)
Q_PROPERTY(QList<QSharedPointer<Contact>> contacts READ getContacts WRITE
setContacts)
Q_PROPERTY(QList<QSharedPointer<Address>> addresses READ
getAddresses WRITE setAddresses)
// Q_PROPERTY(QList<QSharedPointer<Contact>> contacts READ getContacts WRITE
// setContacts)
// Q_PROPERTY(QList<QSharedPointer<Address>> addresses READ
// getAddresses WRITE setAddresses)
public:
enum class Gender {MALE, FEMALE, UNKNOWNGENDER};
......
QString customPictureFileName = QString(), QString namePrefix = QString(),
QString nickName = QString(), QDate birthday = QDate(), QObject *parent = 0);
virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const;
virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const override;
bool isPresent(QDateTime date = QDateTime::currentDateTime());
QString fullName(NameOrder nameOrder = NameOrder::FAMILY_FIRST_NAME_ORDER)
samples/example/models/pupil.h
QString getLegalGuardianNote() const;
void setLegalGuardianNote(const QString &value);
virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const;
virtual const QHash<QString, CuteEntityManager::Relation> getRelations() const override;
QString getForm() const;
void setForm(const QString &value);
src/entitymanager.cpp
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include <QVariantList>
#include "entitymanager.h"
#include "enums/databasetype.h"
#include "databasemigration.h"
......
const QMetaProperty &property) const {
QVariant var;
var.setValue<QList<QSharedPointer<Entity>>>(list);
property.write(entity.data(), var);
property.write(entity.data(),var);
}
void EntityManager::addEntityToListProperty(const QSharedPointer<Entity>
......
q.bindValue(1, item->getProperty(ptr->getPrimaryKey()));
this->schema->getDatabase()->exec(q);
if (prop.isReadable()) {
this->addEntityToListProperty(entity, ptr, prop);
this->addEntityToListProperty(ptr, entity, prop);
} else {
qDebug() << "Query exec for many to many relation failed." <<
q.lastError().text();
......
secEntityPtr));
if (!refresh
&& this->cache.contains(id.toLongLong(), secEntityPtr->getClassname())) {
entities.append(this->cache.get(id.toLongLong(), secEntityPtr->getClassname()));
auto entity2 = this->cache.get(id.toLongLong(), secEntityPtr->getClassname());
entities.append(entity2);
//this->addEntityToListProperty(entity,entity2,property);
} else {
entities.append(this->findById(id.toLongLong(), secEntityPtr->getClassname()));
auto entity2 = this->findById(id.toLongLong(), secEntityPtr->getClassname());
//this->addEntityToListProperty(entity,entity2,property);
entities.append(entity2);
}
}
if(!entities.isEmpty()) {
this->setListProperty(entity, entities, property);
}
} else {
qDebug() << "MANY_TO_MANY Table " << tblName << " not exists";
}
src/querybuilder.cpp
QStringList(ptr->getPrimaryKey()), remove, update));
} else if (relation.getType() == RelationType::MANY_TO_MANY) {
QString tableName = this->generateManyToManyTableName(entity, ptr,relation);
QString tableName = this->generateManyToManyTableName(entity, ptr, relation);
queries.append(this->createForeignKeyManyToMany(tableName, entity, update,
remove));
queries.append(this->createForeignKeyManyToMany(tableName, ptr, update,

Auch abrufbar als: Unified diff