Revision 813205af
Von Christian Ehringfeld vor mehr als 10 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();
|
||
|
}
|
||
| ... | ... | |
|
QString Entity::getPrimaryKey() {
|
||
|
return "id";
|
||
|
}
|
||
|
qint32 Entity::getId() const {
|
||
|
|
||
|
QHash<QString, QMetaProperty> Entity::getMetaProperties() {
|
||
|
QHash<QString, QMetaProperty> h = QHash<QString, QMetaProperty>();
|
||
|
for (int var = 0; var < this->metaObject()->propertyCount(); ++var) {
|
||
|
QMetaProperty m = this->metaObject()->property(var);
|
||
|
if (m.name() != QString("objectName")) {
|
||
|
h.insert(m.name(), m);
|
||
|
}
|
||
|
}
|
||
|
return h;
|
||
|
}
|
||
|
|
||
|
qint64 Entity::getId() const {
|
||
|
return id;
|
||
|
}
|
||
|
|
||
|
void Entity::setId(const qint32 &value) {
|
||
|
void Entity::setId(const qint64 &value) {
|
||
|
id = value;
|
||
|
}
|
||
| src/entity.h | ||
|---|---|---|
|
#include <QMap>
|
||
|
#include <QDebug>
|
||
|
#include <QObject>
|
||
|
#include <QMetaProperty>
|
||
|
#include "relation.h"
|
||
|
#include <QStringList>
|
||
|
namespace CuteEntityManager {
|
||
| ... | ... | |
|
* @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-n 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
|
||
| ... | ... | |
|
virtual QStringList getBLOBColumns();
|
||
|
//return value must be the exact name defined in Q_PROPERTY
|
||
|
virtual QString getPrimaryKey();
|
||
|
QHash<QString, QMetaProperty> getMetaProperties();
|
||
|
|
||
|
qint32 getId() const;
|
||
|
void setId(const qint32 &value);
|
||
|
qint64 getId() const;
|
||
|
void setId(const qint64 &value);
|
||
|
|
||
|
protected:
|
||
|
qint32 id;
|
||
|
protected:
|
||
|
qint64 id;
|
||
|
};
|
||
|
}
|
||
|
#endif // ENTITY_H
|
||
| src/querybuilder.cpp | ||
|---|---|---|
|
auto map = QHash<QString, QString>();
|
||
|
auto o = entity.data()->metaObject();
|
||
|
QHash<QString, Relation> relations = entity.data()->getRelations();
|
||
|
QHash<QString, QSharedPointer<Entity>> relationObjects = entity.data()->getRelationObjects();
|
||
|
for (int var = 0; var < o->propertyCount(); ++var) {
|
||
|
o->property(var);
|
||
|
auto m = o->property(var);
|
||
| ... | ... | |
|
} else if (relations.contains(m.name())) {
|
||
|
Relation r = relations.value(m.name());
|
||
|
if (r.getType() == RelationType::BELONGS_TO) {
|
||
|
map.insert(QString(m.name()) + "_id", this->schema.data()->TYPE_INTEGER);
|
||
|
map.insert(QString(m.name()) + "_id", this->schema.data()->TYPE_BIGINT);
|
||
|
}
|
||
|
} else if (entity.data()->getBLOBColumns().contains(m.name())) {
|
||
|
map.insert(m.name(), this->schema.data()->getTypeMap().data()->value(this->schema.data()->TYPE_BINARY));
|
||
| ... | ... | |
|
return map;
|
||
|
}
|
||
|
|
||
|
QList<QHash<QString, QString>> QueryBuilder::generateRelationTables(const QSharedPointer<Entity> &entity) {
|
||
|
QHash<QString, Relation> m = entity.data()->getRelations();
|
||
|
for(auto i = m.begin(); i != m.end(); ++i) {
|
||
|
Relation r = i.value();
|
||
|
if(r.getType() == HAS_MANY) {
|
||
|
QHash<QString, QString> h = QHash<QString, QString>();
|
||
|
h.insert("id",this->schema.data()->TYPE_BIGPK);
|
||
|
//h.insert(entity.data()->metaObject()->className()+ "_id", this->schema.data()->)
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
QString QueryBuilder::transformTypeToAbstractDbType(QString typeName) const {
|
||
|
QHash<QString, QString> *m = this->schema.data()->getAbstractTypeMap().data();
|
||
|
if (m->contains(typeName)) {
|
||
|
return m->value(typeName);
|
||
|
}
|
||
|
QHash<QString, QString>::iterator i;
|
||
|
for (i = m->begin(); i != m->end(); ++i) {
|
||
|
for (auto i = m->begin(); i != m->end(); ++i) {
|
||
|
if (i.key().contains(typeName)) {
|
||
|
return i.value();
|
||
|
}
|
||
Auch abrufbar als: Unified diff
wip, not working