| QxOrm 1.5.0 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 ** 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_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 namespace qx {
    00055
    00056 class IxClass;
    00057 class IxDataMember;
    00058 class IxDataMemberX;
    00059 class IxSqlRelation;
    00060
    00061 typedef QxCollection<QString, IxSqlRelation *> IxSqlRelationX;
    00062 typedef std::shared_ptr<IxSqlRelationX> IxSqlRelationX_ptr;
    00063
    00068 class QX_DLL_EXPORT IxSqlRelation : public qx::QxPropertyBag
    00069 {
    00070
    00071 private:
    00072
    00073    struct IxSqlRelationImpl;
    00074    std::unique_ptr<IxSqlRelationImpl> m_pImpl;
    00075
    00076 public:
    00077
    00078    enum relation_type { no_relation, one_to_one, one_to_many, many_to_one, many_to_many };
    00079
    00080    IxSqlRelation(IxDataMember * p);
    00081    virtual ~IxSqlRelation() = 0;
    00082
    00083    QxCollection<QString, IxDataMember *> * getLstDataMember() const;
    00084    IxSqlRelationX * getLstRelation() const;
    00085
    00086    void setSqlJoinType(qx::dao::sql_join::join_type e);
    00087    qx::dao::sql_join::join_type getSqlJoinType() const;
    00088    relation_type getRelationType() const;
    00089    IxClass * getClass() const;
    00090    IxClass * getClassOwner() const;
    00091    IxDataMember * getDataMember() const;
    00092    IxDataMemberX * getDataMemberX() const;
    00093    IxDataMember * getDataId() const;
    00094    IxDataMember * getDataIdOwner() const;
    00095
    00096    void linkRelationKeyTo(IxDataMember * p);
    00097    IxDataMember * getLinkRelationKey() const;
    00098
    00099    QString getKey() const;
    00100    QString getForeignKey() const;
    00101    QString getForeignKeyOwner() const;
    00102    QString getForeignKeyDataType() const;
    00103    QString getExtraTable() const;
    00104    long getDataCount() const;
    00105    long getRelationCount() const;
    00106    IxDataMember * getDataByKey(const QString & sKey) const;
    00107    IxDataMember * nextData(long & lIndex) const;
    00108    IxSqlRelation * nextRelation(long & lIndex) const;
    00109    QString table() const;
    00110    QString tableAlias(QxSqlRelationParams & params) const;
    00111    QString tableAliasOwner(QxSqlRelationParams & params) const;
    00112    QString getSqlJoin(qx::dao::sql_join::join_type e = qx::dao::sql_join::no_join) const;
    00113    bool traceSqlQuery() const;
    00114
    00115    virtual void init();
    00116    virtual QString getDescription() const = 0;
    00117    virtual QString createExtraTable() const = 0;
    00118    virtual bool getCartesianProduct() const = 0;
    00119    virtual QVariant getIdFromQuery(bool bEager, QxSqlRelationParams & params, int iOffset, int iNameIndex) 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    bool verifyOffset(QxSqlRelationParams & params, bool bId) const QX_USED;
    00145
    00146    static void setTraceRelationInit(bool bTrace);
    00147
    00148 protected:
    00149
    00150    QVariant getIdFromQuery_ManyToMany(bool bEager, QxSqlRelationParams & params, int iOffset, int iNameIndex) const;
    00151    QVariant getIdFromQuery_ManyToOne(bool bEager, QxSqlRelationParams & params, int iOffset, int iNameIndex) const;
    00152    QVariant getIdFromQuery_OneToMany(bool bEager, QxSqlRelationParams & params, int iOffset, int iNameIndex) const;
    00153    QVariant getIdFromQuery_OneToOne(bool bEager, QxSqlRelationParams & params, int iOffset, int iNameIndex) const;
    00154
    00155    void updateOffset_ManyToMany(bool bEager, QxSqlRelationParams & params) const;
    00156    void updateOffset_ManyToOne(bool bEager, QxSqlRelationParams & params) const;
    00157    void updateOffset_OneToMany(bool bEager, QxSqlRelationParams & params) const;
    00158    void updateOffset_OneToOne(bool bEager, QxSqlRelationParams & params) const;
    00159
    00160    void eagerSelect_ManyToMany(QxSqlRelationParams & params) const;
    00161    void eagerSelect_ManyToOne(QxSqlRelationParams & params) const;
    00162    void eagerSelect_OneToMany(QxSqlRelationParams & params) const;
    00163    void eagerSelect_OneToOne(QxSqlRelationParams & params) const;
    00164
    00165    void eagerJoin_ManyToMany(QxSqlRelationParams & params) const;
    00166    void eagerJoin_ManyToOne(QxSqlRelationParams & params) const;
    00167    void eagerJoin_OneToMany(QxSqlRelationParams & params) const;
    00168    void eagerJoin_OneToOne(QxSqlRelationParams & params) const;
    00169
    00170    void eagerWhereSoftDelete_ManyToMany(QxSqlRelationParams & params) const;
    00171    void eagerWhereSoftDelete_ManyToOne(QxSqlRelationParams & params) const;
    00172    void eagerWhereSoftDelete_OneToMany(QxSqlRelationParams & params) const;
    00173    void eagerWhereSoftDelete_OneToOne(QxSqlRelationParams & params) const;
    00174
    00175    void lazySelect_ManyToOne(QxSqlRelationParams & params) const;
    00176    void lazyInsert_ManyToOne(QxSqlRelationParams & params) const;
    00177    void lazyInsert_Values_ManyToOne(QxSqlRelationParams & params) const;
    00178    void lazyUpdate_ManyToOne(QxSqlRelationParams & params) const;
    00179
    00180    void createTable_ManyToOne(QxSqlRelationParams & params) const;
    00181    QSqlError deleteFromExtraTable_ManyToMany(QxSqlRelationParams & params) const;
    00182    QString createExtraTable_ManyToMany() const;
    00183
    00184    bool addLazyRelation(QxSqlRelationParams & params, IxSqlRelation * pRelation) const;
    00185
    00186    bool canInit() const;
    00187    void setIsSameDataOwner(int i);
    00188    void setClass(IxClass * pClass, IxClass * pClassOwner);
    00189    void setRelationType(relation_type e);
    00190    void setForeignKey(const QString & s) const;
    00191    void setForeignKeyOwner(const QString & s) const;
    00192    void setForeignKeyDataType(const QString & s) const;
    00193    void setExtraTable(const QString & s) const;
    00194
    00195 };
    00196
    00197 } // namespace qx
    00198
    00199 #endif // _IX_SQL_RELATION_H_