Revision ac8aede7
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
example/main.cpp | ||
---|---|---|
#include "models/artikel.h"
|
||
#include "models/person.h"
|
||
#include <typeinfo>
|
||
#include <QThread>
|
||
#include <QMetaMethod>
|
||
#include <QMetaProperty>
|
||
#include "models/group.h"
|
||
... | ... | |
CuteEntityManager::EntityManager *e = new
|
||
CuteEntityManager::EntityManager("QSQLITE",
|
||
QDir::currentPath() + "/db.sqlite");
|
||
QThread *entityManager = new QThread();
|
||
e->moveToThread(entityManager);
|
||
|
||
|
||
QSharedPointer<Artikel> a = QSharedPointer<Artikel>(new Artikel(20.0,
|
||
"Müsli"));
|
||
auto ep = a.dynamicCast<CuteEntityManager::Entity>();
|
||
... | ... | |
// e->create(pptr);
|
||
//e->createTable(grp.dynamicCast<CuteEntityManager::Entity>());
|
||
|
||
// QTime t;
|
||
// t.start();
|
||
QTime t;
|
||
t.start();
|
||
// e->createTable(QSharedPointer<Artikel>(new Artikel()));
|
||
// for (int var = 0; var < 10; ++var) {
|
||
for (int var = 0; var < 10000; ++var) {
|
||
EntityInstanceFactory::createInstance<Artikel*>();
|
||
// QSharedPointer<Entity> a = QSharedPointer<Artikel>(new Artikel(var,QString("a")+QString::number(var)));
|
||
// e->save(a);
|
||
// }
|
||
// qDebug() << "Dauer:" << t.elapsed();
|
||
}
|
||
qDebug() << "Dauer:" << t.elapsed();
|
||
//QSharedPointer<Artikel> aPtr = QSharedPointer<Artikel>(entity);
|
||
Pupil *p = new Pupil();
|
||
// auto iterator = hash.constBegin();
|
src/entity.cpp | ||
---|---|---|
if (this->getInheritanceStrategy() == JOINED_TABLE) {
|
||
Entity *e = 0;
|
||
while (superMetaObject != 0
|
||
&& QString(superMetaObject->className()) != QString("CuteEntityManager::Entity")) {
|
||
&& QString(superMetaObject->className()) !=
|
||
QString("CuteEntityManager::Entity")) {
|
||
e = EntityInstanceFactory::createInstance(superMetaObject->className());
|
||
if (e) {
|
||
classes.push(superMetaObject);
|
src/entitymanager.cpp | ||
---|---|---|
this->schema.data()->setTables(this->schema.data()->getTableSchemas());
|
||
}
|
||
|
||
EntityManager::EntityManager(QSqlDatabase database) {
|
||
EntityManager::EntityManager(QSqlDatabase database) : QObject() {
|
||
auto db = new Database(database);
|
||
this->db = QSharedPointer<Database>(db);
|
||
this->init();
|
||
... | ... | |
EntityManager::EntityManager(const QString &databaseType, QString databasename ,
|
||
QString hostname,
|
||
QString username,
|
||
QString password, QString port) {
|
||
QString password, QString port) : QObject() {
|
||
auto db = new Database(databaseType, this->createConnection(), hostname,
|
||
databasename, username,
|
||
password,
|
src/entitymanager.h | ||
---|---|---|
#include <QtSql/QSqlField>
|
||
#include <QString>
|
||
#include <QStringList>
|
||
#include <QObject>
|
||
#include <QSharedPointer>
|
||
#include <QDebug>
|
||
#include "schema.h"
|
||
... | ... | |
|
||
namespace CuteEntityManager {
|
||
|
||
class EntityManager {
|
||
class EntityManager : public QObject {
|
||
Q_OBJECT
|
||
signals:
|
||
void actionFinished(qint64 id);
|
||
|
||
... | ... | |
const QString &sql) {
|
||
Entity *e = EntityInstanceFactory::createInstance<T>();
|
||
if (e) {
|
||
QSqlQuery q = this->schema.data()->getQueryBuilder().data()->getQuery();
|
||
q = this->db.data()->select(sql);
|
||
QSqlQuery q = this->db.data()->select(sql);
|
||
auto result = this->convertQueryResult(q);
|
||
auto ret = this->convert(result, e->getClassname());
|
||
delete e;
|
Auch abrufbar als: Unified diff
entitymanager inherits from qobject for acting as a worker object