![]() |
QxOrm
1.2.3
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** http://www.qxorm.com/ 00004 ** http://sourceforge.net/projects/qxorm/ 00005 ** Original file by Lionel Marty 00006 ** 00007 ** This file is part of the QxOrm library 00008 ** 00009 ** This software is provided 'as-is', without any express or implied 00010 ** warranty. In no event will the authors be held liable for any 00011 ** damages arising from the use of this software. 00012 ** 00013 ** GNU Lesser General Public License Usage 00014 ** This file must be used under the terms of the GNU Lesser 00015 ** General Public License version 2.1 as published by the Free Software 00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the 00017 ** packaging of this file. Please review the following information to 00018 ** ensure the GNU Lesser General Public License version 2.1 requirements 00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 00020 ** 00021 ** If you have questions regarding the use of this file, please contact : 00022 ** contact@qxorm.com 00023 ** 00024 ****************************************************************************/ 00025 00026 #ifndef _IX_SQL_RELATION_H_ 00027 #define _IX_SQL_RELATION_H_ 00028 00029 #ifdef _MSC_VER 00030 #pragma once 00031 #endif 00032 00040 #include <QxCommon/QxPropertyBag.h> 00041 00042 #include <QxDao/QxSqlRelationParams.h> 00043 #include <QxDao/QxSoftDelete.h> 00044 00045 #include <QxCollection/QxCollection.h> 00046 00047 #define QX_CONSTRUCT_IX_RELATION() \ 00048 m_pClass(NULL), m_pClassOwner(NULL), m_pDataMember(p), m_pDataMemberX(NULL), \ 00049 m_pDataMemberId(NULL), m_pDataMemberIdOwner(NULL), m_lOffsetRelation(100), \ 00050 m_eJoinType(left_outer_join), m_lstDataMemberPtr(NULL), m_lstSqlRelationPtr(NULL) 00051 00052 namespace qx { 00053 00054 class IxClass; 00055 class IxDataMember; 00056 class IxDataMemberX; 00057 class IxSqlRelation; 00058 00059 typedef QxCollection<QString, IxSqlRelation *> IxSqlRelationX; 00060 00065 class QX_DLL_EXPORT IxSqlRelation : public qx::QxPropertyBag 00066 { 00067 00068 public: 00069 00070 enum join_type { left_outer_join, inner_join }; 00071 00072 protected: 00073 00074 IxClass * m_pClass; 00075 IxClass * m_pClassOwner; 00076 IxDataMember * m_pDataMember; 00077 IxDataMemberX * m_pDataMemberX; 00078 IxDataMember * m_pDataMemberId; 00079 IxDataMember * m_pDataMemberIdOwner; 00080 long m_lOffsetRelation; 00081 join_type m_eJoinType; 00082 QxSoftDelete m_oSoftDelete; 00083 00084 QxCollection<QString, IxDataMember *> * m_lstDataMemberPtr; 00085 IxSqlRelationX * m_lstSqlRelationPtr; 00086 00087 public: 00088 00089 IxSqlRelation(IxDataMember * p) : qx::QxPropertyBag(), QX_CONSTRUCT_IX_RELATION() { qAssert(p); } 00090 virtual ~IxSqlRelation() = 0; 00091 00092 inline QxCollection<QString, IxDataMember *> * getLstDataMember() const { return m_lstDataMemberPtr; } 00093 inline IxSqlRelationX * getLstRelation() const { return m_lstSqlRelationPtr; } 00094 00095 inline void setSqlJoinType(join_type e) { m_eJoinType = e; } 00096 inline join_type getSqlJoinType() const { return m_eJoinType; } 00097 inline IxClass * getClass() const { return m_pClass; } 00098 inline IxClass * getClassOwner() const { return m_pClassOwner; } 00099 inline IxDataMember * getDataMember() const { return m_pDataMember; } 00100 inline IxDataMemberX * getDataMemberX() const { return m_pDataMemberX; } 00101 inline IxDataMember * getDataId() const { return m_pDataMemberId; } 00102 inline IxDataMember * getDataIdOwner() const { return m_pDataMemberIdOwner; } 00103 00104 QString getKey() const; 00105 long getDataCount() const; 00106 long getRelationCount() const; 00107 IxDataMember * getDataByKey(const QString & sKey) const; 00108 IxDataMember * nextData(long & lIndex) const; 00109 IxSqlRelation * nextRelation(long & lIndex) const; 00110 QString table() const; 00111 QString tableAlias(QxSqlRelationParams & params) const; 00112 QString getSqlJoin() const; 00113 00114 virtual void init() = 0; 00115 virtual QString getDescription() const = 0; 00116 virtual QString getExtraTable() const = 0; 00117 virtual QString createExtraTable() const = 0; 00118 virtual bool getCartesianProduct() const = 0; 00119 virtual QVariant getIdFromQuery(bool bEager, QxSqlRelationParams & params) const = 0; 00120 virtual void updateOffset(bool bEager, QxSqlRelationParams & params) const = 0; 00121 virtual void createTable(QxSqlRelationParams & params) const = 0; 00122 virtual void lazySelect(QxSqlRelationParams & params) const = 0; 00123 virtual void eagerSelect(QxSqlRelationParams & params) const = 0; 00124 virtual void lazyFrom(QxSqlRelationParams & params) const = 0; 00125 virtual void eagerFrom(QxSqlRelationParams & params) const = 0; 00126 virtual void lazyJoin(QxSqlRelationParams & params) const = 0; 00127 virtual void eagerJoin(QxSqlRelationParams & params) const = 0; 00128 virtual void lazyWhere(QxSqlRelationParams & params) const = 0; 00129 virtual void eagerWhere(QxSqlRelationParams & params) const = 0; 00130 virtual void lazyWhereSoftDelete(QxSqlRelationParams & params) const = 0; 00131 virtual void eagerWhereSoftDelete(QxSqlRelationParams & params) const = 0; 00132 virtual void lazyFetch_ResolveInput(QxSqlRelationParams & params) const = 0; 00133 virtual void eagerFetch_ResolveInput(QxSqlRelationParams & params) const = 0; 00134 virtual void lazyFetch_ResolveOutput(QxSqlRelationParams & params) const = 0; 00135 virtual void eagerFetch_ResolveOutput(QxSqlRelationParams & params) const = 0; 00136 virtual void lazyInsert(QxSqlRelationParams & params) const = 0; 00137 virtual void lazyInsert_Values(QxSqlRelationParams & params) const = 0; 00138 virtual void lazyUpdate(QxSqlRelationParams & params) const = 0; 00139 virtual void lazyInsert_ResolveInput(QxSqlRelationParams & params) const = 0; 00140 virtual void lazyUpdate_ResolveInput(QxSqlRelationParams & params) const = 0; 00141 virtual QSqlError onBeforeSave(QxSqlRelationParams & params) const = 0; 00142 virtual QSqlError onAfterSave(QxSqlRelationParams & params) const = 0; 00143 00144 #ifndef NDEBUG 00145 bool verifyOffset(QxSqlRelationParams & params, bool bId) const; 00146 #else 00147 inline bool verifyOffset(QxSqlRelationParams & params, bool bId) const { Q_UNUSED(params); Q_UNUSED(bId); return true; } 00148 #endif // NDEBUG 00149 00150 }; 00151 00152 } // namespace qx 00153 00154 #endif // _IX_SQL_RELATION_H_