Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision ae497991

Von Christian Ehringfeld vor mehr als 8 Jahren hinzugefügt

  • ID ae4979916820b06073cda2e179a956774901310f
  • Vorgänger f48a8e1e
  • Nachfolger 98ac5809

related to #589

Unterschiede anzeigen:

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()) {

Auch abrufbar als: Unified diff