Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision aa44e7d1

Von Christian Ehringfeld vor fast 10 Jahren hinzugefügt

  • ID aa44e7d1b48b226bae925e8c9dad33ee1effbc8e
  • Vorgänger 6899f814
  • Nachfolger 4d58ef6a

cleanup

Unterschiede anzeigen:

EntityManager.pro
HEADERS += \
src/entity.h \
src/entitymanager.h \
src/enums/persistencetype.h \
src/database.h \
src/enums/databasetype.h \
src/enums/relationtype.h \
src/relation.h
src/schema.h
SOURCES += \
src/base/entity.cpp \
src/entitymanager.cpp \
src/database.cpp \
src/relation.cpp
src/schema.cpp
unix {
target.path = /usr/lib
example/Example.pro
#-------------------------------------------------
#
# Project created by QtCreator 2013-08-01T15:03:24
#
#-------------------------------------------------
QT += core
QT += sql
QT -= gui
TARGET = EntityManager
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
HEADERS += \
models/artikel.h
SOURCES += \
models/artikel.cpp
example/main.cpp
#include <QCoreApplication>
#include "src/entitymanager.h"
#include <typeinfo>
#include <QDir>
#include <QDebug>
/**
* create,remove und merge funktionieren
*/
int main(int argc, char *argv[])
{
OpenTeacherTool::EntityManager *e = new OpenTeacherTool::EntityManager("QSQLITE",QDir::currentPath() + "/db.sqlite");
OpenTeacherTool::Artikel *b= new OpenTeacherTool::Artikel(30,"Peter123");
OpenTeacherTool::Entity *entity = b->getEntity();
qDebug() << "findByAttributes:" << e->findByAttributes(entity,true);
qDebug() << "create:" << e->create(entity);
qDebug() << "findAll:" << e->findAll(entity->getTablename());
entity->setAttributes(e->findByAttributes(entity,true).at(0));
qDebug() << "AttributeValues, Artikel:" << *b->getAttributeValues();
b->setName("Peter");
b->setPreis(20);
e->remove(entity);
qDebug() << "TypID:" << typeid(entity).name();
qDebug() << entity->getId();
qDebug() << "merge:" << e->merge(entity);
delete entity;
return 0;
}
src/entity.h
#include <QtGlobal>
#include <QMap>
#include <QDebug>
#include <QObject>
#include "enums/persistencetype.h"
#include "enums/databasetype.h"
namespace CuteEntityManager {
class Entity
{
class Entity : public QObject {
Q_OBJECT
public:
qint64 getId();
void setId(qint64 id);
Entity* getEntity();
void addAttributeVal(const QString name, QVariant *var);
qint64 getId() = 0;
void setId(qint64 id) = 0;
virtual ~Entity();
virtual QHash<QString, QString> getProperties(DatabaseType type) = 0;
virtual PersistenceType getPersistenceType() = 0;
virtual QHash<QString,Entity*>* getRelations() = 0;
virtual QHash<QString, QVariant>* getAttributeValues() = 0;
virtual void setAttributes(QHash<QString, QVariant>) = 0;
virtual QString getTablename() = 0;
virtual QString idColumnSQL();
// virtual QMap<QString, QString> getManyToManyRelations() = 0; //Key = Table, Value = joined Table Column
protected:
Entity();
qint64 id;
QHash<QString,QVariant> *attributeValues;
QHash<QString,Entity*> *relations;
};
}
#endif // MODEL_H
src/enums/persistencetype.h
/*
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef PERSISTENCETYPE_H
#define PERSISTENCETYPE_H
#include <QObject>
#include <QMap>
#include <QString>
namespace CuteEntityManager {
enum PersistenceType {
LOCAL=0,
XML=1,
REMOTEDATABASE=2
};
static QMap<PersistenceType, QString> initMap() {
QMap<PersistenceType, QString> map;
map[LOCAL] = QObject::tr("LocalDatabase");
map[XML] = QObject::tr("XMLFile");
map[REMOTEDATABASE] = QObject::tr("RemoteDatabase");
return map;
}
static QString toString(const PersistenceType &type) {
static QMap<PersistenceType, QString> map = initMap();
return map[type];
}
}
#endif // PERSISTENCETYPE_H
src/enums/relationtype.h
/*
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RELATIONTYPE_H
#define RELATIONTYPE_H
namespace CuteEntityManager{
enum Relationtype {
ONETOONE=0,
ONETOMANY=1,
MANYTOONE=2,
MANYTOMANY=3
};
}
#endif // RELATIONTYPE_H
src/relation.cpp
/*
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "relation.h"
namespace CuteEntityManager {
Relation::Relation()
{
}
}
src/relation.h
/*
* Copyright (C) 2015 Christian Ehringfeld <c.ehringfeld@t-online.de>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef RELATION_H
#define RELATION_H
#include "entity.h"
#include "src/enums/relationtype.h"
namespace CuteEntityManager {
class Relation
{
public:
Relation();
private:
Entity* foreignEntity;
OpenTeacherTool::Relationtype Relationtype;
};
}
#endif // RELATION_H
src/schema.cpp
#include "schema.h"
Schema::Schema()
{
}
Schema::~Schema()
{
}
src/schema.h
#ifndef SCHEMA_H
#define SCHEMA_H
class Schema
{
public:
Schema();
~Schema();
};
#endif // SCHEMA_H
test/EntityManager.pro
#-------------------------------------------------
#
# Project created by QtCreator 2013-08-01T15:03:24
#
#-------------------------------------------------
QT += core
QT += sql
QT -= gui
TARGET = EntityManager
CONFIG += console
CONFIG -= app_bundle
TEMPLATE = app
HEADERS += \
src/entity.h \
src/entitymanager.h \
src/enums/persistencetype.h \
src/database.h \
src/enums/databasetype.h \
src/enums/relationtype.h \
src/relation.h
SOURCES += \
src/base/entity.cpp \
src/entitymanager.cpp \
src/database.cpp \
src/relation.cpp
test/main.cpp
#include <QCoreApplication>
#include "src/entitymanager.h"
#include <typeinfo>
#include <QDir>
#include <QDebug>
/**
* create,remove und merge funktionieren
*/
int main(int argc, char *argv[])
{
OpenTeacherTool::EntityManager *e = new OpenTeacherTool::EntityManager("QSQLITE",QDir::currentPath() + "/db.sqlite");
OpenTeacherTool::Artikel *b= new OpenTeacherTool::Artikel(30,"Peter123");
OpenTeacherTool::Entity *entity = b->getEntity();
qDebug() << "findByAttributes:" << e->findByAttributes(entity,true);
qDebug() << "create:" << e->create(entity);
qDebug() << "findAll:" << e->findAll(entity->getTablename());
entity->setAttributes(e->findByAttributes(entity,true).at(0));
qDebug() << "AttributeValues, Artikel:" << *b->getAttributeValues();
b->setName("Peter");
b->setPreis(20);
e->remove(entity);
qDebug() << "TypID:" << typeid(entity).name();
qDebug() << entity->getId();
qDebug() << "merge:" << e->merge(entity);
delete entity;
return 0;
}

Auch abrufbar als: Unified diff