![]() |
QxOrm
1.2.5
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** http://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_SQL_RELATION_H_ 00033 #define _IX_SQL_RELATION_H_ 00034 00035 #ifdef _MSC_VER 00036 #pragma once 00037 #endif 00038 00046 #include <QxCommon/QxPropertyBag.h> 00047 00048 #include <QxDao/QxSqlRelationParams.h> 00049 #include <QxDao/QxSoftDelete.h> 00050 #include <QxDao/QxSqlJoin.h> 00051 00052 #include <QxCollection/QxCollection.h> 00053 00054 #define QX_CONSTRUCT_IX_RELATION() \ 00055 m_pClass(NULL), m_pClassOwner(NULL), m_pDataMember(p), m_pDataMemberX(NULL), \ 00056 m_pDataMemberId(NULL), m_pDataMemberIdOwner(NULL), m_lOffsetRelation(100), \ 00057 m_eJoinType(qx::dao::sql_join::left_outer_join), m_eRelationType(no_relation), \ 00058 m_lstDataMemberPtr(NULL), m_lstSqlRelationPtr(NULL) 00059 00060 namespace qx { 00061 00062 class IxClass; 00063 class IxDataMember; 00064 class IxDataMemberX; 00065 class IxSqlRelation; 00066 00067 typedef QxCollection<QString, IxSqlRelation *> IxSqlRelationX; 00068 00073 class QX_DLL_EXPORT IxSqlRelation : public qx::QxPropertyBag 00074 { 00075 00076 public: 00077 00078 enum relation_type { no_relation, one_to_one, one_to_many, many_to_one, many_to_many }; 00079 00080 protected: 00081 00082 IxClass * m_pClass; 00083 IxClass * m_pClassOwner; 00084 IxDataMember * m_pDataMember; 00085 IxDataMemberX * m_pDataMemberX; 00086 IxDataMember * m_pDataMemberId; 00087 IxDataMember * m_pDataMemberIdOwner; 00088 long m_lOffsetRelation; 00089 qx::dao::sql_join::join_type m_eJoinType; 00090 relation_type m_eRelationType; 00091 QxSoftDelete m_oSoftDelete; 00092 00093 QxCollection<QString, IxDataMember *> * m_lstDataMemberPtr; 00094 IxSqlRelationX * m_lstSqlRelationPtr; 00095 00096 public: 00097 00098 IxSqlRelation(IxDataMember * p) : qx::QxPropertyBag(), QX_CONSTRUCT_IX_RELATION() { ; } 00099 virtual ~IxSqlRelation() = 0; 00100 00101 inline QxCollection<QString, IxDataMember *> * getLstDataMember() const { return m_lstDataMemberPtr; } 00102 inline IxSqlRelationX * getLstRelation() const { return m_lstSqlRelationPtr; } 00103 00104 inline void setSqlJoinType(qx::dao::sql_join::join_type e) { m_eJoinType = e; } 00105 inline qx::dao::sql_join::join_type getSqlJoinType() const { return m_eJoinType; } 00106 inline relation_type getRelationType() const { return m_eRelationType; } 00107 inline IxClass * getClass() const { return m_pClass; } 00108 inline IxClass * getClassOwner() const { return m_pClassOwner; } 00109 inline IxDataMember * getDataMember() const { return m_pDataMember; } 00110 inline IxDataMemberX * getDataMemberX() const { return m_pDataMemberX; } 00111 inline IxDataMember * getDataId() const { return m_pDataMemberId; } 00112 inline IxDataMember * getDataIdOwner() const { return m_pDataMemberIdOwner; } 00113 00114 QString getKey() const; 00115 long getDataCount() const; 00116 long getRelationCount() const; 00117 IxDataMember * getDataByKey(const QString & sKey) const; 00118 IxDataMember * nextData(long & lIndex) const; 00119 IxSqlRelation * nextRelation(long & lIndex) const; 00120 QString table() const; 00121 QString tableAlias(QxSqlRelationParams & params) const; 00122 QString tableAliasOwner(QxSqlRelationParams & params) const; 00123 QString getSqlJoin(qx::dao::sql_join::join_type e = qx::dao::sql_join::no_join) const; 00124 bool traceSqlQuery() const; 00125 00126 virtual void init() = 0; 00127 virtual QString getDescription() const = 0; 00128 virtual QString getExtraTable() const = 0; 00129 virtual QString createExtraTable() const = 0; 00130 virtual bool getCartesianProduct() const = 0; 00131 virtual QVariant getIdFromQuery(bool bEager, QxSqlRelationParams & params) const = 0; 00132 virtual void updateOffset(bool bEager, QxSqlRelationParams & params) const = 0; 00133 virtual void createTable(QxSqlRelationParams & params) const = 0; 00134 virtual void lazySelect(QxSqlRelationParams & params) const = 0; 00135 virtual void eagerSelect(QxSqlRelationParams & params) const = 0; 00136 virtual void lazyFrom(QxSqlRelationParams & params) const = 0; 00137 virtual void eagerFrom(QxSqlRelationParams & params) const = 0; 00138 virtual void lazyJoin(QxSqlRelationParams & params) const = 0; 00139 virtual void eagerJoin(QxSqlRelationParams & params) const = 0; 00140 virtual void lazyWhere(QxSqlRelationParams & params) const = 0; 00141 virtual void eagerWhere(QxSqlRelationParams & params) const = 0; 00142 virtual void lazyWhereSoftDelete(QxSqlRelationParams & params) const = 0; 00143 virtual void eagerWhereSoftDelete(QxSqlRelationParams & params) const = 0; 00144 virtual void lazyFetch_ResolveInput(QxSqlRelationParams & params) const = 0; 00145 virtual void eagerFetch_ResolveInput(QxSqlRelationParams & params) const = 0; 00146 virtual void lazyFetch_ResolveOutput(QxSqlRelationParams & params) const = 0; 00147 virtual void * eagerFetch_ResolveOutput(QxSqlRelationParams & params) const = 0; 00148 virtual void lazyInsert(QxSqlRelationParams & params) const = 0; 00149 virtual void lazyInsert_Values(QxSqlRelationParams & params) const = 0; 00150 virtual void lazyUpdate(QxSqlRelationParams & params) const = 0; 00151 virtual void lazyInsert_ResolveInput(QxSqlRelationParams & params) const = 0; 00152 virtual void lazyUpdate_ResolveInput(QxSqlRelationParams & params) const = 0; 00153 virtual QSqlError onBeforeSave(QxSqlRelationParams & params) const = 0; 00154 virtual QSqlError onAfterSave(QxSqlRelationParams & params) const = 0; 00155 00156 #ifndef NDEBUG 00157 bool verifyOffset(QxSqlRelationParams & params, bool bId) const; 00158 #else 00159 inline bool verifyOffset(QxSqlRelationParams & params, bool bId) const { Q_UNUSED(params); Q_UNUSED(bId); return true; } 00160 #endif // NDEBUG 00161 00162 }; 00163 00164 } // namespace qx 00165 00166 #endif // _IX_SQL_RELATION_H_