QxOrm  1.5.0
C++ Object Relational Mapping library
QxSqlRelationParams.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 _QX_SQL_RELATION_PARAMS_H_
00033 #define _QX_SQL_RELATION_PARAMS_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00046 #include <QtSql/qsqldatabase.h>
00047 #include <QtSql/qsqlquery.h>
00048 
00049 #include <QxDao/QxSqlJoin.h>
00050 #include <QxDao/QxSqlSaveMode.h>
00051 
00052 #include <QxCollection/QxCollection.h>
00053 
00054 namespace qx {
00055 
00056 class QxSqlRelationLinked;
00057 class IxSqlQueryBuilder;
00058 class IxSqlRelation;
00059 
00064 class QX_DLL_EXPORT QxSqlRelationParams
00065 {
00066 
00067 public:
00068 
00069    typedef std::shared_ptr<QxSqlRelationLinked> type_relation_linked_ptr;
00070    typedef QHash<QString, type_relation_linked_ptr> type_lst_relation_linked;
00071 
00072 protected:
00073 
00074    QVariant                                     m_vId;                  
00075    long                                         m_lIndex;               
00076    long                                         m_lIndexOwner;          
00077    long                                         m_lOffset;              
00078    QString *                                    m_sql;                  
00079    IxSqlQueryBuilder *                          m_builder;              
00080    QSqlQuery *                                  m_query;                
00081    QSqlDatabase *                               m_database;             
00082    void *                                       m_pOwner;               
00083    qx::dao::sql_join::join_type                 m_eJoinType;            
00084    type_lst_relation_linked *                   m_pRelationX;           
00085    QString                                      m_sTableAlias;          
00086    qx::dao::save_mode::e_save_mode              m_eSaveMode;            
00087    bool                                         m_bRecursiveMode;       
00088    QSet<void *>                                 m_lstRecursiveItems;    
00089    QPair<QSet<QString>, long> *                 m_pColumns;             
00090    QString                                      m_sCustomAlias;         
00091    QString                                      m_sCustomAliasOwner;    
00092    qx::QxCollection<QString, QVariantList> *    m_pLstExecBatch;        
00093    bool                                         m_bIsDistinct;          
00094 
00095 public:
00096 
00097    QxSqlRelationParams();
00098    QxSqlRelationParams(long lIndex, long lOffset, QString * sql, IxSqlQueryBuilder * builder, QSqlQuery * query, void * pOwner, const QVariant & vId = QVariant(), qx::QxCollection<QString, QVariantList> * pLstExecBatch = NULL);
00099    virtual ~QxSqlRelationParams();
00100 
00101    inline QVariant id() const                                                 { return m_vId; }
00102    inline long index() const                                                  { return m_lIndex; }
00103    inline long indexOwner() const                                             { return m_lIndexOwner; }
00104    inline long offset() const                                                 { return m_lOffset; }
00105    inline QString & sql()                                                     { qAssert(m_sql); return (* m_sql); }
00106    inline const QString & sql() const                                         { qAssert(m_sql); return (* m_sql); }
00107    inline QSqlQuery & query()                                                 { qAssert(m_query); return (* m_query); }
00108    inline const QSqlQuery & query() const                                     { qAssert(m_query); return (* m_query); }
00109    inline QSqlDatabase & database()                                           { qAssert(m_database); return (* m_database); }
00110    inline const QSqlDatabase & database() const                               { qAssert(m_database); return (* m_database); }
00111    inline IxSqlQueryBuilder & builder()                                       { qAssert(m_builder); return (* m_builder); }
00112    inline const IxSqlQueryBuilder & builder() const                           { qAssert(m_builder); return (* m_builder); }
00113    inline void * owner() const                                                { return m_pOwner; }
00114    inline qx::dao::sql_join::join_type joinType() const                       { return m_eJoinType; }
00115    inline type_lst_relation_linked * relationX() const                        { return m_pRelationX; }
00116    inline QString getTableAlias() const                                       { return m_sTableAlias; }
00117    inline qx::dao::save_mode::e_save_mode saveMode() const                    { return m_eSaveMode; }
00118    inline bool recursiveMode() const                                          { return m_bRecursiveMode; }
00119    inline bool existRecursiveItem(void * p) const                             { return m_lstRecursiveItems.contains(p); }
00120    inline QSet<QString> getColumns() const                                    { return (m_pColumns ? m_pColumns->first : QSet<QString>()); }
00121    inline bool checkColumns(const QString & s) const                          { return (! m_pColumns || m_pColumns->first.isEmpty() || m_pColumns->first.contains(s)); }
00122    inline long getColumnsCount() const                                        { return (m_pColumns ? m_pColumns->first.count() : 0); }
00123    inline long getColumnsOffset() const                                       { return (m_pColumns ? m_pColumns->second : 0); }
00124    inline QString getCustomAlias() const                                      { return m_sCustomAlias; }
00125    inline QString getCustomAliasOwner() const                                 { return m_sCustomAliasOwner; }
00126    inline qx::QxCollection<QString, QVariantList> * getLstExecBatch() const   { return m_pLstExecBatch; }
00127    inline bool isDistinct() const                                             { return m_bIsDistinct; }
00128 
00129    inline void setId(const QVariant & vId)                                    { m_vId = vId; }
00130    inline void setIndex(long lIndex)                                          { m_lIndex = lIndex; }
00131    inline void setIndexOwner(long lIndex)                                     { m_lIndexOwner = lIndex; }
00132    inline void setOffset(long lOffset)                                        { m_lOffset = lOffset; }
00133    inline void setSql(QString * sql)                                          { m_sql = sql; }
00134    inline void setQuery(QSqlQuery * query)                                    { m_query = query; }
00135    inline void setDatabase(QSqlDatabase * database)                           { m_database = database; }
00136    inline void setOwner(void * pOwner)                                        { m_pOwner = pOwner; }
00137    inline void setJoinType(qx::dao::sql_join::join_type e)                    { m_eJoinType = e; }
00138    inline void setRelationX(type_lst_relation_linked * p)                     { m_pRelationX = p; }
00139    inline void setTableAlias(const QString & s)                               { m_sTableAlias = s; }
00140    inline void setSaveMode(qx::dao::save_mode::e_save_mode e)                 { m_eSaveMode = e; }
00141    inline void setRecursiveMode(bool b)                                       { m_bRecursiveMode = b; }
00142    inline void insertRecursiveItem(void * p)                                  { if (p) { m_lstRecursiveItems.insert(p); } }
00143    inline void setColumns(QPair<QSet<QString>, long> * p)                     { m_pColumns = p; }
00144    inline void setColumnsOffset(long l)                                       { if (m_pColumns) { m_pColumns->second = l; } }
00145    inline void setCustomAlias(const QString & s)                              { m_sCustomAlias = s; }
00146    inline void setCustomAliasOwner(const QString & s)                         { m_sCustomAliasOwner = s; }
00147    inline void setLstExecBatch(qx::QxCollection<QString, QVariantList> * p)   { m_pLstExecBatch = p; }
00148    void setBuilder(IxSqlQueryBuilder * builder);
00149 
00150 };
00151 
00152 } // namespace qx
00153 
00154 #endif // _QX_SQL_RELATION_PARAMS_H_