Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 1e213c09

Von Christian Ehringfeld vor mehr als 9 Jahren hinzugefügt

  • ID 1e213c091347cfd9cbd2c50354e234b5b0ef42dd
  • Vorgänger f4e3904b
  • Nachfolger d568923d

...

Unterschiede anzeigen:

src/databasemigration.cpp
}
DatabaseMigration::DatabaseMigration(QString version, QDateTime applyTime) {
this->version = version;
this->applyTime = applyTime;
}
DatabaseMigration::~DatabaseMigration() {
}
src/databasemigration.h
public:
DatabaseMigration();
DatabaseMigration(QString version, QDateTime applyTime);
~DatabaseMigration();
QString getVersion() const;
void setVersion(const QString &value);
src/entitymanager.cpp
#include "entitymanager.h"
#include "enums/databasetype.h"
#include "entityinstancefactory.h"
#include "databasemigration.h"
using namespace CuteEntityManager;
QStringList EntityManager::connectionNames = QStringList();
......
this->init();
}
bool EntityManager::startup(QString version, QStringList toInitialize) {
DatabaseMigration dbm = DatabaseMigration();
QHash<QString, QVariant> map = QHash<QString, QVariant>();
map.insert("version", version);
this->findAllByAttributes(map, dbm.getTablename());
}
EntityManager::EntityManager(const QString &databaseType, QString databasename , QString hostname, QString username,
QString password, QString port) {
auto db = new Database(databaseType, this->createConnection(), hostname, databasename, username, password,
......
QList<QSharedPointer<Entity> > EntityManager::findEntityByAttributes(const QSharedPointer<Entity> &entity,
bool ignoreID) {
auto maps = this->findByAttributes(entity, ignoreID);
auto maps = this->findAllByAttributes(entity, ignoreID);
return this->convert(maps, entity.data()->getClassname());
}
......
}
QList<QHash<QString, QVariant> > EntityManager::findByAttributes(const QSharedPointer<Entity> &entity, bool ignoreID) {
QList<QHash<QString, QVariant> > EntityManager::findAllByAttributes(const QSharedPointer<Entity> &entity,
bool ignoreID) {
QSqlQuery q = this->schema.data()->getQueryBuilder().data()->findByAttributes(entity, ignoreID);
return this->convertQueryResult(q);
}
QList<QHash <QString, QVariant> > EntityManager::findByAttributes(const QHash<QString, QVariant> &m,
QList<QHash <QString, QVariant> > EntityManager::findAllByAttributes(const QHash<QString, QVariant> &m,
const QString &tblname,
bool ignoreID) {
QSqlQuery q = this->schema.data()->getQueryBuilder().data()->findByAttributes(m,
src/entitymanager.h
QHash<QString, QVariant> find(QSharedPointer<Entity> entity);
QHash<QString, QVariant> find(qint64 id, QString tblname);
QSharedPointer<Entity> convert(const QHash<QString, QVariant> &map, const char *classname);
QList<QSharedPointer<Entity>> convert(QList<QHash<QString, QVariant> > maps,const char *classname);
QList<QSharedPointer<Entity>> convert(QList<QHash<QString, QVariant> > maps, const char *classname);
QList<QHash<QString, QVariant> > findByAttributes(const QSharedPointer<Entity> &entity, bool ignoreID = false);
QList<QHash<QString, QVariant> > findByAttributes(const QHash<QString, QVariant> &m, const QString &tblname,
QList<QHash<QString, QVariant> > findAllByAttributes(const QSharedPointer<Entity> &entity, bool ignoreID = false);
QList<QHash<QString, QVariant> > findAllByAttributes(const QHash<QString, QVariant> &m, const QString &tblname,
bool ignoreID = false);
public:
......
QString password = "", QString port = "");
~EntityManager();
static QStringList getConnectionNames();
/**
* @brief startup
* @param version must be unique
* @param toInitialize list of entity classnames which database tables should be created
* @return
*/
bool startup(QString version, QStringList toInitialize);
static void removeConnectionName(const QString &name);
QList<QSharedPointer<Entity>> findAllEntities(QSharedPointer<Entity> entity);
QSharedPointer<Entity> findEntity(QSharedPointer<Entity> entity);
src/querybuilder.cpp
return q;
}
QString QueryBuilder::limit(const qint8 limit, const qint64 offset) const {
return " LIMIT " + QString(limit) + (offset > 0 ? QString("," + offset) : "");
}
QHash<QString, QVariant> QueryBuilder::saveAttributes(const QSharedPointer<Entity> &entity) const {
auto props = entity.data()->getMetaProperties();
auto values = this->getEntityAttributes(props, entity);
src/querybuilder.h
QSqlQuery count(const QString &tableName) const;
QSqlQuery merge(const QSharedPointer<Entity> &entity) const;
QSqlQuery create(const QSharedPointer<Entity> &entity) const;
virtual QString limit(const qint8 limit, const qint64 offset) const;
protected:
void insertRelationId(const Entity *e, QHash<QString, QVariant> &map, QString relName) const;

Auch abrufbar als: Unified diff