Revision 244c6d53
Von Christian Ehringfeld vor fast 11 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);
|
||
Auch abrufbar als: Unified diff
persisting relations, some todos left