Revision 03fe3afa
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
src/entity.cpp | ||
---|---|---|
return QHash<QString, Relation>();
|
||
}
|
||
|
||
QHash<QString, QSharedPointer<Entity> > Entity::getRelationObjects() {
|
||
return QHash<QString, QSharedPointer<Entity>>();
|
||
}
|
||
|
||
QStringList Entity::getTransientAttributes() {
|
||
return QStringList();
|
||
}
|
src/entity.h | ||
---|---|---|
virtual ~Entity();
|
||
virtual QString getTablename();
|
||
/**
|
||
* Relation with BELONGS_TO should use qint32 as primary key
|
||
* @brief getRelations
|
||
* @return
|
||
*/
|
||
virtual QHash<QString, Relation> getRelations();
|
||
/**
|
||
* The hashmap keys must be equal to the ones which are defined in the hashmap of getRelations()
|
||
* The EntityManager will only introspect Entity Objects, non-Entity inherited relations will be processed in a other way
|
||
* You must use this method, if you have a n-m Relation with Entity Objects.
|
||
* @brief getRelationObjects
|
||
* @return
|
||
*/
|
||
virtual QHash<QString, QSharedPointer<Entity> > getRelationObjects();
|
||
/**
|
||
* You should return the names of properties which should not persisted e.g. Properties which are only exposed to qml
|
||
* @brief getTransientAttributes
|
||
* @return
|
||
*/
|
||
virtual QStringList getTransientAttributes();
|
||
virtual QStringList getBLOBColumns();
|
||
//return value must be the exact name defined in Q_PROPERTY
|
src/querybuilder.cpp | ||
---|---|---|
const {
|
||
auto relations = QHash<QString, QHash<QString, QString>>();
|
||
QHash<QString, Relation> m = entity.data()->getRelations();
|
||
QHash<QString, QSharedPointer<Entity>> os = entity.data()->getRelationObjects();
|
||
auto props = this->getMetaProperties(entity);
|
||
for (auto i = m.begin(); i != m.end(); ++i) {
|
||
Relation r = i.value();
|
||
if (r.getType() == MANY_TO_MANY && r.getMappedBy().isEmpty()) {
|
||
QHash<QString, QString> h = QHash<QString, QString>();
|
||
h.insert("id", this->schema.data()->TYPE_BIGPK);
|
||
h.insert(QString(entity.data()->metaObject()->className()) + QString("_id"), this->schema.data()->TYPE_BIGINT);
|
||
if (os.contains(i.key())) {
|
||
h.insert(QString(os.value(i.key()).data()->metaObject()->className()) + QString("_id"),
|
||
this->schema.data()->TYPE_BIGINT);
|
||
if (r.getTableName().isEmpty()) {
|
||
relations.insert(this->generateManyToManyTableName(entity, os.value(i.key())), h);
|
||
} else {
|
||
relations.insert(r.getTableName(), h);
|
||
}
|
||
auto m = props.value(r.getPropertyName());
|
||
Entity *e = this->createInstance(m.type());
|
||
QSharedPointer<Entity> ptr = QSharedPointer<Entity>(e);
|
||
h.insert(QString(ptr.data()->metaObject()->className()) + QString("_id"),
|
||
this->schema.data()->TYPE_BIGINT);
|
||
if (r.getTableName().isEmpty()) {
|
||
relations.insert(this->generateManyToManyTableName(entity, ptr), h);
|
||
} else {
|
||
relations.insert(r.getTableName(), h);
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
return values;
|
||
}
|
||
|
||
Entity *QueryBuilder::createInstance(const char *className) const {
|
||
return this->createInstance(QMetaType::type(className));
|
||
}
|
||
|
||
Entity *QueryBuilder::createInstance(int id) const {
|
||
Entity *e = 0;
|
||
if (id != -1) {
|
||
e = static_cast<Entity *>(QMetaType::create(id));
|
||
}
|
||
return e;
|
||
}
|
||
|
||
QHash<QString, QVariant> QueryBuilder::getEntityAttributes(const QHash<QString, QMetaProperty> &props,
|
||
const QSharedPointer<Entity> &entity) const {
|
||
Entity *e = entity.data();
|
||
... | ... | |
if (!(rc == "")) {
|
||
rc += " " + conjunction + " ";
|
||
}
|
||
rc += this->schema.data()->quoteColumnName(i.key()) + "= :" + i.key();
|
||
rc += this->schema.data()->quoteColumnName(i.key()) + "=:" + i.key();
|
||
}
|
||
++i;
|
||
}
|
||
... | ... | |
return rc;
|
||
}
|
||
|
||
|
||
QSharedPointer<Schema> QueryBuilder::getSchema() const {
|
||
return schema;
|
||
}
|
src/querybuilder.h | ||
---|---|---|
QString where(const QHash<QString, QVariant> &m, const QString &conjunction = ",", bool ignoreID = false) const;
|
||
QString attributes(const QHash<QString, QVariant> &m, const QString &conjunction = ",", bool ignoreID = false) const;
|
||
QHash<QString, QVariant> saveAttributes(const QSharedPointer<Entity> &entity) const;
|
||
Entity* createInstance(const char *className) const;
|
||
Entity* createInstance(int id) const;
|
||
|
||
QSharedPointer<Schema> schema;
|
||
QSharedPointer<Database> database;
|
Auch abrufbar als: Unified diff
qmetatype