QxOrm
1.5.0
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** https://www.qxorm.com/ 00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com) 00005 ** 00006 ** This file is part of the QxOrm library 00007 ** 00008 ** This software is provided 'as-is', without any express or implied 00009 ** warranty. In no event will the authors be held liable for any 00010 ** damages arising from the use of this software 00011 ** 00012 ** Commercial Usage 00013 ** Licensees holding valid commercial QxOrm licenses may use this file in 00014 ** accordance with the commercial license agreement provided with the 00015 ** Software or, alternatively, in accordance with the terms contained in 00016 ** a written agreement between you and Lionel Marty 00017 ** 00018 ** GNU General Public License Usage 00019 ** Alternatively, this file may be used under the terms of the GNU 00020 ** General Public License version 3.0 as published by the Free Software 00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the 00022 ** packaging of this file. Please review the following information to 00023 ** ensure the GNU General Public License version 3.0 requirements will be 00024 ** met : http://www.gnu.org/copyleft/gpl.html 00025 ** 00026 ** If you are unsure which license is appropriate for your use, or 00027 ** if you have questions regarding the use of this file, please contact : 00028 ** contact@qxorm.com 00029 ** 00030 ****************************************************************************/ 00031 00032 #ifndef _IX_REPOSITORY_H_ 00033 #define _IX_REPOSITORY_H_ 00034 00035 #ifdef _MSC_VER 00036 #pragma once 00037 #endif 00038 00046 #include <QtSql/qsqldatabase.h> 00047 #include <QtSql/qsqlquery.h> 00048 #include <QtSql/qsqlerror.h> 00049 #include <QtSql/qsqldriver.h> 00050 00051 #include <QxCommon/QxBool.h> 00052 00053 #include <QxDao/QxSqlQuery.h> 00054 00055 #include <QxCollection/IxCollection.h> 00056 00057 namespace qx { 00058 00059 class IxClass; 00060 class QxSession; 00061 00073 class QX_DLL_EXPORT IxRepository 00074 { 00075 00076 protected: 00077 00078 bool m_bRegister; 00079 QString m_sKeyRepository; 00080 QSqlDatabase m_database; 00081 QxSession * m_pSession; 00082 00083 public: 00084 00085 IxRepository(bool bRegister, const QString & sKey); 00086 IxRepository(bool bRegister, const QString & sKey, const QSqlDatabase & database); 00087 IxRepository(bool bRegister, const QString & sKey, QxSession * pSession); 00088 virtual ~IxRepository(); 00089 00090 QSqlDatabase * database(); 00091 QxSession * session() const; 00092 00093 virtual long _count(const qx::QxSqlQuery & query = qx::QxSqlQuery()) = 0; 00094 virtual void * _fetchById(const QVariant & id, const QStringList & columns = QStringList(), const QStringList & relation = QStringList()) = 0; 00095 virtual QSqlError _fetchById(QObject * p, const QStringList & columns = QStringList(), const QStringList & relation = QStringList()) = 0; 00096 virtual QSqlError _fetchById(qx::IxCollection * p, const QStringList & columns = QStringList(), const QStringList & relation = QStringList()) = 0; 00097 virtual QSqlError _fetchAll(QObject * p, const QStringList & columns = QStringList(), const QStringList & relation = QStringList()) = 0; 00098 virtual QSqlError _fetchAll(qx::IxCollection * p, const QStringList & columns = QStringList(), const QStringList & relation = QStringList()) = 0; 00099 virtual QSqlError _fetchByQuery(const qx::QxSqlQuery & query, QObject * p, const QStringList & columns = QStringList(), const QStringList & relation = QStringList()) = 0; 00100 virtual QSqlError _fetchByQuery(const qx::QxSqlQuery & query, qx::IxCollection * p, const QStringList & columns = QStringList(), const QStringList & relation = QStringList()) = 0; 00101 virtual QSqlError _insert(QObject * p, const QStringList & relation = QStringList()) = 0; 00102 virtual QSqlError _insert(qx::IxCollection * p, const QStringList & relation = QStringList()) = 0; 00103 virtual QSqlError _update(QObject * p, const qx::QxSqlQuery & query = qx::QxSqlQuery(), const QStringList & columns = QStringList(), const QStringList & relation = QStringList()) = 0; 00104 virtual QSqlError _update(qx::IxCollection * p, const qx::QxSqlQuery & query = qx::QxSqlQuery(), const QStringList & columns = QStringList(), const QStringList & relation = QStringList()) = 0; 00105 virtual QSqlError _save(QObject * p, const QStringList & relation = QStringList()) = 0; 00106 virtual QSqlError _save(qx::IxCollection * p, const QStringList & relation = QStringList()) = 0; 00107 virtual QSqlError _deleteById(const QVariant & id) = 0; 00108 virtual QSqlError _deleteById(QObject * p) = 0; 00109 virtual QSqlError _deleteById(qx::IxCollection * p) = 0; 00110 virtual QSqlError _deleteAll() = 0; 00111 virtual QSqlError _deleteByQuery(const qx::QxSqlQuery & query) = 0; 00112 virtual QSqlError _destroyById(const QVariant & id) = 0; 00113 virtual QSqlError _destroyById(QObject * p) = 0; 00114 virtual QSqlError _destroyById(qx::IxCollection * p) = 0; 00115 virtual QSqlError _destroyAll() = 0; 00116 virtual QSqlError _destroyByQuery(const qx::QxSqlQuery & query) = 0; 00117 virtual qx_bool _exist(QObject * p) = 0; 00118 virtual qx_bool _exist(qx::IxCollection * p) = 0; 00119 virtual qx::IxCollection_ptr _newCollection() const = 0; 00120 virtual qx::IxClass * _getClass() const = 0; 00121 00122 public: 00123 00124 static qx::IxCollection_ptr _fetchAll(const QString & repositoryKey, const QStringList & columns = QStringList(), const QStringList & relation = QStringList()); 00125 static qx::IxCollection_ptr _fetchByQuery(const QString & repositoryKey, const qx::QxSqlQuery & query, const QStringList & columns = QStringList(), const QStringList & relation = QStringList()); 00126 00127 }; 00128 00129 } // namespace qx 00130 00131 #endif // _IX_REPOSITORY_H_