Revision 244c6d53
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
src/entitymanager.cpp | ||
---|---|---|
}
|
||
|
||
/**
|
||
* @todo should be an insert statement with much values
|
||
* @todo should be an insert statement with many values
|
||
* not really usefull atm
|
||
* @brief EntityManager::create
|
||
* @param entities
|
||
* @return
|
||
*/
|
||
bool EntityManager::create(QList<QSharedPointer<Entity> > entities) {
|
||
bool EntityManager::create(QList<QSharedPointer<Entity> > entities,
|
||
const bool persistRelations) {
|
||
bool ok = true;
|
||
foreach (QSharedPointer<Entity> ent, entities) {
|
||
ok = this->create(ent);
|
||
ok = this->create(ent, persistRelations);
|
||
if (!ok) {
|
||
break;
|
||
}
|
||
... | ... | |
return ok;
|
||
}
|
||
|
||
/**
|
||
* @TODO insert Relations
|
||
* @brief EntityManager::create
|
||
* @param entity
|
||
* @return
|
||
*/
|
||
bool EntityManager::create(QSharedPointer<Entity> &entity) {
|
||
bool EntityManager::create(QSharedPointer<Entity> &entity,
|
||
const bool persistRelations) {
|
||
bool rc = false;
|
||
if (this->checkTable(entity) && this->count(entity) == 0) {
|
||
QSqlQuery q = this->schema.data()->getQueryBuilder().data()->create(entity);
|
||
rc = this->db->transaction(q);
|
||
if (rc) {
|
||
entity.data()->setId(this->schema.data()->getLastInsertID().toLongLong(&rc));
|
||
if (persistRelations) {
|
||
this->saveRelations(entity);
|
||
}
|
||
this->cache.insert(entity);
|
||
}
|
||
}
|
||
... | ... | |
return this->convertQueryResult(q);
|
||
}
|
||
|
||
/**
|
||
* @TODO insert Relations
|
||
* @brief EntityManager::merge
|
||
* @param entity
|
||
* @param withRelations
|
||
* @return
|
||
*/
|
||
bool EntityManager::merge(QSharedPointer<Entity> &entity, bool withRelations) {
|
||
if (this->count(entity) == 0 && entity->getId() != -1) {
|
||
QSqlQuery q = this->schema.data()->getQueryBuilder().data()->merge(entity);
|
||
return this->db->transaction(q);
|
||
bool ok = this->db->transaction(q);
|
||
if (ok && withRelations) {
|
||
this->saveRelations(entity);
|
||
}
|
||
return ok;
|
||
} else {
|
||
return false;
|
||
}
|
||
... | ... | |
}
|
||
}
|
||
|
||
bool EntityManager::save(QSharedPointer<Entity> &entity) {
|
||
bool EntityManager::save(QSharedPointer<Entity> &entity,
|
||
const bool persistRelations) {
|
||
if (entity.data()->getId() > -1) {
|
||
return this->merge(entity);
|
||
return this->merge(entity, persistRelations);
|
||
} else {
|
||
return this->create(entity);
|
||
return this->create(entity, persistRelations);
|
||
}
|
||
}
|
||
|
||
... | ... | |
return r;
|
||
}
|
||
|
||
|
||
bool EntityManager::remove(QSharedPointer<Entity> &entity) {
|
||
bool rc = false;
|
||
QSqlQuery q = this->schema.data()->getQueryBuilder().data()->remove(entity);
|
src/entitymanager.h | ||
---|---|---|
void manyToOne(const QSharedPointer<Entity> &entity, const QVariant &id,
|
||
const QMetaProperty &property, const bool refresh = false);
|
||
void oneToMany(const QSharedPointer<Entity> &entity, const Relation &r,
|
||
const QMetaProperty &property,const bool refresh = false);
|
||
const QMetaProperty &property, const bool refresh = false);
|
||
void manyToMany(const QSharedPointer<Entity> &entity, const Relation &r,
|
||
const QMetaProperty &property,const bool refresh = false);
|
||
const QMetaProperty &property, const bool refresh = false);
|
||
void oneToOne(const QSharedPointer<Entity> &entity, const Relation &r,
|
||
const QMetaProperty &property, const bool refresh = false,
|
||
const QVariant &id = "");
|
||
const bool canPersistRelation(const Relation &relation, const RelationType &r, const QVariant &var) const;
|
||
const bool canPersistRelation(const Relation &relation, const RelationType &r,
|
||
const QVariant &var) const;
|
||
QList<QHash<QString, QVariant> > findAllByAttributes(const
|
||
QSharedPointer<Entity> &entity,
|
||
bool ignoreID = false);
|
||
... | ... | |
QHash<QString, QVariant> &m,
|
||
const QString &tblname,
|
||
bool ignoreID = false);
|
||
QSharedPointer<Entity> findById(const qint64 &id, Entity *&e, const bool refresh=false);
|
||
QSharedPointer<Entity> findById(const qint64 &id, Entity *&e,
|
||
const bool refresh = false);
|
||
void setListProperty(const QSharedPointer<Entity> &entity,
|
||
QList<QSharedPointer<Entity>> &list,
|
||
const QMetaProperty &property) const;
|
||
... | ... | |
QList<QSharedPointer<Entity>> findEntityByAttributes(const
|
||
QSharedPointer<Entity> &entity,
|
||
bool ignoreID = false);
|
||
bool create(QList<QSharedPointer<Entity>> entities);
|
||
bool create(QSharedPointer<Entity> &entity);
|
||
bool save(QSharedPointer<Entity> &entity);
|
||
bool create(QList<QSharedPointer<Entity>> entities,
|
||
const bool persistRelations = true);
|
||
bool create(QSharedPointer<Entity> &entity, const bool persistRelations = true);
|
||
bool save(QSharedPointer<Entity> &entity, const bool persistRelations = true);
|
||
qint64 findId(QSharedPointer<Entity> &entity);
|
||
bool merge(QSharedPointer<Entity> &entity, bool withRelations = true);
|
||
bool remove(QSharedPointer<Entity> &entity);
|
||
... | ... | |
QSharedPointer<Schema> getSchema() const;
|
||
void refresh(QSharedPointer<Entity> &entity);
|
||
void setSchema(const QSharedPointer<Schema> &value);
|
||
|
||
/**
|
||
*@TODO create indexes
|
||
* /
|
||
/**
|
||
*@TODO use conditions
|
||
*/
|
Auch abrufbar als: Unified diff
persisting relations, some todos left