| QxOrm 1.4.1 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

IxSqlRelation.h
Go to the documentation of this file.

    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    QString                          m_sForeignKey;
    00093    QString                          m_sExtraTable;
    00094    QString                          m_sForeignKeyOwner;
    00095    QString                          m_sForeignKeyDataType;
    00096
    00097    QxCollection<QString, IxDataMember *> * m_lstDataMemberPtr;
    00098    IxSqlRelationX * m_lstSqlRelationPtr;
    00099
    00100 public:
    00101
    00102    IxSqlRelation(IxDataMember * p) : qx::QxPropertyBag(), QX_CONSTRUCT_IX_RELATION() { ; }
    00103    virtual ~IxSqlRelation() = 0;
    00104
    00105    inline QxCollection<QString, IxDataMember *> * getLstDataMember() const { return m_lstDataMemberPtr; }
    00106    inline IxSqlRelationX * getLstRelation() const                          { return m_lstSqlRelationPtr; }
    00107
    00108    inline void setSqlJoinType(qx::dao::sql_join::join_type e)     { m_eJoinType = e; }
    00109    inline qx::dao::sql_join::join_type getSqlJoinType() const     { return m_eJoinType; }
    00110    inline relation_type getRelationType() const                   { return m_eRelationType; }
    00111    inline IxClass * getClass() const                              { return m_pClass; }
    00112    inline IxClass * getClassOwner() const                         { return m_pClassOwner; }
    00113    inline IxDataMember * getDataMember() const                    { return m_pDataMember; }
    00114    inline IxDataMemberX * getDataMemberX() const                  { return m_pDataMemberX; }
    00115    inline IxDataMember * getDataId() const                        { return m_pDataMemberId; }
    00116    inline IxDataMember * getDataIdOwner() const                   { return m_pDataMemberIdOwner; }
    00117
    00118    QString getKey() const;
    00119    long getDataCount() const;
    00120    long getRelationCount() const;
    00121    IxDataMember * getDataByKey(const QString & sKey) const;
    00122    IxDataMember * nextData(long & lIndex) const;
    00123    IxSqlRelation * nextRelation(long & lIndex) const;
    00124    QString table() const;
    00125    QString tableAlias(QxSqlRelationParams & params) const;
    00126    QString tableAliasOwner(QxSqlRelationParams & params) const;
    00127    QString getSqlJoin(qx::dao::sql_join::join_type e = qx::dao::sql_join::no_join) const;
    00128    bool traceSqlQuery() const;
    00129
    00130    virtual void init() = 0;
    00131    virtual QString getDescription() const = 0;
    00132    virtual QString getExtraTable() const = 0;
    00133    virtual QString createExtraTable() const = 0;
    00134    virtual bool getCartesianProduct() const = 0;
    00135    virtual QVariant getIdFromQuery(bool bEager, QxSqlRelationParams & params) const = 0;
    00136    virtual void updateOffset(bool bEager, QxSqlRelationParams & params) const = 0;
    00137    virtual void createTable(QxSqlRelationParams & params) const = 0;
    00138    virtual void lazySelect(QxSqlRelationParams & params) const = 0;
    00139    virtual void eagerSelect(QxSqlRelationParams & params) const = 0;
    00140    virtual void lazyFrom(QxSqlRelationParams & params) const = 0;
    00141    virtual void eagerFrom(QxSqlRelationParams & params) const = 0;
    00142    virtual void lazyJoin(QxSqlRelationParams & params) const = 0;
    00143    virtual void eagerJoin(QxSqlRelationParams & params) const = 0;
    00144    virtual void lazyWhere(QxSqlRelationParams & params) const = 0;
    00145    virtual void eagerWhere(QxSqlRelationParams & params) const = 0;
    00146    virtual void lazyWhereSoftDelete(QxSqlRelationParams & params) const = 0;
    00147    virtual void eagerWhereSoftDelete(QxSqlRelationParams & params) const = 0;
    00148    virtual void lazyFetch_ResolveInput(QxSqlRelationParams & params) const = 0;
    00149    virtual void eagerFetch_ResolveInput(QxSqlRelationParams & params) const = 0;
    00150    virtual void lazyFetch_ResolveOutput(QxSqlRelationParams & params) const = 0;
    00151    virtual void * eagerFetch_ResolveOutput(QxSqlRelationParams & params) const = 0;
    00152    virtual void lazyInsert(QxSqlRelationParams & params) const = 0;
    00153    virtual void lazyInsert_Values(QxSqlRelationParams & params) const = 0;
    00154    virtual void lazyUpdate(QxSqlRelationParams & params) const = 0;
    00155    virtual void lazyInsert_ResolveInput(QxSqlRelationParams & params) const = 0;
    00156    virtual void lazyUpdate_ResolveInput(QxSqlRelationParams & params) const = 0;
    00157    virtual QSqlError onBeforeSave(QxSqlRelationParams & params) const = 0;
    00158    virtual QSqlError onAfterSave(QxSqlRelationParams & params) const = 0;
    00159
    00160    bool verifyOffset(QxSqlRelationParams & params, bool bId) const BOOST_USED;
    00161
    00162 protected:
    00163
    00164    QVariant getIdFromQuery_ManyToMany(bool bEager, QxSqlRelationParams & params) const;
    00165    QVariant getIdFromQuery_ManyToOne(bool bEager, QxSqlRelationParams & params) const;
    00166    QVariant getIdFromQuery_OneToMany(bool bEager, QxSqlRelationParams & params) const;
    00167    QVariant getIdFromQuery_OneToOne(bool bEager, QxSqlRelationParams & params) const;
    00168
    00169    void updateOffset_ManyToMany(bool bEager, QxSqlRelationParams & params) const;
    00170    void updateOffset_ManyToOne(bool bEager, QxSqlRelationParams & params) const;
    00171    void updateOffset_OneToMany(bool bEager, QxSqlRelationParams & params) const;
    00172    void updateOffset_OneToOne(bool bEager, QxSqlRelationParams & params) const;
    00173
    00174    void eagerSelect_ManyToMany(QxSqlRelationParams & params) const;
    00175    void eagerSelect_ManyToOne(QxSqlRelationParams & params) const;
    00176    void eagerSelect_OneToMany(QxSqlRelationParams & params) const;
    00177    void eagerSelect_OneToOne(QxSqlRelationParams & params) const;
    00178
    00179    void eagerJoin_ManyToMany(QxSqlRelationParams & params) const;
    00180    void eagerJoin_ManyToOne(QxSqlRelationParams & params) const;
    00181    void eagerJoin_OneToMany(QxSqlRelationParams & params) const;
    00182    void eagerJoin_OneToOne(QxSqlRelationParams & params) const;
    00183
    00184    void eagerWhereSoftDelete_ManyToMany(QxSqlRelationParams & params) const;
    00185    void eagerWhereSoftDelete_ManyToOne(QxSqlRelationParams & params) const;
    00186    void eagerWhereSoftDelete_OneToMany(QxSqlRelationParams & params) const;
    00187    void eagerWhereSoftDelete_OneToOne(QxSqlRelationParams & params) const;
    00188
    00189    void lazySelect_ManyToOne(QxSqlRelationParams & params) const;
    00190    void lazyInsert_ManyToOne(QxSqlRelationParams & params) const;
    00191    void lazyInsert_Values_ManyToOne(QxSqlRelationParams & params) const;
    00192    void lazyUpdate_ManyToOne(QxSqlRelationParams & params) const;
    00193
    00194    void createTable_ManyToOne(QxSqlRelationParams & params) const;
    00195    QSqlError deleteFromExtraTable_ManyToMany(QxSqlRelationParams & params) const;
    00196    QString createExtraTable_ManyToMany() const;
    00197
    00198    bool addLazyRelation(QxSqlRelationParams & params, IxSqlRelation * pRelation) const;
    00199
    00200 };
    00201
    00202 } // namespace qx
    00203
    00204 #endif // _IX_SQL_RELATION_H_