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