Projekt

Allgemein

Profil

Herunterladen als
Herunterladen (3,36 KB) Statistiken
| Zweig: | Revision:
81c23b56 Christian Ehringfeld
/*
6899f814 Christian Ehringfeld
* 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/>.
*/
81c23b56 Christian Ehringfeld
#ifndef ENTITYMANAGER_H
#define ENTITYMANAGER_H
#include <QtSql/QSqlDatabase>
#include <QtSql/QSqlRecord>
#include <QtSql/QSqlField>
#include <QString>
#include <QStringList>
586bb527 Christian Ehringfeld
#include <QSharedPointer>
81c23b56 Christian Ehringfeld
#include <QDebug>
9d05e414 Christian Ehringfeld
#include "schema.h"
81c23b56 Christian Ehringfeld
#include <QtSql/QSqlError>
#include "entity.h"
#include "database.h"

6899f814 Christian Ehringfeld
namespace CuteEntityManager {
81c23b56 Christian Ehringfeld
426974c6 Christian Ehringfeld
class EntityManager {
private:
81c23b56 Christian Ehringfeld
static QStringList connectionNames;
9d05e414 Christian Ehringfeld
QSharedPointer<Schema> schema;
81c23b56 Christian Ehringfeld
static void setConnectionNames(QStringList list);
9d05e414 Christian Ehringfeld
QSharedPointer<Database> db;
81c23b56 Christian Ehringfeld
QString createConnection();
586bb527 Christian Ehringfeld
QString createTableQuery(const QSharedPointer<Entity> &entity);
QString attributes(const QHash<QString, QVariant> &m, const QString &conjunction = ",", bool ignoreID = false);
81c23b56 Christian Ehringfeld
QList<QHash<QString, QVariant> > convertQueryResult(QSqlQuery &q);
586bb527 Christian Ehringfeld
bool checkTable(const QSharedPointer<Entity> &entity);
426974c6 Christian Ehringfeld
QString buildCreateQuery(QHash<QString, QVariant>::const_iterator i, QHash<QString, QVariant>::const_iterator end,
QString &p1, QString &p2);
586bb527 Christian Ehringfeld
void bindValues(const QHash<QString, QVariant> &h, QSqlQuery &q, bool ignoreID = false);
81c23b56 Christian Ehringfeld
426974c6 Christian Ehringfeld
protected:
7e233492 Christian Ehringfeld
void init();
586bb527 Christian Ehringfeld
QString where(const QSharedPointer<Entity> &entity, QString conjunction = ",", bool ignoreID = false);
QString where(const QHash<QString, QVariant> &m, const QString &conjunction = ",", bool ignoreID = false);
81c23b56 Christian Ehringfeld
426974c6 Christian Ehringfeld
public:
81c23b56 Christian Ehringfeld
EntityManager(QSqlDatabase database);
426974c6 Christian Ehringfeld
EntityManager(const QString &databaseType, QString databasename = "" , QString hostname = "", QString username = "",
QString password = "", QString port = "");
81c23b56 Christian Ehringfeld
~EntityManager();
static QStringList getConnectionNames();
static void removeConnectionName(const QString &name);
586bb527 Christian Ehringfeld
bool create(QSharedPointer<Entity> &entity);
bool save(QSharedPointer<Entity> &entity);
qint64 findId(QSharedPointer<Entity> &entity);
426974c6 Christian Ehringfeld
QList<QHash<QString, QVariant> > findAll(QString tblname);
QHash<QString, QVariant> find(qint64 id, QString tblname);
586bb527 Christian Ehringfeld
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,
426974c6 Christian Ehringfeld
bool ignoreID = false);
586bb527 Christian Ehringfeld
bool merge(QSharedPointer<Entity> &entity);
bool remove(QSharedPointer<Entity> &entity);
81c23b56 Christian Ehringfeld
bool removeAll(QString tblname);
586bb527 Christian Ehringfeld
bool createTable(QSharedPointer<Entity> &entity);
426974c6 Christian Ehringfeld
qint8 count(Entity *entity, bool ignoreID = true);
9d05e414 Christian Ehringfeld
QSharedPointer<Database> getDb() const;
void setDb(const QSharedPointer<Database> &value);
QSharedPointer<Schema> getSchema() const;
void setSchema(const QSharedPointer<Schema> &value);
586bb527 Christian Ehringfeld
81c23b56 Christian Ehringfeld
};
}
#endif // ENTITYMANAGER_H