Revision ae497991
Von Christian Ehringfeld vor etwa 10 Jahren hinzugefügt
| src/entitymanager.cpp | ||
|---|---|---|
|
#include "validators/validator.h"
|
||
|
#include "validators/validatorrule.h"
|
||
|
#include <QHash>
|
||
|
|
||
|
using namespace CuteEntityManager;
|
||
|
|
||
|
QStringList EntityManager::connectionNames = QStringList();
|
||
| ... | ... | |
|
return relation.getType() == r && var.canConvert<QVariantList>();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief EntityManager::savePrePersistedRelations
|
||
|
* @param entity
|
||
|
* @param mergedObjects
|
||
|
* @throw can throw in debug mode a QString exception when the type of any Relation is wrong @see EntityManager::checkRelation
|
||
|
*/
|
||
|
void EntityManager::savePrePersistedRelations(const QSharedPointer<Entity>
|
||
|
&entity, QList<Entity *> &mergedObjects) {
|
||
|
auto relations = EntityHelper::getRelationProperties(entity.data());
|
||
| ... | ... | |
|
const Relation r = iterator.key();
|
||
|
auto var = iterator.value().read(entity.data());
|
||
|
if (!var.isNull()) {
|
||
|
#ifdef QT_DEBUG //we only want this in debug mode, cause in production/release mode this check shouldn't needed
|
||
|
this->checkRelation(var, r);
|
||
|
#endif
|
||
|
if (r.getType() == RelationType::MANY_TO_ONE) {
|
||
|
auto e = EntityInstanceFactory::castQVariant(var);
|
||
|
if (this->shouldBeSaved(e, r)) {
|
||
| ... | ... | |
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void EntityManager::checkRelation(const QVariant &entity,
|
||
|
const Relation &r) const {
|
||
|
bool canConvert = entity.canConvert<QVariantList>();
|
||
|
bool many = r.getType() == RelationType::MANY_TO_MANY
|
||
|
|| r.getType() == RelationType::ONE_TO_MANY;
|
||
|
if ((many && !canConvert) || (!many && canConvert)) {
|
||
|
throw new QString("Relation " + r.getPropertyName() +
|
||
|
" has a wrong relation type.");
|
||
|
} else if (many && r.getType() == RelationType::ONE_TO_MANY
|
||
|
&& r.getMappedBy().isEmpty()) {
|
||
|
throw new QString("Relation " + r.getPropertyName() +
|
||
|
" needs a mappedBy attribute of the foreign class.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @brief EntityManager::savePostPersistedRelations
|
||
|
* @param entity
|
||
|
* @param mergedObjects
|
||
|
* @throw can throw in debug mode a QString exception when the type of any Relation is wrong @see EntityManager::checkRelation
|
||
|
*/
|
||
|
void EntityManager::savePostPersistedRelations(const QSharedPointer<Entity>
|
||
|
&entity, QList<Entity *> &mergedObjects) {
|
||
|
auto relations = EntityHelper::getRelationProperties(entity.data());
|
||
| ... | ... | |
|
const Relation r = iterator.key();
|
||
|
auto var = iterator.value().read(entity.data());
|
||
|
if (!var.isNull()) {
|
||
|
if (this->canPersistRelation(r, RelationType::MANY_TO_MANY, var)) {
|
||
|
#ifdef QT_DEBUG //we only want this in debug mode, cause in production/release mode this check shouldn't needed
|
||
|
this->checkRelation(var, r);
|
||
|
#endif
|
||
|
if (r.getType() == RelationType::MANY_TO_MANY) {
|
||
|
this->persistManyToMany(entity, r, var, mergedObjects);
|
||
|
} else if (this->canPersistRelation(r, RelationType::ONE_TO_MANY, var)) {
|
||
|
} else if (r.getType() == RelationType::ONE_TO_MANY) {
|
||
|
QList<QSharedPointer<Entity>> list = EntityInstanceFactory::castQVariantList(
|
||
|
var);
|
||
|
if (!list.isEmpty()) {
|
||
| src/entitymanager.h | ||
|---|---|---|
|
void oneToOne(const QSharedPointer<Entity> &entity, const Relation &r,
|
||
|
const QMetaProperty &property, const bool refresh = false,
|
||
|
const QVariant &id = "");
|
||
|
bool canPersistRelation(const Relation &relation, const RelationType &r,
|
||
|
const QVariant &var) const;
|
||
|
void persistManyToMany(const QSharedPointer<Entity> &entity, const Relation &r,
|
||
|
QVariant &property, QList<Entity*> &mergedObjects);
|
||
|
QList<QHash<QString, QVariant> > findAllByAttributes(const
|
||
| ... | ... | |
|
Cache cache;
|
||
|
QString createConnection();
|
||
|
QList<QHash<QString, QVariant> > convertQueryResult(QSqlQuery &q);
|
||
|
void checkRelation(const QVariant &entity, const Relation &r) const;
|
||
|
bool canPersistRelation(const Relation &relation, const RelationType &r,
|
||
|
const QVariant &var) const;
|
||
|
bool checkTable(const QSharedPointer<Entity> &entity);
|
||
|
QSharedPointer<QueryInterpreter> queryInterpreter;
|
||
|
|
||
Auch abrufbar als: Unified diff
related to #589