Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 57d6da31

Von Christian Ehringfeld vor etwa 9 Jahren hinzugefügt

  • ID 57d6da31ebe73a2e53794d881a5d64d276b331e4
  • Vorgänger 9e2d71d6
  • Nachfolger 5b3fa099

structure

Unterschiede anzeigen:

Doxyfile
# Note that relative paths are relative to the directory from which doxygen is
# run.
EXCLUDE =
EXCLUDE = samples tests
# The EXCLUDE_SYMLINKS tag can be used to select whether or not files or
# directories that are symbolic links (a Unix file system feature) are excluded
EntityManager.pro
include(EntityManager.pri)
TEMPLATE = subdirs
SUBDIRS = src
samples/example/example.pro
QT += core
QT += sql
include(../samples.pri)
TEMPLATE = app
QT -= gui
#TARGET = EntityManager
CONFIG += console
CONFIG -= app_bundle
CONFIG += c++14
TEMPLATE = app
HEADERS += \
models/person.h \
......
models/address.cpp \
models/contact.cpp \
models/faker/createfakemodeldata.cpp
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug -lCuteEntityManager
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/ -lCuteEntityManager
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/release/ -lCuteEntityManager
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug/debug/ -lCuteEntityManager
INCLUDEPATH += $$PWD/../../src
DEPENDPATH += $$PWD/../../src
unix {
QMAKE_CXXFLAGS += -Wall -Wextra -Wmaybe-uninitialized -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -O -Winit-self
}
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
samples/samples.pri
include(../EntityManager.pri)
QT += core
QT += sql
CONFIG += c++14
QMAKE_CXXFLAGS += -Wall -Wextra
INCLUDEPATH += $$PWD/../src
DEPENDPATH += $$PWD/../src
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/src/ -lCuteEntityManager
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/src/ -lCuteEntityManager
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/release/src/ -lCuteEntityManager
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/debug/src/ -lCuteEntityManager
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
samples/simple/main.cpp
int main(int argc, char *argv[]) {
Q_UNUSED(argc) Q_UNUSED(argv)
EntityInstanceFactory::registerClass<Artikel>();
CuteEntityManager::EntityManager *e = new
CuteEntityManager::EntityManager("QSQLITE",
QDir::currentPath() + "/db.sqlite");
EntityInstanceFactory::registerClass<Artikel>();
QSharedPointer<CuteEntityManager::EntityManager> e = QSharedPointer<CuteEntityManager::EntityManager>(new
CuteEntityManager::EntityManager("QSQLITE", QDir::currentPath() + "/db.sqlite"));
QStringList inits = QStringList() << "Artikel";
e->startup("0.1", inits);
QSharedPointer<Artikel> a = QSharedPointer<Artikel>(new Artikel(20.0,
"Müsli"));
auto ep = a.objectCast<CuteEntityManager::Entity>();
qDebug() << e->create(ep, true, true);
int i = 0;
while(false); {
i++;
}
qDebug() << i;
// QSharedPointer<Artikel> a = QSharedPointer<Artikel>(new Artikel(20.0,
// "Müsli"));
// auto ep = a.objectCast<CuteEntityManager::Entity>();
// qDebug() << e->create(ep, true, true);
return 0;
}
samples/simple/simple.pro
# Project created by QtCreator 2013-08-01T15:03:24
#
#-------------------------------------------------
include(../samples.pri)
QT += core
QT += sql
QT -= gui
#TARGET = EntityManager
......
SOURCES += \
main.cpp \
artikel.cpp
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug -lCuteEntityManager
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/ -lCuteEntityManager
unix:INCLUDEPATH += $$PWD/../../src
unix:DEPENDPATH += $$PWD/../../src
CONFIG += c++14
QMAKE_CXXFLAGS += -std=c++14
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/release/ -lCuteEntityManager
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug/debug/ -lCuteEntityManager
win32:INCLUDEPATH += $$PWD/../../../build-EntityManager-Desktop-Debug/debug
win32:DEPENDPATH += $$PWD/../../../build-EntityManager-Desktop-Debug/debug
INCLUDEPATH += $$PWD/../../src
DEPENDPATH += $$PWD/../../src
unix {
QMAKE_CXXFLAGS += -Wall -Wextra -Wmaybe-uninitialized -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -O -Winit-self
}
win32-g++ {
CONFIG += c++11
QMAKE_CXXFLAGS += -std=c++11 -Wall
}
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
samples/validators/validators.pro
# Project created by QtCreator 2013-08-01T15:03:24
#
#-------------------------------------------------
include(../samples.pri)
QT += core
QT += sql
......
main.cpp \
address.cpp \
person.cpp
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug -lCuteEntityManager
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/ -lCuteEntityManager
unix:INCLUDEPATH += $$PWD/../../src
unix:DEPENDPATH += $$PWD/../../src
CONFIG += c++14
QMAKE_CXXFLAGS += -std=c++14
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Release/release/ -lCuteEntityManager
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../build-EntityManager-Desktop-Debug/debug/ -lCuteEntityManager
win32:INCLUDEPATH += $$PWD/../../../build-EntityManager-Desktop-Debug/debug
win32:DEPENDPATH += $$PWD/../../../build-EntityManager-Desktop-Debug/debug
INCLUDEPATH += $$PWD/../../src
DEPENDPATH += $$PWD/../../src
unix {
QMAKE_CXXFLAGS += -Wall -Wextra -Wmaybe-uninitialized -Wsuggest-final-types -Wsuggest-final-methods -Wsuggest-override -Wunsafe-loop-optimizations -pedantic -Wfloat-equal -Wundef -Wpointer-arith -Wcast-align -Wunreachable-code -O -Winit-self
}
win32-g++ {
CONFIG += c++11
QMAKE_CXXFLAGS += -std=c++11 -Wall
}
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
src/database.cpp
if (this->database.isOpen()) {
this->database.close();
}
this->database = QSqlDatabase();
QSqlDatabase::removeDatabase(this->connectionName);
}
......
}
}
QSharedPointer<Schema> Database::getSchema(DatabaseType db,
QSharedPointer<Database> database) {
Schema *Database::getSchema(DatabaseType db,
QSharedPointer<Database> database) {
switch (db) {
case DatabaseType::SQLITE:
return QSharedPointer<Schema>(new SqliteSchema(database));;
return new SqliteSchema(database);
break;
// case PGSQL:
// return QSharedPointer<Schema>(new PgSqlSchema());
// break;
case DatabaseType::MYSQL:
return QSharedPointer<Schema>(new MysqlSchema(database));
return new MysqlSchema(database);
break;
default:
return QSharedPointer<Schema>(new SqliteSchema(database));
return new SqliteSchema(database);
break;
}
}
src/database.h
void logMsg(const QString &value);
bool rollbackTransaction();
static DatabaseType getDatabaseType(QString s);
static QSharedPointer<Schema> getSchema(DatabaseType db,
static Schema *getSchema(DatabaseType db,
QSharedPointer<Database> database);
Logger *getLogger() const;
};
src/entity.h
#ifndef ENTITY_H
#define ENTITY_H
#include <QtGlobal>
#include <QMap>
#include <QObject>
#include <QMetaProperty>
#include <QSharedPointer>
#include "relation.h"
#include <QStringList>
#include <QSharedPointer>
#include <QStack>
#include <QQueue>
#include "entityinstancefactory.h"
#include "validators/validatorrule.h"
#include "validators/errormsg.h"
src/entitymanager.cpp
EntityManager::EntityManager(QSqlDatabase database, bool logQueries,
const bool inspectEntities,
MsgType logActions) : QObject() {
auto db = new Database(database, true, logQueries, logActions);
this->db = QSharedPointer<Database>(db);
this->db = QSharedPointer<Database>(new Database(database, true, logQueries, logActions));
this->init(inspectEntities, logActions);
}
void EntityManager::init(bool inspect, const MsgType msgType) {
EntityInstanceFactory::registerClass<DatabaseMigration>();
auto schema = Database::getSchema(Database::getDatabaseType(
this->db->getDatabase().driverName()), this->db);
this->schema = QSharedPointer<Schema>(schema);
this->schema = QSharedPointer<Schema>(Database::getSchema(Database::getDatabaseType(
this->db->getDatabase().driverName()), this->db));
this->schema->setTables(this->schema->getTableSchemas());
this->queryInterpreter = QSharedPointer<QueryInterpreter>(new QueryInterpreter(
this->schema->getQueryBuilder()));
this->schema->getQueryBuilder().data()));
this->appendToInstanceList();
if (inspect) {
EntityInspector inspector = EntityInspector(msgType);
......
QString hostname, QString username, QString password, QString port,
bool logQueries, QString databaseOptions, const bool inspectEntities,
CuteEntityManager::MsgType logActions) : QObject() {
auto db = new Database(databaseType, this->createConnection(), hostname,
databasename, username,
password,
port.toInt(), true, logQueries, databaseOptions, logActions);
this->db = QSharedPointer<Database>(db);
this->db = QSharedPointer<Database>(new Database(databaseType, this->createConnection(), hostname,
databasename, username,
password,
port.toInt(), true, logQueries, databaseOptions, logActions));
this->init(inspectEntities, logActions);
}
......
EntityHelper::getClassName(entity.data()));
}
void EntityManager::setSchema(const QSharedPointer<Schema> &value) {
schema = value;
}
QList<QHash<QString, QVariant> > EntityManager::selectByQuery(Query &query) {
QSqlQuery q = this->queryInterpreter->build(query);
return this->convertQueryResult(q);
src/entitymanager.h
* @param entity
*/
void refresh(QSharedPointer<Entity> &entity);
void setSchema(const QSharedPointer<Schema> &value);
QList<QHash<QString, QVariant> > selectByQuery(Query &query);
QList<QHash<QString, QVariant> > selectBySql(const QString &sql);
qint8 count(Query &query);
src/querybuilder.cpp
using namespace CuteEntityManager;
QueryBuilder::QueryBuilder(QSharedPointer<Schema> schema,
QSharedPointer<Database> database) {
QueryBuilder::QueryBuilder(Schema *schema,
QSharedPointer<Database> &database) {
this->schema = schema;
this->database = database;
this->separator = " ";
......
return QString("CuteEntityManager::Entity");
}
Schema *QueryBuilder::getSchema() const {
return schema;
}
QStringList QueryBuilder::quoteTableNames(const QStringList &tables) {
QStringList r = QStringList();
for (int i = 0; i < tables.size(); ++i) {
......
return rc;
}
QSharedPointer<Schema> QueryBuilder::getSchema() const {
return schema;
}
void QueryBuilder::setSchema(const QSharedPointer<Schema> &value) {
schema = value;
}
QueryBuilder::ClassAttributes::ClassAttributes(const QString name,
const QHash<QString, QVariant> attributes, QString pk) {
this->name = name;
src/querybuilder.h
friend class EntityManager;
friend class QueryInterpreter;
public:
QueryBuilder(QSharedPointer<Schema> schema, QSharedPointer<Database> database);
QueryBuilder(Schema *schema, QSharedPointer<Database> &database);
virtual ~QueryBuilder();
virtual bool createTable(const QSharedPointer<Entity> &entity,
bool createRelationTables = true) const;
......
const QSharedPointer<Entity> &entity, const QString &update,
const QString &remove) const;
QSharedPointer<Schema> getSchema() const;
void setSchema(const QSharedPointer<Schema> &value);
QSharedPointer<Database> getDatabase() const;
void setDatabase(const QSharedPointer<Database> &value);
QHash<QString, QHash<QString, QString>> generateRelationTables(
......
virtual Expression appendCondition(QString ph1, QString ph2, QVariant val1,
QVariant val2, QString condition) const;
QString entityClassname() const;
Schema *getSchema() const;
QString separator;
QSharedPointer<Schema> schema;
Schema *schema;
QSharedPointer<Database> database;
};
}
src/queryinterpreter.cpp
using namespace CuteEntityManager;
QueryInterpreter::QueryInterpreter(QSharedPointer<QueryBuilder> builder) {
QueryInterpreter::QueryInterpreter(QueryBuilder *builder) {
this->builder = builder;
}
src/queryinterpreter.h
class Expression;
class QueryInterpreter {
public:
QueryInterpreter(QSharedPointer<QueryBuilder> builder);
QueryInterpreter(QueryBuilder *builder);
QSqlQuery build(Query &q);
protected:
......
QString buildCondition(Query &q, const QList<Expression> &conditions) const;
private:
QSharedPointer<QueryBuilder> builder;
QueryBuilder *builder;
};
src/schema/mysqlquerybuilder.cpp
#include "../schema.h"
CuteEntityManager::MysqlQueryBuilder::MysqlQueryBuilder(
QSharedPointer<CuteEntityManager::Schema> schema,
QSharedPointer<CuteEntityManager::Database> database) : QueryBuilder(schema,
database) {
CuteEntityManager::Schema *schema,
QSharedPointer<CuteEntityManager::Database> database) :
CuteEntityManager::QueryBuilder(schema,
database) {
}
src/schema/mysqlquerybuilder.h
class MysqlQueryBuilder : public QueryBuilder
{
public:
MysqlQueryBuilder(QSharedPointer<Schema> schema,
MysqlQueryBuilder(Schema *schema,
QSharedPointer<Database> database);
QString renameColumn(QString tableName, QString oldName,
QString newName) const override;
QString createIndex(QString name, QString tableName,
src/schema/mysqlschema.cpp
using namespace CuteEntityManager;
MysqlSchema::MysqlSchema(QSharedPointer<Database> database) : Schema(
database, QSharedPointer<QueryBuilder>(new MysqlQueryBuilder(
QSharedPointer<Schema>
(this), database))) {
database, QSharedPointer<QueryBuilder>(new MysqlQueryBuilder(this, database))) {
}
QSharedPointer<QHash<QString, QString> > MysqlSchema::getTypeMap() {
src/schema/sqlitequerybuilder.cpp
#include "sqlitequerybuilder.h"
#include "../schema.h"
CuteEntityManager::SqliteQueryBuilder::SqliteQueryBuilder(
QSharedPointer<CuteEntityManager::Schema>
schema,
CuteEntityManager::SqliteQueryBuilder::SqliteQueryBuilder(Schema *schema,
QSharedPointer<CuteEntityManager::Database> database) : QueryBuilder(schema,
database) {
src/schema/sqlitequerybuilder.h
namespace CuteEntityManager {
class SqliteQueryBuilder : public QueryBuilder {
public:
SqliteQueryBuilder(QSharedPointer<Schema> schema,
SqliteQueryBuilder(Schema *schema,
QSharedPointer<Database> database);
~SqliteQueryBuilder();
src/schema/sqliteschema.cpp
using namespace CuteEntityManager;
SqliteSchema::SqliteSchema(QSharedPointer<Database> database) : Schema(
database, QSharedPointer<QueryBuilder>(new SqliteQueryBuilder(
QSharedPointer<Schema>
(this), database))) {
database, QSharedPointer<QueryBuilder>(new SqliteQueryBuilder(this, database))) {
}
SqliteSchema::~SqliteSchema() {
tests/tests.pri
include(../EntityManager.pri)
QT += core
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += c++14
QMAKE_CXXFLAGS += -Wall -Wextra
QT += testlib
CONFIG -= app_bundle
CONFIG += testcase
INCLUDEPATH += $$PWD/../src
DEPENDPATH += $$PWD/../src
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug -lCuteEntityManager
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/ -lCuteEntityManager
unix:!macx:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/src/ -lCuteEntityManager
else:unix:!macx:CONFIG(release, release|debug): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/src/ -lCuteEntityManager
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/release/src/ -lCuteEntityManager
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/debug/src/ -lCuteEntityManager
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Release/release/ -lCuteEntityManager
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../build-EntityManager-Desktop-Debug/debug/ -lCuteEntityManager
tests/tests.pro
include(tests.pri)
TEMPLATE = subdirs
SUBDIRS += \
tables

Auch abrufbar als: Unified diff