Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision be2e9500

Von Christian Ehringfeld vor fast 9 Jahren hinzugefügt

  • ID be2e950073b175c0e08fb4b7f34251d0ab482e05
  • Vorgänger f9dccfc5
  • Nachfolger d3d65c98

attribute resolver integration

Unterschiede anzeigen:

src/attributeresolver.cpp
if(foreignBaseObj != target.data()) {
delete foreignBaseObj;
}
qDebug() << "RESOLVE";
return attrObj;
}
src/entityinstancefactory.cpp
}
return registered;
}
Entity *EntityInstanceFactory::createInstance(Attribute *&attr) {
return EntityInstanceFactory::createInstance(
EntityInstanceFactory::extractEntityType(
attr->getMetaProperty().typeName()));
}
src/entityinstancefactory.h
#include <QString>
#include <QVariant>
#include <QHash>
#include "attribute.h"
namespace CuteEntityManager {
class Entity;
class EntityInstanceFactory {
......
static Entity *createInstance() {
return EntityInstanceFactory::createInstance(qMetaTypeId<T>());
}
static Entity *createInstance(Attribute *&attr);
//http://www.mimec.org/node/350
template<typename T>
src/entitymanager.cpp
void EntityManager::manyToOne(const QSharedPointer<Entity> &entity,
const QVariant &id,
const QMetaProperty &property, const bool refresh) {
Attribute *&attr, const bool refresh) {
qint64 convertedId = -1;
bool ok = false;
if ((convertedId = id.toLongLong(&ok)) && ok && convertedId > -1) {
QString className = EntityInstanceFactory::extractEntityType(
property.typeName());
QString className = attr->getRelatedClass()->className();
QSharedPointer<Entity> ptr = QSharedPointer<Entity>();
if (refresh || !(this->cache.contains(convertedId, className)
&& (ptr = this->cache.get(convertedId, className)))) {
ptr = this->findById(convertedId, className);
}
EntityHelper::setProperty(entity, ptr, property);
EntityHelper::setProperty(entity, ptr, attr->getMetaProperty());
}
}
void EntityManager::oneToMany(const QSharedPointer<Entity> &entity,
const Relation &r,
const QMetaProperty &property, const bool refresh) {
Attribute *&attr, const bool refresh) {
if (entity.data() && entity->getId() > -1) {
auto e = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(
EntityInstanceFactory::extractEntityType(
property.typeName())));
auto e = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(attr));
if (e) {
QSqlQuery q = this->schema->getQueryBuilder()->oneToMany(e->getTablename(),
this->schema->getQueryBuilder()->generateColumnNameID(r.getMappedBy()),
entity->getId());
QSqlQuery q = this->schema->getQueryBuilder()->oneToMany(attr->getTableName(),
attr->getColumnName(), entity->getId());
auto listMap = this->convertQueryResult(q);
auto entities = this->convert(listMap, EntityHelper::getClassname(e.data()),
refresh);
EntityHelper::setListProperty(entity, entities, property);
EntityHelper::setListProperty(entity, entities, attr->getMetaProperty());
}
}
}
void EntityManager::oneToOne(const QSharedPointer<Entity> &entity,
const Relation &r, const QMetaProperty &property, const bool refresh,
Attribute *&attr, const bool refresh,
const QVariant &id) {
if (r.getMappedBy().isEmpty()) {
this->manyToOne(entity, id, property);
if (attr->getRelation().getMappedBy().isEmpty()) {
this->manyToOne(entity, id, attr);
} else {
auto e = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(
EntityInstanceFactory::extractEntityType(property.typeName())));
auto e = QSharedPointer<Entity>(EntityInstanceFactory::createInstance(attr));
if (e) {
QSqlQuery q = this->schema->getQueryBuilder()->oneToMany(
e->getTablename(),
this->schema->getQueryBuilder()->generateColumnNameID(
r.getMappedBy()),
attr->getRelation().getMappedBy()),
entity->getProperty(entity->getPrimaryKey()).toLongLong(), 1);
auto listMap = this->convertQueryResult(q);
auto entities = this->convert(listMap, EntityHelper::getClassname(e.data()),
refresh);
if (!entities.isEmpty()) {
QSharedPointer<Entity> ptr = entities.at(0);
EntityHelper::setProperty(entity, ptr, property);
EntityHelper::setProperty(entity, ptr, attr->getMetaProperty());
}
}
}
......
}
}
} else {
this->missingManyToManyTable(attr->getTableName(), entity, attr->getRelation());
this->missingManyToManyTable(attr->getConjunctedTable(), entity, attr->getRelation());
}
}
}
......
switch (r.getType()) {
case RelationType::MANY_TO_ONE:
if (map.contains(colName)) {
this->manyToOne(entity, map.value(colName), property, refresh);
this->manyToOne(entity, map.value(colName), attr, refresh);
}
break;
case RelationType::MANY_TO_MANY:
this->manyToMany(entity, attr, refresh);
break;
case RelationType::ONE_TO_MANY:
this->oneToMany(entity, r, property, refresh);
this->oneToMany(entity, attr, refresh);
break;
case RelationType::ONE_TO_ONE:
this->oneToOne(entity, r, property, refresh, map.value(colName));
this->oneToOne(entity, attr, refresh, map.value(colName));
break;
}
}
src/entitymanager.h
const QHash<QString, QVariant> &map, const bool refresh = false);
QHash<QString, QVariant> findByPk(qint64 id, const QSharedPointer<Entity> &e);
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);
Attribute *&attr, const bool refresh = false);
void oneToMany(const QSharedPointer<Entity> &entity, Attribute *&attr, const bool refresh = false);
void manyToMany(const QSharedPointer<Entity> &entity, Attribute *&attr,
const bool refresh = false);
void oneToOne(const QSharedPointer<Entity> &entity, const Relation &r,
const QMetaProperty &property, const bool refresh = false,
void oneToOne(const QSharedPointer<Entity> &entity, Attribute *&attr, const bool refresh = false,
const QVariant &id = "");
void persistManyToMany(const QSharedPointer<Entity> &entity, const Relation &r,
QVariant &property, QList<Entity *> &mergedObjects,

Auch abrufbar als: Unified diff