Revision a205e8a9
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
example/main.cpp | ||
---|---|---|
qDebug() << "Tabelle artikel erstellt:" << e->createTable(ep);
|
||
e->create(ep);
|
||
|
||
QSharedPointer<Person> p = QSharedPointer<Person>(new Person("Max", "Mustermann", Person::MALE, "", "", "",
|
||
QSharedPointer<CuteEntityManager::Entity> p = QSharedPointer<CuteEntityManager::Entity>(new Person("Max", "Mustermann", Person::MALE, "", "", "",
|
||
QDate::currentDate()));
|
||
auto pptr = p.dynamicCast<CuteEntityManager::Entity>();
|
||
e->createTable(pptr);
|
src/entity.cpp | ||
---|---|---|
}
|
||
|
||
void Entity::setId(const qint64 &value) {
|
||
id = value;
|
||
if(value != this->id) {
|
||
id = value;
|
||
emit idChanged();
|
||
}
|
||
}
|
src/entityinstancefactory.h | ||
---|---|---|
static Entity *createInstance(const QString &className);
|
||
static Entity *createInstance(int metaTypeId);
|
||
static Entity *createInstance(const char *className, const QHash<QString, QVariant> &attributes);
|
||
static Entity *setAttributes(Entity *e, const QHash<QString, QVariant> &attributes, QHash<QString, QMetaProperty> metaprops);
|
||
static Entity *setAttributes(Entity *e, const QHash<QString, QVariant> &attributes,
|
||
QHash<QString, QMetaProperty> metaprops);
|
||
static Entity *setAttributes(Entity *e, const QHash<QString, QVariant> &attributes);
|
||
|
||
template<typename T>
|
||
static Entity *createInstance() {
|
||
return EntityInstanceFactory::createInstance(qMetaTypeId<T>());
|
||
}
|
||
protected:
|
||
EntityInstanceFactory();
|
||
};
|
src/entitymanager.cpp | ||
---|---|---|
|
||
#include "entitymanager.h"
|
||
#include "enums/databasetype.h"
|
||
#include "entityinstancefactory.h"
|
||
#include "databasemigration.h"
|
||
using namespace CuteEntityManager;
|
||
|
src/entitymanager.h | ||
---|---|---|
#include <QDebug>
|
||
#include "schema.h"
|
||
#include <QtSql/QSqlError>
|
||
#include <QMetaType>
|
||
#include "entity.h"
|
||
#include "database.h"
|
||
#include "entityinstancefactory.h"
|
||
|
||
namespace CuteEntityManager {
|
||
|
||
... | ... | |
QList<QSharedPointer<Entity>> findAllEntities(QSharedPointer<Entity> entity);
|
||
QSharedPointer<Entity> findEntity(QSharedPointer<Entity> entity);
|
||
QList<QSharedPointer<Entity>> findEntityByAttributes(const QSharedPointer<Entity> &entity, bool ignoreID = false);
|
||
|
||
template<class T> QSharedPointer<Entity> findById(const qint64 &id) {
|
||
Entity *e = EntityInstanceFactory::createInstance<T>();
|
||
QSharedPointer<Entity> ptr = QSharedPointer<Entity>(e);
|
||
e->setId(id);
|
||
return this->findEntity(ptr);
|
||
}
|
||
|
||
bool create(QSharedPointer<Entity> &entity);
|
||
bool save(QSharedPointer<Entity> &entity);
|
Auch abrufbar als: Unified diff
...