Projekt

Allgemein

Profil

Herunterladen als
Herunterladen (2,53 KB) Statistiken
| Zweig: | Revision:
b7446f4c Christian Ehringfeld
#include <QCoreApplication>
#include <QDir>
#include <QDebug>
#include <QThread>
#include "../src/entity.h"
#include "../src/entitymanager.h"
#include "../src/relation.h"
#include "entityinstancefactory.h"
#include "models/pupil.h"
#include "models/address.h"
#include "models/contact.h"
#include "models/group.h"
#include "models/faker/createfakemodeldata.h"
5c3d9487 Christian Ehringfeld
b7446f4c Christian Ehringfeld
using namespace CuteEntityManager;
int main(int argc, char *argv[]) {
Q_UNUSED(argc) Q_UNUSED(argv)
QTime t;
t.start();
CuteEntityManager::EntityManager *e = new
CuteEntityManager::EntityManager("QSQLITE",
QDir::currentPath() + "/db.sqlite");
a82e4cea Christian Ehringfeld
// CuteEntityManager::EntityManager("QSQLITE",
// ":memory:");
b7446f4c Christian Ehringfeld
EntityInstanceFactory::registerClass<Group>();
EntityInstanceFactory::registerClass<Person>();
EntityInstanceFactory::registerClass<Pupil>();
EntityInstanceFactory::registerClass<Contact>();
EntityInstanceFactory::registerClass<Address>();
QThread *entityManager = new QThread();
e->moveToThread(entityManager);
5c3d9487 Christian Ehringfeld
QStringList inits = QStringList() << "Contact" << "Address" << "Person" <<
"Pupil" << "Group";
e->startup("0.1", inits);
b7446f4c Christian Ehringfeld
5c3d9487 Christian Ehringfeld
QSharedPointer<CuteEntityManager::Entity> p =
QSharedPointer<CuteEntityManager::Entity>(new Person("Max", "Mustermann",
Person::Gender::MALE, "", "", "",
QDate::currentDate()));
/** ---------------------------------
* PERSIST
* ---------------------------------
*/
b7446f4c Christian Ehringfeld
Group *g = new Group();
5c3d9487 Christian Ehringfeld
g->setName("9b");
b7446f4c Christian Ehringfeld
CreateFakeModelData::fillGroup(g);
QSharedPointer<Group> gPtr = QSharedPointer<Group>(g);
e->createTable(gPtr);
5c3d9487 Christian Ehringfeld
QSharedPointer<Entity> groupPtr = gPtr.objectCast<Entity>();
df1e56bd Christian Ehringfeld
QSharedPointer<Person> mainTeacher = QSharedPointer<Person>(new Person("Max",
"Mustermann", Person::Gender::MALE));
gPtr->setMainTeacher(mainTeacher);
5c3d9487 Christian Ehringfeld
//Persons will also persisted
e->create(groupPtr, true, true);

/** ---------------------------------
* FIND
* ---------------------------------
*/
QSharedPointer<Entity> groupFindPtr = e->findById<Group *>(1);
QSharedPointer<Group> grp = groupFindPtr.objectCast<Group>();
6c58eb3f Christian Ehringfeld
qDebug()<< "Group:" << groupFindPtr->toString();
5c3d9487 Christian Ehringfeld
qDebug() << "PersonSize:" << grp->getPersons().size();
df1e56bd Christian Ehringfeld
qDebug() << "MainTeacher:" << grp->getMainTeacher()->toString();
b7446f4c Christian Ehringfeld
qDebug() << "Duration:" << t.elapsed();
return 0;
}