Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 09b2592d

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 09b2592d9638db1fdc29d479c3354d59c753f4fd
  • Vorgänger af84b9c4
  • Nachfolger f9cef58f

ticket #572

Unterschiede anzeigen:

src/entitymanager.cpp
if (!list.isEmpty()) {
auto builder = this->schema->getQueryBuilder();
auto ptr = list.at(0);
QString tblName = builder->generateManyToManyTableName(e, ptr);
QString tblName = builder->generateManyToManyTableName(e, ptr, r);
if (this->schema->getTables().contains(tblName)) {
QSqlQuery q = builder->manyToManyDelete(
tblName, builder->generateManyToManyColumnName(e),
......
void EntityManager::persistManyToMany(const QSharedPointer<Entity> &entity,
const Relation &r, QVariant &property) {
Q_UNUSED(r)
auto list = property.value<QList<QVariant>>();
if (!list.isEmpty() && !(list.at(0).isNull())) {
auto var = list.at(0);
auto ptr = EntityInstanceFactory::castQVariant(var);
auto builder = this->schema->getQueryBuilder();
QString tblName = builder->generateManyToManyTableName(entity, ptr);
QString tblName = builder->generateManyToManyTableName(entity, ptr, r);
if (this->schema->getTables().contains(tblName)) {
QSqlQuery q = builder->manyToManyDelete(
tblName, builder->generateManyToManyColumnName(entity),
......
void EntityManager::manyToMany(const QSharedPointer<Entity> &entity,
const QMetaProperty &property, const bool refresh) {
const QMetaProperty &property, const Relation &relation, const bool refresh) {
QSharedPointer<Entity> secEntityPtr = QSharedPointer<Entity>
(EntityInstanceFactory::createInstance(EntityInstanceFactory::extractEntityType(
QString(property.typeName()))));
auto builder = this->schema->getQueryBuilder();
if (secEntityPtr) {
QString tblName = builder->generateManyToManyTableName(entity, secEntityPtr);
QString tblName = builder->generateManyToManyTableName(entity, secEntityPtr,
relation);
if (this->schema->getTables().contains(tblName)) {
QSqlQuery q = builder->manyToMany(tblName,
builder->generateManyToManyColumnName(entity),
......
}
break;
case RelationType::MANY_TO_MANY:
this->manyToMany(entity, property, refresh);
this->manyToMany(entity, property, r, refresh);
break;
case RelationType::ONE_TO_MANY:
this->oneToMany(entity, r, property, refresh);
src/entitymanager.h
void oneToMany(const QSharedPointer<Entity> &entity, const Relation &r,
const QMetaProperty &property, const bool refresh = false);
void manyToMany(const QSharedPointer<Entity> &entity,
const QMetaProperty &property, const bool refresh = false);
const QMetaProperty &property, const Relation &relation, const bool refresh = false);
void oneToOne(const QSharedPointer<Entity> &entity, const Relation &r,
const QMetaProperty &property, const bool refresh = false,
const QVariant &id = "");
src/querybuilder.cpp
QStringList(ptr->getPrimaryKey()), remove, update));
} else if (relation.getType() == RelationType::MANY_TO_MANY) {
QString tableName = this->generateManyToManyTableName(entity, ptr);
QString tableName = this->generateManyToManyTableName(entity, ptr,relation);
queries.append(this->createForeignKeyManyToMany(tableName, entity, update,
remove));
queries.append(this->createForeignKeyManyToMany(tableName, ptr, update,
......
QString QueryBuilder::generateManyToManyTableName(const QSharedPointer<Entity>
&firstEntity,
const QSharedPointer<Entity> &secondEntity) const {
QString first = QString(firstEntity->getClassname());
QString second = QString(secondEntity->getClassname());
if (QString::compare(first, second, Qt::CaseSensitive) <= 0) {
return firstEntity->getTablename() + "_" +
secondEntity->getTablename();
const QSharedPointer<Entity> &secondEntity, const Relation &r) const {
if (r.getMappedBy().isEmpty()) {
return firstEntity->getTablename() + "_" + r.getPropertyName();
} else {
return secondEntity->getTablename() + "_" +
firstEntity->getTablename();
return secondEntity->getTablename() + "_" + r.getMappedBy();
}
}
......
QMetaType::typeName(meta.userType()))));
h.insert(this->generateManyToManyColumnName(ptr),
this->schema->TYPE_BIGINT);
relations.insert(this->generateManyToManyTableName(entity, ptr), h);
relations.insert(this->generateManyToManyTableName(entity, ptr, r), h);
}
}
return relations;
src/querybuilder.h
&entity)
const;
QString generateManyToManyTableName(const QSharedPointer<Entity> &firstEntity,
const QSharedPointer<Entity> &secondEntity) const;
const QSharedPointer<Entity> &secondEntity, const Relation &r) const;
QString transformTypeToAbstractDbType(QString typeName) const;
QString transformAbstractTypeToRealDbType(QString typeName) const;

Auch abrufbar als: Unified diff