Revision 1a3b37ba
Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt
example/main.cpp | ||
---|---|---|
|
||
Pupil *p = new Pupil();
|
||
auto hash = p->getMetaProperties();
|
||
auto iterator = hash.constBegin();
|
||
while(iterator != hash.constEnd()) {
|
||
qDebug() << iterator.key() << " Value:" << iterator.value().read(p);
|
||
|
||
iterator++;
|
||
}
|
||
// auto iterator = hash.constBegin();
|
||
// while(iterator != hash.constEnd()) {
|
||
// qDebug() << iterator.key() << " Value:" << iterator.value().read(p);
|
||
|
||
// iterator++;
|
||
// }
|
||
qDebug() << p->metaObject()->superClass()->className();
|
||
|
||
return 0;
|
||
}
|
src/entity.cpp | ||
---|---|---|
return QStringList();
|
||
}
|
||
|
||
const InheritanceStrategy Entity::getInheritanceStrategy() const {
|
||
return JOINED_TABLE;
|
||
}
|
||
|
||
QString Entity::getPrimaryKey() {
|
||
return "id";
|
||
}
|
src/entity.h | ||
---|---|---|
virtual const QHash<QString, Relation> getRelations() const;
|
||
virtual const QStringList getTransientAttributes() const;
|
||
virtual const QStringList getBLOBColumns() const;
|
||
virtual const InheritanceStrategy getInheritanceStrategy() const;
|
||
|
||
//return value must be the exact name defined in Q_PROPERTY
|
||
virtual QString getPrimaryKey();
|
src/querybuilder.cpp | ||
---|---|---|
const {
|
||
auto map = QHash<QString, QString>();
|
||
auto o = entity.data()->metaObject();
|
||
auto superMetaObject = entity.data()->metaObject()->superClass();
|
||
auto superMetaObjectPropertyMap = this->superMetaObjectPropMap(superMetaObject,
|
||
entity);
|
||
QHash<QString, Relation> relations = entity.data()->getRelations();
|
||
for (int var = 0; var < o->propertyCount(); ++var) {
|
||
auto m = o->property(var);
|
||
if (m.name() != QString("objectName") && m.isReadable()
|
||
if (!superMetaObjectPropertyMap.contains(QString(m.name()))
|
||
&& m.name() != QString("objectName") && m.isReadable()
|
||
&& !entity.data()->getTransientAttributes().contains(m.name())) {
|
||
if (m.isEnumType()) {
|
||
map.insert(m.name(), this->schema.data()->getTypeMap().data()->value(
|
||
... | ... | |
}
|
||
}
|
||
QString pkType = map.value(entity.data()->getPrimaryKey());
|
||
if (pkType == this->schema.data()->TYPE_BIGINT) {
|
||
map.insert(entity.data()->getPrimaryKey(), this->schema.data()->TYPE_BIGPK);
|
||
} else {
|
||
map.insert(entity.data()->getPrimaryKey(), this->schema.data()->TYPE_PK);
|
||
if (entity.data()->getInheritanceStrategy() != JOINED_TABLE
|
||
|| QString(superMetaObject->className()) == QString("Entity")) {
|
||
if (pkType == this->schema.data()->TYPE_BIGINT) {
|
||
map.insert(entity.data()->getPrimaryKey(), this->schema.data()->TYPE_BIGPK);
|
||
} else {
|
||
map.insert(entity.data()->getPrimaryKey(), this->schema.data()->TYPE_PK);
|
||
}
|
||
}
|
||
return map;
|
||
}
|
||
... | ... | |
tableName + "." + foreignKey);
|
||
}
|
||
|
||
QHash<QString, QMetaProperty> QueryBuilder::superMetaObjectPropMap(
|
||
const QMetaObject *&superMeta, const QSharedPointer<Entity> &entity) const {
|
||
auto superMetaObjectPropertyMap = QHash<QString, QMetaProperty>();
|
||
if (QString(superMeta->className()) != QString("Entity")
|
||
&& entity.data()->getInheritanceStrategy() == JOINED_TABLE) {
|
||
for (int var = 0; var < superMeta->propertyCount(); ++var) {
|
||
QMetaProperty prop = superMeta->property(var);
|
||
if (prop.isReadable() && prop.isWritable()) {
|
||
superMetaObjectPropertyMap.insert(QString(prop.name()), prop);
|
||
}
|
||
}
|
||
}
|
||
return superMetaObjectPropertyMap;
|
||
}
|
||
|
||
QString QueryBuilder::superClassColumnName(const QMetaObject *&superMeta)
|
||
const {
|
||
return QString(superMeta->className()).toLower();
|
||
}
|
||
|
||
QString QueryBuilder::limit(const qint64 &limit, const qint64 &offset) const {
|
||
QString s = "";
|
||
if (limit > 0) {
|
||
... | ... | |
auto i = relations.constBegin();
|
||
while (i != relations.constEnd()) {
|
||
Relation r = i.value();
|
||
if (r.getType() == MANY_TO_ONE && props.contains(i.key())
|
||
if ((r.getType() == MANY_TO_ONE && props.contains(i.key()))
|
||
|| (r.getType() == ONE_TO_ONE && r.getMappedBy().isEmpty())) {
|
||
auto v = props.value(i.key()).read(e);
|
||
if (v.canConvert<Entity *>()) {
|
src/querybuilder.h | ||
---|---|---|
const;
|
||
QString leftJoin(const QString &foreignTable, const QString &tableName,
|
||
const QString &foreignKey);
|
||
QHash<QString, QMetaProperty> superMetaObjectPropMap(const QMetaObject
|
||
* &superMeta, const QSharedPointer<Entity> &entity) const;
|
||
QString superClassColumnName(const QMetaObject *&superMeta) const;
|
||
|
||
QSharedPointer<Schema> schema;
|
||
QSharedPointer<Database> database;
|
src/relation.h | ||
---|---|---|
MANY_TO_MANY,
|
||
};
|
||
|
||
enum InheritanceStrategy {
|
||
PER_CLASS_TABLE,
|
||
JOINED_TABLE,
|
||
};
|
||
|
||
enum CascadeType {
|
||
ALL,
|
||
MERGE,
|
Auch abrufbar als: Unified diff
Inheritance gedöns