Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 86e5c917

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 86e5c91751659eac014d5222c008bcf05a183efc
  • Vorgänger ed03d112
  • Nachfolger 4677e852

not working wip...

Unterschiede anzeigen:

samples/example/main.cpp
t.start();
CuteEntityManager::EntityManager *e = new
CuteEntityManager::EntityManager("QSQLITE",
QDir::currentPath() + "/db.sqlite");
QDir::currentPath() + "/db.sqlite","","","",0,true);
// CuteEntityManager::EntityManager("QSQLITE",
// ":memory:");
src/entityhelper.cpp
}
return prop;
}
QHash<QString, QVariant> EntityHelper::getEntityAttributes(
const QHash<QString, QMetaProperty>
&props,
const QSharedPointer<Entity> &entity) {
auto map = QHash<QString, QVariant>();
auto transientAttrs = entity->getTransientAttributes();
auto relations = entity->getRelations();
auto i = props.constBegin();
while (i != props.constEnd()) {
if (!transientAttrs.contains(i.key()) && !relations.contains(i.key())) {
map.insert(i.key(), i.value().read(entity.data()));
}
++i;
}
return map;
}
src/entityhelper.h
const QString property);
static QMetaProperty mappedProperty(const Relation &r,
const QSharedPointer<Entity> &foreignEntity);
static QHash<QString, QVariant> getEntityAttributes(const QHash<QString, QMetaProperty>
&props,
const QSharedPointer<Entity> &entity);
};
}
src/querybuilder.cpp
bool ignoreID,
const qint64 limit,
const qint64 offset) {
QHash<QString, QVariant> values = this->getEntityAttributes(
QHash<QString, QVariant> values = EntityHelper::getEntityAttributes(
EntityHelper::getMetaProperties(e.data()), e);
return this->findByAttributes(values, e->getTablename(), ignoreID, limit,
offset);
......
}
QSqlQuery QueryBuilder::findId(const QSharedPointer<Entity> &entity) const {
QHash<QString, QVariant> values = this->getEntityAttributes(
QHash<QString, QVariant> values = EntityHelper::getEntityAttributes(
EntityHelper::getMetaProperties(entity.data()),
entity);
QSqlQuery q = this->database->getQuery(this->selectBase(QStringList(
......
QSqlQuery QueryBuilder::count(const QSharedPointer<Entity> &entity,
bool ignoreID) const {
QHash<QString, QVariant> values = this->getEntityAttributes(
QHash<QString, QVariant> values = EntityHelper::getEntityAttributes(
EntityHelper::getMetaProperties(entity.data()),
entity);
QSqlQuery q = this->database->getQuery(this->selectBase(QStringList(
......
if (props.isEmpty()) {
props = EntityHelper::getMetaProperties(entity.data());
}
auto values = this->getEntityAttributes(props, entity);
auto values = EntityHelper::getEntityAttributes(props, entity);
auto relValues = this->getManyToOneAttributes(props, entity, relations);
auto iterator = relValues.constBegin();
while (iterator != relValues.constEnd()) {
......
tableName + "." + foreignKey);
}
QHash<QString, QVariant> QueryBuilder::getEntityAttributes(
const QHash<QString, QMetaProperty>
&props,
const QSharedPointer<Entity> &entity) const {
auto map = QHash<QString, QVariant>();
auto transientAttrs = entity->getTransientAttributes();
auto relations = entity->getRelations();
auto i = props.constBegin();
while (i != props.constEnd()) {
if (!transientAttrs.contains(i.key()) && !relations.contains(i.key())) {
map.insert(i.key(), i.value().read(entity.data()));
}
++i;
}
return map;
}
QHash<QString, QVariant> QueryBuilder::getManyToOneAttributes(
QHash<QString, QMetaProperty>
props,
......
QString QueryBuilder::where(const QHash<QString, QVariant> &m,
const QString &conjunction,
bool ignoreID, const QString &primaryKey) const {
bool ignoreID, const QString &primaryKey, bool withKeyword) const {
if (m.size() == 0 || (ignoreID && m.contains(primaryKey) && m.size() == 1)) {
return "";
}
return " WHERE " + this->attributes(m, conjunction, ignoreID, primaryKey);
return (withKeyword ? " WHERE " : "") + this->attributes(m, conjunction, ignoreID, primaryKey);
}
QString QueryBuilder::attributes(const QHash<QString, QVariant> &m,
......
void QueryBuilder::where(Query &query, QHash<QString, QVariant> conditions,
QString concat) {
}
void QueryBuilder::where(Query &query,
QHash<QString, QList<QVariant> > conditions, QString concat) {
QString condition = this->where(conditions,concat,false,"id",false);
for (auto i = conditions.constBegin(); i != conditions.constEnd(); ++i) {
query.appendParam(i.key(),i.value());
}
query.appendCondition(condition);
}
void QueryBuilder::between(Query &query, QString column, QVariant firstValue,
......
QString QueryBuilder::where(const QSharedPointer<Entity> &entity,
QString conjunction,
bool ignoreID) const {
return this->where(this->getEntityAttributes(EntityHelper::getMetaProperties(
return this->where(EntityHelper::getEntityAttributes(EntityHelper::getMetaProperties(
entity.data()),
entity),
conjunction, ignoreID, entity->getPrimaryKey());
src/querybuilder.h
};
class QueryBuilder {
/**
* EntityManager is a friend class, cause we want a light public api.
*/
friend class EntityManager;
public:
QueryBuilder(QSharedPointer<Schema> schema, QSharedPointer<Database> database);
virtual ~QueryBuilder();
......
QString refTableName,
QStringList refColumns, QString deleteConstraint,
QString updateConstraint) const;
QString generateIndexName(const QString &name, const QString &table,
const QString &refColumn, const QString &refTable, const bool fk) const;
QString generateColumnNameID(QString name) const;
virtual QString getForeignKeyCascade(DbForeignKeyCascade cascade) const;
virtual QString dropForeignKey(QString name, QString tableName) const;
virtual QString createIndex(QString name, QString tableName,
......
bool unique)const;
virtual QString dropIndex(QString name, QString tableName)const;
virtual QString createFkSuperClass(const Entity *e) const;
QHash<QString, QVariant> getEntityAttributes(const QHash<QString, QMetaProperty>
&props,
const QSharedPointer<Entity> &entity) const;
virtual QStringList relationFks(const QSharedPointer<Entity> &entity) const;
virtual bool supportsForeignKeys() const;
......
QHash<QString, QString> generateTableDefinition(const QSharedPointer<Entity>
&entity)
const;
QString generateManyToManyTableName(const QSharedPointer<Entity> &firstEntity,
const QSharedPointer<Entity> &secondEntity, const Relation &r) const;
QSqlQuery getQuery() const;
QString transformTypeToAbstractDbType(QString typeName) const;
QString transformAbstractTypeToRealDbType(QString typeName) const;
QString getColumnType(const QString &type) const;
QSqlQuery find(const qint64 &id, const QString &tableName) const;
QSqlQuery find(const qint64 &id, const QSharedPointer<Entity> &entity,
qint64 offset = 0, QString pk = "id") const;
QSqlQuery findByAttributes(const QHash<QString, QVariant> &m,
const QString &tableName,
const bool &ignoreID = true, const qint64 limit = 0,
const qint64 offset = 0) const;
QSqlQuery findByAttributes(const QSharedPointer<Entity> &e,
bool ignoreID = true,
const qint64 limit = 0, const qint64 offset = 0);
QSqlQuery findAll(const QString &tableName) const;
QSqlQuery findAll(const QSharedPointer<Entity> &entity, const qint64 limit = 0,
qint64 offset = 0);
QList<QSqlQuery> remove(const QSharedPointer<Entity> &entity) const;
QSqlQuery findId(const QSharedPointer<Entity> &entity) const;
QSqlQuery count(const QSharedPointer<Entity> &entity, bool ignoreID) const;
QSqlQuery count(const QString &tableName) const;
QList<QSqlQuery> merge(const QSharedPointer<Entity> &entity) const;
QList<QSqlQuery> create(const QSharedPointer<Entity> &entity) const;
QSqlQuery removeAll(const QString &tableName) const;
QSqlQuery oneToMany(const QString &tableName, const QString &attribute,
const qint64 &id,
const qint64 &limit = 0);
QSqlQuery manyToMany(const QString &tableName, const QString &attribute,
const qint64 &id);
QSqlQuery manyToManyDelete(const QString &tableName, const QString &attribute,
const qint64 &id);
QSqlQuery manyToManyInsert(const QString &tableName, const QString &col1,
const QString &col2) const;
virtual QString limit(const qint64 &limit, const qint64 &offset) const;
QString generateManyToManyColumnName(const QSharedPointer<Entity> &entity)
const;
QSqlQuery getQuery() const;
void bindValues(const QHash<QString, QVariant> &h, QSqlQuery &q,
bool ignoreID = false, const QString &primaryKey = "id") const;
void bindValue(const QString &key, const QVariant &value, QSqlQuery &q) const;
virtual QString placeHolder(const QString &key) const;
void where(Query &query, QString column, QVariant value);
void where(Query &query,QHash<QString, QVariant> conditions, QString concat="AND");
void where(Query &query,QHash<QString, QList<QVariant>> conditions, QString concat="AND");
void between(Query &query,QString column, QVariant firstValue, QVariant secondValue);
void notBetween(Query &query,QString column, QVariant firstValue, QVariant secondValue);
void in(Query &query,QString column, QList<QVariant> values);
void notIn(Query &query,QString column, QList<QVariant> values);
void notOperator(Query &query,QString column, QVariant value);
void orOperator(Query &query, QHash<QString, QVariant> conditions, bool like=false);
void andOperator(Query &query,QHash<QString, QVariant> conditions);
void arbitraryOperator(Query &query,QString op, QString column, QVariant value);
void where(Query &query, QHash<QString, QVariant> conditions,
QString concat = "AND");
//void where(Query &query,QHash<QString, QList<QVariant>> conditions, QString concat="AND");
void between(Query &query, QString column, QVariant firstValue,
QVariant secondValue);
void notBetween(Query &query, QString column, QVariant firstValue,
QVariant secondValue);
void in(Query &query, QString column, QList<QVariant> values);
void notIn(Query &query, QString column, QList<QVariant> values);
void notOperator(Query &query, QString column, QVariant value);
void orOperator(Query &query, QHash<QString, QVariant> conditions,
bool like = false);
void andOperator(Query &query, QHash<QString, QVariant> conditions);
void arbitraryOperator(Query &query, QString op, QString column,
QVariant value);
void plainOr(Query &query); //adds a simple OR to condition
void plainAnd(Query &query); //add a simple AND to condition
......
* @param condition
* @param concat
*/
void like(QHash<QString, QVariant> conditions, QString concat ="AND", JokerPosition = JokerPosition::BOTH);
void like(QHash<QString, QVariant> conditions, QString concat = "AND",
JokerPosition = JokerPosition::BOTH);
......
QHash<QString, QVariant> attributes;
};
QSqlQuery find(const qint64 &id, const QString &tableName) const;
QSqlQuery find(const qint64 &id, const QSharedPointer<Entity> &entity,
qint64 offset = 0, QString pk = "id") const;
QSqlQuery findByAttributes(const QHash<QString, QVariant> &m,
const QString &tableName,
const bool &ignoreID = true, const qint64 limit = 0,
const qint64 offset = 0) const;
QSqlQuery findByAttributes(const QSharedPointer<Entity> &e,
bool ignoreID = true,
const qint64 limit = 0, const qint64 offset = 0);
QSqlQuery findAll(const QString &tableName) const;
QSqlQuery findAll(const QSharedPointer<Entity> &entity, const qint64 limit = 0,
qint64 offset = 0);
QList<QSqlQuery> remove(const QSharedPointer<Entity> &entity) const;
QSqlQuery findId(const QSharedPointer<Entity> &entity) const;
QSqlQuery count(const QSharedPointer<Entity> &entity, bool ignoreID) const;
QSqlQuery count(const QString &tableName) const;
QList<QSqlQuery> merge(const QSharedPointer<Entity> &entity) const;
QList<QSqlQuery> create(const QSharedPointer<Entity> &entity) const;
QSqlQuery removeAll(const QString &tableName) const;
QSqlQuery oneToMany(const QString &tableName, const QString &attribute,
const qint64 &id,
const qint64 &limit = 0);
QSqlQuery manyToMany(const QString &tableName, const QString &attribute,
const qint64 &id);
QSqlQuery manyToManyDelete(const QString &tableName, const QString &attribute,
const qint64 &id);
QSqlQuery manyToManyInsert(const QString &tableName, const QString &col1,
const QString &col2) const;
QSqlQuery remove(const QString &tableName, const qint64 &id,
const QString &primaryKey = "id") const;
QSqlQuery insert(const QString &tableName, QHash<QString, QVariant> &attributes,
......
const QString &primaryKey = "id") const;
QList<QSqlQuery> createOrMerge(const QSharedPointer<Entity> &entity,
bool insert) const;
virtual QString limit(const qint64 &limit, const qint64 &offset) const;
QString generateIndexName(const QString &name, const QString &table,
const QString &refColumn, const QString &refTable, const bool fk) const;
QString generateColumnNameID(QString name) const;
virtual void createRelationFK(QStringList &queries,
const QSharedPointer<Entity> &entity, const Relation &relation,
const QMetaProperty &metaProperty, const QString &update,
......
QHash<QString, QVariant> getPropertyValues(const QHash<QString, QMetaProperty>
&metaProps,
const QSharedPointer<Entity> &entity) const;
QString generateManyToManyTableName(const QSharedPointer<Entity> &firstEntity,
const QSharedPointer<Entity> &secondEntity, const Relation &r) const;
QString generateManyToManyColumnName(const QSharedPointer<Entity> &entity)
const;
QString buildCreateQuery(QHash<QString, QVariant>::const_iterator i,
QHash<QString, QVariant>::const_iterator end,
QString &p1, QString &p2) const;
......
bool ignoreID = false) const;
QString where(const QHash<QString, QVariant> &m,
const QString &conjunction = ",",
bool ignoreID = false, const QString &primaryKey = "id") const;
bool ignoreID = false, const QString &primaryKey = "id",
bool withKeyword = true) const;
QString attributes(const QHash<QString, QVariant> &m,
const QString &conjunction = ",",
bool ignoreID = false, const QString &primaryKey = "id") const;
......
virtual QString inKeyword() const;
virtual QString whereKeyword() const;
virtual QString countKeyword() const;
virtual QString inFunction(Query &q, QString column, QList<QVariant> values, bool notOp=false);
virtual QString between(QString colName, QString valName1, QString valName2, bool notOp=false);
virtual QString inFunction(Query &q, QString column, QList<QVariant> values,
bool notOp = false);
virtual QString between(QString colName, QString valName1, QString valName2,
bool notOp = false);
QString appendNot(bool notOp);
virtual void appendCondition(Query &q, QString ph1, QString ph2, QVariant val1, QVariant val2, QString condition);
virtual void appendCondition(Query &q, QString ph1, QString ph2, QVariant val1,
QVariant val2, QString condition);
QString entityClassname() const;
QSharedPointer<Schema> schema;

Auch abrufbar als: Unified diff