QxOrm  1.3.2
C++ Object Relational Mapping library
IxSqlElement.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_ELEMENT_H_
00033 #define _IX_SQL_ELEMENT_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00046 #include <boost/serialization/serialization.hpp>
00047 #include <boost/serialization/split_free.hpp>
00048 #include <boost/serialization/version.hpp>
00049 #include <boost/serialization/nvp.hpp>
00050 
00051 #include <QtSql/qsqlquery.h>
00052 
00053 #include <QxDao/QxSqlGenerator/IxSqlGenerator.h>
00054 
00055 #include <QxSerialize/Qt/QxSerialize_QList.h>
00056 #include <QxSerialize/Qt/QxSerialize_QStringList.h>
00057 #include <QxSerialize/Qt/QxSerialize_QVariant.h>
00058 
00059 namespace qx {
00060 namespace dao {
00061 namespace detail {
00062 
00067 class QX_DLL_EXPORT IxSqlElement
00068 {
00069 
00070 public:
00071 
00072    enum type_class { _no_type, _sql_compare, _sql_element_temp, _sql_expression, _sql_free_text, 
00073                      _sql_in, _sql_is_between, _sql_is_null, _sql_limit, _sql_sort };
00074 
00075 protected:
00076 
00077    int               m_iIndex;            
00078    QStringList       m_lstColumns;        
00079    QStringList       m_lstKeys;           
00080    QList<QVariant>   m_lstValues;         
00081    IxSqlGenerator *  m_pSqlGenerator;     
00082 
00083 public:
00084 
00085    IxSqlElement(int index);
00086    virtual ~IxSqlElement();
00087 
00088    void setColumn(const QString & column);
00089    void setColumns(const QStringList & columns);
00090    void setValue(const QVariant & val);
00091    void setValues(const QVariantList & values);
00092 
00093    virtual IxSqlElement::type_class getTypeClass() const = 0;
00094 
00095    virtual QString toString() const = 0;
00096    virtual void resolve(QSqlQuery & query) const = 0;
00097    virtual void postProcess(QString & sql) const = 0;
00098 
00099    virtual void clone(IxSqlElement * other);
00100 
00101    template <class Archive>
00102    void qxSave(Archive & ar) const
00103    {
00104       QString sExtraSettings = getExtraSettings();
00105       ar << boost::serialization::make_nvp("index", m_iIndex);
00106       ar << boost::serialization::make_nvp("list_columns", m_lstColumns);
00107       ar << boost::serialization::make_nvp("list_keys", m_lstKeys);
00108       ar << boost::serialization::make_nvp("list_values", m_lstValues);
00109       ar << boost::serialization::make_nvp("extra_settings", sExtraSettings);
00110    }
00111 
00112    template <class Archive>
00113    void qxLoad(Archive & ar)
00114    {
00115       QString sExtraSettings;
00116       ar >> boost::serialization::make_nvp("index", m_iIndex);
00117       ar >> boost::serialization::make_nvp("list_columns", m_lstColumns);
00118       ar >> boost::serialization::make_nvp("list_keys", m_lstKeys);
00119       ar >> boost::serialization::make_nvp("list_values", m_lstValues);
00120       ar >> boost::serialization::make_nvp("extra_settings", sExtraSettings);
00121       setExtraSettings(sExtraSettings);
00122    }
00123 
00124 protected:
00125 
00126    void updateKeys();
00127 
00128    virtual QString getExtraSettings() const = 0;
00129    virtual void setExtraSettings(const QString & s) = 0;
00130 
00131 };
00132 
00133 typedef boost::shared_ptr<IxSqlElement> IxSqlElement_ptr;
00134 
00135 } // namespace detail
00136 } // namespace dao
00137 } // namespace qx
00138 
00139 #endif // _IX_SQL_ELEMENT_H_