Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 0e3a3d7f

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 0e3a3d7fd6c50bc6a7077f16a734f496bc36fd1b
  • Vorgänger d2c13492
  • Nachfolger 992116ed

refactoring

Unterschiede anzeigen:

src/querybuilder.cpp
return q;
}
//@TODO Looks like create() - Refactor code
QList<QSqlQuery> QueryBuilder::merge(const QSharedPointer<Entity> &entity)
const {
return this->createOrMerge(entity, false);
}
QList<QSqlQuery> QueryBuilder::createOrMerge(const QSharedPointer<Entity>
&entity, bool insert) const {
auto attrs = this->inheritedAttributes(entity);
auto queries = QList<QSqlQuery>();
for (int var = 0; var < attrs.size(); ++var) {
auto attr = attrs.at(var);
auto attrHash = attr.getAttributes();
queries.append(this->update(attr.getName(), attrHash, attr.getPk()));
queries.append(insert ? this->insert(attr.getName(), attrHash,
attr.getPk()) : this->update(attr.getName(), attrHash, attr.getPk()));
}
return queries;
}
QList<QSqlQuery> QueryBuilder::create(const QSharedPointer<Entity> &entity)
const {
auto attrs = this->inheritedAttributes(entity);
auto queries = QList<QSqlQuery>();
for (int var = 0; var < attrs.size(); ++var) {
auto attr = attrs.at(var);
auto attrHash = attr.getAttributes();
queries.append(this->insert(attr.getName(), attrHash, attr.getPk()));
}
return queries;
return this->createOrMerge(entity, true);
}
QSqlQuery QueryBuilder::insert(const QString &tableName,
......
void QueryBuilder::ClassAttributes::setPk(const QString &value) {
pk = value;
}
src/querybuilder.h
const QString &primaryKey = "id") const;
QSqlQuery update(const QString &tableName, QHash<QString, QVariant> &attributes,
const QString &primaryKey = "id") const;
QList<QSqlQuery> createOrMerge(const QSharedPointer<Entity> &entity, bool insert) const;
virtual void createRelationFK(QStringList &queries,
const QSharedPointer<Entity> &entity, const Relation &relation,
const QMetaProperty &metaProperty, const QString &update,

Auch abrufbar als: Unified diff