first commit

This commit is contained in:
bing
2026-04-03 11:32:07 +08:00
commit 003be19522
1142 changed files with 185854 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_COLLECTION_H_
#define _IX_COLLECTION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxCollection.h
* \author XDL Team
* \ingroup QxCollection
* \brief Common interface for all QxOrm containers qx::QxCollection<Key, Value>
*/
#include <QxTraits/get_class_name.h>
#include <QxCommon/QxAnyCastDynamic.h>
namespace qx
{
/*!
* \ingroup QxCollection
* \brief qx::IxCollection : common interface for all QxOrm containers qx::QxCollection<Key, Value>
*/
class QX_DLL_EXPORT IxCollection
{
public:
IxCollection() { ; }
virtual ~IxCollection() = 0;
virtual long _count() const = 0;
virtual void _clear() = 0;
virtual bool _remove(long index) = 0;
virtual qx::any _at(long index) const = 0;
template <typename T>
T _get(long index) const
{
return qx::any_cast_dynamic<T>::get(_at(index));
}
};
typedef std::shared_ptr<qx::IxCollection> IxCollection_ptr;
} // namespace qx
QX_REGISTER_CLASS_NAME(IxCollection)
#endif // _IX_COLLECTION_H_

View File

@@ -0,0 +1,285 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_COLLECTION_H_
#define _QX_COLLECTION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxCollection.h
* \author XDL Team
* \ingroup QxCollection
* \brief QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
*/
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#pragma warning(disable : 4503)
#endif // _MSC_VER
#include <QtCore/qmutex.h>
#include <QxCollection/IxCollection.h>
#include <QxCollection/QxForeach.h>
#include <QxCommon/QxHashValue.h>
#include <QxTraits/get_class_name.h>
#include <QxTraits/is_smart_ptr.h>
namespace qx
{
/*!
* \ingroup QxCollection
* \brief qx::QxCollection<Key, Value> : QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
*
* Based on boost::multi_index_container, this collection has advantages of std::vector<T> (keep insertion order + quick access by index)
* and boost::unordered_map<Key, Value> or QHash<Key, Value> (quick access by key : hash-map).
*
* <i>Note :</i> qx::QxCollection<Key, Value> is compatible with the foreach macro provided by Qt library and the BOOST_FOREACH macro provided by boost library.
* However, each element returned by these 2 macros corresponds to an object of type std::pair<Key, Value>.
* To obtain a more natural and more readable result, it is advised to use the _foreach macro : this macro uses BOOST_FOREACH for all the containers except for qx::QxCollection<Key, Value>.
* In this case, the returned element corresponds to the Value type (cf. following sample).
* The macro _foreach is compatible with all containers (stl, Qt, boost...) since it uses the macro BOOST_FOREACH.
*
* <i>Additional note :</i> qx::QxCollection<Key, Value> is particularly suited to receive data resulting from a database.
* Indeed, these data can be sorted (by using ORDER BY in a SQL request for example), it is thus important to preserve the insertion order of the elements in the list.
* Furthermore, each data resulting from a database has a unique id. It is thus important to be able to access quickly to an element based on this single identifier (hash-map).
*
* Quick sample using qx::QxCollection<Key, Value> container :
* \code
// definition of drug class with 3 properties : 'code', 'name' and 'description'
class drug { public: QString code; QString name; QString desc; };
// typedef a smart-pointer of drug class
typedef std::shared_ptr<drug> drug_ptr;
// collection of drugs indexed by 'code' property (QString type)
qx::QxCollection<QString, drug_ptr> lstDrugs;
// create 3 new drugs
drug_ptr d1; d1.reset(new drug()); d1->code = "code1"; d1->name = "name1"; d1->desc = "desc1";
drug_ptr d2; d2.reset(new drug()); d2->code = "code2"; d2->name = "name2"; d2->desc = "desc2";
drug_ptr d3; d3.reset(new drug()); d3->code = "code3"; d3->name = "name3"; d3->desc = "desc3";
// insert 3 drugs into the collection
lstDrugs.insert(d1->code, d1);
lstDrugs.insert(d2->code, d2);
lstDrugs.insert(d3->code, d3);
// iterate over drugs container using QxOrm '_foreach' keyword
_foreach(drug_ptr p, lstDrugs)
{ qDebug() << qPrintable(p->name) << " " << qPrintable(p->desc); }
// iterate over drugs container using classic C++ 'for' keyword
for (long l = 0; l < lstDrugs.count(); ++l)
{
drug_ptr p = lstDrugs.getByIndex(l);
QString code = lstDrugs.getKeyByIndex(l);
qDebug() << qPrintable(p->name) << " " << qPrintable(p->desc);
}
// iterate over drugs container using 'qx::QxCollectionIterator' Java-style iterator
qx::QxCollectionIterator<QString, drug_ptr> itr(lstDrugs);
while (itr.next())
{
QString code = itr.key();
qDebug() << qPrintable(itr.value()->name) << " " << qPrintable(itr.value()->desc);
}
// sort drugs container ascending by key and sort descending by value
lstDrugs.sortByKey(true);
lstDrugs.sortByValue(false);
// access to a drug into the collection by its 'code' property
drug_ptr p = lstDrugs.getByKey("code2");
// access to a drug into the collection by index (position in the list)
drug_ptr p = lstDrugs.getByIndex(2);
// test if a drug exists into the collection and if the collection is empty
bool bExist = lstDrugs.exist("code3");
bool bEmpty = lstDrugs.empty();
// remove the second drug from the collection
lstDrugs.removeByIndex(2);
// remove a drug from the collection using its 'code' property
lstDrugs.removeByKey("code3");
// clear the collection : remove all items from the list
lstDrugs.clear();
* \endcode
*/
template <typename Key, typename Value>
class QxCollection : public IxCollection
{
public:
typedef QPair<Key, Value> type_pair_key_value;
protected:
typedef QList<type_pair_key_value> type_list_pair_key_value;
typedef QHash<Key, long> type_hash_position;
public:
typedef typename type_list_pair_key_value::iterator iterator;
typedef typename type_list_pair_key_value::const_iterator const_iterator;
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
typedef typename type_list_pair_key_value::reverse_iterator reverse_iterator;
typedef typename type_list_pair_key_value::const_reverse_iterator const_reverse_iterator;
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
typedef const Key &const_reference_key;
typedef const Value &const_reference_value;
protected:
mutable QMutex m_mutex; //!< Mutex => qx::QxCollection is thread-safe
type_list_pair_key_value m_list; //!< Container to keep insertion order
type_hash_position m_hash; //!< Container for fast search by key
bool m_batch; //!< Batch mode to sync internal containers
public:
QxCollection(); //!< Construct an empty list
QxCollection(const QxCollection<Key, Value> &other); //!< Construct a copy of 'other'
virtual ~QxCollection(); //!< Destroy the list
QxCollection<Key, Value> &operator=(const QxCollection<Key, Value> &other); //!< Assign 'other' to this list and return a reference to this list
bool operator==(const QxCollection<Key, Value> &other) const; //!< Return 'true' if 'other' is equal to this list, otherwise return 'false' (same values in the same order)
bool operator!=(const QxCollection<Key, Value> &other) const; //!< Return 'true' if 'other' is not equal to this list, otherwise return 'false'
iterator begin(); //!< Return an STL-style iterator pointing to the first item in the list
iterator end(); //!< Return an STL-style iterator pointing to the imaginary item after the last item in the list
const_iterator begin() const; //!< Return a const STL-style iterator pointing to the first item in the list
const_iterator end() const; //!< Return a const STL-style iterator pointing to the imaginary item after the last item in the list
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
reverse_iterator rbegin(); //!< Return a reverse STL-style iterator pointing to the first item in the list
reverse_iterator rend(); //!< Return a reverse STL-style iterator pointing to the imaginary item after the last item in the list
const_reverse_iterator rbegin() const; //!< Return a const reverse STL-style iterator pointing to the first item in the list
const_reverse_iterator rend() const; //!< Return a const reverse STL-style iterator pointing to the imaginary item after the last item in the list
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
void reserve(long size); //!< Request that the capacity of the allocated storage space for the items of the container be at least enough to hold 'size' elements
void reverse(); //!< Reverse all items in the list
void clear(); //!< Remove all items from the list
long count() const; //!< Return the number of items in the list (same as 'size()')
long size() const; //!< Return the number of items in the list (same as 'count()')
bool contains(const Key &key) const; //!< Return 'true' if the list contains an occurrence of 'key', otherwise return 'false' (same as 'exist()')
bool exist(const Key &key) const; //!< Return 'true' if the list contains an occurrence of 'key', otherwise return 'false' (same as 'contains()')
bool empty() const; //!< Return 'true' if the list contains no items; otherwise return 'false'
bool push_back(const Key &key, const Value &value); //!< Add element 'value' at the end of the list indexed by 'key'
bool push_front(const Key &key, const Value &value); //!< Insert 'value' at the beginning of the list indexed by 'key'
bool insert(const Key &key, const Value &value); //!< Add element 'value' at the end of the list indexed by 'key'
bool insert(long index, const Key &key, const Value &value); //!< Insert element 'value' at position 'index' in the list indexed by 'key'
bool insert(const QxCollection<Key, Value> &other); //!< Add all items of 'other' at the end of the list
bool insert(long index, const QxCollection<Key, Value> &other); //!< Insert all items of 'other' at the end of the list
bool replace(long index, const Key &key, const Value &value); //!< Replace the item at index position 'index' with element 'value' indexed by 'key'
bool swap(long index1, long index2); //!< Exchange the item at index position 'index1' with the item at index position 'index2'
bool move(long indexFrom, long indexTo); //!< Move the item at index position 'indexFrom' to index position 'indexTo'
bool removeByKey(const Key &key); //!< Remove the item indexed by 'key' in the list
bool removeByIndex(long index); //!< Remove the item at index position 'index'
bool removeByIndex(long first, long last); //!< Remove all items from index position 'first' to index position 'last'
bool removeFirst(); //!< Remove the first item in the list
bool removeLast(); //!< Remove the last item in the list
const_reference_value getByKey(const Key &key) const; //!< Return the item associated with the 'key'
const_reference_value getByIndex(long index) const; //!< Return the item at index position 'index'
const_reference_value getFirst() const; //!< Return the first element in the list
const_reference_value getLast() const; //!< Return the last element in the list
const_reference_key getKeyByIndex(long index) const; //!< Return the key associated with the element at index position 'index'
void sortByKey(bool bAscending = true); //!< Sort all items in the list using associated keys to compare
void sortByValue(bool bAscending = true); //!< Sort all items in the list
template <typename Compare>
void sort(Compare comp)
{
{
QMutexLocker locker(&m_mutex);
std::sort(m_list.begin(), m_list.end(), comp);
}
updateHashPosition();
}
protected:
void cloneCollection(QxCollection<Key, Value> *pClone, const QxCollection<Key, Value> &pRef);
bool isSameCollection(const QxCollection<Key, Value> *p1, const QxCollection<Key, Value> &p2) const;
void updateHashPosition(long from = 0, long to = -1, bool check = false);
template <bool bIsPointer /* = false */, int dummy>
struct compareKeyValue
{
static bool compareByKeyAscending(const type_pair_key_value &v1, const type_pair_key_value &v2) { return (v1.first < v2.first); }
static bool compareByKeyDescending(const type_pair_key_value &v1, const type_pair_key_value &v2) { return (v1.first > v2.first); }
static bool compareByValueAscending(const type_pair_key_value &v1, const type_pair_key_value &v2) { return (v1.second < v2.second); }
static bool compareByValueDescending(const type_pair_key_value &v1, const type_pair_key_value &v2) { return (v1.second > v2.second); }
};
template <int dummy>
struct compareKeyValue<true, dummy>
{
static bool compareByKeyAscending(const type_pair_key_value &v1, const type_pair_key_value &v2) { return ((v1.first && v2.first) ? ((*v1.first) < (*v2.first)) : false); }
static bool compareByKeyDescending(const type_pair_key_value &v1, const type_pair_key_value &v2) { return ((v1.first && v2.first) ? ((*v1.first) > (*v2.first)) : true); }
static bool compareByValueAscending(const type_pair_key_value &v1, const type_pair_key_value &v2) { return ((v1.second && v2.second) ? ((*v1.second) < (*v2.second)) : false); }
static bool compareByValueDescending(const type_pair_key_value &v1, const type_pair_key_value &v2) { return ((v1.second && v2.second) ? ((*v1.second) > (*v2.second)) : true); }
};
public:
virtual long _count() const { return this->count(); }
virtual void _clear() { this->clear(); }
virtual bool _remove(long index) { return this->removeByIndex(index); }
virtual qx::any _at(long index) const
{
Value val = this->getByIndex(index);
return qx::any(val);
}
};
} // namespace qx
#include "../../inl/QxCollection/QxCollection.inl"
QX_REGISTER_CLASS_NAME_TEMPLATE_2(qx::QxCollection)
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
#endif // _QX_COLLECTION_H_

View File

@@ -0,0 +1,100 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_COLLECTION_ITERATOR_H_
#define _QX_COLLECTION_ITERATOR_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxCollectionIterator.h
* \author XDL Team
* \ingroup QxCollection
* \brief Java-style iterator to iterate over a qx::QxCollection<Key, Value> container
*/
#include <QxCollection/QxCollection.h>
namespace qx
{
/*!
* \ingroup QxCollection
* \brief qx::QxCollectionIterator : Java-style iterator to iterate over a qx::QxCollection<Key, Value> container
*
* Quick sample using qx::QxCollectionIterator Java-style iterator :
* \code
// iterate over a drugs container using 'qx::QxCollectionIterator' Java-style iterator
qx::QxCollectionIterator<QString, drug_ptr> itr(lstDrugs);
while (itr.next())
{
QString code = itr.key();
qDebug() << qPrintable(itr.value()->name) << " " << qPrintable(itr.value()->desc);
}
* \endcode
*/
template <typename Key, typename Value>
class QxCollectionIterator
{
private:
const QxCollection<Key, Value> *m_pCollection; //!< Collection to iterate over
long m_lCurrIndex; //!< Current index (position) in the collection
public:
QxCollectionIterator(const QxCollection<Key, Value> &col); //!< Construct an iterator for traversing the collection. The iterator is set to be at the front of the list (before the first item)
~QxCollectionIterator(); //!< Destroy the iterator
inline const Key &key() const; //!< Return the 'key' at current position
inline const Value &value() const; //!< Return the 'value' at current position
inline void toFirst(); //!< Move the iterator to the front of the container (before the first item)
inline void toLast(); //!< Move the iterator to the back of the container (after the last item)
inline bool next(); //!< Advance the iterator by one position. Return 'true' if there is at least one item ahead of the iterator, i.e. the iterator is not at the back of the container; otherwise return 'false'
inline bool previous(); //!< Move the iterator back by one position. Return 'true' if there is at least one item behind the iterator, i.e. the iterator is not at the front of the container; otherwise return 'false'
private:
QxCollectionIterator(const QxCollectionIterator &other) { Q_UNUSED(other); }
QxCollectionIterator &operator=(const QxCollectionIterator &other)
{
Q_UNUSED(other);
return (*this);
}
};
} // namespace qx
#include "../../inl/QxCollection/QxCollectionIterator.inl"
#endif // _QX_COLLECTION_ITERATOR_H_

View File

@@ -0,0 +1,206 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_BOOST
#ifndef _QX_FOREACH_H_
#define _QX_FOREACH_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxForeach.h
* \author XDL Team
* \ingroup QxCollection
* \brief foreach-style (based on BOOST_FOREACH macro) to iterate over all stl, boost and Qt containers + qx::QxCollection<Key, Value> QxOrm library container
*
* Quick sample using QX_FOREACH (or _foreach) macro :
* \code
// iterate over drugs container using QxOrm '_foreach' keyword
_foreach(drug_ptr p, lstDrugs)
{ qDebug() << qPrintable(p->name) << " " << qPrintable(p->desc); }
* \endcode
*
* \note QxOrm library provides also other macros to iterator over all containers : _foreach_reverse, _foreach_if, _foreach_reverse_if
*/
#include <boost/foreach.hpp>
#ifndef BOOST_FOREACH_ID
#define BOOST_FOREACH_ID(x) x
#endif
#include <QxTraits/is_qx_collection.h>
namespace qx
{
namespace foreach
{
template <typename T, typename C, bool is_qx_collection = false>
struct qx_deref_boost_or_qx
{
typedef typename boost::foreach_detail_::foreach_reference<T, C>::type type;
};
template <typename T, typename C>
struct qx_deref_boost_or_qx<T, C, true>
{
typedef typename T::type_pair_key_value::second_type type;
};
template <typename T, typename C, bool is_qx_collection = false>
struct qx_deref_deduce
{
static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, false>::type
deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> *ptmp)
{
return boost::foreach_detail_::deref(cur, ptmp);
}
static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, false>::type
rderef(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> *ptmp)
{
return boost::foreach_detail_::rderef(cur, ptmp);
}
};
template <typename T, typename C>
struct qx_deref_deduce<T, C, true>
{
static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, true>::type
deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> *ptmp)
{
return boost::foreach_detail_::deref(cur, ptmp).second;
}
static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, true>::type
rderef(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> *ptmp)
{
return boost::foreach_detail_::rderef(cur, ptmp).second;
}
};
struct qx_deref
{
template <typename T, typename C>
static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, qx::trait::is_qx_collection<T>::value>::type
deref(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> *ptmp)
{
return qx::foreach::qx_deref_deduce<T, C, qx::trait::is_qx_collection<T>::value>::deref(cur, ptmp);
}
template <typename T, typename C>
static inline typename qx::foreach::qx_deref_boost_or_qx<T, C, qx::trait::is_qx_collection<T>::value>::type
deref_reverse(boost::foreach_detail_::auto_any_t cur, boost::foreach_detail_::type2type<T, C> *ptmp)
{
return qx::foreach::qx_deref_deduce<T, C, qx::trait::is_qx_collection<T>::value>::rderef(cur, ptmp);
}
};
} // namespace foreach
} // namespace qx
#define QX_FOREACH_DEREF(COL) \
qx::foreach::qx_deref::deref(BOOST_FOREACH_ID(_foreach_cur), BOOST_FOREACH_TYPEOF(COL))
#define QX_FOREACH_DEREF_REVERSE(COL) \
qx::foreach::qx_deref::deref_reverse(BOOST_FOREACH_ID(_foreach_cur), BOOST_FOREACH_TYPEOF(COL))
#define QX_FOREACH(VAR, COL) \
BOOST_FOREACH_PREAMBLE() \
if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) \
{ \
} \
else if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_BEGIN(COL)) \
{ \
} \
else if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_END(COL)) \
{ \
} \
else \
for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \
BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_DONE(COL); \
BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_NEXT(COL) : (void)0) \
if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) \
{ \
} \
else \
for (VAR = QX_FOREACH_DEREF(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
#define QX_FOREACH_REVERSE(VAR, COL) \
BOOST_FOREACH_PREAMBLE() \
if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_col) = BOOST_FOREACH_CONTAIN(COL)) \
{ \
} \
else if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_cur) = BOOST_FOREACH_RBEGIN(COL)) \
{ \
} \
else if (boost::foreach_detail_::auto_any_t BOOST_FOREACH_ID(_foreach_end) = BOOST_FOREACH_REND(COL)) \
{ \
} \
else \
for (bool BOOST_FOREACH_ID(_foreach_continue) = true; \
BOOST_FOREACH_ID(_foreach_continue) && !BOOST_FOREACH_RDONE(COL); \
BOOST_FOREACH_ID(_foreach_continue) ? BOOST_FOREACH_RNEXT(COL) : (void)0) \
if (boost::foreach_detail_::set_false(BOOST_FOREACH_ID(_foreach_continue))) \
{ \
} \
else \
for (VAR = QX_FOREACH_DEREF_REVERSE(COL); !BOOST_FOREACH_ID(_foreach_continue); BOOST_FOREACH_ID(_foreach_continue) = true)
#ifdef _foreach
#undef _foreach
#endif // _foreach
#ifdef _foreach_reverse
#undef _foreach_reverse
#endif // _foreach_reverse
#ifdef _foreach_if
#undef _foreach_if
#endif // _foreach_if
#ifdef _foreach_reverse_if
#undef _foreach_reverse_if
#endif // _foreach_reverse_if
#define _foreach QX_FOREACH
#define _foreach_reverse QX_FOREACH_REVERSE
#define _foreach_if(VAR, COL, COND) _foreach(VAR, COL) if (COND)
#define _foreach_reverse_if(VAR, COL, COND) _foreach_reverse(VAR, COL) if (COND)
#endif // _QX_FOREACH_H_
#endif // _QX_ENABLE_BOOST

199
include/QxCommon/QxAny.h Normal file
View File

@@ -0,0 +1,199 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_ANY_H_
#define _QX_ANY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxAny.h
* \author XDL Team
* \ingroup QxCommon
* \brief qx::any : basic implementation of boost::any (written by Kevlin Henney) when boost dependency is not available
*/
#ifndef _QX_NO_RTTI
#include <typeinfo>
#define QX_TYPE_ID(T) typeid(T)
#else // _QX_NO_RTTI
#include <QxTraits/get_class_name.h>
#include <QxTraits/get_class_name_primitive.h>
#define QX_TYPE_ID(T) std::string(qx::trait::get_class_name<T>::get())
#endif // _QX_NO_RTTI
#ifndef Q_OS_WIN
#if (__GNUC__ >= 4)
#define QX_ANY_FORCE_HIDDEN_VISIBILITY __attribute__((visibility("hidden"))) // To avoid a GCC warning : 'qx::any::holder<T>' declared with greater visibility than the type of its field 'qx::any::holder<T>::held' [-Wattributes]
#endif // (__GNUC__ >= 4)
#endif // Q_OS_WIN
#ifndef QX_ANY_FORCE_HIDDEN_VISIBILITY
#define QX_ANY_FORCE_HIDDEN_VISIBILITY /* Nothing */
#endif // QX_ANY_FORCE_HIDDEN_VISIBILITY
namespace qx
{
class any;
template <typename ValueType>
ValueType *any_cast(any *);
template <typename ValueType>
ValueType *unsafe_any_cast(any *);
class any
{
template <typename ValueType>
friend ValueType *qx::any_cast(any *);
template <typename ValueType>
friend ValueType *qx::unsafe_any_cast(any *);
public:
#ifndef _QX_NO_RTTI
typedef const std::type_info &type_check;
#else // _QX_NO_RTTI
typedef std::string type_check;
#endif // _QX_NO_RTTI
any() : content(NULL) { ; }
any(const any &other) : content(other.content ? other.content->clone() : NULL) { ; }
~any()
{
if (content)
{
delete content;
}
}
template <typename ValueType>
any(const ValueType &value) : content(new holder<typename std::remove_cv<typename std::decay<const ValueType>::type>::type>(value)) { ; }
any &swap(any &other)
{
std::swap(content, other.content);
return (*this);
}
template <typename ValueType>
any &operator=(const ValueType &other)
{
any(other).swap(*this);
return (*this);
}
any &operator=(any other)
{
any(other).swap(*this);
return (*this);
}
bool empty() const { return (!content); }
void clear() { any().swap(*this); }
type_check type() const { return (content ? content->type() : QX_TYPE_ID(void)); }
private:
struct placeholder
{
virtual ~placeholder() { ; }
virtual type_check type() const = 0;
virtual placeholder *clone() const = 0;
};
template <typename ValueType>
struct QX_ANY_FORCE_HIDDEN_VISIBILITY holder : public placeholder
{
holder(const ValueType &value) : held(value) { ; }
virtual type_check type() const { return QX_TYPE_ID(ValueType); }
virtual placeholder *clone() const { return new holder(held); }
ValueType held;
private:
holder &operator=(const holder &);
};
placeholder *content;
};
inline void swap(any &lhs, any &other) { lhs.swap(other); }
struct bad_any_cast : public std::exception
{
virtual const char *what() const throw() { return "qx::bad_any_cast : failed conversion using qx::any_cast"; }
};
template <typename ValueType>
ValueType *any_cast(any *operand)
{
return ((operand && (operand->type() == QX_TYPE_ID(ValueType))) ? (&static_cast<any::holder<typename std::remove_cv<ValueType>::type> *>(operand->content)->held) : NULL);
}
template <typename ValueType>
const ValueType *any_cast(const any *operand)
{
return any_cast<ValueType>(const_cast<any *>(operand));
}
template <typename ValueType>
ValueType any_cast(any &operand)
{
typedef typename std::remove_reference<ValueType>::type nonref;
nonref *result = any_cast<nonref>(&operand);
if (!result)
{
throw qx::bad_any_cast();
}
return static_cast<ValueType>(*result);
}
template <typename ValueType>
ValueType any_cast(const any &operand)
{
typedef typename std::remove_reference<ValueType>::type nonref;
return any_cast<const nonref &>(const_cast<any &>(operand));
}
template <typename ValueType>
ValueType *unsafe_any_cast(any *operand)
{
return (&static_cast<any::holder<ValueType> *>(operand->content)->held);
}
template <typename ValueType>
const ValueType *unsafe_any_cast(const any *operand)
{
return unsafe_any_cast<ValueType>(const_cast<any *>(operand));
}
} // namespace qx
#endif // _QX_ANY_H_

View File

@@ -0,0 +1,162 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_ANY_CAST_DYNAMIC_H_
#define _QX_ANY_CAST_DYNAMIC_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxAnyCastDynamic.h
* \author XDL Team
* \ingroup QxCommon
* \brief qx::any_cast_dynamic<T>::get() : provides a tool to use qx::any_cast and polymorphism
*/
#include <QtCore/qsharedpointer.h>
#include <QxCommon/QxAny.h>
#include <QxDao/QxDaoPointer.h>
namespace qx
{
template <typename T>
struct any_cast_dynamic
{
static T get(const qx::any &a) { return qx::any_cast<T>(a); }
};
template <typename T>
struct any_cast_dynamic<T *>
{
static T *get(const qx::any &a)
{
if (a.empty())
{
return NULL;
}
qx::any *b = const_cast<qx::any *>(&a);
T **t = qx::unsafe_any_cast<T *>(b);
if (!t)
{
return NULL;
}
return (*t);
}
};
#ifdef _QX_ENABLE_BOOST
template <typename T>
struct any_cast_dynamic<boost::shared_ptr<T>>
{
static boost::shared_ptr<T> get(const qx::any &a)
{
if (a.empty())
{
return boost::shared_ptr<T>();
}
qx::any *b = const_cast<qx::any *>(&a);
boost::shared_ptr<T> *t = qx::unsafe_any_cast<boost::shared_ptr<T>>(b);
if (!t)
{
return boost::shared_ptr<T>();
}
return (*t);
}
};
#endif // _QX_ENABLE_BOOST
template <typename T>
struct any_cast_dynamic<QSharedPointer<T>>
{
static QSharedPointer<T> get(const qx::any &a)
{
if (a.empty())
{
return QSharedPointer<T>();
}
qx::any *b = const_cast<qx::any *>(&a);
QSharedPointer<T> *t = qx::unsafe_any_cast<QSharedPointer<T>>(b);
if (!t)
{
return QSharedPointer<T>();
}
return (*t);
}
};
template <typename T>
struct any_cast_dynamic<qx::dao::ptr<T>>
{
static qx::dao::ptr<T> get(const qx::any &a)
{
if (a.empty())
{
return qx::dao::ptr<T>();
}
qx::any *b = const_cast<qx::any *>(&a);
qx::dao::ptr<T> *t = qx::unsafe_any_cast<qx::dao::ptr<T>>(b);
if (!t)
{
return qx::dao::ptr<T>();
}
return (*t);
}
};
template <typename T>
struct any_cast_dynamic<std::shared_ptr<T>>
{
static std::shared_ptr<T> get(const qx::any &a)
{
if (a.empty())
{
return std::shared_ptr<T>();
}
qx::any *b = const_cast<qx::any *>(&a);
std::shared_ptr<T> *t = qx::unsafe_any_cast<std::shared_ptr<T>>(b);
if (!t)
{
return std::shared_ptr<T>();
}
return (*t);
}
};
} // namespace qx
#endif // _QX_ANY_CAST_DYNAMIC_H_

190
include/QxCommon/QxBool.h Normal file
View File

@@ -0,0 +1,190 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_BOOL_H_
#define _QX_BOOL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxBool.h
* \author XDL Team
* \ingroup QxCommon
* \brief qx_bool : QxOrm library boolean type with code and description message when an error occured
*/
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#include <QtCore/qdatastream.h>
#include <QxSerialize/Qt/QxSerialize_QString.h>
#include <QxTraits/get_class_name.h>
namespace qx
{
class QxBool;
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::QxBool &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::QxBool &t) QX_USED;
namespace qx
{
/*!
* \ingroup QxCommon
* \brief qx_bool : boolean type with code and description message when an error occured
*/
class QxBool
{
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
friend class boost::serialization::access;
#endif // _QX_ENABLE_BOOST_SERIALIZATION
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::QxBool &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::QxBool &t);
private:
bool m_bValue; //!< Data boolean value
long m_lCode; //!< Error code when value is false
QString m_sDesc; //!< Error description when value is false
public:
QxBool() : m_bValue(false), m_lCode(0) { ; }
QxBool(bool b) : m_bValue(b), m_lCode(0) { qAssert(checkInitialized(b)); }
QxBool(long lCode, const QString &sDesc) : m_bValue(false), m_lCode(lCode), m_sDesc(sDesc) { ; }
QxBool(bool bValue, long lCode, const QString &sDesc) : m_bValue(bValue), m_lCode(lCode), m_sDesc(sDesc) { qAssert(checkInitialized(bValue)); }
QxBool(const QxBool &other) : m_bValue(other.getValue()), m_lCode(other.getCode()), m_sDesc(other.getDesc()) { ; }
~QxBool() { ; }
inline bool getValue() const { return m_bValue; }
inline long getCode() const { return m_lCode; }
inline QString getDesc() const { return m_sDesc; }
inline void setValue(bool bValue)
{
m_bValue = bValue;
qAssert(checkInitialized(bValue));
}
inline void setCode(long lCode) { m_lCode = lCode; }
inline void setDesc(const QString &sDesc) { m_sDesc = sDesc; }
inline QxBool &operator=(const QxBool &other)
{
m_bValue = other.getValue();
m_lCode = other.getCode();
m_sDesc = other.getDesc();
return (*this);
}
inline QxBool &operator=(const bool b)
{
m_bValue = b;
qAssert(checkInitialized(b));
return (*this);
}
inline operator bool() const { return (m_bValue != false); }
inline bool operator!() const { return (m_bValue == false); }
inline bool operator==(const QxBool &other) const { return ((m_bValue == other.getValue()) && (m_lCode == other.getCode()) && (m_sDesc == other.getDesc())); }
inline bool operator==(const bool b) const
{
qAssert(checkInitialized(b));
return (m_bValue == b);
}
inline bool operator!=(const QxBool &other) const { return ((m_bValue != other.getValue()) || (m_lCode != other.getCode()) || (m_sDesc != other.getDesc())); }
inline bool operator!=(const bool b) const
{
qAssert(checkInitialized(b));
return (m_bValue != b);
}
inline bool operator&&(const QxBool &other) const { return (m_bValue && other.getValue()); }
inline bool operator&&(const bool b) const
{
qAssert(checkInitialized(b));
return (m_bValue && b);
}
inline bool operator||(const QxBool &other) const { return (m_bValue || other.getValue()); }
inline bool operator||(const bool b) const
{
qAssert(checkInitialized(b));
return (m_bValue || b);
}
QString toString() const { return (QString(m_bValue ? "1" : "0") + "|" + QString::number(static_cast<qlonglong>(m_lCode)) + "|" + m_sDesc); }
void fromString(const QString &s)
{
if (s.trimmed().isEmpty())
{
(*this) = QxBool();
return;
}
bool bValue = s.startsWith("1");
int iPos = s.indexOf("|", 2);
if (iPos == -1)
{
(*this) = QxBool(bValue);
return;
}
long lCode = s.mid(2, (iPos - 2)).toLong();
QString sDesc = s.right(s.size() - (iPos + 1));
(*this) = QxBool(bValue, lCode, sDesc);
}
private:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
Q_UNUSED(file_version);
ar &boost::serialization::make_nvp("value", m_bValue);
ar &boost::serialization::make_nvp("code", m_lCode);
ar &boost::serialization::make_nvp("desc", m_sDesc);
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
inline bool checkInitialized(const bool b) const { return ((static_cast<int>(b) == 0) || (static_cast<int>(b) == 1)); }
};
} // namespace qx
typedef qx::QxBool qx_bool;
QX_REGISTER_CLASS_NAME(qx_bool)
#endif // _QX_BOOL_H_

264
include/QxCommon/QxCache.h Normal file
View File

@@ -0,0 +1,264 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_CACHE_H_
#define _QX_CACHE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxCache.h
* \author XDL Team
* \ingroup QxCache
* \brief qx::cache : based on singleton pattern, provide basic thread-safe cache feature to backup and restore any kind of objects (for example, object fetched from database)
*/
#include <QxCommon/QxBool.h>
#include <QxCommon/QxAny.h>
#include <QxCollection/QxCollection.h>
#include <QxSingleton/QxSingleton.h>
namespace qx
{
namespace cache
{
namespace detail
{
class QX_DLL_EXPORT QxCache : public qx::QxSingleton<QxCache>
{
friend class qx::QxSingleton<QxCache>;
protected:
typedef std::tuple<long, QDateTime, qx::any> type_qx_cache;
typedef qx::QxCollection<QString, type_qx_cache> type_qx_lst_cache;
type_qx_lst_cache m_cache; //!< List of objects in cache under qx::any format
QMutex m_oMutexCache; //!< Mutex => 'QxCache' is thread-safe
long m_lMaxCost; //!< Max cost before deleting object in cache
long m_lCurrCost; //!< Current cost in cache
public:
QxCache();
virtual ~QxCache();
long getCurrCost() const;
long getMaxCost() const;
void setMaxCost(long l);
long count() const;
long size() const;
bool isEmpty() const;
bool exist(const QString &sKey) const;
bool contains(const QString &sKey) const;
qx::any at(const QString &sKey);
long insertionCost(const QString &sKey);
QDateTime insertionDateTime(const QString &sKey);
void clear();
bool insert(const QString &sKey, const qx::any &anyObj, long lCost = 1, const QDateTime &dt = QDateTime());
bool remove(const QString &sKey);
private:
void updateCost();
};
} // namespace detail
} // namespace cache
} // namespace qx
QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::cache::detail::QxCache)
namespace qx
{
namespace cache
{
/*!
* \ingroup QxCache
* \brief Set the maximum allowed total cost of the cache to l. If the current total cost is greater than l, some objects are deleted immediately
*/
inline void max_cost(long l)
{
qx::cache::detail::QxCache::getSingleton()->setMaxCost(l);
}
/*!
* \ingroup QxCache
* \brief Return the maximum allowed total cost of the cache
*/
inline long max_cost()
{
return qx::cache::detail::QxCache::getSingleton()->getMaxCost();
}
/*!
* \ingroup QxCache
* \brief Return the current cost used by the cache
*/
inline long current_cost()
{
return qx::cache::detail::QxCache::getSingleton()->getCurrCost();
}
/*!
* \ingroup QxCache
* \brief Return the number of objects in the cache
*/
inline long count()
{
return qx::cache::detail::QxCache::getSingleton()->count();
}
/*!
* \ingroup QxCache
* \brief Return true if the cache contains no object; otherwise return false
*/
inline bool is_empty()
{
return qx::cache::detail::QxCache::getSingleton()->isEmpty();
}
/*!
* \ingroup QxCache
* \brief Delete all the objects in the cache
*/
inline void clear()
{
qx::cache::detail::QxCache::getSingleton()->clear();
}
/*!
* \ingroup QxCache
* \brief Return true if the cache contains an object associated with key sKey; otherwise return false
*/
inline bool exist(const QString &sKey)
{
return qx::cache::detail::QxCache::getSingleton()->exist(sKey);
}
/*!
* \ingroup QxCache
* \brief Delete the object associated with key sKey. Return true if the object was found in the cache; otherwise return false
*/
inline bool remove(const QString &sKey)
{
return qx::cache::detail::QxCache::getSingleton()->remove(sKey);
}
/*!
* \ingroup QxCache
* \brief Insert object t into the cache with key sKey, associated cost lCost and insertion date-time dt. Any object with the same key already in the cache will be removed
*/
template <typename T>
inline bool set(const QString &sKey, T &t, long lCost = 1, const QDateTime &dt = QDateTime())
{
qx::any obj(t);
return qx::cache::detail::QxCache::getSingleton()->insert(sKey, obj, lCost, dt);
}
/*!
* \ingroup QxCache
* \brief Return the object of type T associated with key sKey, or return default instance of T() if the key does not exist in the cache
*/
template <typename T>
inline T get(const QString &sKey)
{
qx::any obj = qx::cache::detail::QxCache::getSingleton()->at(sKey);
if (obj.empty())
{
return T();
}
try
{
return qx::any_cast<T>(obj);
}
catch (const qx::bad_any_cast &err)
{
Q_UNUSED(err);
return T();
}
catch (...)
{
return T();
}
}
/*!
* \ingroup QxCache
* \brief Return true if object t can be fetched with associated key sKey and insertion date-time dt; otherwise return false with an error description
*/
template <typename T>
inline qx_bool get(const QString &sKey, T &t, QDateTime &dt)
{
dt = QDateTime();
if (!qx::cache::exist(sKey))
{
return qx_bool(false, 0, "[QxOrm] qx::cache : key doesn't exist in cache");
}
qx::any obj = qx::cache::detail::QxCache::getSingleton()->at(sKey);
dt = qx::cache::detail::QxCache::getSingleton()->insertionDateTime(sKey);
try
{
t = qx::any_cast<T>(obj);
return qx_bool(true);
}
catch (const qx::bad_any_cast &err)
{
Q_UNUSED(err);
return qx_bool(false, 0, "[QxOrm] qx::cache : bad any cast exception");
}
catch (...)
{
return qx_bool(false, 0, "[QxOrm] qx::cache : unknown cast exception");
}
}
/*!
* \ingroup QxCache
* \brief Return true if object t can be fetched with associated key sKey; otherwise return false with an error description
*/
template <typename T>
inline qx_bool get(const QString &sKey, T &t)
{
QDateTime dt;
return qx::cache::get<T>(sKey, t, dt);
}
} // namespace cache
} // namespace qx
#endif // _QX_CACHE_H_

184
include/QxCommon/QxConfig.h Normal file
View File

@@ -0,0 +1,184 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_CONFIG_H_
#define _QX_CONFIG_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxConfig.h
* \author XDL Team
* \ingroup QxCommon
* \brief List of parameters to compile and build QxOrm library
*/
#define QX_VERSION 0x010500
#define QX_VERSION_STR "1.5.0"
#ifndef _QX_MODE_DEBUG
#ifndef _QX_MODE_RELEASE
#ifdef QT_NO_DEBUG
#define _QX_MODE_RELEASE
#else // QT_NO_DEBUG
#define _QX_MODE_DEBUG
#endif // QT_NO_DEBUG
#endif // _QX_MODE_RELEASE
#endif // _QX_MODE_DEBUG
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_BINARY
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_XML
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_TEXT
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
#ifndef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
#define _QX_ENABLE_BOOST_SERIALIZATION_BINARY
#define _QX_ENABLE_BOOST_SERIALIZATION_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
#endif // _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
#endif // _QX_ENABLE_BOOST_SERIALIZATION_TEXT
#endif // _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
#endif // _QX_ENABLE_BOOST_SERIALIZATION_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION_BINARY
#ifndef _QX_ENABLE_BOOST_SERIALIZATION
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_BINARY
#undef _QX_ENABLE_BOOST_SERIALIZATION_BINARY
#endif // _QX_ENABLE_BOOST_SERIALIZATION_BINARY
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_XML
#undef _QX_ENABLE_BOOST_SERIALIZATION_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION_XML
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
#undef _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
#endif // _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_TEXT
#undef _QX_ENABLE_BOOST_SERIALIZATION_TEXT
#endif // _QX_ENABLE_BOOST_SERIALIZATION_TEXT
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
#undef _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
#endif // _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
#undef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
#undef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
#undef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
#define _QX_SERIALIZE_POLYMORPHIC 1
#else // _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
#define _QX_SERIALIZE_POLYMORPHIC 0
#endif // _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_BINARY
#define _QX_SERIALIZE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 1)
#else // _QX_ENABLE_BOOST_SERIALIZATION_BINARY
#define _QX_SERIALIZE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 0)
#endif // _QX_ENABLE_BOOST_SERIALIZATION_BINARY
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_TEXT
#define _QX_SERIALIZE_TEXT (!_QX_SERIALIZE_POLYMORPHIC && 1)
#else // _QX_ENABLE_BOOST_SERIALIZATION_TEXT
#define _QX_SERIALIZE_TEXT (!_QX_SERIALIZE_POLYMORPHIC && 0)
#endif // _QX_ENABLE_BOOST_SERIALIZATION_TEXT
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_XML
#define _QX_SERIALIZE_XML (!_QX_SERIALIZE_POLYMORPHIC && 1)
#else // _QX_ENABLE_BOOST_SERIALIZATION_XML
#define _QX_SERIALIZE_XML (!_QX_SERIALIZE_POLYMORPHIC && 0)
#endif // _QX_ENABLE_BOOST_SERIALIZATION_XML
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
#define _QX_SERIALIZE_PORTABLE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 1)
#else // _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
#define _QX_SERIALIZE_PORTABLE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 0)
#endif // _QX_ENABLE_BOOST_SERIALIZATION_PORTABLE_BINARY
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
#define _QX_SERIALIZE_WIDE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 1)
#else // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
#define _QX_SERIALIZE_WIDE_BINARY (!_QX_SERIALIZE_POLYMORPHIC && 0)
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_BINARY
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
#define _QX_SERIALIZE_WIDE_TEXT (!_QX_SERIALIZE_POLYMORPHIC && 1)
#else // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
#define _QX_SERIALIZE_WIDE_TEXT (!_QX_SERIALIZE_POLYMORPHIC && 0)
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_TEXT
#ifdef _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
#define _QX_SERIALIZE_WIDE_XML (!_QX_SERIALIZE_POLYMORPHIC && 1)
#else // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
#define _QX_SERIALIZE_WIDE_XML (!_QX_SERIALIZE_POLYMORPHIC && 0)
#endif // _QX_ENABLE_BOOST_SERIALIZATION_WIDE_XML
#define _QX_AUTO_REGISTER_REPOSITORY 0
#define _QX_USE_MEM_LEAK_DETECTION 0
#define _QX_USE_EXPORT_DLL_BOOST_SERIALIZATION_SINGLETON 1
#define _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER 0
#define _QX_USE_MODIFY_BOOST_SERIALIZATION_EXPORT_HPP 0
#define _QX_WRITE_BOOST_CLASS_EXPORT_IN_HPP_FILE 0
#define _QX_WRITE_BOOST_CLASS_EXPORT_IN_CPP_FILE 1
#define _QX_INCLUDE_BOOST_SERIALIZE_EXPORT_HPP_INTO_QX_MEM_LEAK_HPP 1
#define _QX_INCLUDE_BOOST_SERIALIZE_ARCHIVE_IMPL_IPP 0
#define _QX_MEM_LEAK_ONLY_KNOWN_SRC_FILE 1
#define _QX_SUPPORT_BOOST_SERIALIZE_SHARED_PTR_132 0
#define _QX_USE_QX_CONVERT_EXPORT 0
#define _QX_USE_GCC_EXPORT_ALL_SYMBOLS 0
#define _QX_USE_GCC_VISIBILITY 0
#define _QX_USE_ASSERT 1
#define _QX_SUPPORT_COVARIANT_RETURN_TYPE 1
#define _QX_USE_QX_SINGLETON_X 1
#ifdef _MSC_VER
/* -- Link error with VC++ 9.0 => Qt uses "-Zc:wchar_t-" option to compile and boost serialization library is compiled without this option -- */
#define _QX_USE_SERIALIZE_POLYMORPHIC_PATCH (_QX_SERIALIZE_POLYMORPHIC && 1)
#else // _MSC_VER
#define _QX_USE_SERIALIZE_POLYMORPHIC_PATCH 0
#endif // _MSC_VER
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
#ifndef _QX_NO_JSON
#define _QX_NO_JSON
#endif // _QX_NO_JSON
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
#endif // _QX_CONFIG_H_

View File

@@ -0,0 +1,83 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_EXCEPTION_H_
#define _QX_EXCEPTION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxException.h
* \author XDL Team
* \ingroup QxCommon
* \brief Exception with error code and error description
*/
#include <iostream>
#include <exception>
#include <QxCommon/QxBool.h>
namespace qx
{
/*!
* \ingroup QxCommon
* \brief qx::exception : exception with error code and error description
*/
class exception : public std::exception
{
private:
long m_code; //!< Error code
QString m_desc; //!< Error description
QString m_what; //!< Formatted error : code + "^" + description
public:
exception(const QString &desc) : std::exception(), m_code(0), m_desc(desc) { updateWhat(); }
exception(long code, const QString &desc) : std::exception(), m_code(code), m_desc(desc) { updateWhat(); }
virtual ~exception() throw() { ; }
virtual const char *what() const throw() { return qPrintable(m_what); }
long getCode() const { return m_code; }
QString getDescription() const { return m_desc; }
qx_bool toQxBool() const { return qx_bool(m_code, m_desc); }
private:
void updateWhat() { m_what = (QString::number(m_code) + QString("^") + m_desc); }
};
} // namespace qx
#endif // _QX_EXCEPTION_H_

View File

@@ -0,0 +1,64 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_EXCEPTION_CODE_H_
#define _QX_EXCEPTION_CODE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxExceptionCode.h
* \author XDL Team
* \ingroup QxCommon
* \brief Some errors codes defined by QxOrm library
*/
#include <QxCommon/QxException.h>
#define QX_ERROR_UNKNOWN 1
#define QX_ERROR_SERVICE_NOT_SPECIFIED 2
#define QX_ERROR_SERVICE_INVALID 3
#define QX_ERROR_SERVER_NOT_FOUND 4
#define QX_ERROR_SERVICE_WRITE_ERROR 5
#define QX_ERROR_SERVICE_READ_ERROR 6
#define QX_ERROR_SERVICE_SSL_ENCRYPTED 7
#define QX_EXCEPTION_UNKNOWN qx::exception(QX_ERROR_UNKNOWN, "unknown error")
#define QX_EXCEPTION_SERVICE_NOT_SPECIFIED qx::exception(QX_ERROR_SERVICE_NOT_SPECIFIED, "[QxOrm] empty service name")
#define QX_EXCEPTION_SERVICE_INVALID qx::exception(QX_ERROR_SERVICE_INVALID, "[QxOrm] invalid service")
#define QX_EXCEPTION_SERVER_NOT_FOUND qx::exception(QX_ERROR_SERVER_NOT_FOUND, "[QxOrm] unable to connect to server")
#define QX_EXCEPTION_SERVICE_WRITE_ERROR qx::exception(QX_ERROR_SERVICE_WRITE_ERROR, "[QxOrm] unable to write request to socket")
#define QX_EXCEPTION_SERVICE_READ_ERROR qx::exception(QX_ERROR_SERVICE_READ_ERROR, "[QxOrm] unable to read reply from socket")
#define QX_EXCEPTION_SERVICE_SSL_ENCRYPTED qx::exception(QX_ERROR_SERVICE_SSL_ENCRYPTED, "[QxOrm] SSL socket encrypted error")
#endif // _QX_EXCEPTION_CODE_H_

View File

@@ -0,0 +1,493 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_HASH_VALUE_H_
#define _QX_HASH_VALUE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxHashValue.h
* \author XDL Team
* \ingroup QxCommon
* \brief Specialize hash_value function for some Qt and boost types (used for example by qx::QxCollection<Key, Value> container)
*/
#include <QtCore/qstring.h>
#include <QtCore/qdatetime.h>
#include <QtCore/qvariant.h>
#include <QtCore/qpair.h>
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#define qx_hash_result uint
#else // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#define qx_hash_result std::size_t
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
inline std::size_t hash_value(const QString &s) { return qHash(s); }
inline std::size_t hash_value(const QVariant &v) { return qHash(v.toString()); }
inline std::size_t hash_value(const QDate &d) { return qHash(d.toJulianDay()); }
inline std::size_t hash_value(const QTime &t) { return qHash(t.toString()); }
inline std::size_t hash_value(const QDateTime &dt) { return qHash(dt.toString()); }
inline qx_hash_result qHash(const QVariant &v) { return static_cast<qx_hash_result>(hash_value(v)); }
#if (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
inline qx_hash_result qHash(const QDate &d) { return static_cast<qx_hash_result>(hash_value(d)); }
inline qx_hash_result qHash(const QTime &t) { return static_cast<qx_hash_result>(hash_value(t)); }
inline qx_hash_result qHash(const QDateTime &dt) { return static_cast<qx_hash_result>(hash_value(dt)); }
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 0, 0))
namespace qx
{
template <class T>
inline void hash_combine(std::size_t &seed, const T &t)
{
seed ^= qHash(t) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
}
} // namespace qx
template <typename T0, typename T1>
inline std::size_t hash_value(const QPair<T0, T1> &p)
{
std::size_t seed = 0;
qx::hash_combine(seed, p.first);
qx::hash_combine(seed, p.second);
return seed;
}
#ifdef _QX_ENABLE_BOOST
namespace boost
{
namespace tuples
{
template <typename T0, typename T1>
inline std::size_t hash_value(const boost::tuple<T0, T1> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, boost::get<0>(tu));
qx::hash_combine(seed, boost::get<1>(tu));
return seed;
}
template <typename T0, class T1, typename T2>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, boost::get<0>(tu));
qx::hash_combine(seed, boost::get<1>(tu));
qx::hash_combine(seed, boost::get<2>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, boost::get<0>(tu));
qx::hash_combine(seed, boost::get<1>(tu));
qx::hash_combine(seed, boost::get<2>(tu));
qx::hash_combine(seed, boost::get<3>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, boost::get<0>(tu));
qx::hash_combine(seed, boost::get<1>(tu));
qx::hash_combine(seed, boost::get<2>(tu));
qx::hash_combine(seed, boost::get<3>(tu));
qx::hash_combine(seed, boost::get<4>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, boost::get<0>(tu));
qx::hash_combine(seed, boost::get<1>(tu));
qx::hash_combine(seed, boost::get<2>(tu));
qx::hash_combine(seed, boost::get<3>(tu));
qx::hash_combine(seed, boost::get<4>(tu));
qx::hash_combine(seed, boost::get<5>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, boost::get<0>(tu));
qx::hash_combine(seed, boost::get<1>(tu));
qx::hash_combine(seed, boost::get<2>(tu));
qx::hash_combine(seed, boost::get<3>(tu));
qx::hash_combine(seed, boost::get<4>(tu));
qx::hash_combine(seed, boost::get<5>(tu));
qx::hash_combine(seed, boost::get<6>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, boost::get<0>(tu));
qx::hash_combine(seed, boost::get<1>(tu));
qx::hash_combine(seed, boost::get<2>(tu));
qx::hash_combine(seed, boost::get<3>(tu));
qx::hash_combine(seed, boost::get<4>(tu));
qx::hash_combine(seed, boost::get<5>(tu));
qx::hash_combine(seed, boost::get<6>(tu));
qx::hash_combine(seed, boost::get<7>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, boost::get<0>(tu));
qx::hash_combine(seed, boost::get<1>(tu));
qx::hash_combine(seed, boost::get<2>(tu));
qx::hash_combine(seed, boost::get<3>(tu));
qx::hash_combine(seed, boost::get<4>(tu));
qx::hash_combine(seed, boost::get<5>(tu));
qx::hash_combine(seed, boost::get<6>(tu));
qx::hash_combine(seed, boost::get<7>(tu));
qx::hash_combine(seed, boost::get<8>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
inline std::size_t hash_value(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, boost::get<0>(tu));
qx::hash_combine(seed, boost::get<1>(tu));
qx::hash_combine(seed, boost::get<2>(tu));
qx::hash_combine(seed, boost::get<3>(tu));
qx::hash_combine(seed, boost::get<4>(tu));
qx::hash_combine(seed, boost::get<5>(tu));
qx::hash_combine(seed, boost::get<6>(tu));
qx::hash_combine(seed, boost::get<7>(tu));
qx::hash_combine(seed, boost::get<8>(tu));
qx::hash_combine(seed, boost::get<9>(tu));
return seed;
}
template <typename T0, typename T1>
inline qx_hash_result qHash(const boost::tuple<T0, T1> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, class T1, typename T2>
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3>
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4>
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
inline qx_hash_result qHash(const boost::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
} // namespace tuples
} // namespace boost
#endif // _QX_ENABLE_BOOST
// Compilation option '_QX_HASH_NO_STD_NAMESPACE'
// Try to avoid compilation error, something like : error: no matching function for call to 'qHash(const std::tuple<...>&)'
// This is due to C++ ADL to resolve specialized functions : qHash(T) should be implemented in the same namespace as T
// For 'std' classes, it should be NOT allowed : the behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std
// More details here : https://www.kdab.com/how-to-declare-a-qhash-overload/
// And here : https://stackoverflow.com/questions/47460098/using-standard-library-types-as-keys-in-qhash-or-qset
#ifndef _QX_HASH_NO_STD_NAMESPACE
namespace std
{
#endif // _QX_HASH_NO_STD_NAMESPACE
#ifndef QT_NO_STL
inline qx_hash_result qHash(const std::string &s)
{
QString tmp = QString::fromStdString(s);
return qHash(tmp);
}
inline qx_hash_result qHash(const std::wstring &s)
{
QString tmp = QString::fromStdWString(s);
return qHash(tmp);
}
#else // QT_NO_STL
inline qx_hash_result qHash(const std::string &s)
{
QString tmp = QString::fromLatin1(s.data(), int(s.size()));
return qHash(tmp);
}
inline qx_hash_result qHash(const std::wstring &s)
{
qAssert(false); /* Need STL compatibility ! */
return 0;
}
#endif // QT_NO_STL
template <typename T0, typename T1>
inline std::size_t hash_value(const std::tuple<T0, T1> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, std::get<0>(tu));
qx::hash_combine(seed, std::get<1>(tu));
return seed;
}
template <typename T0, class T1, typename T2>
inline std::size_t hash_value(const std::tuple<T0, T1, T2> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, std::get<0>(tu));
qx::hash_combine(seed, std::get<1>(tu));
qx::hash_combine(seed, std::get<2>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3>
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, std::get<0>(tu));
qx::hash_combine(seed, std::get<1>(tu));
qx::hash_combine(seed, std::get<2>(tu));
qx::hash_combine(seed, std::get<3>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4>
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, std::get<0>(tu));
qx::hash_combine(seed, std::get<1>(tu));
qx::hash_combine(seed, std::get<2>(tu));
qx::hash_combine(seed, std::get<3>(tu));
qx::hash_combine(seed, std::get<4>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, std::get<0>(tu));
qx::hash_combine(seed, std::get<1>(tu));
qx::hash_combine(seed, std::get<2>(tu));
qx::hash_combine(seed, std::get<3>(tu));
qx::hash_combine(seed, std::get<4>(tu));
qx::hash_combine(seed, std::get<5>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, std::get<0>(tu));
qx::hash_combine(seed, std::get<1>(tu));
qx::hash_combine(seed, std::get<2>(tu));
qx::hash_combine(seed, std::get<3>(tu));
qx::hash_combine(seed, std::get<4>(tu));
qx::hash_combine(seed, std::get<5>(tu));
qx::hash_combine(seed, std::get<6>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, std::get<0>(tu));
qx::hash_combine(seed, std::get<1>(tu));
qx::hash_combine(seed, std::get<2>(tu));
qx::hash_combine(seed, std::get<3>(tu));
qx::hash_combine(seed, std::get<4>(tu));
qx::hash_combine(seed, std::get<5>(tu));
qx::hash_combine(seed, std::get<6>(tu));
qx::hash_combine(seed, std::get<7>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, std::get<0>(tu));
qx::hash_combine(seed, std::get<1>(tu));
qx::hash_combine(seed, std::get<2>(tu));
qx::hash_combine(seed, std::get<3>(tu));
qx::hash_combine(seed, std::get<4>(tu));
qx::hash_combine(seed, std::get<5>(tu));
qx::hash_combine(seed, std::get<6>(tu));
qx::hash_combine(seed, std::get<7>(tu));
qx::hash_combine(seed, std::get<8>(tu));
return seed;
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
inline std::size_t hash_value(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> &tu)
{
std::size_t seed = 0;
qx::hash_combine(seed, std::get<0>(tu));
qx::hash_combine(seed, std::get<1>(tu));
qx::hash_combine(seed, std::get<2>(tu));
qx::hash_combine(seed, std::get<3>(tu));
qx::hash_combine(seed, std::get<4>(tu));
qx::hash_combine(seed, std::get<5>(tu));
qx::hash_combine(seed, std::get<6>(tu));
qx::hash_combine(seed, std::get<7>(tu));
qx::hash_combine(seed, std::get<8>(tu));
qx::hash_combine(seed, std::get<9>(tu));
return seed;
}
#if ((QT_VERSION < QT_VERSION_CHECK(5, 7, 0)) || ((QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))))
template <typename T0, typename T1>
inline qx_hash_result qHash(const std::pair<T0, T1> &p)
{
std::size_t seed = 0;
qx::hash_combine(seed, p.first);
qx::hash_combine(seed, p.second);
return static_cast<qx_hash_result>(seed);
}
#endif // ((QT_VERSION < QT_VERSION_CHECK(5, 7, 0)) || ((QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) && (QT_VERSION < QT_VERSION_CHECK(6, 2, 0))))
template <typename T0, typename T1>
inline qx_hash_result qHash(const std::tuple<T0, T1> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, class T1, typename T2>
inline qx_hash_result qHash(const std::tuple<T0, T1, T2> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3>
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4>
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5>
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
template <typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
inline qx_hash_result qHash(const std::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> &tu)
{
return static_cast<qx_hash_result>(hash_value(tu));
}
#ifndef _QX_HASH_NO_STD_NAMESPACE
} // namespace std
#endif // _QX_HASH_NO_STD_NAMESPACE
#endif // _QX_HASH_VALUE_H_

298
include/QxCommon/QxMacro.h Normal file
View File

@@ -0,0 +1,298 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_MACRO_H_
#define _QX_MACRO_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxMacro.h
* \author XDL Team
* \ingroup QxCommon
* \brief List of common macros used by QxOrm library
*/
#include <QxCommon/QxConfig.h>
#ifndef qAssert
#if _QX_USE_ASSERT
#define qAssert Q_ASSERT
#else // _QX_USE_ASSERT
#define qAssert(x) /* Nothing */
#endif // _QX_USE_ASSERT
#endif // qAssert
#ifndef qAssertMsg
#if _QX_USE_ASSERT
#define qAssertMsg(test, where, what) Q_ASSERT_X(test, where, what)
#else // _QX_USE_ASSERT
#define qAssertMsg(test, where, what) /* Nothing */
#endif // _QX_USE_ASSERT
#endif // qAssertMsg
#ifndef QX_PRAGMA
#ifdef __GNUC__
#define QX_PRAGMA(x) _Pragma(#x)
#endif // __GNUC__
#ifdef _MSC_VER
#define QX_PRAGMA(x) __pragma(x)
#endif // _MSC_VER
#ifndef QX_PRAGMA
#define QX_PRAGMA(x) /* Nothing */
#endif // QX_PRAGMA
#endif // QX_PRAGMA
#ifndef QX_DLL_EXPORT_HELPER
#ifdef Q_OS_WIN
#define QX_DLL_EXPORT_HELPER __declspec(dllexport)
#elif (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
#define QX_DLL_EXPORT_HELPER __attribute__((visibility("default")))
#else
#define QX_DLL_EXPORT_HELPER /* Nothing */
#endif // Q_OS_WIN
#endif // QX_DLL_EXPORT_HELPER
#ifndef QX_DLL_IMPORT_HELPER
#ifdef Q_OS_WIN
#define QX_DLL_IMPORT_HELPER __declspec(dllimport)
#elif (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
#define QX_DLL_IMPORT_HELPER __attribute__((visibility("default")))
#else
#define QX_DLL_IMPORT_HELPER /* Nothing */
#endif // Q_OS_WIN
#endif // QX_DLL_IMPORT_HELPER
#ifdef __GNUC__
#if _QX_USE_GCC_EXPORT_ALL_SYMBOLS
#undef QX_DLL_EXPORT_HELPER
#undef QX_DLL_IMPORT_HELPER
#define QX_DLL_EXPORT_HELPER /* Nothing */
#define QX_DLL_IMPORT_HELPER /* Nothing */
#endif // _QX_USE_GCC_EXPORT_ALL_SYMBOLS
#endif // __GNUC__
#ifdef _QX_STATIC_BUILD
#undef QX_DLL_EXPORT_HELPER
#undef QX_DLL_IMPORT_HELPER
#define QX_DLL_EXPORT_HELPER /* Nothing */
#define QX_DLL_IMPORT_HELPER /* Nothing */
#endif // _QX_STATIC_BUILD
#ifndef QX_DLL_INTERNAL_HELPER
#if (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
#define QX_DLL_INTERNAL_HELPER __attribute__((visibility("hidden")))
#else
#define QX_DLL_INTERNAL_HELPER /* Nothing */
#endif // (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
#endif // QX_DLL_INTERNAL_HELPER
#ifndef QX_DLL_EXPORT_TEMPLATE_HELPER
#ifdef _MSC_VER
#define QX_DLL_EXPORT_TEMPLATE_HELPER QX_DLL_EXPORT_HELPER
#else // _MSC_VER
#define QX_DLL_EXPORT_TEMPLATE_HELPER /* Nothing */
#endif // _MSC_VER
#endif // QX_DLL_EXPORT_TEMPLATE_HELPER
#ifndef QX_DLL_IMPORT_TEMPLATE_HELPER
#ifdef _MSC_VER
#define QX_DLL_IMPORT_TEMPLATE_HELPER QX_DLL_IMPORT_HELPER
#else // _MSC_VER
#define QX_DLL_IMPORT_TEMPLATE_HELPER /* Nothing */
#endif // _MSC_VER
#endif // QX_DLL_IMPORT_TEMPLATE_HELPER
#ifndef QX_PRAGMA_VISIBILITY_BEGIN
#ifndef Q_OS_WIN
#if (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
#define QX_PRAGMA_VISIBILITY_BEGIN QX_PRAGMA(GCC visibility push(default))
#endif // (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
#endif // Q_OS_WIN
#ifndef QX_PRAGMA_VISIBILITY_BEGIN
#define QX_PRAGMA_VISIBILITY_BEGIN /* Nothing */
#endif // QX_PRAGMA_VISIBILITY_BEGIN
#endif // QX_PRAGMA_VISIBILITY_BEGIN
#ifndef QX_PRAGMA_VISIBILITY_END
#ifndef Q_OS_WIN
#if (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
#define QX_PRAGMA_VISIBILITY_END QX_PRAGMA(GCC visibility pop)
#endif // (_QX_USE_GCC_VISIBILITY && (__GNUC__ >= 4))
#endif // Q_OS_WIN
#ifndef QX_PRAGMA_VISIBILITY_END
#define QX_PRAGMA_VISIBILITY_END /* Nothing */
#endif // QX_PRAGMA_VISIBILITY_END
#endif // QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_HPP(CL, T) \
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T; \
QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(CL, T, P1) \
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T<P1>; \
QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_T_U_P1_HPP(CL, T, U, P1) \
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T<U<P1>>; \
QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_T_P1_P2_HPP(CL, T, P1, P2) \
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T<P1, P2>; \
QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_T_U_P1_P2_HPP(CL, T, U, P1, P2) \
QX_PRAGMA_VISIBILITY_BEGIN extern template CL QX_DLL_IMPORT_TEMPLATE_HELPER T<U<P1, P2>>; \
QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_CPP(CL, T) \
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T; \
QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_T_P1_CPP(CL, T, P1) \
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T<P1>; \
QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_T_U_P1_CPP(CL, T, U, P1) \
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T<U<P1>>; \
QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_T_P1_P2_CPP(CL, T, P1, P2) \
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T<P1, P2>; \
QX_PRAGMA_VISIBILITY_END
#define QX_DLL_EXPORT_TEMPLATE_T_U_P1_P2_CPP(CL, T, U, P1, P2) \
QX_PRAGMA_VISIBILITY_BEGIN template CL QX_DLL_EXPORT_TEMPLATE_HELPER T<U<P1, P2>>; \
QX_PRAGMA_VISIBILITY_END
#define QX_TEMPLATE_T(T) T<>
#define QX_TEMPLATE_T_P1(T, P1) T<P1>
#define QX_TEMPLATE_T_P1_P2(T, P1, P2) T<P1, P2>
#define QX_TEMPLATE_T_P1_P2_P3(T, P1, P2, P3) T<P1, P2, P3>
#define QX_TEMPLATE_T_U_P1(T, U, P1) T<U<P1>>
#define QX_TEMPLATE_T_U_P1_P2(T, U, P1, P2) T<U<P1, P2>>
#define QX_TEMPLATE_T_U_P1_P2_P3(T, U, P1, P2, P3) T<U<P1, P2, P3>>
#ifndef QX_DLL_EXPORT
#ifdef _QX_BUILDING_QX_ORM
#define QX_DLL_EXPORT QX_DLL_EXPORT_HELPER
#else // _QX_BUILDING_QX_ORM
#define QX_DLL_EXPORT QX_DLL_IMPORT_HELPER
#endif // _QX_BUILDING_QX_ORM
#endif // QX_DLL_EXPORT
#ifndef QX_DLL_EXPORT_QX_SINGLETON_HPP
#ifdef _QX_BUILDING_QX_ORM
#define QX_DLL_EXPORT_QX_SINGLETON_HPP(x) /* Nothing */
#else // _QX_BUILDING_QX_ORM
#define QX_DLL_EXPORT_QX_SINGLETON_HPP(x) QX_DLL_EXPORT_TEMPLATE_HPP(class, qx::QxSingleton<x>)
#endif // _QX_BUILDING_QX_ORM
#endif // QX_DLL_EXPORT_QX_SINGLETON_HPP
#ifndef QX_DLL_EXPORT_QX_SINGLETON_CPP
#ifdef _QX_BUILDING_QX_ORM
#define QX_DLL_EXPORT_QX_SINGLETON_CPP(x) QX_DLL_EXPORT_TEMPLATE_CPP(class, qx::QxSingleton<x>)
#else // _QX_BUILDING_QX_ORM
#define QX_DLL_EXPORT_QX_SINGLETON_CPP(x) /* Nothing */
#endif // _QX_BUILDING_QX_ORM
#endif // QX_DLL_EXPORT_QX_SINGLETON_CPP
#ifndef QX_DLL_EXPORT_INLINE_FCT
#ifdef _MSC_VER
#define QX_DLL_EXPORT_INLINE_FCT QX_DLL_EXPORT
#else // _MSC_VER
#define QX_DLL_EXPORT_INLINE_FCT /* Nothing */
#endif // _MSC_VER
#endif // QX_DLL_EXPORT_INLINE_FCT
#ifdef __GNUC__
#define QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE inline
#elif (defined(_MSC_VER) && (_MSC_VER >= 1920)) // MSVC 2019
#define QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE inline
#else
#define QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE /* Nothing */
#endif // __GNUC__
#ifdef _MSC_VER
#define QX_STRNCPY strncpy_s
#define QX_VSPRINTF vsprintf_s
#else // _MSC_VER
#define QX_STRNCPY strncpy
#define QX_VSPRINTF vsprintf
#endif // _MSC_VER
#ifdef _QX_MODE_RELEASE
#ifndef NDEBUG
#define NDEBUG
#endif // NDEBUG
#endif // _QX_MODE_RELEASE
// From file <boost/serialization/force_include.hpp> (written by Robert Ramey)
#if !defined(_WIN32) && !defined(_WIN64)
#if defined(__GNUC__) && (__GNUC__ >= 3)
#define QX_USED __attribute__((__used__))
#elif defined(__IBMCPP__) && (__IBMCPP__ >= 1110)
#define QX_USED __attribute__((__used__))
#elif defined(__INTEL_COMPILER)
#define QX_USED __attribute__((__used__))
#endif
#endif // ! defined(_WIN32) && ! defined(_WIN64)
#ifndef QX_USED
#define QX_USED /* Nothing */
#endif // QX_USED
#ifdef QT_NO_OPENSSL
#ifndef QT_NO_SSL
#define QT_NO_SSL /* Nothing */
#endif // QT_NO_SSL
#endif // QT_NO_OPENSSL
#ifndef Q_DECL_OVERRIDE
#define Q_DECL_OVERRIDE /* Nothing */
#endif // Q_DECL_OVERRIDE
#ifndef Q_DECL_FINAL
#define Q_DECL_FINAL /* Nothing */
#endif // Q_DECL_FINAL
#ifndef Q_DECL_HIDDEN
#define Q_DECL_HIDDEN /* Nothing */
#endif // Q_DECL_HIDDEN
#ifndef Q_DECL_NOEXCEPT
#define Q_DECL_NOEXCEPT /* Nothing */
#endif // Q_DECL_NOEXCEPT
#ifndef Q_NULLPTR
#define Q_NULLPTR NULL
#endif // Q_NULLPTR
// From 'QtCore' directory, 'qtversionchecks.h' file
#ifndef QT_VERSION_CHECK
#define QT_VERSION_CHECK(major, minor, patch) ((major << 16) | (minor << 8) | (patch))
#endif // QT_VERSION_CHECK
#endif // _QX_MACRO_H_

View File

@@ -0,0 +1,367 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
/* -- Main page for Doxygen documentation -- */
/*!
* \mainpage QxOrm - C++ Object Relational Mapping library
*
* QxOrm is a C++ library designed to provide Object Relational Mapping (ORM) feature to C++/Qt developers (like Hibernate in Java, or NHibernate in .Net).<br>
* QxOrm engine is based on a simple and non intrusive mapping function per class to provide :
*
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_30" target="_blank"><b>Persistence</b></a> (based on QtSql Qt module) ;
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_60" target="_blank"><b>Serialization</b></a> (JSON, XML and binary, based on Qt and boost serialization engines) ;
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_70" target="_blank"><b>Reflection</b></a> or <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_70" target="_blank"><b>Introspection</b></a> (invoke dynamically class methods and access to properties) ;
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_96" target="_blank"><b>HTTP web server</b></a> : standalone multi-threaded HTTP 1.1 web server (support SSL/TLS, persistent connections, cookies, sessions, chunked responses, URL dispatcher/routing) ;
* - <a href="https://www.qxorm.com/qxorm_en/manual.html#manual_97" target="_blank"><b>JSON API</b></a> : interoperability with other technology than C++/Qt (REST web services, QML applications, scripting language).
*
* QxOrm is developed by XDL Team, a software development engineer since 2003.<br>
* QxOrm library has been accepted into the <a href="http://forum.qt.io/category/24/qt-ambassador-program" target="_blank">Qt Ambassador Program</a>.<br>
* QxOrm library is available on <a href="https://github.com/QxOrm/QxOrm" target="_blank">GitHub</a>.
*
* For more information about QxOrm library (quick sample, tutorial and forum), please visit : <a href="https://www.qxorm.com/" target="_blank">https://www.qxorm.com/</a>.<br>
* <a href="https://www.qxorm.com/qxorm_en/manual.html" target="_blank">A manual (user guide) to learn how to work with QxOrm library is available on QxOrm website</a>.
* <br><br>
*
* \section quick_sample Quick sample using QxOrm library
*
* 1- <i>drug.h</i> file : drug class definition with 3 properties : <i>id</i>, <i>name</i> and <i>description</i>
* \code
#ifndef _CLASS_DRUG_H_
#define _CLASS_DRUG_H_
class drug
{
public:
long id;
QString name;
QString description;
drug() : id(0) { ; }
virtual ~drug() { ; }
};
QX_REGISTER_HPP_MY_TEST_EXE(drug, qx::trait::no_base_class_defined, 1)
// This macro is necessary to register 'drug' class in QxOrm context
// param 1 : the current class to register => 'drug'
// param 2 : the base class, if no base class, use the qx trait => 'qx::trait::no_base_class_defined'
// param 3 : the class version used by serialization to provide 'ascendant compatibility'
#endif // _CLASS_DRUG_H_
* \endcode
*
* <br>
* 2- <i>drug.cpp</i> file : setting function implementation - <i>void qx::register_class()</i>
* \code
#include "precompiled.h" // Precompiled-header with '#include <QxOrm.h>' and '#include "export.h"'
#include "drug.h" // Class definition 'drug'
#include <QxOrm_Impl.h> // Automatic memory leak detection and boost serialization export macro
QX_REGISTER_CPP_MY_TEST_EXE(drug) // This macro is necessary to register 'drug' class in QxOrm context
namespace qx {
template <> void register_class(QxClass<drug> & t)
{
t.id(& drug::id, "id"); // Register 'drug::id' <=> primary key in your database
t.data(& drug::name, "name", 1); // Register 'drug::name' property with key 'name' and version '1'
t.data(& drug::description, "desc"); // Register 'drug::description' property with key 'desc'
}}
* \endcode
*
* <br>
* 3- <i>main.cpp</i> file : basic functionalities of QxOrm library with drug class
* \code
#include "precompiled.h"
#include "drug.h"
#include <QxOrm_Impl.h>
int main(int argc, char * argv[])
{
QApplication app(argc, argv); // Qt application
// Create 3 new drugs
// It is possible to use 'boost' and 'Qt' smart pointer : 'boost::shared_ptr', 'QSharedPointer', etc...
typedef std::shared_ptr<drug> drug_ptr;
drug_ptr d1; d1.reset(new drug()); d1->name = "name1"; d1->description = "desc1";
drug_ptr d2; d2.reset(new drug()); d2->name = "name2"; d2->description = "desc2";
drug_ptr d3; d3.reset(new drug()); d3->name = "name3"; d3->description = "desc3";
// Insert drugs into container
// It is possible to use a lot of containers from 'std', 'boost', 'Qt' and 'qx::QxCollection<Key, Value>'
typedef std::vector<drug_ptr> type_lst_drug;
type_lst_drug lst_drug;
lst_drug.push_back(d1);
lst_drug.push_back(d2);
lst_drug.push_back(d3);
// Init parameters to communicate with a database
qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE");
qx::QxSqlDatabase::getSingleton()->setDatabaseName("./test_qxorm.db");
qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
qx::QxSqlDatabase::getSingleton()->setUserName("root");
qx::QxSqlDatabase::getSingleton()->setPassword("");
// Create table 'drug' into database to store drugs
QSqlError daoError = qx::dao::create_table<drug>();
// Insert drugs from container to database
// 'id' property of 'd1', 'd2' and 'd3' are auto-updated
daoError = qx::dao::insert(lst_drug);
// Modify and update the second drug into database
d2->name = "name2 modified";
d2->description = "desc2 modified";
daoError = qx::dao::update(d2);
// Delete the first drug from database
daoError = qx::dao::delete_by_id(d1);
// Count drugs into database
long lDrugCount = qx::dao::count<drug>();
// Fetch drug with id '3' into a new variable
drug_ptr d_tmp; d_tmp.reset(new drug());
d_tmp->id = 3;
daoError = qx::dao::fetch_by_id(d_tmp);
// Export drugs from container to a file under XML format (serialization)
qx::serialization::xml::to_file(lst_drug, "./export_drugs.xml");
// Import drugs from XML file into a new container
type_lst_drug lst_drug_tmp;
qx::serialization::xml::from_file(lst_drug_tmp, "./export_drugs.xml");
// Clone a drug
drug_ptr d_clone = qx::clone(* d1);
// Create a new drug by class name (factory)
qx::any d_any = qx::create("drug");
// Insert drugs container into 'qx::cache'
qx::cache::set("drugs", lst_drug);
// Remove all elements from 'qx::cache'
qx::cache::clear();
// Create a dummy memory leak
drug * pDummy = new drug();
return 0;
}
* \endcode
*
* <br>
* 4- execute program and trace output debug
* \code
[QxOrm] qx::QxSqlDatabase : create new database connection in thread '3616' with key '{d315250c-b5c9-46e0-9402-f800368a6673}'
[QxOrm] sql query (78 ms) : CREATE TABLE drug (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, name TEXT, desc TEXT)
[QxOrm] sql query (63 ms) : INSERT INTO drug (name, desc) VALUES (:name, :desc)
[QxOrm] sql query (62 ms) : UPDATE drug SET id = :id, name = :name, desc = :desc WHERE id = :id_bis
[QxOrm] sql query (63 ms) : DELETE FROM drug WHERE id = :id
[QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM drug
[QxOrm] sql query (0 ms) : SELECT drug.id AS drug_id_0, drug.name AS drug_name_0, drug.desc AS drug_desc_0 FROM drug WHERE drug_id_0 = :id
[QxOrm] Leaked object at 0xf52ad8 (size 16, src\main.cpp:74)
[QxOrm] **** 1 memory leaks found ****
* \endcode
*
* <br>
* 5- <i>export_drugs.xml</i> file created by the program
* \code
<std.vector-boost.shared_ptr-drug-- class_id="0" tracking_level="0" version="0">
<count>3</count>
<item_version>1</item_version>
<item class_id="1" tracking_level="0" version="1">
<px class_id="2" tracking_level="1" version="1" object_id="_0">
<id>1</id>
<name class_id="3" tracking_level="0" version="0">name1</name>
<desc>desc1</desc>
</px>
</item>
<item>
<px class_id_reference="2" object_id="_1">
<id>2</id>
<name>name2 modified</name>
<desc>desc2 modified</desc>
</px>
</item>
<item>
<px class_id_reference="2" object_id="_2">
<id>3</id>
<name>name3</name>
<desc>desc3</desc>
</px>
</item>
</std.vector-boost.shared_ptr-drug-->
* \endcode
*/
/*!
* \brief Root namespace for all QxOrm library features
*/
namespace qx
{
/*!
* \ingroup QxCache
* \brief Provide basic thread-safe cache feature to backup and restore any kind of objects (for example, object fetched from database)
*/
namespace cache
{
/*!
* \ingroup QxCache
* \brief Internal helper tools for qx::cache namespace
*/
namespace detail
{
} // namespace detail
} // namespace cache
/*!
* \ingroup QxDao
* \brief Database communication used by persistence engine (ORM - Object Relational Mapping)
*/
namespace dao
{
/*!
* \ingroup QxDao
* \brief Internal helper tools for qx::dao namespace
*/
namespace detail
{
} // namespace detail
} // namespace dao
/*!
* \ingroup QxFunction
* \brief Register function into QxOrm context used by introspection engine
*/
namespace function
{
/*!
* \ingroup QxFunction
* \brief Internal helper tools for qx::function namespace
*/
namespace detail
{
} // namespace detail
} // namespace function
/*!
* \ingroup QxMemLeak
* \brief QxOrm library memory leak detection (by Wu Yongwei)
*/
namespace memory
{
} // namespace memory
/*!
* \ingroup QxSerialize
* \brief QxOrm library serialization engine based on boost::serialization library
*/
namespace serialization
{
/*!
* \ingroup QxSerialize
* \brief Internal helper tools for qx::serialization namespace
*/
namespace detail
{
} // namespace detail
/*!
* \ingroup QxSerialize
* \brief QxOrm library serialization engine for wide archive
*/
namespace wide
{
} // namespace wide
} // namespace serialization
/*!
* \ingroup QxService
* \brief QxOrm library services engine to provide easy and powerful way to create C++ application server (to transfer data over network)
*/
namespace service
{
} // namespace service
/*!
* \ingroup QxTraits
* \brief QxOrm library traits (template metaprogramming) not available in boost::type_traits library
*/
namespace trait
{
/*!
* \ingroup QxTraits
* \brief Internal helper tools for qx::trait namespace
*/
namespace detail
{
} // namespace detail
} // namespace trait
/*!
* \ingroup QxCollection
* \brief Foreach-style (based on BOOST_FOREACH macro) to iterate over all stl, boost and Qt containers + qx::QxCollection<Key, Value> QxOrm library container
*/
namespace foreach
{
} // namespace foreach
/*!
* \ingroup QxCommon
* \brief Provide global functions to convert any kind of objects to/from QString and QVariant format
*/
namespace cvt
{
/*!
* \ingroup QxCommon
* \brief Internal helper tools for qx::cvt namespace
*/
namespace detail
{
} // namespace detail
} // namespace cvt
} // namespace qx

View File

@@ -0,0 +1,105 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_PROPERTY_BAG_H_
#define _QX_PROPERTY_BAG_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxPropertyBag.h
* \author XDL Team
* \ingroup QxCommon
* \brief Used by introspection engine (IxClass, IxDataMember, IxFunction, etc.) to add meta-data (property bag)
*/
#include <QtCore/qhash.h>
#include <QtCore/qstring.h>
#include <QtCore/qvariant.h>
namespace qx
{
/*!
* \ingroup QxCommon
* \brief qx::QxPropertyBag : used by introspection engine (IxClass, IxDataMember, IxFunction, etc.) to add meta-data (property bag)
*/
class QxPropertyBag
{
protected:
typedef QHash<QString, QVariant> type_hash_prop_bag;
typedef std::shared_ptr<type_hash_prop_bag> type_hash_prop_bag_ptr;
type_hash_prop_bag_ptr m_lstPropertyBag; //!< List of all properties in the bag (meta-data)
public:
QxPropertyBag() { ; }
virtual ~QxPropertyBag() { ; }
void setPropertyBag(const QString &key, const QVariant &value)
{
initPropertyBag();
m_lstPropertyBag->insert(key, value);
}
QVariant getPropertyBag(const QString &key) const { return ((m_lstPropertyBag && m_lstPropertyBag->contains(key)) ? m_lstPropertyBag->value(key) : QVariant()); }
void removePropertyBag(const QString &key)
{
if (m_lstPropertyBag)
{
m_lstPropertyBag->remove(key);
}
}
void clearPropertyBag()
{
if (m_lstPropertyBag)
{
m_lstPropertyBag->clear();
}
}
long countPropertyBag() const { return (m_lstPropertyBag ? m_lstPropertyBag->count() : 0); }
QList<QString> getAllPropertyBagKeys() const { return (m_lstPropertyBag ? m_lstPropertyBag->keys() : QList<QString>()); }
private:
inline void initPropertyBag()
{
if (!m_lstPropertyBag)
{
m_lstPropertyBag = std::make_shared<type_hash_prop_bag>();
}
}
};
} // namespace qx
#endif // _QX_PROPERTY_BAG_H_

View File

@@ -0,0 +1,250 @@
/*
Copyright (c) 2011, Andre Somers
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the Rathenau Instituut, Andre Somers nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL ANDRE SOMERS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _QX_SIMPLECRYPT_H_
#define _QX_SIMPLECRYPT_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSimpleCrypt.h
* \author Andre Somers
* \ingroup QxCommon
* \brief qx::QxSimpleCrypt : simple encryption and decryption of strings and byte arrays
*/
#include <QtCore/qglobal.h>
#include <QtCore/qstring.h>
#include <QtCore/qvector.h>
#include <QtCore/qbytearray.h>
namespace qx {
/**
@ingroup QxCommon
@short Simple encryption and decryption of strings and byte arrays
This class provides a simple implementation of encryption and decryption
of strings and byte arrays : http://qt-project.org/wiki/Simple_encryption
@warning The encryption provided by this class is NOT strong encryption. It may
help to shield things from curious eyes, but it will NOT stand up to someone
determined to break the encryption. Don't say you were not warned.
The class uses a 64 bit key. Simply create an instance of the class, set the key,
and use the encryptToString() method to calculate an encrypted version of the input string.
To decrypt that string again, use an instance of QxSimpleCrypt initialized with
the same key, and call the decryptToString() method with the encrypted string. If the key
matches, the decrypted version of the string will be returned again.
If you do not provide a key, or if something else is wrong, the encryption and
decryption function will return an empty string or will return a string containing nonsense.
lastError() will return a value indicating if the method was succesful, and if not, why not.
QxSimpleCrypt is prepared for the case that the encryption and decryption
algorithm is changed in a later version, by prepending a version identifier to the cypertext.
*/
class QX_DLL_EXPORT QxSimpleCrypt
{
public:
/**
CompressionMode describes if compression will be applied to the data to be
encrypted.
*/
enum CompressionMode {
CompressionAuto, /*!< Only apply compression if that results in a shorter plaintext. */
CompressionAlways, /*!< Always apply compression. Note that for short inputs, a compression may result in longer data */
CompressionNever /*!< Never apply compression. */
};
/**
IntegrityProtectionMode describes measures taken to make it possible to detect problems with the data
or wrong decryption keys.
Measures involve adding a checksum or a cryptograhpic hash to the data to be encrypted. This
increases the length of the resulting cypertext, but makes it possible to check if the plaintext
appears to be valid after decryption.
*/
enum IntegrityProtectionMode {
ProtectionNone, /*!< The integerity of the encrypted data is not protected. It is not really possible to detect a wrong key, for instance. */
ProtectionChecksum,/*!< A simple checksum is used to verify that the data is in order. If not, an empty string is returned. */
ProtectionHash /*!< A cryptographic hash is used to verify the integrity of the data. This method produces a much stronger, but longer check */
};
/**
Error describes the type of error that occured.
*/
enum Error {
ErrorNoError, /*!< No error occurred. */
ErrorNoKeySet, /*!< No key was set. You can not encrypt or decrypt without a valid key. */
ErrorUnknownVersion, /*!< The version of this data is unknown, or the data is otherwise not valid. */
ErrorIntegrityFailed, /*!< The integrity check of the data failed. Perhaps the wrong key was used. */
};
/**
Constructor.
Constructs a QxSimpleCrypt instance without a valid key set on it.
*/
QxSimpleCrypt();
/**
Constructor.
Constructs a QxSimpleCrypt instance and initializes it with the given @arg key.
*/
explicit QxSimpleCrypt(quint64 key);
/**
(Re-) initializes the key with the given @arg key.
*/
void setKey(quint64 key);
/**
Returns true if QxSimpleCrypt has been initialized with a key.
*/
bool hasKey() const {return !m_keyParts.isEmpty();}
/**
Sets the compression mode to use when encrypting data. The default mode is Auto.
Note that decryption is not influenced by this mode, as the decryption recognizes
what mode was used when encrypting.
*/
void setCompressionMode(CompressionMode mode) {m_compressionMode = mode;}
/**
Returns the CompressionMode that is currently in use.
*/
CompressionMode compressionMode() const {return m_compressionMode;}
/**
Sets the integrity mode to use when encrypting data. The default mode is Checksum.
Note that decryption is not influenced by this mode, as the decryption recognizes
what mode was used when encrypting.
*/
void setIntegrityProtectionMode(IntegrityProtectionMode mode) {m_protectionMode = mode;}
/**
Returns the IntegrityProtectionMode that is currently in use.
*/
IntegrityProtectionMode integrityProtectionMode() const {return m_protectionMode;}
/**
Returns the last error that occurred.
*/
Error lastError() const {return m_lastError;}
/**
Encrypts the @arg plaintext string with the key the class was initialized with, and returns
a cyphertext the result. The result is a base64 encoded version of the binary array that is the
actual result of the string, so it can be stored easily in a text format.
*/
QString encryptToString(const QString& plaintext) ;
/**
Encrypts the @arg plaintext QByteArray with the key the class was initialized with, and returns
a cyphertext the result. The result is a base64 encoded version of the binary array that is the
actual result of the encryption, so it can be stored easily in a text format.
*/
QString encryptToString(QByteArray plaintext) ;
/**
Encrypts the @arg plaintext string with the key the class was initialized with, and returns
a binary cyphertext in a QByteArray the result.
This method returns a byte array, that is useable for storing a binary format. If you need
a string you can store in a text file, use encryptToString() instead.
*/
QByteArray encryptToByteArray(const QString& plaintext) ;
/**
Encrypts the @arg plaintext QByteArray with the key the class was initialized with, and returns
a binary cyphertext in a QByteArray the result.
This method returns a byte array, that is useable for storing a binary format. If you need
a string you can store in a text file, use encryptToString() instead.
*/
QByteArray encryptToByteArray(QByteArray plaintext) ;
/**
Decrypts a cyphertext string encrypted with this class with the set key back to the
plain text version.
If an error occured, such as non-matching keys between encryption and decryption,
an empty string or a string containing nonsense may be returned.
*/
QString decryptToString(const QString& cyphertext) ;
/**
Decrypts a cyphertext string encrypted with this class with the set key back to the
plain text version.
If an error occured, such as non-matching keys between encryption and decryption,
an empty string or a string containing nonsense may be returned.
*/
QByteArray decryptToByteArray(const QString& cyphertext) ;
/**
Decrypts a cyphertext binary encrypted with this class with the set key back to the
plain text version.
If an error occured, such as non-matching keys between encryption and decryption,
an empty string or a string containing nonsense may be returned.
*/
QString decryptToString(QByteArray cypher) ;
/**
Decrypts a cyphertext binary encrypted with this class with the set key back to the
plain text version.
If an error occured, such as non-matching keys between encryption and decryption,
an empty string or a string containing nonsense may be returned.
*/
QByteArray decryptToByteArray(QByteArray cypher) ;
// enum to describe options that have been used for the encryption. Currently only one, but
// that only leaves room for future extensions like adding a cryptographic hash...
enum CryptoFlag{CryptoFlagNone = 0,
CryptoFlagCompression = 0x01,
CryptoFlagChecksum = 0x02,
CryptoFlagHash = 0x04
};
Q_DECLARE_FLAGS(CryptoFlags, CryptoFlag);
private:
void splitKey();
quint64 m_key;
QVector<char> m_keyParts;
CompressionMode m_compressionMode;
IntegrityProtectionMode m_protectionMode;
Error m_lastError;
};
} // namespace qx
Q_DECLARE_OPERATORS_FOR_FLAGS(qx::QxSimpleCrypt::CryptoFlags)
#endif // _QX_SIMPLECRYPT_H_

View File

@@ -0,0 +1,117 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_CONVERT_H_
#define _QX_CONVERT_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxConvert.h
* \author XDL Team
* \ingroup QxConvert
* \brief qx::cvt : namespace to provide global functions to convert any kind of objects to/from QString and QVariant format
*/
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#include <QtCore/qjsonobject.h>
#include <QtCore/qjsonarray.h>
#include <QtCore/qjsondocument.h>
#endif // _QX_NO_JSON
#include <QxCommon/QxBool.h>
namespace qx
{
namespace cvt
{
namespace detail
{
template <typename T>
struct QxConvert_ToString;
template <typename T>
struct QxConvert_FromString;
template <typename T>
struct QxConvert_ToVariant;
template <typename T>
struct QxConvert_FromVariant;
template <typename T>
struct QxConvert_WithIndex_ToString;
template <typename T>
struct QxConvert_WithIndex_FromString;
template <typename T>
struct QxConvert_WithIndex_ToVariant;
template <typename T>
struct QxConvert_WithIndex_FromVariant;
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvert_ToJson;
template <typename T>
struct QxConvert_FromJson;
#endif // _QX_NO_JSON
} // namespace detail
struct context
{
enum ctx_type
{
e_no_context,
e_database,
e_serialize_registered
};
};
template <typename T>
inline QString to_string(const T &t, const QString &format = QString(), int index = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) { return qx::cvt::detail::QxConvert_WithIndex_ToString<T>::toString(t, format, index, ctx); }
template <typename T>
inline qx_bool from_string(const QString &s, T &t, const QString &format = QString(), int index = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) { return qx::cvt::detail::QxConvert_WithIndex_FromString<T>::fromString(t, s, format, index, ctx); }
template <typename T>
inline QVariant to_variant(const T &t, const QString &format = QString(), int index = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) { return qx::cvt::detail::QxConvert_WithIndex_ToVariant<T>::toVariant(t, format, index, ctx); }
template <typename T>
inline qx_bool from_variant(const QVariant &v, T &t, const QString &format = QString(), int index = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) { return qx::cvt::detail::QxConvert_WithIndex_FromVariant<T>::fromVariant(t, v, format, index, ctx); }
#ifndef _QX_NO_JSON
template <typename T>
inline QJsonValue to_json(const T &t, const QString &format = QString()) { return qx::cvt::detail::QxConvert_ToJson<T>::toJson(t, format); }
template <typename T>
inline qx_bool from_json(const QJsonValue &j, T &t, const QString &format = QString()) { return qx::cvt::detail::QxConvert_FromJson<T>::fromJson(j, t, format); }
#endif // _QX_NO_JSON
} // namespace cvt
} // namespace qx
#endif // _QX_CONVERT_H_

View File

@@ -0,0 +1,224 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_CONVERT_EXPORT_H_
#define _QX_CONVERT_EXPORT_H_
#if _QX_USE_QX_CONVERT_EXPORT
#ifdef _MSC_VER
#pragma once
#endif
#include <QxConvert/QxConvert.h>
#include <QxConvert/QxConvert_Impl.h>
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, qx::trait::no_type)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QString)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QDate)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QTime)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QDateTime)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QByteArray)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QVariant)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, qx_bool)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, bool)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, char)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, short)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, int)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, long long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, float)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, double)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, unsigned short)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, unsigned int)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, unsigned long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, unsigned long long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, std::string)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, std::wstring)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QBrush)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QColor)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QFont)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QObject)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QPoint)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QRect)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QRegion)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QSize)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QStringList)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QUrl)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QImage)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QPicture)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QPixmap)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QUuid)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, qx::QxDateNeutral)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, qx::QxTimeNeutral)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, qx::QxDateTimeNeutral)
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QRegExp)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToString, QMatrix)
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, qx::trait::no_type)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QString)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QDate)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QTime)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QDateTime)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QByteArray)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QVariant)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, qx_bool)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, bool)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, char)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, short)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, int)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, long long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, float)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, double)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, unsigned short)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, unsigned int)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, unsigned long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, unsigned long long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, std::string)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, std::wstring)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QBrush)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QColor)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QFont)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QObject)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QPoint)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QRect)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QRegion)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QSize)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QStringList)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QUrl)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QImage)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QPicture)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QPixmap)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QUuid)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, qx::QxDateNeutral)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, qx::QxTimeNeutral)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, qx::QxDateTimeNeutral)
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QRegExp)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromString, QMatrix)
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, qx::trait::no_type)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QString)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QDate)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QTime)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QDateTime)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QByteArray)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QVariant)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, qx_bool)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, bool)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, char)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, short)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, int)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, long long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, float)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, double)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, unsigned short)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, unsigned int)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, unsigned long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, unsigned long long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, std::string)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, std::wstring)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QBrush)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QColor)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QFont)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QObject)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QPoint)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QRect)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QRegion)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QSize)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QStringList)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QUrl)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QImage)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QPicture)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QPixmap)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QUuid)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, qx::QxDateNeutral)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, qx::QxTimeNeutral)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, qx::QxDateTimeNeutral)
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QRegExp)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_ToVariant, QMatrix)
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, qx::trait::no_type)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QString)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QDate)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QTime)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QDateTime)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QByteArray)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QVariant)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, qx_bool)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, bool)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, char)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, short)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, int)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, long long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, float)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, double)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, unsigned short)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, unsigned int)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, unsigned long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, unsigned long long)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, std::string)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, std::wstring)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QBrush)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QColor)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QFont)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QObject)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QPoint)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QRect)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QRegion)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QSize)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QStringList)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QUrl)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QImage)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QPicture)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QPixmap)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QUuid)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, qx::QxDateNeutral)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, qx::QxTimeNeutral)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, qx::QxDateTimeNeutral)
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QRegExp)
QX_DLL_EXPORT_TEMPLATE_T_P1_HPP(struct, qx::cvt::detail::QxConvert_FromVariant, QMatrix)
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#endif // _QX_USE_QX_CONVERT_EXPORT
#endif // _QX_CONVERT_EXPORT_H_

View File

@@ -0,0 +1,906 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_CONVERT_IMPL_H_
#define _QX_CONVERT_IMPL_H_
#ifdef _MSC_VER
#pragma once
#endif
#include <QxConvert/QxConvert.h>
#include <QxCommon/QxBool.h>
#include <QxDao/QxDateNeutral.h>
#include <QxDao/QxTimeNeutral.h>
#include <QxDao/QxDateTimeNeutral.h>
#include <QxDao/QxSqlQuery.h>
#include <QxDao/IxPersistable.h>
#include <QxCollection/QxCollection.h>
#include <QxRegister/QxClass.h>
#include <QxSerialize/QxArchive.h>
#include <QxSerialize/QxSerializeQDataStream.h>
#include <QxSerialize/QDataStream/QxSerializeQDataStream_all_include.h>
#include <QxSerialize/QJson/QxSerializeQJson_qx_registered_class.h>
#include <QxValidator/QxInvalidValue.h>
#include <QxValidator/QxInvalidValueX.h>
#include <QxTraits/is_smart_ptr.h>
#include <QxTraits/is_container.h>
#include <QxTraits/is_qx_registered.h>
#include <QxTraits/is_qt_variant_compatible.h>
#include <QxTraits/get_class_name_primitive.h>
#include <QxTraits/construct_ptr.h>
#include <QxTraits/generic_container.h>
#define QX_STR_CVT_QDATE_FORMAT "yyyyMMdd"
#define QX_STR_CVT_QTIME_FORMAT "hhmmsszzz"
#define QX_STR_CVT_QDATETIME_FORMAT "yyyyMMddhhmmsszzz"
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::polymorphic_xml
#elif _QX_SERIALIZE_XML
#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::xml
#elif _QX_SERIALIZE_TEXT
#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::text
#elif _QX_SERIALIZE_BINARY
#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::binary
#endif // _QX_SERIALIZE_XML
#else // _QX_ENABLE_BOOST_SERIALIZATION
#define QX_CVT_DEFAULT_ARCHIVE qx::serialization::qt
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#define QX_CVT_USING_ARCHIVE_IMPL(className) \
namespace qx \
{ \
namespace cvt \
{ \
namespace detail \
{ \
template <> \
struct QxConvert_ToString<className> \
{ \
static inline QString toString(const className &t, const QString &format, int index, qx::cvt::context::ctx_type ctx) \
{ \
Q_UNUSED(format); \
Q_UNUSED(index); \
Q_UNUSED(ctx); \
return QX_CVT_DEFAULT_ARCHIVE::to_string(t); \
} \
}; \
template <> \
struct QxConvert_FromString<className> \
{ \
static inline qx_bool fromString(const QString &s, className &t, const QString &format, int index, qx::cvt::context::ctx_type ctx) \
{ \
Q_UNUSED(format); \
Q_UNUSED(index); \
Q_UNUSED(ctx); \
return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); \
} \
}; \
template <> \
struct QxConvert_ToVariant<className> \
{ \
static inline QVariant toVariant(const className &t, const QString &format, int index, qx::cvt::context::ctx_type ctx) \
{ \
Q_UNUSED(format); \
Q_UNUSED(index); \
Q_UNUSED(ctx); \
return QX_CVT_DEFAULT_ARCHIVE::to_string(t); \
} \
}; \
template <> \
struct QxConvert_FromVariant<className> \
{ \
static inline qx_bool fromVariant(const QVariant &v, className &t, const QString &format, int index, qx::cvt::context::ctx_type ctx) \
{ \
Q_UNUSED(format); \
Q_UNUSED(index); \
Q_UNUSED(ctx); \
QString s = v.toString(); \
return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s); \
} \
}; \
} \
} \
} // namespace qx::cvt::detail
#if (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
#define QX_JSON_DATE_TIME_FORMAT Qt::ISODateWithMs
#define QX_JSON_DATE_TIME_FORMAT_SIZE 23 // yyyy-MM-ddTHH:mm:ss.zzz
#else // (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
#define QX_JSON_DATE_TIME_FORMAT Qt::ISODate
#define QX_JSON_DATE_TIME_FORMAT_SIZE 19 // yyyy-MM-ddTHH:mm:ss
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 8, 0))
namespace qx
{
namespace cvt
{
namespace detail
{
namespace helper
{
struct QxConvertHelper_Generic
{
};
struct QxConvertHelper_Ptr
{
};
struct QxConvertHelper_Registered
{
};
struct QxConvertHelper_Persistable
{
};
struct QxConvertHelper_Container
{
};
struct QxConvertHelper_Enum
{
};
inline bool checkConvertQVariantToString(const QVariant &v) { return ((v.type() == QVariant::List) || (v.type() == QVariant::Map) || (v.type() == QVariant::Hash) || (v.type() == QVariant::StringList)); }
} // namespace helper
template <typename T, typename H>
struct QxConvertHelper_ToString
{
static inline QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_ToString", "template must be specialized");
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString();
}
};
template <typename T, typename H>
struct QxConvertHelper_FromString
{
static inline qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_FromString", "template must be specialized");
Q_UNUSED(s);
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return qx_bool();
}
};
template <typename T, typename H>
struct QxConvertHelper_ToVariant
{
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_ToVariant", "template must be specialized");
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QVariant();
}
};
template <typename T, typename H>
struct QxConvertHelper_FromVariant
{
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_FromVariant", "template must be specialized");
Q_UNUSED(v);
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return qx_bool();
}
};
#ifndef _QX_NO_JSON
template <typename T, typename H>
struct QxConvertHelper_ToJson
{
static inline QJsonValue toJson(const T &t, const QString &format)
{
qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_ToJson", "template must be specialized");
Q_UNUSED(t);
Q_UNUSED(format);
return QJsonValue();
}
};
template <typename T, typename H>
struct QxConvertHelper_FromJson
{
static inline qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
{
qAssertMsg(false, "qx::cvt::detail::QxConvertHelper_FromJson", "template must be specialized");
Q_UNUSED(j);
Q_UNUSED(t);
Q_UNUSED(format);
return qx_bool();
}
};
#endif // _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
{
enum
{
qx_need_to_specialize_template_convert_to_string_from_string = 0
};
static inline QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
static_assert(qx_need_to_specialize_template_convert_to_string_from_string, "qx_need_to_specialize_template_convert_to_string_from_string"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_ToString< MyType >'
return QString();
}
};
template <typename T>
struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
{
enum
{
qx_need_to_specialize_template_convert_to_string_from_string = 0
};
static inline qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(s);
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
static_assert(qx_need_to_specialize_template_convert_to_string_from_string, "qx_need_to_specialize_template_convert_to_string_from_string"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_FromString< MyType >'
return qx_bool(true);
}
};
template <typename T>
struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
{
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
return cvtQVariant<qx::trait::is_qt_variant_compatible<T>::value, 0>::toVariant(t, format, index, ctx);
}
private:
template <bool isQVariantCompatible /* = false */, int dummy>
struct cvtQVariant
{
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx) { return qx::cvt::to_string(t, format, index, ctx); };
};
template <int dummy>
struct cvtQVariant<true, dummy>
{
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QVariant(t);
};
};
};
template <typename T>
struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
{
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
return cvtQVariant<qx::trait::is_qt_variant_compatible<T>::value, 0>::fromVariant(v, t, format, index, ctx);
}
private:
template <bool isQVariantCompatible /* = false */, int dummy>
struct cvtQVariant
{
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx) { return qx::cvt::from_string(v.toString(), t, format, index, ctx); };
};
template <int dummy>
struct cvtQVariant<true, dummy>
{
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.value<T>();
return qx_bool(true);
};
};
};
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
{
static inline QJsonValue toJson(const T &t, const QString &format)
{
return QJsonValue::fromVariant(qx::cvt::detail::QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>::toVariant(t, format, -1, qx::cvt::context::e_no_context));
}
};
template <typename T>
struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Generic>
{
static inline qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
{
QVariant v = j.toVariant();
return qx::cvt::detail::QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Generic>::fromVariant(v, t, format, -1, qx::cvt::context::e_no_context);
}
};
#endif // _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
{
enum
{
qx_need_to_specialize_template_convert_to_string_from_string = 0
};
static inline QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
#ifndef _QX_NO_JSON
return t.toJson(format);
#else // _QX_NO_JSON
static_assert(qx_need_to_specialize_template_convert_to_string_from_string, "qx_need_to_specialize_template_convert_to_string_from_string"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_ToString< MyType >'
return QString();
#endif // _QX_NO_JSON
}
};
template <typename T>
struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
{
enum
{
qx_need_to_specialize_template_convert_to_string_from_string = 0
};
static inline qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(s);
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
#ifndef _QX_NO_JSON
return t.fromJson(s, format);
#else // _QX_NO_JSON
static_assert(qx_need_to_specialize_template_convert_to_string_from_string, "qx_need_to_specialize_template_convert_to_string_from_string"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_FromString< MyType >'
return qx_bool(true);
#endif // _QX_NO_JSON
}
};
template <typename T>
struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
{
enum
{
qx_need_to_specialize_template_convert_to_variant_from_variant = 0
};
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
#ifndef _QX_NO_JSON
return QVariant(t.toJson(format));
#else // _QX_NO_JSON
static_assert(qx_need_to_specialize_template_convert_to_variant_from_variant, "qx_need_to_specialize_template_convert_to_variant_from_variant"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_ToVariant< MyType >'
return QVariant();
#endif // _QX_NO_JSON
}
};
template <typename T>
struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
{
enum
{
qx_need_to_specialize_template_convert_to_variant_from_variant = 0
};
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(v);
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
#ifndef _QX_NO_JSON
return t.fromJson(v.toString(), format);
#else // _QX_NO_JSON
static_assert(qx_need_to_specialize_template_convert_to_variant_from_variant, "qx_need_to_specialize_template_convert_to_variant_from_variant"); // If a compilation error occurred here : you have to specialize template 'qx::cvt::detail::QxConvert_FromVariant< MyType >'
return qx_bool(true);
#endif // _QX_NO_JSON
}
};
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
{
static inline QJsonValue toJson(const T &t, const QString &format)
{
const qx::IxPersistable *p = static_cast<const qx::IxPersistable *>(&t);
return qx::cvt::to_json((*p), format);
}
};
template <typename T>
struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Persistable>
{
static inline qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
{
qx::IxPersistable *p = static_cast<qx::IxPersistable *>(&t);
return qx::cvt::from_json(j, (*p), format);
}
};
#endif // _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
{
static inline QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
return (t ? qx::cvt::to_string((*t), format, index, ctx) : "");
}
};
template <typename T>
struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
{
static inline qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (!t)
{
qx::trait::construct_ptr<T>::get(t);
};
return (t ? qx::cvt::from_string(s, (*t), format, index, ctx) : qx_bool(false));
}
};
template <typename T>
struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
{
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
return (t ? qx::cvt::to_variant((*t), format, index, ctx) : QVariant());
}
};
template <typename T>
struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
{
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (!t && !v.isNull())
{
qx::trait::construct_ptr<T>::get(t);
}
else if (v.isNull())
{
qx::trait::construct_ptr<T>::get(t, true);
};
return (t ? qx::cvt::from_variant(v, (*t), format, index, ctx) : qx_bool(false));
}
};
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
{
static inline QJsonValue toJson(const T &t, const QString &format)
{
return (t ? qx::cvt::to_json((*t), format) : QJsonValue());
}
};
template <typename T>
struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Ptr>
{
static inline qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
{
if (!t && !j.isNull())
{
qx::trait::construct_ptr<T>::get(t);
}
else if (j.isNull())
{
qx::trait::construct_ptr<T>::get(t, true);
};
return (t ? qx::cvt::from_json(j, (*t), format) : qx_bool(false));
}
};
#endif // _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
{
static inline QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (ctx != qx::cvt::context::e_serialize_registered)
{
qx::IxDataMember *pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy();
return (pId ? pId->toVariant((&t), format, index, ctx).toString() : QString());
}
return qx::serialization::qt::to_string<T>(t);
}
};
template <typename T>
struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
{
static inline qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (ctx != qx::cvt::context::e_serialize_registered)
{
qx::IxDataMember *pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy();
QVariant tmp(s);
return (pId ? pId->fromVariant((&t), tmp, format, index, ctx) : qx_bool(false));
}
return qx::serialization::qt::from_string<T>(t, s);
}
};
template <typename T>
struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
{
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (ctx != qx::cvt::context::e_serialize_registered)
{
qx::IxDataMember *pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy();
return (pId ? pId->toVariant((&t), format, index, ctx) : QVariant());
}
return qx::serialization::qt::to_byte_array<T>(t);
}
};
template <typename T>
struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
{
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (ctx != qx::cvt::context::e_serialize_registered)
{
qx::IxDataMember *pId = qx::QxClass<T>::getSingleton()->getDataMemberX()->getId_WithDaoStrategy();
return (pId ? pId->fromVariant((&t), v, format, index, ctx) : qx_bool(false));
}
return qx::serialization::qt::from_byte_array<T>(t, v.toByteArray());
}
};
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
{
static inline QJsonValue toJson(const T &t, const QString &format)
{
return qx::cvt::detail::QxSerializeJsonRegistered<T>::save(t, format);
}
};
template <typename T>
struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Registered>
{
static inline qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
{
return qx::cvt::detail::QxSerializeJsonRegistered<T>::load(j, t, format);
}
};
#endif // _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Container>
{
static inline QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QX_CVT_DEFAULT_ARCHIVE::to_string(t);
}
};
template <typename T>
struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Container>
{
static inline qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QX_CVT_DEFAULT_ARCHIVE::from_string(t, s);
}
};
template <typename T>
struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>
{
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QX_CVT_DEFAULT_ARCHIVE::to_string(t);
}
};
template <typename T>
struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>
{
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QX_CVT_DEFAULT_ARCHIVE::from_string(t, v.toString());
}
};
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Container>
{
static inline QJsonValue toJson(const T &t, const QString &format)
{
return QJsonValue::fromVariant(qx::cvt::detail::QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>::toVariant(t, format, -1, qx::cvt::context::e_no_context));
}
};
template <typename T>
struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Container>
{
static inline qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
{
QVariant v = j.toVariant();
return qx::cvt::detail::QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Container>::fromVariant(v, t, format, -1, qx::cvt::context::e_no_context);
}
};
#endif // _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToString<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
{
static inline QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString::number(static_cast<long>(t));
}
};
template <typename T>
struct QxConvertHelper_FromString<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
{
static inline qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
bool bOk = false;
t = static_cast<T>(static_cast<long>(s.toLongLong(&bOk)));
return bOk;
}
};
template <typename T>
struct QxConvertHelper_ToVariant<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
{
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QVariant(static_cast<qlonglong>(t));
}
};
template <typename T>
struct QxConvertHelper_FromVariant<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
{
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
bool bOk = false;
t = static_cast<T>(static_cast<long>(v.toLongLong(&bOk)));
return bOk;
}
};
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvertHelper_ToJson<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
{
static inline QJsonValue toJson(const T &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(static_cast<int>(t));
}
};
template <typename T>
struct QxConvertHelper_FromJson<T, qx::cvt::detail::helper::QxConvertHelper_Enum>
{
static inline qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
{
Q_UNUSED(format);
t = static_cast<T>(static_cast<long>(qRound(j.toDouble())));
return qx_bool(true);
}
};
#endif // _QX_NO_JSON
template <typename T>
struct QxConvertHelper
{
private:
typedef typename std::conditional<qx::trait::is_ix_persistable<T>::value, qx::cvt::detail::helper::QxConvertHelper_Persistable, qx::cvt::detail::helper::QxConvertHelper_Generic>::type type_str_cvt_helper_0;
typedef typename std::conditional<std::is_pointer<T>::value, qx::cvt::detail::helper::QxConvertHelper_Ptr, type_str_cvt_helper_0>::type type_str_cvt_helper_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::cvt::detail::helper::QxConvertHelper_Ptr, type_str_cvt_helper_1>::type type_str_cvt_helper_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::cvt::detail::helper::QxConvertHelper_Container, type_str_cvt_helper_2>::type type_str_cvt_helper_3;
typedef typename std::conditional<qx::trait::is_qx_registered<T>::value, qx::cvt::detail::helper::QxConvertHelper_Registered, type_str_cvt_helper_3>::type type_str_cvt_helper_4;
typedef typename std::conditional<std::is_enum<T>::value, qx::cvt::detail::helper::QxConvertHelper_Enum, type_str_cvt_helper_4>::type type_str_cvt_helper_5;
public:
typedef typename QxConvertHelper<T>::type_str_cvt_helper_5 type;
};
template <typename T>
struct QxConvert_ToString
{
static inline QString toString(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
return qx::cvt::detail::QxConvertHelper_ToString<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::toString(t, format, index, ctx);
}
};
template <typename T>
struct QxConvert_FromString
{
static inline qx_bool fromString(const QString &s, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
return qx::cvt::detail::QxConvertHelper_FromString<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::fromString(s, t, format, index, ctx);
}
};
template <typename T>
struct QxConvert_ToVariant
{
static inline QVariant toVariant(const T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
return qx::cvt::detail::QxConvertHelper_ToVariant<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::toVariant(t, format, index, ctx);
}
};
template <typename T>
struct QxConvert_FromVariant
{
static inline qx_bool fromVariant(const QVariant &v, T &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
return qx::cvt::detail::QxConvertHelper_FromVariant<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::fromVariant(v, t, format, index, ctx);
}
};
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvert_ToJson
{
static inline QJsonValue toJson(const T &t, const QString &format)
{
return qx::cvt::detail::QxConvertHelper_ToJson<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::toJson(t, format);
}
};
template <typename T>
struct QxConvert_FromJson
{
static inline qx_bool fromJson(const QJsonValue &j, T &t, const QString &format)
{
return qx::cvt::detail::QxConvertHelper_FromJson<T, typename qx::cvt::detail::QxConvertHelper<T>::type>::fromJson(j, t, format);
}
};
#endif // _QX_NO_JSON
} // namespace detail
} // namespace cvt
} // namespace qx
#include "../../inl/QxConvert/QxConvert_WithIndex.inl"
#include "../../inl/QxConvert/QxConvert_ToString.inl"
#include "../../inl/QxConvert/QxConvert_FromString.inl"
#include "../../inl/QxConvert/QxConvert_ToVariant.inl"
#include "../../inl/QxConvert/QxConvert_FromVariant.inl"
#include "../../inl/QxConvert/QxConvert_ToJson.inl"
#include "../../inl/QxConvert/QxConvert_FromJson.inl"
#include "../../inl/QxConvert/QxConvert_Qt.inl"
#endif // _QX_CONVERT_IMPL_H_

View File

@@ -0,0 +1,237 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_DAO_HELPER_H_
#define _IX_DAO_HELPER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxDao_Helper.h
* \author XDL Team
* \ingroup QxDao
* \brief Helper class to communicate with database
*/
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlquery.h>
#include <QtSql/qsqlerror.h>
#include <QtSql/qsqldriver.h>
#include <QtSql/qsqlrecord.h>
#include <QxTraits/get_primary_key.h>
#include <QxTraits/is_valid_primary_key.h>
#include <QxDao/QxSqlDatabase.h>
#include <QxDao/IxSqlQueryBuilder.h>
#include <QxDao/QxSqlQuery.h>
#include <QxDao/IxSqlRelation.h>
#include <QxDao/QxSqlRelationLinked.h>
#include <QxDao/QxSqlGenerator/IxSqlGenerator.h>
#include <QxCollection/QxCollection.h>
#include <QxDataMember/IxDataMemberX.h>
#include <QxValidator/QxInvalidValueX.h>
#include <QxValidator/QxValidatorError.h>
namespace qx
{
template <class T>
QxInvalidValueX validate(T &t, const QString &group);
class QxSession;
} // namespace qx
namespace qx
{
namespace dao
{
namespace detail
{
struct IxDao_Timer;
/*!
* \ingroup QxDao
* \brief qx::dao::detail::IxDao_Helper : helper class to communicate with database
*/
class QX_DLL_EXPORT IxDao_Helper
{
friend struct IxDao_Timer;
public:
enum timer_type
{
timer_none,
timer_total,
timer_db_exec,
timer_db_next,
timer_db_prepare,
timer_cpp_build_hierarchy,
timer_cpp_build_instance,
timer_cpp_read_instance,
timer_build_sql,
timer_db_open,
timer_db_transaction
};
private:
struct IxDao_HelperImpl;
std::unique_ptr<IxDao_HelperImpl> m_pImpl; //!< Private implementation idiom
protected:
IxDao_Helper(qx::IxSqlQueryBuilder *pBuilder, const qx::QxSqlQuery *pQuery = NULL);
virtual ~IxDao_Helper();
public:
bool isValid() const;
bool hasFeature(QSqlDriver::DriverFeature ft) const;
QSqlDatabase &database();
const QSqlDatabase &database() const;
QSqlQuery &query();
const QSqlQuery &query() const;
QSqlError &error();
const QSqlError &error() const;
qx::QxSqlQuery &qxQuery();
const qx::QxSqlQuery &qxQuery() const;
qx::IxSqlQueryBuilder &builder();
const qx::IxSqlQueryBuilder &builder() const;
qx::IxDataMemberX *getDataMemberX() const;
long getDataCount() const;
qx::IxDataMember *getDataId() const;
qx::IxDataMember *nextData(long &l) const;
QString sql() const;
qx::QxSqlRelationLinked *getSqlRelationLinked() const;
qx::QxSession *getSession() const;
QString getIgnoreSoftDeleteHash() const;
bool getCartesianProduct() const;
QStringList getSqlColumns() const;
void setSqlColumns(const QStringList &lst);
bool getUseExecBatch() const;
void setUseExecBatch(bool b);
qx::QxCollection<QString, QVariantList> &getListExecBatch();
IxSqlGenerator *getSqlGenerator() const;
void addInvalidValues(const qx::QxInvalidValueX &lst);
bool getAddAutoIncrementIdToUpdateQuery() const;
QStringList &itemsAsJson();
bool isReadOnly() const;
bool isMongoDB() const;
bool isDistinct() const;
QVariant getIdFromQuery(int iNameIndex = -1) const;
QSqlError errFailed(bool bPrepare = false);
QSqlError errEmpty();
QSqlError errNoData();
QSqlError errInvalidId();
QSqlError errInvalidRelation();
QSqlError errReadOnly();
bool transaction();
bool nextRecord();
void quiet();
bool exec(bool bForceEmptyExec = false);
bool prepare(QString &sql);
QSqlError updateError(const QSqlError &error);
bool updateSqlRelationX(const QStringList &relation);
void addQuery(bool bResolve);
void dumpRecord() const;
void resolveQuery();
template <class U>
inline bool isValidPrimaryKey(const U &u)
{
return (getDataId() && qx::trait::is_valid_primary_key(getDataId()->toVariant((&u), -1, qx::cvt::context::e_database)));
}
template <class U>
inline void updateLastInsertId(U &u)
{
if (getDataId() && getDataId()->getAutoIncrement() && this->hasFeature(QSqlDriver::LastInsertId))
{
getDataId()->fromVariant((&u), query().lastInsertId(), -1, qx::cvt::context::e_database);
}
}
template <class U>
inline bool validateInstance(U &u)
{
qx::QxInvalidValueX invalidValues = qx::validate(u, "");
this->addInvalidValues(invalidValues);
return (invalidValues.count() <= 0);
}
protected:
void dumpBoundValues() const;
QSqlError updateError(const QString &sError);
void timerStart(IxDao_Helper::timer_type timer);
qint64 timerElapsed(IxDao_Helper::timer_type timer);
void init(QSqlDatabase *pDatabase, const QString &sContext);
void terminate();
};
/*!
* \ingroup QxDao
* \brief qx::dao::detail::IxDao_Timer : scoped timer to measure database elapsed times (using C++ RAII)
*/
struct IxDao_Timer
{
IxDao_Helper *m_pDaoHelper; //!< Pointer to dao helper class
IxDao_Helper::timer_type m_eTimerType; //!< Timer type (database or C++ action)
IxDao_Timer(IxDao_Helper *pDaoHelper, IxDao_Helper::timer_type timer) : m_pDaoHelper(pDaoHelper), m_eTimerType(timer)
{
if (m_pDaoHelper)
{
m_pDaoHelper->timerStart(m_eTimerType);
}
}
~IxDao_Timer()
{
if (m_pDaoHelper)
{
m_pDaoHelper->timerElapsed(m_eTimerType);
}
}
};
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _IX_DAO_HELPER_H_

View File

@@ -0,0 +1,713 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_PERSISTABLE_H_
#define _IX_PERSISTABLE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxPersistable.h
* \author XDL Team
* \ingroup QxDao
* \brief Common interface (abstract class) for persistents classes using QX_PERSISTABLE_HPP() and QX_PERSISTABLE_CPP() macros
*/
#include <QxDao/QxSqlQuery.h>
#include <QxDao/QxDao.h>
#include <QxDao/QxSqlSaveMode.h>
#include <QxRegister/QxClass.h>
#include <QxCollection/QxCollection.h>
#include <QxValidator/QxInvalidValueX.h>
#include <QxValidator/QxValidatorFct.h>
#include <QxTraits/get_class_name.h>
namespace qx
{
class IxPersistableCollection;
/*!
* \ingroup QxDao
* \brief qx::IxPersistable : common interface (abstract class) for persistents classes using QX_PERSISTABLE_HPP() and QX_PERSISTABLE_CPP() macros
*
* To use this common interface for persistents classes : <br>
* <b>1-</b> inherit your persistent class from <i>qx::IxPersistable</i> ; <br>
* <b>2-</b> into your class definition (<i>myClass.h</i> for example), add <i>QX_PERSISTABLE_HPP(myClass)</i> macro ; <br>
* <b>3-</b> into your class implementation (<i>myClass.cpp</i> for example), add <i>QX_PERSISTABLE_CPP(myClass)</i> macro.
*
* <b>Note :</b> for a list of objects (<i>qxFetchAll()</i> method or <i>qxFetchByQuery()</i> method), use <i>qx::QxCollection<type_primary_key, std::shared_ptr<my_type>></i> type.
* Or just use <i>qx::QxPersistableCollectionHelper<T>::type</i> to retrieve your persistent collection type.
* A convenient way to fetch a list of objects is to use following static methods <i>qxFetchAll()</i> and <i>qxFetchByQuery()</i> :
* \code
std::shared_ptr<qx::IxPersistableCollection> lst = qx::IxPersistable::qxFetchAll("myClass");
for (long l = 0; l < lst->_count(); l++)
{ qx::IxPersistable_ptr ptr = lst->_get<qx::IxPersistable_ptr>(l); etc... }
* \endcode
*/
class QX_DLL_EXPORT IxPersistable
{
public:
IxPersistable();
virtual ~IxPersistable();
/*!
* \brief Return the number of lines in the table (database) mapped to the current C++ class (registered into QxOrm context) and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
*
* qx::IxPersistable * p = ...;<br>
* p->qxCount(...) execute following SQL query :<br>
* <i>SELECT COUNT(*) FROM my_table</i> + <i>XXX_JOINS_XXX</i> + <i>WHERE my_query...</i>
*/
virtual long qxCount(const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL, const QStringList &relation = QStringList()) = 0;
/*!
* \brief Return the number of lines in the table (database) mapped to the current C++ class (registered into QxOrm context) and filtered by a user SQL query
* \param lCount Output parameter with the number of lines in the table associated to the SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
*
* qx::IxPersistable * p = ...;<br>
* p->qxCount(...) execute following SQL query :<br>
* <i>SELECT COUNT(*) FROM my_table</i> + <i>XXX_JOINS_XXX</i> + <i>WHERE my_query...</i>
*/
virtual QSqlError qxCount(long &lCount, const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL, const QStringList &relation = QStringList()) = 0;
/*!
* \brief Fetch current instance (retrieve all its properties) mapped to a table in the database (current instance must have a valid id before to be fetched without error, or pass the id to the first parameter of this method)
* \param id Unique id to fetch properties from database (if empty, check id of current instance)
* \param columns List of database table columns (mapped to properties of C++ class) to fetch (if empty, all columns are fetched)
* \param relation List of relationships keys to fetch (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxFetchById(...) execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
virtual QSqlError qxFetchById(const QVariant &id = QVariant(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Fetch a list of objects (retrieve all elements and properties associated) of current type (container registered into QxOrm context) mapped to a table in the database
* \param list Container to fetch all items (retrieve all elements and properties associated); list is cleared before executing SQL query
* \param columns List of database table columns (mapped to properties of C++ class) to fetch (if empty, all columns are fetched)
* \param relation List of relationships keys to fetch (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* std::shared_ptr<qx::IxPersistableCollection> lst = p->qxNewPersistableCollection();<br>
* p->qxFetchAll(& lst, ...) execute following SQL query :<br>
* <i>SELECT * FROM my_table</i>
*/
virtual QSqlError qxFetchAll(qx::IxPersistableCollection *list = NULL, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Fetch a list of objects (retrieve all elements and properties associated) of current type (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param list Container to fetch all items (retrieve all elements and properties associated); list is cleared before executing SQL query
* \param columns List of database table columns (mapped to properties of C++ class) to fetch (if empty, all columns are fetched)
* \param relation List of relationships keys to fetch (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* std::shared_ptr<qx::IxPersistableCollection> lst = p->qxNewPersistableCollection();<br>
* p->qxFetchByQuery(my_query, & lst, ...) execute following SQL query :<br>
* <i>SELECT * FROM my_table</i> + <i>WHERE my_query...</i>
*/
virtual QSqlError qxFetchByQuery(const qx::QxSqlQuery &query, qx::IxPersistableCollection *list = NULL, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Insert current instance into database
* \param relation List of relationships keys to insert in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance inserting a list of instances to database (but doesn't fill the last inserted identifier in the C++ instances)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxInsert(...) execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
*/
virtual QSqlError qxInsert(const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false) = 0;
/*!
* \brief Update current instance into database (you can add a user SQL query to the default SQL query builded by QxOrm library)
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param columns List of database table columns (mapped to properties of C++ class) to update (if empty, all columns are updated)
* \param relation List of relationships keys to update in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxUpdate(...) execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
virtual QSqlError qxUpdate(const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false) = 0;
/*!
* \brief Insert (if no exist) or update (if already exist) current instance into database
* \param relation List of relationships keys to insert or update in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \param eSaveRecursiveMode Parameter to call qx::dao::save_with_relation_recursive function
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxSave(...) execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
virtual QSqlError qxSave(const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, qx::dao::save_mode::e_save_mode eSaveRecursiveMode = qx::dao::save_mode::e_none) = 0;
/*!
* \brief Delete current instance from database
* \param id Unique id to delete from database (if empty, check id of current instance)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance deleting a list of instances in database
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxDeleteById(...) execute following SQL query :<br>
* <i>DELETE FROM my_table WHERE my_id = ?</i><br>
* <br>
* If a soft delete behavior is defined for current class, p->qxDeleteById(...) execute following SQL query :<br>
* <i>UPDATE my_table SET is_deleted='1' WHERE my_id = ?</i>
*/
virtual QSqlError qxDeleteById(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false) = 0;
/*!
* \brief Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxDeleteAll(...) execute following SQL query :<br>
* <i>DELETE FROM my_table</i><br>
* <br>
* If a soft delete behavior is defined for current class, p->qxDeleteAll(...) execute following SQL query :<br>
* <i>UPDATE my_table SET is_deleted='1'</i>
*/
virtual QSqlError qxDeleteAll(QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context) and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxDeleteByQuery(...) execute following SQL query :<br>
* <i>DELETE FROM my_table</i> + <i>WHERE my_query...</i><br>
* <br>
* If a soft delete behavior is defined for current class, p->qxDeleteByQuery(...) execute following SQL query :<br>
* <i>UPDATE my_table SET is_deleted='1'</i> + <i>WHERE my_query...</i>
*/
virtual QSqlError qxDeleteByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Delete current instance from database
* \param id Unique id to delete from database (if empty, check id of current instance)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance destroying a list of instances in database
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxDestroyById(...) execute following SQL query :<br>
* <i>DELETE FROM my_table WHERE my_id = ?</i><br>
*/
virtual QSqlError qxDestroyById(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false) = 0;
/*!
* \brief Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxDestroyAll(...) execute following SQL query :<br>
* <i>DELETE FROM my_table</i><br>
*/
virtual QSqlError qxDestroyAll(QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context) and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxDestroyByQuery(...) execute following SQL query :<br>
* <i>DELETE FROM my_table</i> + <i>WHERE my_query...</i><br>
*/
virtual QSqlError qxDestroyByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Execute a custom SQL query or a stored procedure, all columns that can be mapped to the instance of type T will be fetched automatically
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*/
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Execute a custom SQL query or a stored procedure, all columns that can be mapped to the instance of type T will be fetched automatically
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param list Container to fetch all items (retrieve all elements and properties associated); list is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*/
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, qx::IxPersistableCollection *list = NULL, QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Search if current instance already exists into database
* \param id Unique id to check into database (if empty, check id of current instance)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
* \return Return true if element already exists into database; otherwise return false; if an error occurred, qx_bool object contains a description of database error executing SQL query
*
* qx::IxPersistable * p = ...;<br>
* p->qxExist(...) execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
virtual qx_bool qxExist(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL) = 0;
/*!
* \brief Check if current instance is valid or not
* \param groups List of groups to check (defined into QxValidator module for current class)
* \return Return list of invalid values (if empty, current instance is valid)
*
* For more details about <b>QxValidator</b> module : https://www.qxorm.com/qxorm_en/faq.html#faq_250
*/
virtual qx::QxInvalidValueX qxValidate(const QStringList &groups = QStringList()) = 0;
/*!
* \brief Create a new collection smart-pointer to fetch a list of items of current class type
* \param bAsList If true, returns a list (array) of persistent instances instead of key/value hash-map
* \return Return a new collection smart-pointer to fetch a list of items of current class type
*/
virtual std::shared_ptr<qx::IxPersistableCollection> qxNewPersistableCollection(bool bAsList = false) const = 0;
/*!
* \brief Access to introspection engine (or reflection engine) of QxOrm library
* \return Return a qx::IxClass pointer to access to introspection engine (or reflection engine) of QxOrm library, and get some informations about current class (properties, methods, etc...)
*/
virtual qx::IxClass *qxClass() const = 0;
#ifndef _QX_NO_JSON
virtual QString toJson(const QString &format = QString()) const = 0;
virtual QJsonValue toJson_(const QString &format = QString()) const = 0;
virtual qx_bool fromJson(const QString &json, const QString &format = QString()) = 0;
virtual qx_bool fromJson_(const QJsonValue &json, const QString &format = QString()) = 0;
#endif // _QX_NO_JSON
public:
static std::shared_ptr<qx::IxPersistableCollection> qxFetchAll(const QString &className, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bAsList = false);
static std::shared_ptr<qx::IxPersistableCollection> qxFetchByQuery(const QString &className, const qx::QxSqlQuery &query, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bAsList = false);
static std::shared_ptr<qx::IxPersistableCollection> qxExecuteQuery(const QString &className, qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL, bool bAsList = false);
};
typedef std::shared_ptr<qx::IxPersistable> IxPersistable_ptr;
} // namespace qx
namespace qx
{
namespace trait
{
/*!
* \ingroup QxTraits
* \brief qx::trait::is_ix_persistable<T>::value : return true if T implements qx::IxPersistable interface, otherwise return false
*/
template <typename T>
struct is_ix_persistable
{
enum
{
value = std::is_base_of<qx::IxPersistable, T>::value
};
};
} // namespace trait
} // namespace qx
#ifndef _QX_NO_JSON
#define QX_PERSISTABLE_JSON_HPP(className) \
virtual QString toJson(const QString &format = QString()) const; \
virtual QJsonValue toJson_(const QString &format = QString()) const; \
virtual qx_bool fromJson(const QString &json, const QString &format = QString()); \
virtual qx_bool fromJson_(const QJsonValue &json, const QString &format = QString());
#else // _QX_NO_JSON
#define QX_PERSISTABLE_JSON_HPP(className) /* Nothing */
#endif // _QX_NO_JSON
#define QX_PERSISTABLE_HPP(className) \
public: \
virtual long qxCount(const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL, const QStringList &relation = QStringList()); \
virtual QSqlError qxCount(long &lCount, const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL, const QStringList &relation = QStringList()); \
virtual QSqlError qxFetchById(const QVariant &id = QVariant(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL); \
virtual QSqlError qxFetchAll(qx::IxPersistableCollection *list = NULL, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL); \
virtual QSqlError qxFetchByQuery(const qx::QxSqlQuery &query, qx::IxPersistableCollection *list = NULL, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL); \
virtual QSqlError qxInsert(const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false); \
virtual QSqlError qxUpdate(const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false); \
virtual QSqlError qxSave(const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, qx::dao::save_mode::e_save_mode eSaveRecursiveMode = qx::dao::save_mode::e_none); \
virtual QSqlError qxDeleteById(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false); \
virtual QSqlError qxDeleteAll(QSqlDatabase *pDatabase = NULL); \
virtual QSqlError qxDeleteByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL); \
virtual QSqlError qxDestroyById(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false); \
virtual QSqlError qxDestroyAll(QSqlDatabase *pDatabase = NULL); \
virtual QSqlError qxDestroyByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL); \
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL); \
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, qx::IxPersistableCollection *list = NULL, QSqlDatabase *pDatabase = NULL); \
virtual qx_bool qxExist(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL); \
virtual qx::QxInvalidValueX qxValidate(const QStringList &groups = QStringList()); \
virtual std::shared_ptr<qx::IxPersistableCollection> qxNewPersistableCollection(bool bAsList = false) const; \
virtual qx::IxClass *qxClass() const; \
QX_PERSISTABLE_JSON_HPP(className)
#ifdef _QX_NO_RTTI
#define QX_PERSISTABLE_CAST_COLLECTION(className) \
if (!list) \
{ \
return QSqlError(); \
} \
qx::QxPersistableCollectionHelper<className>::type_coll *list_typed = static_cast<qx::QxPersistableCollectionHelper<className>::type *>(list);
#else // _QX_NO_RTTI
#define QX_PERSISTABLE_CAST_COLLECTION(className) \
if (!list) \
{ \
return QSqlError(); \
} \
qx::QxPersistableCollectionHelper<className>::type_coll *list_typed = dynamic_cast<qx::QxPersistableCollectionHelper<className>::type *>(list);
#endif // _QX_NO_RTTI
#ifndef _QX_NO_JSON
#define QX_PERSISTABLE_JSON_CPP(className) \
QString className::toJson(const QString &format) const { return qx::serialization::json::to_string((*this), 1, format); } \
QJsonValue className::toJson_(const QString &format) const { return qx::cvt::to_json((*this), format); } \
qx_bool className::fromJson(const QString &json, const QString &format) { return qx::serialization::json::from_string((*this), json, 1, format); } \
qx_bool className::fromJson_(const QJsonValue &json, const QString &format) { return qx::cvt::from_json(json, (*this), format); }
#else // _QX_NO_JSON
#define QX_PERSISTABLE_JSON_CPP(className) /* Nothing */
#endif // _QX_NO_JSON
#define QX_PERSISTABLE_CPP(className) \
\
long className::qxCount(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase, const QStringList &relation) \
{ \
if (relation.count() == 0) \
{ \
return qx::dao::count<className>(query, pDatabase); \
} \
else \
{ \
long lCount(0); \
qx::dao::count_with_relation<className>(lCount, relation, query, pDatabase); \
return lCount; \
} \
} \
\
QSqlError className::qxCount(long &lCount, const qx::QxSqlQuery &query, QSqlDatabase *pDatabase, const QStringList &relation) \
{ \
if (relation.count() == 0) \
{ \
return qx::dao::count<className>(lCount, query, pDatabase); \
} \
else \
{ \
return qx::dao::count_with_relation<className>(lCount, relation, query, pDatabase); \
} \
} \
\
QSqlError className::qxFetchById(const QVariant &id, const QStringList &columns, const QStringList &relation, QSqlDatabase *pDatabase) \
{ \
if (id.isValid()) \
{ \
qx::IxDataMemberX *pDataMemberX = qx::QxClass<className>::getSingleton()->getDataMemberX(); \
qx::IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL); \
if (!pDataMemberId) \
{ \
qDebug("[QxOrm] problem with 'qxFetchById()' method : '%s'", "data member id not registered"); \
qAssert(false); \
} \
if (!pDataMemberId) \
{ \
return QSqlError("[QxOrm] problem with 'qxFetchById()' method : 'data member id not registered'", "", QSqlError::UnknownError); \
} \
pDataMemberId->fromVariant(this, id, -1, qx::cvt::context::e_database); \
} \
QSqlError err; \
if (relation.count() == 0) \
{ \
err = qx::dao::fetch_by_id((*this), pDatabase, columns); \
} \
else \
{ \
err = qx::dao::fetch_by_id_with_relation(relation, (*this), pDatabase); \
} \
return err; \
} \
\
QSqlError className::qxFetchAll(qx::IxPersistableCollection *list, const QStringList &columns, const QStringList &relation, QSqlDatabase *pDatabase) \
{ \
QX_PERSISTABLE_CAST_COLLECTION(className) \
if (!list_typed) \
{ \
qDebug("[QxOrm] problem with 'qxFetchAll()' method : '%s'", "dynamic_cast failed using collection qx::QxCollection< type_primary_key, std::shared_ptr<type> >"); \
qAssert(false); \
} \
if (!list_typed) \
{ \
return QSqlError("[QxOrm] problem with 'qxFetchAll()' method : 'dynamic_cast failed using collection qx::QxCollection< type_primary_key, std::shared_ptr<type> >'", "", QSqlError::UnknownError); \
} \
QSqlError err; \
if (relation.count() == 0) \
{ \
err = qx::dao::fetch_all((*list_typed), pDatabase, columns); \
} \
else \
{ \
err = qx::dao::fetch_all_with_relation(relation, (*list_typed), pDatabase); \
} \
return err; \
} \
\
QSqlError className::qxFetchByQuery(const qx::QxSqlQuery &query, qx::IxPersistableCollection *list, const QStringList &columns, const QStringList &relation, QSqlDatabase *pDatabase) \
{ \
QX_PERSISTABLE_CAST_COLLECTION(className) \
if (!list_typed) \
{ \
qDebug("[QxOrm] problem with 'qxFetchByQuery()' method : '%s'", "dynamic_cast failed using collection qx::QxCollection< type_primary_key, std::shared_ptr<type> >"); \
qAssert(false); \
} \
if (!list_typed) \
{ \
return QSqlError("[QxOrm] problem with 'qxFetchByQuery()' method : 'dynamic_cast failed using collection qx::QxCollection< type_primary_key, std::shared_ptr<type> >'", "", QSqlError::UnknownError); \
} \
QSqlError err; \
if (relation.count() == 0) \
{ \
err = qx::dao::fetch_by_query(query, (*list_typed), pDatabase, columns); \
} \
else \
{ \
err = qx::dao::fetch_by_query_with_relation(relation, query, (*list_typed), pDatabase); \
} \
return err; \
} \
\
QSqlError className::qxInsert(const QStringList &relation, QSqlDatabase *pDatabase, bool bUseExecBatch) \
{ \
QSqlError err; \
if (relation.count() == 0) \
{ \
err = qx::dao::insert((*this), pDatabase, bUseExecBatch); \
} \
else \
{ \
err = qx::dao::insert_with_relation(relation, (*this), pDatabase); \
} \
return err; \
} \
\
QSqlError className::qxUpdate(const qx::QxSqlQuery &query, const QStringList &columns, const QStringList &relation, QSqlDatabase *pDatabase, bool bUseExecBatch) \
{ \
QSqlError err; \
if (relation.count() == 0) \
{ \
err = qx::dao::update_by_query(query, (*this), pDatabase, columns, bUseExecBatch); \
} \
else \
{ \
err = qx::dao::update_by_query_with_relation(relation, query, (*this), pDatabase); \
} \
return err; \
} \
\
QSqlError className::qxSave(const QStringList &relation, QSqlDatabase *pDatabase, qx::dao::save_mode::e_save_mode eSaveRecursiveMode) \
{ \
QSqlError err; \
if (eSaveRecursiveMode != qx::dao::save_mode::e_none) \
{ \
err = qx::dao::save_with_relation_recursive((*this), eSaveRecursiveMode, pDatabase); \
} \
else if (relation.count() == 0) \
{ \
err = qx::dao::save((*this), pDatabase); \
} \
else \
{ \
err = qx::dao::save_with_relation(relation, (*this), pDatabase); \
} \
return err; \
} \
\
QSqlError className::qxDeleteById(const QVariant &id, QSqlDatabase *pDatabase, bool bUseExecBatch) \
{ \
if (id.isValid()) \
{ \
qx::IxDataMemberX *pDataMemberX = qx::QxClass<className>::getSingleton()->getDataMemberX(); \
qx::IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL); \
if (!pDataMemberId) \
{ \
qDebug("[QxOrm] problem with 'qxDeleteById()' method : '%s'", "data member id not registered"); \
qAssert(false); \
} \
if (!pDataMemberId) \
{ \
return QSqlError("[QxOrm] problem with 'qxDeleteById()' method : 'data member id not registered'", "", QSqlError::UnknownError); \
} \
pDataMemberId->fromVariant(this, id, -1, qx::cvt::context::e_database); \
} \
return qx::dao::delete_by_id((*this), pDatabase, bUseExecBatch); \
} \
\
QSqlError className::qxDeleteAll(QSqlDatabase *pDatabase) \
{ \
return qx::dao::delete_all<className>(pDatabase); \
} \
\
QSqlError className::qxDeleteByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase) \
{ \
return qx::dao::delete_by_query<className>(query, pDatabase); \
} \
\
QSqlError className::qxDestroyById(const QVariant &id, QSqlDatabase *pDatabase, bool bUseExecBatch) \
{ \
if (id.isValid()) \
{ \
qx::IxDataMemberX *pDataMemberX = qx::QxClass<className>::getSingleton()->getDataMemberX(); \
qx::IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL); \
if (!pDataMemberId) \
{ \
qDebug("[QxOrm] problem with 'qxDestroyById()' method : '%s'", "data member id not registered"); \
qAssert(false); \
} \
if (!pDataMemberId) \
{ \
return QSqlError("[QxOrm] problem with 'qxDestroyById()' method : 'data member id not registered'", "", QSqlError::UnknownError); \
} \
pDataMemberId->fromVariant(this, id, -1, qx::cvt::context::e_database); \
} \
return qx::dao::destroy_by_id((*this), pDatabase, bUseExecBatch); \
} \
\
QSqlError className::qxDestroyAll(QSqlDatabase *pDatabase) \
{ \
return qx::dao::destroy_all<className>(pDatabase); \
} \
\
QSqlError className::qxDestroyByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase) \
{ \
return qx::dao::destroy_by_query<className>(query, pDatabase); \
} \
\
QSqlError className::qxExecuteQuery(qx::QxSqlQuery &query, QSqlDatabase *pDatabase) \
{ \
return qx::dao::execute_query(query, (*this), pDatabase); \
} \
\
QSqlError className::qxExecuteQuery(qx::QxSqlQuery &query, qx::IxPersistableCollection *list, QSqlDatabase *pDatabase) \
{ \
QX_PERSISTABLE_CAST_COLLECTION(className) \
if (!list_typed) \
{ \
qDebug("[QxOrm] problem with 'qxExecuteQuery()' method : '%s'", "dynamic_cast failed using collection qx::QxCollection< type_primary_key, std::shared_ptr<type> >"); \
qAssert(false); \
} \
if (!list_typed) \
{ \
return QSqlError("[QxOrm] problem with 'qxExecuteQuery()' method : 'dynamic_cast failed using collection qx::QxCollection< type_primary_key, std::shared_ptr<type> >'", "", QSqlError::UnknownError); \
} \
return qx::dao::execute_query(query, (*list_typed), pDatabase); \
} \
\
qx_bool className::qxExist(const QVariant &id, QSqlDatabase *pDatabase) \
{ \
if (id.isValid()) \
{ \
qx::IxDataMemberX *pDataMemberX = qx::QxClass<className>::getSingleton()->getDataMemberX(); \
qx::IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL); \
if (!pDataMemberId) \
{ \
qDebug("[QxOrm] problem with 'qxExist()' method : '%s'", "data member id not registered"); \
qAssert(false); \
} \
if (!pDataMemberId) \
{ \
return qx_bool(false); \
} \
pDataMemberId->fromVariant(this, id, -1, qx::cvt::context::e_database); \
} \
return qx::dao::exist((*this), pDatabase); \
} \
\
qx::QxInvalidValueX className::qxValidate(const QStringList &groups) \
{ \
return qx::validate((*this), groups); \
} \
\
std::shared_ptr<qx::IxPersistableCollection> className::qxNewPersistableCollection(bool bAsList) const \
{ \
if (bAsList) \
{ \
std::shared_ptr<qx::IxPersistableCollection> coll = std::make_shared<qx::QxPersistableList<className>>(); \
return coll; \
} \
else \
{ \
std::shared_ptr<qx::IxPersistableCollection> coll = std::make_shared<qx::QxPersistableCollectionHelper<className>::type>(); \
return coll; \
} \
} \
\
qx::IxClass *className::qxClass() const \
{ \
return qx::QxClass<className>::getSingleton(); \
} \
\
QX_PERSISTABLE_JSON_CPP(className)
QX_REGISTER_CLASS_NAME(qx::IxPersistable)
#include <QxDao/IxPersistableCollection.h>
#endif // _IX_PERSISTABLE_H_

View File

@@ -0,0 +1,364 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_PERSISTABLE_COLLECTION_H_
#define _IX_PERSISTABLE_COLLECTION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxPersistableCollection.h
* \author XDL Team
* \ingroup QxDao
* \brief Common interface (abstract class) for collection persistent classes based on qx::IxPersistable and qx::IxCollection
*/
#include <QxDao/IxPersistable.h>
#include <QxCollection/QxCollection.h>
#include <QxTraits/get_primary_key.h>
#include <QxTraits/is_qx_registered.h>
#ifndef _QX_NO_JSON
#include <QxSerialize/QxSerializeQJson.h>
#endif // _QX_NO_JSON
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::IxPersistableCollection : common interface (abstract class) for collection persistent classes based on qx::IxPersistable and qx::IxCollection
*/
class QX_DLL_EXPORT IxPersistableCollection : public qx::IxPersistable
{
public:
IxPersistableCollection();
virtual ~IxPersistableCollection();
virtual long __count() const = 0;
virtual void __clear() = 0;
virtual bool __remove(long idx) = 0;
virtual qx::IxPersistable_ptr __at(long idx) const = 0;
};
typedef std::shared_ptr<qx::IxPersistableCollection> IxPersistableCollection_ptr;
/*!
* \ingroup QxDao
* \brief qx::QxPersistableCollection<Key, Value, T> : concrete class for collection persistent classes based on qx::IxPersistableCollection and qx::QxCollection<Key, Value>
*/
template <typename Key, typename Value, typename T>
class QxPersistableCollection : public qx::IxPersistableCollection, public qx::QxCollection<Key, Value>
{
enum
{
qx_is_valid = qx::trait::is_qx_registered<T>::value
};
public:
QxPersistableCollection() : qx::IxPersistableCollection(), qx::QxCollection<Key, Value>() { static_assert(qx_is_valid, "qx_is_valid"); }
virtual ~QxPersistableCollection() { ; }
virtual long __count() const
{
const qx::QxCollection<Key, Value> *coll = this;
return coll->count();
}
virtual void __clear()
{
qx::QxCollection<Key, Value> *coll = this;
coll->clear();
}
virtual bool __remove(long idx)
{
qx::QxCollection<Key, Value> *coll = this;
return coll->removeByIndex(idx);
}
virtual qx::IxPersistable_ptr __at(long idx) const
{
const qx::QxCollection<Key, Value> *coll = this;
Value val = coll->getByIndex(idx);
return std::static_pointer_cast<qx::IxPersistable>(val);
}
virtual long qxCount(const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL, const QStringList &relation = QStringList())
{
if (relation.count() == 0)
{
return qx::dao::count<T>(query, pDatabase);
}
else
{
long lCount(0);
qx::dao::count_with_relation<T>(lCount, relation, query, pDatabase);
return lCount;
}
}
virtual QSqlError qxCount(long &lCount, const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL, const QStringList &relation = QStringList())
{
if (relation.count() == 0)
{
return qx::dao::count<T>(lCount, query, pDatabase);
}
else
{
return qx::dao::count_with_relation<T>(lCount, relation, query, pDatabase);
}
}
virtual QSqlError qxFetchById(const QVariant &id = QVariant(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(id);
QSqlError err;
qx::QxCollection<Key, Value> *coll = this;
if (relation.count() == 0)
{
err = qx::dao::fetch_by_id((*coll), pDatabase, columns);
}
else
{
err = qx::dao::fetch_by_id_with_relation(relation, (*coll), pDatabase);
}
return err;
}
virtual QSqlError qxFetchAll(qx::IxPersistableCollection *list = NULL, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(list);
QSqlError err;
qx::QxCollection<Key, Value> *coll = this;
if (relation.count() == 0)
{
err = qx::dao::fetch_all((*coll), pDatabase, columns);
}
else
{
err = qx::dao::fetch_all_with_relation(relation, (*coll), pDatabase);
}
return err;
}
virtual QSqlError qxFetchByQuery(const qx::QxSqlQuery &query, qx::IxPersistableCollection *list = NULL, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(list);
QSqlError err;
qx::QxCollection<Key, Value> *coll = this;
if (relation.count() == 0)
{
err = qx::dao::fetch_by_query(query, (*coll), pDatabase, columns);
}
else
{
err = qx::dao::fetch_by_query_with_relation(relation, query, (*coll), pDatabase);
}
return err;
}
virtual QSqlError qxInsert(const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
QSqlError err;
qx::QxCollection<Key, Value> *coll = this;
if (relation.count() == 0)
{
err = qx::dao::insert((*coll), pDatabase, bUseExecBatch);
}
else
{
err = qx::dao::insert_with_relation(relation, (*coll), pDatabase);
}
return err;
}
virtual QSqlError qxUpdate(const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
QSqlError err;
qx::QxCollection<Key, Value> *coll = this;
if (relation.count() == 0)
{
err = qx::dao::update_by_query(query, (*coll), pDatabase, columns, bUseExecBatch);
}
else
{
err = qx::dao::update_by_query_with_relation(relation, query, (*coll), pDatabase);
}
return err;
}
virtual QSqlError qxSave(const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, qx::dao::save_mode::e_save_mode eSaveRecursiveMode = qx::dao::save_mode::e_none)
{
QSqlError err;
qx::QxCollection<Key, Value> *coll = this;
if (eSaveRecursiveMode != qx::dao::save_mode::e_none)
{
err = qx::dao::save_with_relation_recursive((*coll), eSaveRecursiveMode, pDatabase);
}
else if (relation.count() == 0)
{
err = qx::dao::save((*coll), pDatabase);
}
else
{
err = qx::dao::save_with_relation(relation, (*coll), pDatabase);
}
return err;
}
virtual QSqlError qxDeleteById(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
Q_UNUSED(id);
qx::QxCollection<Key, Value> *coll = this;
return qx::dao::delete_by_id((*coll), pDatabase, bUseExecBatch);
}
virtual QSqlError qxDeleteAll(QSqlDatabase *pDatabase = NULL)
{
return qx::dao::delete_all<T>(pDatabase);
}
virtual QSqlError qxDeleteByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::delete_by_query<T>(query, pDatabase);
}
virtual QSqlError qxDestroyById(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
Q_UNUSED(id);
qx::QxCollection<Key, Value> *coll = this;
return qx::dao::destroy_by_id((*coll), pDatabase, bUseExecBatch);
}
virtual QSqlError qxDestroyAll(QSqlDatabase *pDatabase = NULL)
{
return qx::dao::destroy_all<T>(pDatabase);
}
virtual QSqlError qxDestroyByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::destroy_by_query<T>(query, pDatabase);
}
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
qx::QxCollection<Key, Value> *coll = this;
return qx::dao::execute_query(query, (*coll), pDatabase);
}
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, qx::IxPersistableCollection *list = NULL, QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(list);
return qxExecuteQuery(query, pDatabase);
}
virtual qx_bool qxExist(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(id);
qx::QxCollection<Key, Value> *coll = this;
return qx::dao::exist((*coll), pDatabase);
}
virtual qx::QxInvalidValueX qxValidate(const QStringList &groups = QStringList())
{
qx::QxCollection<Key, Value> *coll = this;
return qx::validate((*coll), groups);
}
virtual std::shared_ptr<qx::IxPersistableCollection> qxNewPersistableCollection(bool bAsList = false) const
{
Q_UNUSED(bAsList);
std::shared_ptr<qx::IxPersistableCollection> coll = std::make_shared<qx::QxPersistableCollection<Key, Value, T>>();
return coll;
}
virtual qx::IxClass *qxClass() const
{
return qx::QxClass<T>::getSingleton();
}
#ifndef _QX_NO_JSON
virtual QString toJson(const QString &format = QString()) const
{
const qx::QxCollection<Key, Value> *coll = this;
return qx::serialization::json::to_string((*coll), 1, format);
}
virtual QJsonValue toJson_(const QString &format = QString()) const
{
const qx::QxCollection<Key, Value> *coll = this;
return qx::cvt::to_json((*coll), format);
}
virtual qx_bool fromJson(const QString &json, const QString &format = QString())
{
qx::QxCollection<Key, Value> *coll = this;
return qx::serialization::json::from_string((*coll), json, 1, format);
}
virtual qx_bool fromJson_(const QJsonValue &json, const QString &format = QString())
{
qx::QxCollection<Key, Value> *coll = this;
return qx::cvt::from_json(json, (*coll), format);
}
#endif // _QX_NO_JSON
};
/*!
* \ingroup QxDao
* \brief qx::QxPersistableCollectionHelper<T>::type : return the collection type used by qx::IxPersistable interface, qx::QxPersistableCollection<type_primary_key, std::shared_ptr<my_type>>
*/
template <typename T>
class QxPersistableCollectionHelper
{
private:
typedef typename qx::trait::get_primary_key<T>::type qx_type_primary_key;
typedef std::shared_ptr<T> qx_type_ptr;
public:
typedef qx::QxPersistableCollection<qx_type_primary_key, qx_type_ptr, T> type;
typedef qx::QxCollection<qx_type_primary_key, qx_type_ptr> type_coll;
};
} // namespace qx
QX_REGISTER_CLASS_NAME(qx::IxPersistableCollection)
QX_REGISTER_CLASS_NAME_TEMPLATE_3(qx::QxPersistableCollection)
QX_REGISTER_CLASS_NAME_TEMPLATE_1(qx::QxPersistableCollectionHelper)
#endif // _IX_PERSISTABLE_COLLECTION_H_

View File

@@ -0,0 +1,311 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_PERSISTABLE_LIST_H_
#define _IX_PERSISTABLE_LIST_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxPersistableList.h
* \author XDL Team
* \ingroup QxDao
* \brief Common interface (abstract class) for list persistent classes based on qx::IxPersistable
*/
#include <QxDao/IxPersistable.h>
#include <QxDao/IxPersistableCollection.h>
#include <QxTraits/get_primary_key.h>
#include <QxTraits/is_qx_registered.h>
#ifndef _QX_NO_JSON
#include <QxSerialize/QxSerializeQJson.h>
#endif // _QX_NO_JSON
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxPersistableList<T> : concrete class for list persistent classes based on qx::IxPersistableCollection (as an array instead of key/value hash-map)
*/
template <typename T>
class QxPersistableList : public qx::IxPersistableCollection
{
enum
{
qx_is_valid = qx::trait::is_qx_registered<T>::value
};
protected:
QList<std::shared_ptr<T>> m_list; //!< List of persistable instances
public:
QxPersistableList() : qx::IxPersistableCollection() { static_assert(qx_is_valid, "qx_is_valid"); }
virtual ~QxPersistableList() { ; }
virtual long __count() const { return static_cast<long>(m_list.size()); }
virtual void __clear() { m_list.clear(); }
virtual bool __remove(long idx)
{
if ((idx < 0) || (idx >= static_cast<long>(m_list.size())))
{
return false;
}
m_list.removeAt(idx);
return true;
}
virtual qx::IxPersistable_ptr __at(long idx) const
{
if ((idx < 0) || (idx >= static_cast<long>(m_list.size())))
{
return qx::IxPersistable_ptr();
}
return std::static_pointer_cast<qx::IxPersistable>(m_list.at(idx));
}
virtual long qxCount(const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL, const QStringList &relation = QStringList())
{
if (relation.count() == 0)
{
return qx::dao::count<T>(query, pDatabase);
}
else
{
long lCount(0);
qx::dao::count_with_relation<T>(lCount, relation, query, pDatabase);
return lCount;
}
}
virtual QSqlError qxCount(long &lCount, const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL, const QStringList &relation = QStringList())
{
if (relation.count() == 0)
{
return qx::dao::count<T>(lCount, query, pDatabase);
}
else
{
return qx::dao::count_with_relation<T>(lCount, relation, query, pDatabase);
}
}
virtual QSqlError qxFetchById(const QVariant &id = QVariant(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(id);
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::fetch_by_id(m_list, pDatabase, columns);
}
else
{
err = qx::dao::fetch_by_id_with_relation(relation, m_list, pDatabase);
}
return err;
}
virtual QSqlError qxFetchAll(qx::IxPersistableCollection *list = NULL, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(list);
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::fetch_all(m_list, pDatabase, columns);
}
else
{
err = qx::dao::fetch_all_with_relation(relation, m_list, pDatabase);
}
return err;
}
virtual QSqlError qxFetchByQuery(const qx::QxSqlQuery &query, qx::IxPersistableCollection *list = NULL, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(list);
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::fetch_by_query(query, m_list, pDatabase, columns);
}
else
{
err = qx::dao::fetch_by_query_with_relation(relation, query, m_list, pDatabase);
}
return err;
}
virtual QSqlError qxInsert(const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::insert(m_list, pDatabase, bUseExecBatch);
}
else
{
err = qx::dao::insert_with_relation(relation, m_list, pDatabase);
}
return err;
}
virtual QSqlError qxUpdate(const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::update_by_query(query, m_list, pDatabase, columns, bUseExecBatch);
}
else
{
err = qx::dao::update_by_query_with_relation(relation, query, m_list, pDatabase);
}
return err;
}
virtual QSqlError qxSave(const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL, qx::dao::save_mode::e_save_mode eSaveRecursiveMode = qx::dao::save_mode::e_none)
{
QSqlError err;
if (eSaveRecursiveMode != qx::dao::save_mode::e_none)
{
err = qx::dao::save_with_relation_recursive(m_list, eSaveRecursiveMode, pDatabase);
}
else if (relation.count() == 0)
{
err = qx::dao::save(m_list, pDatabase);
}
else
{
err = qx::dao::save_with_relation(relation, m_list, pDatabase);
}
return err;
}
virtual QSqlError qxDeleteById(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
Q_UNUSED(id);
return qx::dao::delete_by_id(m_list, pDatabase, bUseExecBatch);
}
virtual QSqlError qxDeleteAll(QSqlDatabase *pDatabase = NULL)
{
return qx::dao::delete_all<T>(pDatabase);
}
virtual QSqlError qxDeleteByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::delete_by_query<T>(query, pDatabase);
}
virtual QSqlError qxDestroyById(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
Q_UNUSED(id);
return qx::dao::destroy_by_id(m_list, pDatabase, bUseExecBatch);
}
virtual QSqlError qxDestroyAll(QSqlDatabase *pDatabase = NULL)
{
return qx::dao::destroy_all<T>(pDatabase);
}
virtual QSqlError qxDestroyByQuery(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::destroy_by_query<T>(query, pDatabase);
}
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::execute_query(query, m_list, pDatabase);
}
virtual QSqlError qxExecuteQuery(qx::QxSqlQuery &query, qx::IxPersistableCollection *list = NULL, QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(list);
return qxExecuteQuery(query, pDatabase);
}
virtual qx_bool qxExist(const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL)
{
Q_UNUSED(id);
return qx::dao::exist(m_list, pDatabase);
}
virtual qx::QxInvalidValueX qxValidate(const QStringList &groups = QStringList())
{
return qx::validate(m_list, groups);
}
virtual std::shared_ptr<qx::IxPersistableCollection> qxNewPersistableCollection(bool bAsList = false) const
{
Q_UNUSED(bAsList);
std::shared_ptr<qx::IxPersistableCollection> coll = std::make_shared<qx::QxPersistableList<T>>();
return coll;
}
virtual qx::IxClass *qxClass() const
{
return qx::QxClass<T>::getSingleton();
}
#ifndef _QX_NO_JSON
virtual QString toJson(const QString &format = QString()) const
{
return qx::serialization::json::to_string(m_list, 1, format);
}
virtual QJsonValue toJson_(const QString &format = QString()) const
{
return qx::cvt::to_json(m_list, format);
}
virtual qx_bool fromJson(const QString &json, const QString &format = QString())
{
return qx::serialization::json::from_string(m_list, json, 1, format);
}
virtual qx_bool fromJson_(const QJsonValue &json, const QString &format = QString())
{
return qx::cvt::from_json(json, m_list, format);
}
#endif // _QX_NO_JSON
};
} // namespace qx
QX_REGISTER_CLASS_NAME_TEMPLATE_1(qx::QxPersistableList)
#endif // _IX_PERSISTABLE_LIST_H_

View File

@@ -0,0 +1,159 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_SQL_QUERY_BUILDER_H_
#define _IX_SQL_QUERY_BUILDER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxSqlQueryBuilder.h
* \author XDL Team
* \ingroup QxDao
* \brief Common interface to build SQL queries to communicate with database
*/
#include <QxDataMember/IxDataMemberX.h>
#include <QxDao/IxSqlRelation.h>
#include <QxDao/QxSoftDelete.h>
#include <QxDao/QxSqlRelationLinked.h>
namespace qx
{
namespace dao
{
namespace detail
{
class IxDao_Helper;
} // namespace detail
} // namespace dao
} // namespace qx
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::IxSqlQueryBuilder : common interface to build SQL queries to communicate with database
*/
class QX_DLL_EXPORT IxSqlQueryBuilder
{
private:
struct IxSqlQueryBuilderImpl;
std::unique_ptr<IxSqlQueryBuilderImpl> m_pImpl; //!< Private implementation idiom
public:
IxSqlQueryBuilder();
virtual ~IxSqlQueryBuilder() = 0;
IxDataMemberX *getDataMemberX() const;
QxCollection<QString, IxDataMember *> *getLstDataMember() const;
IxSqlRelationX *getLstRelation() const;
qx::dao::detail::IxDao_Helper *getDaoHelper() const;
void setDaoHelper(qx::dao::detail::IxDao_Helper *p);
void setHashRelation(const QString &s);
void setCartesianProduct(bool b);
QString getSqlQuery() const;
QString getHashRelation() const;
QString table() const;
QxSoftDelete getSoftDelete() const;
bool getCartesianProduct() const;
long getDataCount() const;
long getRelationCount() const;
IxDataMember *getDataId() const;
IxDataMember *nextData(long &l) const;
IxSqlRelation *nextRelation(long &l) const;
QString &getCurrentBuildingSql() const;
void initIdX(long lAllRelationCount);
bool insertIdX(long lIndex, const QVariant &idOwner, const QVariant &idData, void *ptr);
void *existIdX(long lIndex, const QVariant &idOwner, const QVariant &idData);
void setSqlQuery(const QString &sql, const QString &key = QString());
void addSqlQueryAlias(const QString &sql, const QString &sqlAlias);
bool getAddAutoIncrementIdToUpdateQuery() const;
void replaceSqlQueryAlias(QString &sql) const;
virtual void init();
virtual void clone(const IxSqlQueryBuilder &other);
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL) = 0;
static QString addSqlCondition(const QString &sql) { return (sql.contains(" WHERE ") ? " AND " : " WHERE "); }
static void sql_CreateTable(QString &sql, IxSqlQueryBuilder &builder);
static void sql_DeleteById(QString &sql, IxSqlQueryBuilder &builder, bool bSoftDelete);
static void sql_Exist(QString &sql, IxSqlQueryBuilder &builder);
static void sql_FetchAll(QString &sql, IxSqlQueryBuilder &builder);
static void sql_FetchAll(QString &sql, IxSqlQueryBuilder &builder, const QStringList &columns);
static void sql_FetchAll_WithRelation(qx::QxSqlRelationLinked *pRelationX, QString &sql, IxSqlQueryBuilder &builder);
static void sql_FetchById(QString &sql, IxSqlQueryBuilder &builder);
static void sql_FetchById(QString &sql, IxSqlQueryBuilder &builder, const QStringList &columns);
static void sql_FetchById_WithRelation(qx::QxSqlRelationLinked *pRelationX, QString &sql, IxSqlQueryBuilder &builder);
static void sql_Insert(QString &sql, IxSqlQueryBuilder &builder);
static void sql_Update(QString &sql, IxSqlQueryBuilder &builder);
static void sql_Update(QString &sql, IxSqlQueryBuilder &builder, const QStringList &columns);
static void sql_Count_WithRelation(qx::QxSqlRelationLinked *pRelationX, QString &sql, IxSqlQueryBuilder &builder);
static void resolveOutput_FetchAll(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder);
static void resolveOutput_FetchAll(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder, const QStringList &columns);
static void resolveOutput_FetchAll_WithRelation(qx::QxSqlRelationLinked *pRelationX, void *t, QSqlQuery &query, IxSqlQueryBuilder &builder);
static void resolveInput_Insert(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder);
static void resolveInput_Update(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder);
static void resolveInput_Update(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder, const QStringList &columns);
static void resolveInput_DeleteById(void *t, QSqlQuery &query, IxSqlQueryBuilder &builder);
protected:
bool verifyColumns(const QStringList &columns) const QX_USED;
bool isInitDone() const;
QxSoftDelete &softDelete();
const QxSoftDelete &softDelete() const;
void setSoftDelete(const QxSoftDelete &o);
void setDataMemberX(IxDataMemberX *p);
bool findSqlQuery(const QString &key);
bool findSqlAlias(const QString &key);
void insertSqlAlias(const QString &key);
};
typedef std::shared_ptr<IxSqlQueryBuilder> IxSqlQueryBuilder_ptr;
} // namespace qx
#include <QxDao/IxDao_Helper.h>
#endif // _IX_SQL_QUERY_BUILDER_H_

View File

@@ -0,0 +1,203 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_SQL_RELATION_H_
#define _IX_SQL_RELATION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxSqlRelation.h
* \author XDL Team
* \ingroup QxDao
* \brief Common interface for all relationships defined between 2 classes (or between 2 tables in database)
*/
#include <QxCommon/QxPropertyBag.h>
#include <QxDao/QxSqlRelationParams.h>
#include <QxDao/QxSoftDelete.h>
#include <QxDao/QxSqlJoin.h>
#include <QxCollection/QxCollection.h>
namespace qx
{
class IxClass;
class IxDataMember;
class IxDataMemberX;
class IxSqlRelation;
typedef QxCollection<QString, IxSqlRelation *> IxSqlRelationX;
typedef std::shared_ptr<IxSqlRelationX> IxSqlRelationX_ptr;
/*!
* \ingroup QxDao
* \brief qx::IxSqlRelation : common interface for all relationships defined between 2 classes (or between 2 tables in database)
*/
class QX_DLL_EXPORT IxSqlRelation : public qx::QxPropertyBag
{
private:
struct IxSqlRelationImpl;
std::unique_ptr<IxSqlRelationImpl> m_pImpl; //!< Private implementation idiom
public:
enum relation_type
{
no_relation,
one_to_one,
one_to_many,
many_to_one,
many_to_many
};
IxSqlRelation(IxDataMember *p);
virtual ~IxSqlRelation() = 0;
QxCollection<QString, IxDataMember *> *getLstDataMember() const;
IxSqlRelationX *getLstRelation() const;
void setSqlJoinType(qx::dao::sql_join::join_type e);
qx::dao::sql_join::join_type getSqlJoinType() const;
relation_type getRelationType() const;
IxClass *getClass() const;
IxClass *getClassOwner() const;
IxDataMember *getDataMember() const;
IxDataMemberX *getDataMemberX() const;
IxDataMember *getDataId() const;
IxDataMember *getDataIdOwner() const;
void linkRelationKeyTo(IxDataMember *p);
IxDataMember *getLinkRelationKey() const;
QString getKey() const;
QString getForeignKey() const;
QString getForeignKeyOwner() const;
QString getForeignKeyDataType() const;
QString getExtraTable() const;
long getDataCount() const;
long getRelationCount() const;
IxDataMember *getDataByKey(const QString &sKey) const;
IxDataMember *nextData(long &lIndex) const;
IxSqlRelation *nextRelation(long &lIndex) const;
QString table() const;
QString tableAlias(QxSqlRelationParams &params) const;
QString tableAliasOwner(QxSqlRelationParams &params) const;
QString getSqlJoin(qx::dao::sql_join::join_type e = qx::dao::sql_join::no_join) const;
bool traceSqlQuery() const;
virtual void init();
virtual QString getDescription() const = 0;
virtual QString createExtraTable() const = 0;
virtual bool getCartesianProduct() const = 0;
virtual QVariant getIdFromQuery(bool bEager, QxSqlRelationParams &params, int iOffset, int iNameIndex) const = 0;
virtual void updateOffset(bool bEager, QxSqlRelationParams &params) const = 0;
virtual void createTable(QxSqlRelationParams &params) const = 0;
virtual void lazySelect(QxSqlRelationParams &params) const = 0;
virtual void eagerSelect(QxSqlRelationParams &params) const = 0;
virtual void lazyFrom(QxSqlRelationParams &params) const = 0;
virtual void eagerFrom(QxSqlRelationParams &params) const = 0;
virtual void lazyJoin(QxSqlRelationParams &params) const = 0;
virtual void eagerJoin(QxSqlRelationParams &params) const = 0;
virtual void lazyWhere(QxSqlRelationParams &params) const = 0;
virtual void eagerWhere(QxSqlRelationParams &params) const = 0;
virtual void lazyWhereSoftDelete(QxSqlRelationParams &params) const = 0;
virtual void eagerWhereSoftDelete(QxSqlRelationParams &params) const = 0;
virtual void lazyFetch_ResolveInput(QxSqlRelationParams &params) const = 0;
virtual void eagerFetch_ResolveInput(QxSqlRelationParams &params) const = 0;
virtual void lazyFetch_ResolveOutput(QxSqlRelationParams &params) const = 0;
virtual void *eagerFetch_ResolveOutput(QxSqlRelationParams &params) const = 0;
virtual void lazyInsert(QxSqlRelationParams &params) const = 0;
virtual void lazyInsert_Values(QxSqlRelationParams &params) const = 0;
virtual void lazyUpdate(QxSqlRelationParams &params) const = 0;
virtual void lazyInsert_ResolveInput(QxSqlRelationParams &params) const = 0;
virtual void lazyUpdate_ResolveInput(QxSqlRelationParams &params) const = 0;
virtual QSqlError onBeforeSave(QxSqlRelationParams &params) const = 0;
virtual QSqlError onAfterSave(QxSqlRelationParams &params) const = 0;
bool verifyOffset(QxSqlRelationParams &params, bool bId) const QX_USED;
static void setTraceRelationInit(bool bTrace);
protected:
QVariant getIdFromQuery_ManyToMany(bool bEager, QxSqlRelationParams &params, int iOffset, int iNameIndex) const;
QVariant getIdFromQuery_ManyToOne(bool bEager, QxSqlRelationParams &params, int iOffset, int iNameIndex) const;
QVariant getIdFromQuery_OneToMany(bool bEager, QxSqlRelationParams &params, int iOffset, int iNameIndex) const;
QVariant getIdFromQuery_OneToOne(bool bEager, QxSqlRelationParams &params, int iOffset, int iNameIndex) const;
void updateOffset_ManyToMany(bool bEager, QxSqlRelationParams &params) const;
void updateOffset_ManyToOne(bool bEager, QxSqlRelationParams &params) const;
void updateOffset_OneToMany(bool bEager, QxSqlRelationParams &params) const;
void updateOffset_OneToOne(bool bEager, QxSqlRelationParams &params) const;
void eagerSelect_ManyToMany(QxSqlRelationParams &params) const;
void eagerSelect_ManyToOne(QxSqlRelationParams &params) const;
void eagerSelect_OneToMany(QxSqlRelationParams &params) const;
void eagerSelect_OneToOne(QxSqlRelationParams &params) const;
void eagerJoin_ManyToMany(QxSqlRelationParams &params) const;
void eagerJoin_ManyToOne(QxSqlRelationParams &params) const;
void eagerJoin_OneToMany(QxSqlRelationParams &params) const;
void eagerJoin_OneToOne(QxSqlRelationParams &params) const;
void eagerWhereSoftDelete_ManyToMany(QxSqlRelationParams &params) const;
void eagerWhereSoftDelete_ManyToOne(QxSqlRelationParams &params) const;
void eagerWhereSoftDelete_OneToMany(QxSqlRelationParams &params) const;
void eagerWhereSoftDelete_OneToOne(QxSqlRelationParams &params) const;
void lazySelect_ManyToOne(QxSqlRelationParams &params) const;
void lazyInsert_ManyToOne(QxSqlRelationParams &params) const;
void lazyInsert_Values_ManyToOne(QxSqlRelationParams &params) const;
void lazyUpdate_ManyToOne(QxSqlRelationParams &params) const;
void createTable_ManyToOne(QxSqlRelationParams &params) const;
QSqlError deleteFromExtraTable_ManyToMany(QxSqlRelationParams &params) const;
QString createExtraTable_ManyToMany() const;
bool addLazyRelation(QxSqlRelationParams &params, IxSqlRelation *pRelation) const;
bool canInit() const;
void setIsSameDataOwner(int i);
void setClass(IxClass *pClass, IxClass *pClassOwner);
void setRelationType(relation_type e);
void setForeignKey(const QString &s) const;
void setForeignKeyOwner(const QString &s) const;
void setForeignKeyDataType(const QString &s) const;
void setExtraTable(const QString &s) const;
};
} // namespace qx
#endif // _IX_SQL_RELATION_H_

938
include/QxDao/QxDao.h Normal file
View File

@@ -0,0 +1,938 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DAO_H_
#define _QX_DAO_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDao.h
* \author XDL Team
* \ingroup QxDao
* \brief Provide template functions to map C++ class registered into QxOrm context with table database (ORM - Object Relational Mapping)
*/
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlquery.h>
#include <QtSql/qsqlrecord.h>
#include <QtSql/qsqlfield.h>
#include <QtSql/qsqlerror.h>
#include <QtSql/qsqldriver.h>
#include <QxCommon/QxBool.h>
#include <QxDao/QxSoftDelete.h>
#include <QxDao/QxDaoPointer.h>
#include <QxDao/QxSqlQuery.h>
#include <QxDao/QxSqlSaveMode.h>
namespace qx
{
class QxSqlRelationParams;
namespace dao
{
namespace detail
{
class IxDao_Helper;
template <class T>
struct QxDao_Count;
template <class T>
struct QxDao_Count_WithRelation;
template <class T>
struct QxDao_FetchById;
template <class T>
struct QxDao_FetchById_WithRelation;
template <class T>
struct QxDao_FetchAll;
template <class T>
struct QxDao_FetchAll_WithRelation;
template <class T>
struct QxDao_Insert;
template <class T>
struct QxDao_Insert_WithRelation;
template <class T>
struct QxDao_Update;
template <class T>
struct QxDao_Update_Optimized;
template <class T>
struct QxDao_Update_WithRelation;
template <class T>
struct QxDao_Save;
template <class T>
struct QxDao_Save_WithRelation;
template <class T>
struct QxDao_Save_WithRelation_Recursive;
template <class T>
struct QxDao_DeleteById;
template <class T>
struct QxDao_DeleteAll;
template <class T>
struct QxDao_Exist;
template <class T>
struct QxDao_CreateTable;
template <class T>
struct QxDao_Trigger;
template <class T>
struct QxDao_ExecuteQuery;
} // namespace detail
/*!
* \ingroup QxDao
* \brief Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm context) and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library (optional parameter)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
*
* qx::dao::count<T>() execute following SQL query :<br>
* <i>SELECT COUNT(*) FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline long count(const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Count<T>::count(query, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm context) and filtered by a user SQL query
* \param lCount Output parameter with the number of lines in the table associated to the SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library (optional parameter)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
*
* qx::dao::count<T>() execute following SQL query :<br>
* <i>SELECT COUNT(*) FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError count(long &lCount, const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Count<T>::count(lCount, query, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm context) and filtered by a user SQL query (with possibility to add relations to SQL query)
* \param lCount Output parameter with the number of lines in the table associated to the SQL query
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
* \param query Define a user SQL query added to default SQL query builded by QxOrm library (optional parameter)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
*
* qx::dao::count_with_relation<T>() execute following SQL query :<br>
* <i>SELECT COUNT(*) FROM my_table</i> + <i>XXX_JOINS_XXX</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError count_with_relation(long &lCount, const QStringList &relation, const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Count_WithRelation<T>::count(lCount, relation, query, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Insert an element or a list of elements into database
* \param t Element (or list of elements) to be inserted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance inserting a list of instances to database (but doesn't fill the last inserted identifier in the C++ instances)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::insert<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
*/
template <class T>
inline QSqlError insert(T &t, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
return qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase, bUseExecBatch);
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) an element or a list of elements into database
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::save<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline QSqlError save(T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Save<T>::save(t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Delete a line (or list of lines) of a table (database) mapped to a C++ object of type T (registered into QxOrm context)
* \param t Element (or list of elements) to be deleted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance deleting a list of instances in database
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::delete_by_id<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table WHERE my_id = ?</i><br>
* <br>
* If a soft delete behavior is defined for class T, qx::dao::delete_by_id<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET is_deleted='1' WHERE my_id = ?</i>
*/
template <class T>
inline QSqlError delete_by_id(T &t, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true, bUseExecBatch);
}
/*!
* \ingroup QxDao
* \brief Destroy a line (or list of lines) of a table (database) mapped to a C++ object of type T (registered into QxOrm context), even if a soft delete behavior is defined for class T
* \param t Element (or list of elements) to be destroyed into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance destroying a list of instances in database
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::destroy_by_id<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline QSqlError destroy_by_id(T &t, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
return qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false, bUseExecBatch);
}
/*!
* \ingroup QxDao
* \brief Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::delete_all<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table</i><br>
* <br>
* If a soft delete behavior is defined for class T, qx::dao::delete_all<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET is_deleted='1'</i>
*/
template <class T>
inline QSqlError delete_all(QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true);
}
/*!
* \ingroup QxDao
* \brief Destroy all lines of a table (database) mapped to a C++ class T (registered into QxOrm context), even if a soft delete behavior is defined for class T
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::destroy_all<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table</i>
*/
template <class T>
inline QSqlError destroy_all(QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false);
}
/*!
* \ingroup QxDao
* \brief Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context) and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::delete_by_query<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table</i> + <i>WHERE my_query...</i><br>
* <br>
* If a soft delete behavior is defined for class T, qx::dao::delete_by_query<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET is_deleted='1'</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError delete_by_query(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true);
}
/*!
* \ingroup QxDao
* \brief Destroy all lines of a table (database) mapped to a C++ class T (registered into QxOrm context) and filtered by a user SQL query, even if a soft delete behavior is defined for class T
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::destroy_by_query<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError destroy_by_query(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false);
}
/*!
* \ingroup QxDao
* \brief Create a table into database (with all columns) mapped to a C++ class T (registered into QxOrm context) : be careful, this function can be used only with a SQLite database to create examples or prototypes; For other databases, it is recommended to use QxEntityEditor application or to manage the database schema with an external tool provided by the SGBD (SQLite Manager for SQLite, pgAdmin for PostgreSQL, MySQL Workbench for MySQL, etc...)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::create_table<T>() execute following SQL query :<br>
* <i>CREATE TABLE my_table (my_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, my_column_1 TEXT, my_column_2 TEXT, etc.)</i>
*/
template <class T>
inline QSqlError create_table(QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase);
}
/*!
* \ingroup QxDao
* \brief Search if an element (or list of elements) already exists into database
* \param t Element (or list of elements) to be searched into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Return true if element already exists into database; otherwise return false; if an error occurred, qx_bool object contains a description of database error executing SQL query
*
* qx::dao::exist<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline qx_bool exist(T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Exist<T>::exist(t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a table in the database (t must have a valid id before to be fetched without error)
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
* \param t Instance (with a valid id) to be fetched (retrieve all properties from database)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_by_id_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline QSqlError fetch_by_id_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a table in the database (t must have a valid id before to be fetched without error)
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
* \param t Instance (with a valid id) to be fetched (retrieve all properties from database)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_by_id_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline QSqlError fetch_by_id_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Fetch an object t (retrieve all its properties and relationships) of type T (registered into QxOrm context) mapped to a table in the database (t must have a valid id before to be fetched without error)
* \param t Instance (with a valid id) to be fetched (retrieve all properties and relationships from database)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_by_id_with_all_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline QSqlError fetch_by_id_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_all_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i>
*/
template <class T>
inline QSqlError fetch_all_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_all_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i>
*/
template <class T>
inline QSqlError fetch_all_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties + all relationships associated) of type T (container registered into QxOrm context) mapped to a table in the database
* \param t Container to be fetched (retrieve all elements and properties + all relationships associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_all_with_all_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i>
*/
template <class T>
inline QSqlError fetch_all_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_by_query_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError fetch_by_query_with_relation(const QString &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_by_query_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError fetch_by_query_with_relation(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties + all relationships associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Container to be fetched (retrieve all elements and properties + all relationships associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_by_query_with_all_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError fetch_by_query_with_all_relation(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Insert an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be inserted in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param t Element (or list of elements) to be inserted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::insert_with_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
*/
template <class T>
inline QSqlError insert_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Insert an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be inserted in others tables of database
* \param t Element (or list of elements) to be inserted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::insert_with_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
*/
template <class T>
inline QSqlError insert_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Insert an element and all its relationships (or a list of elements + all relationships) into database
* \param t Element (or list of elements) to be inserted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::insert_with_all_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
*/
template <class T>
inline QSqlError insert_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Update an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be updated in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update_with_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline QSqlError update_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Update an element and its relationships (or a list of elements + relationships) into database (adding a user SQL query to the default SQL query builded by QxOrm library)
* \param relation List of relationships keys to be updated in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update_by_query_with_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError update_by_query_with_relation(const QString &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Update an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be updated in others tables of database
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update_with_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline QSqlError update_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Update an element and its relationships (or a list of elements + relationships) into database (adding a user SQL query to the default SQL query builded by QxOrm library)
* \param relation List of relationships keys to be updated in others tables of database
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update_by_query_with_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError update_by_query_with_relation(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Update an element and all its relationships (or a list of elements + all relationships) into database
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update_with_all_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline QSqlError update_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Update an element and all its relationships (or a list of elements + all relationships) into database (adding a user SQL query to the default SQL query builded by QxOrm library)
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update_by_query_with_all_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError update_by_query_with_all_relation(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be inserted or updated in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::save_with_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline QSqlError save_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be inserted or updated in others tables of database
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::save_with_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline QSqlError save_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) an element and all its relationships (or a list of elements + all relationships) into database
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::save_with_all_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline QSqlError save_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) recursively an element and all levels of relationships (or a list of elements + all levels of relationships) into database, useful to save a tree structure for example
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param eSaveMode To improve performance, use this parameter to indicate if you just want to insert or update all elements in database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param pRelationParams Keep this parameter as NULL, it is used internally by QxOrm library to iterate over each level of relationship
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::save_with_relation_recursive<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i><br>
* <br>
* <b>Note :</b> to improve performance, and if you know that you are just inserting or updating items in database, you can use the parameter <i>eSaveMode</i> :<br>
* - <i>qx::dao::save_mode::e_check_insert_or_update</i> : check before saving if item already exists in database ;<br>
* - <i>qx::dao::save_mode::e_insert_only</i> : only insert items in database (use only 1 SQL query to insert collection of items) ;<br>
* - <i>qx::dao::save_mode::e_update_only</i> : only update items in database (use only 1 SQL query to update collection of items).
*/
template <class T>
inline QSqlError save_with_relation_recursive(T &t, qx::dao::save_mode::e_save_mode eSaveMode = qx::dao::save_mode::e_check_insert_or_update, QSqlDatabase *pDatabase = NULL, qx::QxSqlRelationParams *pRelationParams = NULL)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive<T>::save(t, eSaveMode, pDatabase, pRelationParams);
}
/*!
* \ingroup QxDao
* \brief Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a table in the database (t must have a valid id before to be fetched without error)
* \param t Instance (with a valid id) to be fetched (retrieve all properties from database)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be fetched (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_by_id<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline QSqlError fetch_by_id(T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList())
{
return qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns);
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be fetched (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_all<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i>
*/
template <class T>
inline QSqlError fetch_all(T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList())
{
return qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns);
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be fetched (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::fetch_by_query<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError fetch_by_query(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList())
{
return qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns);
}
/*!
* \ingroup QxDao
* \brief Update an element or a list of elements into database
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be updated (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline QSqlError update(T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList(), bool bUseExecBatch = false)
{
return qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns, bUseExecBatch);
}
/*!
* \ingroup QxDao
* \brief Update an element or a list of elements into database (adding a user SQL query to the default SQL query builded by QxOrm library)
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be updated (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update_by_query<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError update_by_query(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList(), bool bUseExecBatch = false)
{
return qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns, bUseExecBatch);
}
/*!
* \ingroup QxDao
* \brief Update only modified fields/properties of an element or a list of elements into database (using is dirty pattern and qx::dao::ptr<T> smart-pointer)
* \param ptr Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update_optimized<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline QSqlError update_optimized(qx::dao::ptr<T> &ptr, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase, bUseExecBatch);
}
/*!
* \ingroup QxDao
* \brief Update only modified fields/properties of an element or a list of elements into database (using is dirty pattern and qx::dao::ptr<T> smart-pointer), adding a user SQL query to the default SQL query builded by QxOrm library
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param ptr Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*
* qx::dao::update_optimized_by_query<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline QSqlError update_optimized_by_query(const qx::QxSqlQuery &query, qx::dao::ptr<T> &ptr, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
return qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase, bUseExecBatch);
}
/*!
* \ingroup QxDao
* \brief Execute a custom SQL query or a stored procedure, all columns that can be mapped to the instance of type T will be fetched automatically
* \param query Define a custom SQL query or a stored procedure to call
* \param t Instance of type T, all columns that can be mapped to this instance will be fetched automatically
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query
*/
template <class T>
inline QSqlError execute_query(qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
return qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase);
}
/*!
* \ingroup QxDao
* \brief Callback before inserting an object into database (<a href="https://www.qxorm.com/qxorm_en/faq.html#faq_130" target="_blank">here is an example using QxOrm Trigger</a>)
*/
template <class T>
inline void on_before_insert(T *t, qx::dao::detail::IxDao_Helper *dao)
{
qx::dao::detail::QxDao_Trigger<T>::onBeforeInsert(t, dao);
}
/*!
* \ingroup QxDao
* \brief Callback before updating an object into database (<a href="https://www.qxorm.com/qxorm_en/faq.html#faq_130" target="_blank">here is an example using QxOrm Trigger</a>)
*/
template <class T>
inline void on_before_update(T *t, qx::dao::detail::IxDao_Helper *dao)
{
qx::dao::detail::QxDao_Trigger<T>::onBeforeUpdate(t, dao);
}
/*!
* \ingroup QxDao
* \brief Callback before deleting an object into database (<a href="https://www.qxorm.com/qxorm_en/faq.html#faq_130" target="_blank">here is an example using QxOrm Trigger</a>)
*/
template <class T>
inline void on_before_delete(T *t, qx::dao::detail::IxDao_Helper *dao)
{
qx::dao::detail::QxDao_Trigger<T>::onBeforeDelete(t, dao);
}
/*!
* \ingroup QxDao
* \brief Callback before fetching an object from database (<a href="https://www.qxorm.com/qxorm_en/faq.html#faq_130" target="_blank">here is an example using QxOrm Trigger</a>)
*/
template <class T>
inline void on_before_fetch(T *t, qx::dao::detail::IxDao_Helper *dao)
{
qx::dao::detail::QxDao_Trigger<T>::onBeforeFetch(t, dao);
}
/*!
* \ingroup QxDao
* \brief Callback after inserting an object into database (<a href="https://www.qxorm.com/qxorm_en/faq.html#faq_130" target="_blank">here is an example using QxOrm Trigger</a>)
*/
template <class T>
inline void on_after_insert(T *t, qx::dao::detail::IxDao_Helper *dao)
{
qx::dao::detail::QxDao_Trigger<T>::onAfterInsert(t, dao);
}
/*!
* \ingroup QxDao
* \brief Callback after updating an object into database (<a href="https://www.qxorm.com/qxorm_en/faq.html#faq_130" target="_blank">here is an example using QxOrm Trigger</a>)
*/
template <class T>
inline void on_after_update(T *t, qx::dao::detail::IxDao_Helper *dao)
{
qx::dao::detail::QxDao_Trigger<T>::onAfterUpdate(t, dao);
}
/*!
* \ingroup QxDao
* \brief Callback after deleting an object into database (<a href="https://www.qxorm.com/qxorm_en/faq.html#faq_130" target="_blank">here is an example using QxOrm trigger</a>)
*/
template <class T>
inline void on_after_delete(T *t, qx::dao::detail::IxDao_Helper *dao)
{
qx::dao::detail::QxDao_Trigger<T>::onAfterDelete(t, dao);
}
/*!
* \ingroup QxDao
* \brief Callback after fetching an object from database (<a href="https://www.qxorm.com/qxorm_en/faq.html#faq_130" target="_blank">here is an example using QxOrm trigger</a>)
*/
template <class T>
inline void on_after_fetch(T *t, qx::dao::detail::IxDao_Helper *dao)
{
qx::dao::detail::QxDao_Trigger<T>::onAfterFetch(t, dao);
}
} // namespace dao
} // namespace qx
#endif // _QX_DAO_H_

238
include/QxDao/QxDaoAsync.h Normal file
View File

@@ -0,0 +1,238 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DAO_ASYNC_H_
#define _QX_DAO_ASYNC_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDaoAsync.h
* \author XDL Team
* \ingroup QxDao
* \brief Helper class to execute SQL queries in another thread (asynchronous way) using qx::IxPersistable interface
*/
#ifdef _QX_NO_PRECOMPILED_HEADER
#ifndef Q_MOC_RUN
#include <QxPrecompiled.h> // Need to include precompiled header for the generated moc file
#endif // Q_MOC_RUN
#endif // _QX_NO_PRECOMPILED_HEADER
#include <QtCore/qqueue.h>
#include <QtSql/qsqlerror.h>
#ifndef Q_MOC_RUN
#include <QxDao/IxPersistable.h>
#include <QxDao/QxSqlQuery.h>
#endif // Q_MOC_RUN
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxDaoAsyncParams : all parameters for qx::QxDaoAsync class to execute queries
*/
struct QxDaoAsyncParams
{
enum dao_action
{
dao_none,
dao_count,
dao_fetch_by_id,
dao_fetch_all,
dao_fetch_by_query,
dao_insert,
dao_update,
dao_save,
dao_delete_by_id,
dao_delete_all,
dao_delete_by_query,
dao_destroy_by_id,
dao_destroy_all,
dao_destroy_by_query,
dao_execute_query,
dao_call_query
};
dao_action daoAction; //!< Action to execute into the thread (asynchronous way)
QString className; //!< Classname parameter to execute action (must implement qx::IxPersistable interface)
qx::QxSqlQuery query; //!< Query parameter to execute action
QSqlDatabase *pDatabase; //!< Database parameter to execute action
IxPersistable_ptr pInstance; //!< Current instance parameter to execute action
IxPersistableCollection_ptr pListOfInstances; //!< List of instances fetched by query
QStringList listColumns; //!< List of columns parameter to execute action
QStringList listRelations; //!< List of relationships parameter to execute action
QVariant id; //!< Current instance id parameter to execute action
long daoCount; //!< Dao count value returned by qx::dao::count query
bool useExecBatch; //!< If true then use the QSqlQuery::execBatch() method to improve performance inserting/updating/deleting a list of instances to database (but doesn't fill the last inserted identifier in the C++ instances)
QxDaoAsyncParams() : daoAction(dao_none), pDatabase(NULL), daoCount(0), useExecBatch(false) { ; }
~QxDaoAsyncParams() { ; }
};
typedef std::shared_ptr<QxDaoAsyncParams> QxDaoAsyncParams_ptr;
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxDaoAsyncRunner : class with a slot to execute queries in another thread
*/
class QX_DLL_EXPORT QxDaoAsyncRunner : public QObject
{
Q_OBJECT
public:
QxDaoAsyncRunner();
virtual ~QxDaoAsyncRunner();
protected:
QSqlError runQuery(qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams);
Q_SIGNALS:
void queryFinished(const QSqlError &daoError, qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams);
public Q_SLOTS:
void onQueryStarted(qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams);
};
} // namespace detail
} // namespace dao
/*!
* \ingroup QxDao
* \brief qx::QxDaoAsync : helper class to execute SQL queries in another thread (asynchronous way) using qx::IxPersistable interface
*
* To use <i>qx::QxDaoAsync</i> helper class :
* 1- be careful to work only with classes implementing <i>qx::IxPersistable</i> interface ;
* 2- create an instance of <i>qx::QxDaoAsync</i> type (for example, a property of a QWidget derived class) ;
* 3- connect a SLOT to the <i>qx::QxDaoAsync::queryFinished()</i> SIGNAL (for example, a SLOT of a QWidget derived class) ;
* 4- run a query using one of <i>qx::QxDaoAsync::asyncXXXX()</i> methods.
*
* For example, with a <i>MyWidget</i> class :
* \code
class MyWidget : public QWidget
{
Q_OBJECT
//...
qx::QxDaoAsync m_daoAsync;
//...
Q_SLOTS:
void onQueryFinished(const QSqlError & daoError, qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams);
//...
};
* \endcode
* And here is the implementation of <i>MyWidget</i> class :
* \code
MyWidget::MyWidget() : QObject()
{
//...
QObject::connect((& m_daoAsync), SIGNAL(queryFinished(const QSqlError &, qx::dao::detail::QxDaoAsyncParams_ptr)), this, SLOT(onQueryFinished(const QSqlError &, qx::dao::detail::QxDaoAsyncParams_ptr)));
//...
}
void MyWidget::onQueryFinished(const QSqlError & daoError, qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams)
{
if (! pDaoParams) { return; }
qx::QxSqlQuery query = pDaoParams->query;
if (! daoError.isValid()) { ; }
// If the async query is associated to a simple object, just use 'pDaoParams->pInstance' method
qx::IxPersistable_ptr ptr = pDaoParams->pInstance;
// If the async query is associated to a list of objects, just use 'pDaoParams->pListOfInstances' method
qx::IxPersistableCollection_ptr lst = pDaoParams->pListOfInstances;
//...
}
* \endcode
*/
class QX_DLL_EXPORT QxDaoAsync : public QThread
{
Q_OBJECT
protected:
QMutex m_mutex; //!< Mutex => qx::QxDaoAsync is thread-safe
qx::dao::detail::QxDaoAsyncParams_ptr m_pDaoParams; //!< Parameters to execute query
public:
QxDaoAsync();
virtual ~QxDaoAsync();
bool asyncCount(const QString &className, const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL);
bool asyncFetchById(IxPersistable_ptr pToFetch, const QVariant &id = QVariant(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL);
bool asyncFetchAll(const QString &className, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL);
bool asyncFetchByQuery(const QString &className, const qx::QxSqlQuery &query, const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL);
bool asyncInsert(IxPersistable_ptr pToInsert, const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL);
bool asyncUpdate(IxPersistable_ptr pToUpdate, const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL);
bool asyncSave(IxPersistable_ptr pToSave, const QStringList &relation = QStringList(), QSqlDatabase *pDatabase = NULL);
bool asyncDeleteById(IxPersistable_ptr pToDelete, const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL);
bool asyncDeleteAll(const QString &className, QSqlDatabase *pDatabase = NULL);
bool asyncDeleteByQuery(const QString &className, const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL);
bool asyncDestroyById(IxPersistable_ptr pToDestroy, const QVariant &id = QVariant(), QSqlDatabase *pDatabase = NULL);
bool asyncDestroyAll(const QString &className, QSqlDatabase *pDatabase = NULL);
bool asyncDestroyByQuery(const QString &className, const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL);
bool asyncExecuteQuery(const QString &className, qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL);
bool asyncCallQuery(qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL);
bool isQueryRunning() const { return (m_pDaoParams.get() != NULL); }
protected:
virtual void run();
void startQuery();
Q_SIGNALS:
void queryStarted(qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams);
void queryFinished(const QSqlError &daoError, qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams);
private Q_SLOTS:
void onQueryFinished(const QSqlError &daoError, qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams);
};
typedef std::shared_ptr<QxDaoAsync> QxDaoAsync_ptr;
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::dao::detail::QxDaoAsyncParams &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::dao::detail::QxDaoAsyncParams &t) QX_USED;
#endif // _QX_DAO_ASYNC_H_

View File

@@ -0,0 +1,333 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DAO_POINTER_H_
#define _QX_DAO_POINTER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDaoPointer.h
* \author XDL Team
* \ingroup QxDao
* \brief qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) with some features associated with QxDao module of QxOrm library
*/
#include <QtCore/qsharedpointer.h>
#include <QtCore/qstringlist.h>
#include <QtCore/qdatastream.h>
#include <QxSerialize/QDataStream/QxSerializeQDataStream_QSharedPointer.h>
namespace qx
{
template <class T>
QSharedPointer<T> clone_to_qt_shared_ptr(const T &obj);
} // namespace qx
namespace qx
{
namespace dao
{
template <typename T>
class ptr;
} // namespace dao
} // namespace qx
template <typename T>
QDataStream &operator<<(QDataStream &stream, const qx::dao::ptr<T> &t);
template <typename T>
QDataStream &operator>>(QDataStream &stream, qx::dao::ptr<T> &t);
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_IsDirty;
} // namespace detail
/*!
* \ingroup QxDao
* \brief qx::dao::ptr<T> : provide a classic smart-pointer (like boost::shared_ptr<T> or QSharedPointer<T>) with some features associated with QxDao module of QxOrm library
*
* QxOrm can be used with smart-pointers of boost and Qt libraries.
* QxOrm smart-pointer is based on QSharedPointer and provides new features with qx::dao::xxx functions of QxDao module.
* qx::dao::ptr<T> keeps automatically values from database.
* So it's possible to detect if an instance has been modified using the method isDirty() : this method can return list of properties changed.
* qx::dao::ptr<T> can also be used with the function qx::dao::update_optimized() to update in database only properties changed.
* qx::dao::ptr<T> can be used with a simple object and with many containers : stl, boost, Qt and qx::QxCollection<Key, Value>.
*
* Quick sample using qx::dao::ptr<T> smart-pointer :
* \code
// Test 'isDirty()' method
qx::dao::ptr<blog> blog_isdirty = qx::dao::ptr<blog>(new blog());
blog_isdirty->m_id = blog_1->m_id;
daoError = qx::dao::fetch_by_id(blog_isdirty);
qAssert(! daoError.isValid() && ! blog_isdirty.isDirty());
blog_isdirty->m_text = "blog property 'text' modified => blog is dirty !!!";
QStringList lstDiff; bool bDirty = blog_isdirty.isDirty(lstDiff);
qAssert(bDirty && (lstDiff.count() == 1) && (lstDiff.at(0) == "blog_text"));
if (bDirty) { qDebug("[QxOrm] test dirty 1 : blog is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
// Update only property 'm_text' of 'blog_isdirty'
daoError = qx::dao::update_optimized(blog_isdirty);
qAssert(! daoError.isValid() && ! blog_isdirty.isDirty());
qx::dump(blog_isdirty);
// Test 'isDirty()' method with a container
typedef qx::dao::ptr< QList<author_ptr> > type_lst_author_test_is_dirty;
type_lst_author_test_is_dirty container_isdirty = type_lst_author_test_is_dirty(new QList<author_ptr>());
daoError = qx::dao::fetch_all(container_isdirty);
qAssert(! daoError.isValid() && ! container_isdirty.isDirty() && (container_isdirty->count() == 3));
author_ptr author_ptr_dirty = container_isdirty->at(1);
author_ptr_dirty->m_name = "author name modified at index 1 => container is dirty !!!";
bDirty = container_isdirty.isDirty(lstDiff);
qAssert(bDirty && (lstDiff.count() == 1));
if (bDirty) { qDebug("[QxOrm] test dirty 2 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
author_ptr_dirty = container_isdirty->at(2);
author_ptr_dirty->m_birthdate = QDate(1998, 03, 06);
bDirty = container_isdirty.isDirty(lstDiff);
qAssert(bDirty && (lstDiff.count() == 2));
if (bDirty) { qDebug("[QxOrm] test dirty 3 : container is dirty => '%s'", qPrintable(lstDiff.join("|"))); }
// Update only property 'm_name' at position 1, only property 'm_birthdate' at position 2 and nothing at position 0
daoError = qx::dao::update_optimized(container_isdirty);
qAssert(! daoError.isValid() && ! container_isdirty.isDirty());
qx::dump(container_isdirty);
// Fetch only property 'm_dt_creation' of blog
QStringList lstColumns = QStringList() << "date_creation";
list_blog lst_blog_with_only_date_creation;
daoError = qx::dao::fetch_all(lst_blog_with_only_date_creation, NULL, lstColumns);
qAssert(! daoError.isValid() && (lst_blog_with_only_date_creation.size() > 0));
if ((lst_blog_with_only_date_creation.size() > 0) && (lst_blog_with_only_date_creation[0] != NULL))
{ qAssert(lst_blog_with_only_date_creation[0]->m_text.isEmpty()); }
qx::dump(lst_blog_with_only_date_creation);
* \endcode
*/
template <typename T>
class ptr
{
template <class U>
friend QDataStream & ::operator<<(QDataStream & stream, const qx::dao::ptr<U> &t);
template <class U>
friend QDataStream & ::operator>>(QDataStream & stream, qx::dao::ptr<U> &t);
private:
QSharedPointer<T> m_pWork; //!< Default pointer => user works with this pointer
QSharedPointer<T> m_pOriginal; //!< Keep original pointer containing all values from database
public:
ptr() { ; }
explicit ptr(T *ptr) : m_pWork(ptr) { ; }
explicit ptr(T *ptr, T *original) : m_pWork(ptr), m_pOriginal(original) { ; }
ptr(const qx::dao::ptr<T> &other) : m_pWork(other.m_pWork), m_pOriginal(other.m_pOriginal) { ; }
ptr(const QSharedPointer<T> &other) : m_pWork(other) { ; }
ptr(const QSharedPointer<T> &other, const QSharedPointer<T> &original) : m_pWork(other), m_pOriginal(original) { ; }
ptr(const QWeakPointer<T> &other) : m_pWork(other) { ; }
ptr(const QWeakPointer<T> &other, const QWeakPointer<T> &original) : m_pWork(other), m_pOriginal(original) { ; }
virtual ~ptr() { ; }
template <typename Deleter>
ptr(T *ptr, Deleter deleter) : m_pWork(ptr, deleter) { ; }
template <typename Deleter>
ptr(T *ptr, T *original, Deleter deleter) : m_pWork(ptr, deleter), m_pOriginal(original) { ; }
template <class X>
ptr(const qx::dao::ptr<X> &other) : m_pWork(qSharedPointerCast<T>(other.m_pWork)), m_pOriginal(qSharedPointerCast<T>(other.m_pOriginal)) { ; }
template <class X>
ptr(const QSharedPointer<X> &other) : m_pWork(qSharedPointerCast<T>(other)) { ; }
template <class X>
ptr(const QSharedPointer<X> &other, const QSharedPointer<T> &original) : m_pWork(qSharedPointerCast<T>(other)), m_pOriginal(qSharedPointerCast<T>(original)) { ; }
template <class X>
ptr(const QWeakPointer<X> &other) : m_pWork(qSharedPointerCast<T>(other.toStrongRef())) { ; }
template <class X>
ptr(const QWeakPointer<X> &other, const QWeakPointer<X> &original) : m_pWork(qSharedPointerCast<T>(other.toStrongRef())), m_pOriginal(qSharedPointerCast<T>(original.toStrongRef())) { ; }
qx::dao::ptr<T> &operator=(const qx::dao::ptr<T> &other)
{
m_pWork = other.m_pWork;
m_pOriginal = other.m_pOriginal;
return (*this);
}
qx::dao::ptr<T> &operator=(const QSharedPointer<T> &other)
{
m_pWork = other;
m_pOriginal.clear();
return (*this);
}
qx::dao::ptr<T> &operator=(const QWeakPointer<T> &other)
{
m_pWork = other;
m_pOriginal.clear();
return (*this);
}
template <class X>
qx::dao::ptr<T> &operator=(const qx::dao::ptr<X> &other)
{
m_pWork = qSharedPointerCast<T>(other.m_pWork);
m_pOriginal = qSharedPointerCast<T>(other.m_pOriginal);
return (*this);
}
template <class X>
qx::dao::ptr<T> &operator=(const QSharedPointer<X> &other)
{
m_pWork = qSharedPointerCast<T>(other);
m_pOriginal.clear();
return (*this);
}
template <class X>
qx::dao::ptr<T> &operator=(const QWeakPointer<X> &other)
{
m_pWork = qSharedPointerCast<T>(other.toStrongRef());
m_pOriginal.clear();
return (*this);
}
inline T *get() const { return m_pWork.data(); }
inline T *getOriginal() const { return m_pOriginal.data(); }
inline T *data() const { return m_pWork.data(); }
inline T *dataOriginal() const { return m_pOriginal.data(); }
inline bool isNull() const { return m_pWork.isNull(); }
inline operator bool() const { return (!m_pWork.isNull()); }
inline bool operator!() const { return m_pWork.isNull(); }
inline T &operator*() const { return (*m_pWork.data()); }
inline T *operator->() const { return m_pWork.data(); }
inline void clear()
{
m_pWork.clear();
m_pOriginal.clear();
}
inline void reset()
{
m_pWork.clear();
m_pOriginal.clear();
}
inline void reset(const QSharedPointer<T> &ptr)
{
m_pWork = ptr;
m_pOriginal.clear();
}
inline void resetOriginal(const QSharedPointer<T> &ptr) { m_pOriginal = ptr; }
inline bool isDirty() const
{
QStringList lstDiff;
return isDirty(lstDiff);
}
inline QSharedPointer<T> toQtSharedPointer() const { return m_pWork; }
inline void saveToOriginal()
{
m_pOriginal.clear();
if (m_pWork)
{
m_pOriginal = qx::clone_to_qt_shared_ptr(*m_pWork);
}
}
inline void restoreFromOriginal()
{
m_pWork.clear();
if (m_pOriginal)
{
m_pWork = qx::clone_to_qt_shared_ptr(*m_pOriginal);
}
}
template <class X>
qx::dao::ptr<X> staticCast() const { return qx::dao::ptr<X>(m_pWork.template staticCast<X>(), m_pOriginal.template staticCast<X>()); }
template <class X>
qx::dao::ptr<X> dynamicCast() const { return qx::dao::ptr<X>(m_pWork.template dynamicCast<X>(), m_pOriginal.template dynamicCast<X>()); }
template <class X>
qx::dao::ptr<X> constCast() const { return qx::dao::ptr<X>(m_pWork.template constCast<X>(), m_pOriginal.template constCast<X>()); }
bool isDirty(QStringList &lstDiff) const
{
lstDiff.clear();
if (m_pWork.isNull() || m_pOriginal.isNull())
{
lstDiff.append("*");
return true;
}
if (m_pWork == m_pOriginal)
{
return false;
}
qx::dao::detail::QxDao_IsDirty<T>::compare((*m_pWork), (*m_pOriginal), lstDiff);
return (!lstDiff.isEmpty());
}
};
} // namespace dao
} // namespace qx
template <class T, class X>
bool operator==(const qx::dao::ptr<T> &ptr1, const qx::dao::ptr<X> &ptr2) { return (ptr1.toQtSharedPointer() == ptr2.toQtSharedPointer()); }
template <class T, class X>
bool operator!=(const qx::dao::ptr<T> &ptr1, const qx::dao::ptr<X> &ptr2) { return (ptr1.toQtSharedPointer() != ptr2.toQtSharedPointer()); }
template <class T, class X>
bool operator==(const qx::dao::ptr<T> &ptr1, const X *ptr2) { return (ptr1.toQtSharedPointer() == ptr2); }
template <class T, class X>
bool operator!=(const qx::dao::ptr<T> &ptr1, const X *ptr2) { return (ptr1.toQtSharedPointer() != ptr2); }
template <class T, class X>
bool operator==(const T *ptr1, const qx::dao::ptr<X> &ptr2) { return (ptr1 == ptr2.toQtSharedPointer()); }
template <class T, class X>
bool operator!=(const T *ptr1, const qx::dao::ptr<X> &ptr2) { return (ptr1 != ptr2.toQtSharedPointer()); }
template <typename T>
QDataStream &operator<<(QDataStream &stream, const qx::dao::ptr<T> &t)
{
stream << t.m_pWork;
stream << t.m_pOriginal;
return stream;
}
template <typename T>
QDataStream &operator>>(QDataStream &stream, qx::dao::ptr<T> &t)
{
stream >> t.m_pWork;
stream >> t.m_pOriginal;
return stream;
}
#endif // _QX_DAO_POINTER_H_

View File

@@ -0,0 +1,78 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DAO_STRATEGY_H_
#define _QX_DAO_STRATEGY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDaoStrategy.h
* \author XDL Team
* \ingroup QxDao
* \brief Class inheritance strategy and database (Concrete Table Inheritance is the default strategy used by QxOrm library)
*/
namespace qx
{
namespace dao
{
/*!
* \ingroup QxDao
* \brief qx::dao::strategy : class inheritance strategy and database (Concrete Table Inheritance is the default strategy used by QxOrm library)
*
* With ORM tools, there is usually 3 strategies to manage inheritance and database :
* - Single Table Inheritance
* - Class Table Inheritance
* - Concrete Table Inheritance
*
* QxOrm works by default with Concrete Table Inheritance strategy (others are not supported yet).
* Many tutorials and forums are available on internet to more details about ORM inheritance and database.
* You can find a sample in the directory ./test/qxDllSample/dll2/ with the class BaseClassTrigger.
*/
struct strategy
{
enum inheritance
{
single_table_inheritance,
class_table_inheritance,
concrete_table_inheritance
};
};
} // namespace dao
} // namespace qx
#endif // _QX_DAO_STRATEGY_H_

View File

@@ -0,0 +1,955 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DAO_THROWABLE_H_
#define _QX_DAO_THROWABLE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDaoThrowable.h
* \author XDL Team
* \ingroup QxDao
* \brief Same functions as qx::dao namespace, but throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred (instead of returning a QSqlError instance)
*/
#include <QxDao/QxDao.h>
#include <QxDao/QxSqlError.h>
namespace qx
{
namespace dao
{
/*!
* \ingroup QxDao
* \brief Same functions as qx::dao namespace, but throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred (instead of returning a QSqlError instance)
*/
namespace throwable
{
/// @cond TO_AVOID_DOXYGEN_WARNINGS
/*!
* \ingroup QxDao
* \brief Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm context) and filtered by a user SQL query
* \param lCount Output parameter with the number of lines in the table associated to the SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library (optional parameter)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
*
* qx::dao::throwable::count<T>() execute following SQL query :<br>
* <i>SELECT COUNT(*) FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void count(long &lCount, const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Count<T>::count(lCount, query, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Return the number of lines in the table (database) mapped to the C++ class T (registered into QxOrm context) and filtered by a user SQL query (with possibility to add relations to SQL query)
* \param lCount Output parameter with the number of lines in the table associated to the SQL query
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
* \param query Define a user SQL query added to default SQL query builded by QxOrm library (optional parameter)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
*
* qx::dao::throwable::count_with_relation<T>() execute following SQL query :<br>
* <i>SELECT COUNT(*) FROM my_table</i> + <i>XXX_JOINS_XXX</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void count_with_relation(long &lCount, const QStringList &relation, const qx::QxSqlQuery &query = qx::QxSqlQuery(), QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Count_WithRelation<T>::count(lCount, relation, query, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Insert an element or a list of elements into database
* \param t Element (or list of elements) to be inserted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance inserting a list of instances to database (but doesn't fill the last inserted identifier in the C++ instances)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::insert<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
*/
template <class T>
inline void insert(T &t, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
QSqlError err = qx::dao::detail::QxDao_Insert<T>::insert(t, pDatabase, bUseExecBatch);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) an element or a list of elements into database
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::save<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline void save(T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Save<T>::save(t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Delete a line (or list of lines) of a table (database) mapped to a C++ object of type T (registered into QxOrm context)
* \param t Element (or list of elements) to be deleted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance deleting a list of instances in database
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::delete_by_id<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table WHERE my_id = ?</i><br>
* <br>
* If a soft delete behavior is defined for class T, qx::dao::throwable::delete_by_id<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET is_deleted='1' WHERE my_id = ?</i>
*/
template <class T>
inline void delete_by_id(T &t, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, true, bUseExecBatch);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Destroy a line (or list of lines) of a table (database) mapped to a C++ object of type T (registered into QxOrm context), even if a soft delete behavior is defined for class T
* \param t Element (or list of elements) to be destroyed into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance destroying a list of instances in database
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::destroy_by_id<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline void destroy_by_id(T &t, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
QSqlError err = qx::dao::detail::QxDao_DeleteById<T>::deleteById(t, pDatabase, false, bUseExecBatch);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::delete_all<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table</i><br>
* <br>
* If a soft delete behavior is defined for class T, qx::dao::throwable::delete_all<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET is_deleted='1'</i>
*/
template <class T>
inline void delete_all(QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, true);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Destroy all lines of a table (database) mapped to a C++ class T (registered into QxOrm context), even if a soft delete behavior is defined for class T
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::destroy_all<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table</i>
*/
template <class T>
inline void destroy_all(QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll("", pDatabase, false);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Delete all lines of a table (database) mapped to a C++ class T (registered into QxOrm context) and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::delete_by_query<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table</i> + <i>WHERE my_query...</i><br>
* <br>
* If a soft delete behavior is defined for class T, qx::dao::throwable::delete_by_query<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET is_deleted='1'</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void delete_by_query(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, true);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Destroy all lines of a table (database) mapped to a C++ class T (registered into QxOrm context) and filtered by a user SQL query, even if a soft delete behavior is defined for class T
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::destroy_by_query<T>() execute following SQL query :<br>
* <i>DELETE FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void destroy_by_query(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_DeleteAll<T>::deleteAll(query, pDatabase, false);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Create a table into database (with all columns) mapped to a C++ class T (registered into QxOrm context) : be careful, this function can be used only with a SQLite database to create examples or prototypes; For other databases, it is recommended to use QxEntityEditor application or to manage the database schema with an external tool provided by the SGBD (SQLite Manager for SQLite, pgAdmin for PostgreSQL, MySQL Workbench for MySQL, etc...)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::create_table<T>() execute following SQL query :<br>
* <i>CREATE TABLE my_table (my_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, my_column_1 TEXT, my_column_2 TEXT, etc.)</i>
*/
template <class T>
inline void create_table(QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_CreateTable<T>::createTable(pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a table in the database (t must have a valid id before to be fetched without error)
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
* \param t Instance (with a valid id) to be fetched (retrieve all properties from database)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_by_id_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline void fetch_by_id_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a table in the database (t must have a valid id before to be fetched without error)
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
* \param t Instance (with a valid id) to be fetched (retrieve all properties from database)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_by_id_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline void fetch_by_id_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById(relation, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch an object t (retrieve all its properties and relationships) of type T (registered into QxOrm context) mapped to a table in the database (t must have a valid id before to be fetched without error)
* \param t Instance (with a valid id) to be fetched (retrieve all properties and relationships from database)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_by_id_with_all_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline void fetch_by_id_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_FetchById_WithRelation<T>::fetchById("*", t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_all_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i>
*/
template <class T>
inline void fetch_all_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_all_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i>
*/
template <class T>
inline void fetch_all_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, "", t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties + all relationships associated) of type T (container registered into QxOrm context) mapped to a table in the database
* \param t Container to be fetched (retrieve all elements and properties + all relationships associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_all_with_all_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i>
*/
template <class T>
inline void fetch_all_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", "", t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_by_query_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void fetch_by_query_with_relation(const QString &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query
* \param relation List of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_by_query_with_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void fetch_by_query_with_relation(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll(relation, query, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties + all relationships associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Container to be fetched (retrieve all elements and properties + all relationships associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_by_query_with_all_relation<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void fetch_by_query_with_all_relation(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_FetchAll_WithRelation<T>::fetchAll("*", query, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Insert an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be inserted in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param t Element (or list of elements) to be inserted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::insert_with_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
*/
template <class T>
inline void insert_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Insert an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be inserted in others tables of database
* \param t Element (or list of elements) to be inserted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::insert_with_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
*/
template <class T>
inline void insert_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert(relation, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Insert an element and all its relationships (or a list of elements + all relationships) into database
* \param t Element (or list of elements) to be inserted into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::insert_with_all_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
*/
template <class T>
inline void insert_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Insert_WithRelation<T>::insert("*", t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be updated in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update_with_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline void update_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update an element and its relationships (or a list of elements + relationships) into database (adding a user SQL query to the default SQL query builded by QxOrm library)
* \param relation List of relationships keys to be updated in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update_by_query_with_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void update_by_query_with_relation(const QString &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be updated in others tables of database
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update_with_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline void update_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, "", t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update an element and its relationships (or a list of elements + relationships) into database (adding a user SQL query to the default SQL query builded by QxOrm library)
* \param relation List of relationships keys to be updated in others tables of database
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update_by_query_with_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void update_by_query_with_relation(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update(relation, query, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update an element and all its relationships (or a list of elements + all relationships) into database
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update_with_all_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline void update_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", "", t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update an element and all its relationships (or a list of elements + all relationships) into database (adding a user SQL query to the default SQL query builded by QxOrm library)
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update_by_query_with_all_relation<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void update_by_query_with_all_relation(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Update_WithRelation<T>::update("*", query, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be inserted or updated in others tables of database : use "|" separator to put many relationships keys into this parameter
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::save_with_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline void save_with_relation(const QString &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) an element and its relationships (or a list of elements + relationships) into database
* \param relation List of relationships keys to be inserted or updated in others tables of database
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::save_with_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline void save_with_relation(const QStringList &relation, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save(relation, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) an element and all its relationships (or a list of elements + all relationships) into database
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::save_with_all_relation<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline void save_with_all_relation(T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Save_WithRelation<T>::save("*", t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Insert (if no exist) or update (if already exist) recursively an element and all levels of relationships (or a list of elements + all levels of relationships) into database, useful to save a tree structure for example
* \param t Element (or list of elements) to be inserted (if no exist) or updated (if already exist) into database
* \param eSaveMode To improve performance, use this parameter to indicate if you just want to insert or update all elements in database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param pRelationParams Keep this parameter as NULL, it is used internally by QxOrm library to iterate over each level of relationship
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::save_with_relation_recursive<T>() execute following SQL query :<br>
* <i>INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)</i>
* <br>or (if already exist into database) :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i><br>
* <br>
* <b>Note :</b> to improve performance, and if you know that you are just inserting or updating items in database, you can use the parameter <i>eSaveMode</i> :<br>
* - <i>qx::dao::save_mode::e_check_insert_or_update</i> : check before saving if item already exists in database ;<br>
* - <i>qx::dao::save_mode::e_insert_only</i> : only insert items in database (use only 1 SQL query to insert collection of items) ;<br>
* - <i>qx::dao::save_mode::e_update_only</i> : only update items in database (use only 1 SQL query to update collection of items).
*/
template <class T>
inline void save_with_relation_recursive(T &t, qx::dao::save_mode::e_save_mode eSaveMode = qx::dao::save_mode::e_check_insert_or_update, QSqlDatabase *pDatabase = NULL, qx::QxSqlRelationParams *pRelationParams = NULL)
{
QSqlError err = qx::dao::detail::QxDao_Save_WithRelation_Recursive<T>::save(t, eSaveMode, pDatabase, pRelationParams);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch an object t (retrieve all its properties) of type T (registered into QxOrm context) mapped to a table in the database (t must have a valid id before to be fetched without error)
* \param t Instance (with a valid id) to be fetched (retrieve all properties from database)
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be fetched (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_by_id<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table WHERE my_id = ?</i>
*/
template <class T>
inline void fetch_by_id(T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList())
{
QSqlError err = qx::dao::detail::QxDao_FetchById<T>::fetchById(t, pDatabase, columns);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be fetched (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_all<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i>
*/
template <class T>
inline void fetch_all(T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList())
{
QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll("", t, pDatabase, columns);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Fetch a list of objects (retrieve all elements and properties associated) of type T (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Container to be fetched (retrieve all elements and properties associated); t is cleared before executing SQL query
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be fetched (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::fetch_by_query<T>() execute following SQL query :<br>
* <i>SELECT * FROM my_table</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void fetch_by_query(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList())
{
QSqlError err = qx::dao::detail::QxDao_FetchAll<T>::fetchAll(query, t, pDatabase, columns);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update an element or a list of elements into database
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be updated (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline void update(T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList(), bool bUseExecBatch = false)
{
QSqlError err = qx::dao::detail::QxDao_Update<T>::update("", t, pDatabase, columns, bUseExecBatch);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update an element or a list of elements into database (adding a user SQL query to the default SQL query builded by QxOrm library)
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param t Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param columns List of database table columns (mapped to properties of C++ class T) to be updated (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update_by_query<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void update_by_query(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL, const QStringList &columns = QStringList(), bool bUseExecBatch = false)
{
QSqlError err = qx::dao::detail::QxDao_Update<T>::update(query, t, pDatabase, columns, bUseExecBatch);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update only modified fields/properties of an element or a list of elements into database (using is dirty pattern and qx::dao::ptr<T> smart-pointer)
* \param ptr Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update_optimized<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i>
*/
template <class T>
inline void update_optimized(qx::dao::ptr<T> &ptr, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized("", ptr, pDatabase, bUseExecBatch);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Update only modified fields/properties of an element or a list of elements into database (using is dirty pattern and qx::dao::ptr<T> smart-pointer), adding a user SQL query to the default SQL query builded by QxOrm library
* \param query Define a user SQL query added to default SQL query builded by QxOrm library
* \param ptr Element (or list of elements) to be updated into database
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \param bUseExecBatch If true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*
* qx::dao::throwable::update_optimized_by_query<T>() execute following SQL query :<br>
* <i>UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.</i> + <i>WHERE my_query...</i>
*/
template <class T>
inline void update_optimized_by_query(const qx::QxSqlQuery &query, qx::dao::ptr<T> &ptr, QSqlDatabase *pDatabase = NULL, bool bUseExecBatch = false)
{
QSqlError err = qx::dao::detail::QxDao_Update_Optimized<T>::update_optimized(query, ptr, pDatabase, bUseExecBatch);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/*!
* \ingroup QxDao
* \brief Execute a custom SQL query or a stored procedure, all columns that can be mapped to the instance of type T will be fetched automatically
* \param query Define a custom SQL query or a stored procedure to call
* \param t Instance of type T, all columns that can be mapped to this instance will be fetched automatically
* \param pDatabase Connection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class (optional parameter)
* \return Throw a <i>qx::dao::sql_error</i> exception when a SQL error occurred
*/
template <class T>
inline void execute_query(qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::detail::QxDao_ExecuteQuery<T>::executeQuery(query, t, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
inline void call_query(qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL)
{
QSqlError err = qx::dao::call_query(query, pDatabase);
if (err.isValid())
{
throw qx::dao::sql_error(err);
}
}
/// @endcond
} // namespace throwable
} // namespace dao
} // namespace qx
#endif // _QX_DAO_THROWABLE_H_

View File

@@ -0,0 +1,88 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DAO_IMPL_H_
#define _QX_DAO_IMPL_H_
#ifdef _MSC_VER
#pragma once
#endif
#include <QxDao/QxDao.h>
#include <QxDao/QxDaoPointer.h>
#include <QxDao/QxDao_IsDirty.h>
#include <QxDao/QxSqlDatabase.h>
#include <QxDao/QxSqlQueryBuilder.h>
#include <QxDao/QxSqlQueryHelper.h>
#include <QxCollection/QxCollection.h>
#include <QxRegister/QxClass.h>
#include <QxTraits/is_qx_registered.h>
#include <QxTraits/is_container.h>
#include <QxTraits/is_smart_ptr.h>
#include <QxTraits/get_base_class.h>
#include <QxTraits/get_class_name_primitive.h>
#include <QxTraits/construct_ptr.h>
#include <QxTraits/generic_container.h>
#include <QxTraits/is_valid_primary_key.h>
#ifdef _QX_ENABLE_MONGODB
#include <QxDao/QxMongoDB/QxMongoDB_Helper.h>
#ifndef _QX_NO_JSON
#include <QxSerialize/QJson/QxSerializeQJson_qx_registered_class.h>
#include <QxSerialize/QxSerializeQJson.h>
#endif // _QX_NO_JSON
#endif // _QX_ENABLE_MONGODB
#include "../../inl/QxDao/QxDao_Helper.inl"
#include "../../inl/QxDao/QxDao_Count.inl"
#include "../../inl/QxDao/QxDao_FetchById.inl"
#include "../../inl/QxDao/QxDao_FetchById_WithRelation.inl"
#include "../../inl/QxDao/QxDao_FetchAll.inl"
#include "../../inl/QxDao/QxDao_FetchAll_WithRelation.inl"
#include "../../inl/QxDao/QxDao_Insert.inl"
#include "../../inl/QxDao/QxDao_Insert_WithRelation.inl"
#include "../../inl/QxDao/QxDao_Update.inl"
#include "../../inl/QxDao/QxDao_Update_Optimized.inl"
#include "../../inl/QxDao/QxDao_Update_WithRelation.inl"
#include "../../inl/QxDao/QxDao_Save.inl"
#include "../../inl/QxDao/QxDao_Save_WithRelation.inl"
#include "../../inl/QxDao/QxDao_Save_WithRelation_Recursive.inl"
#include "../../inl/QxDao/QxDao_DeleteById.inl"
#include "../../inl/QxDao/QxDao_DeleteAll.inl"
#include "../../inl/QxDao/QxDao_Exist.inl"
#include "../../inl/QxDao/QxDao_CreateTable.inl"
#include "../../inl/QxDao/QxDao_Trigger.inl"
#include "../../inl/QxDao/QxDao_ExecuteQuery.inl"
#endif // _QX_DAO_IMPL_H_

View File

@@ -0,0 +1,153 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DAO_IS_DIRTY_H_
#define _QX_DAO_IS_DIRTY_H_
#ifdef _MSC_VER
#pragma once
#endif
#include <QtCore/qstringlist.h>
#include <QxDao/QxSqlQueryBuilder.h>
#include <QxDao/IxSqlRelation.h>
#include <QxTraits/is_qx_registered.h>
#include <QxTraits/is_container.h>
#include <QxTraits/is_smart_ptr.h>
#include <QxTraits/generic_container.h>
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
inline void is_dirty(const T &obj1, const T &obj2, QStringList &lstDiff);
template <class T>
struct QxDao_IsDirty_Generic
{
static void compare(const T &obj1, const T &obj2, QStringList &lstDiff)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::QxSqlQueryBuilder_Count<T> builder;
builder.init();
qx::IxDataMember *pId = builder.getDataId();
if (pId && (!pId->isEqual((&obj1), (&obj2))))
{
lstDiff.append(pId->getKey());
}
long l = 0;
qx::IxDataMember *p = NULL;
while ((p = builder.nextData(l)))
{
if (p && (!p->isEqual((&obj1), (&obj2))))
{
lstDiff.append(p->getKey());
}
}
}
};
template <class T>
struct QxDao_IsDirty_Container
{
static void compare(const T &obj1, const T &obj2, QStringList &lstDiff)
{
if (qx::trait::generic_container<T>::size(obj1) <= 0)
{
return;
}
if (qx::trait::generic_container<T>::size(obj1) != qx::trait::generic_container<T>::size(obj2))
{
lstDiff.append("*");
return;
}
long lCurrIndex = 0;
typename T::const_iterator it2 = obj2.begin();
for (typename T::const_iterator it1 = obj1.begin(); it1 != obj1.end(); ++it1)
{
QStringList lstDiffItem;
qx::dao::detail::is_dirty((*it1), (*it2), lstDiffItem);
if (lstDiffItem.count() > 0)
{
lstDiff.append(QString::number(lCurrIndex) + "|" + lstDiffItem.join("|"));
}
++lCurrIndex;
++it2;
}
}
};
template <class T>
struct QxDao_IsDirty_Ptr
{
static void compare(const T &obj1, const T &obj2, QStringList &lstDiff)
{
qx::dao::detail::is_dirty((*obj1), (*obj2), lstDiff);
}
};
template <class T>
struct QxDao_IsDirty
{
static void compare(const T &obj1, const T &obj2, QStringList &lstDiff)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_IsDirty_Ptr<T>, qx::dao::detail::QxDao_IsDirty_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_IsDirty_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_IsDirty_Container<T>, type_dao_2>::type type_dao_3;
type_dao_3::compare(obj1, obj2, lstDiff);
}
};
template <class T>
inline void is_dirty(const T &obj1, const T &obj2, QStringList &lstDiff)
{
return qx::dao::detail::QxDao_IsDirty<T>::compare(obj1, obj2, lstDiff);
}
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_DAO_IS_DIRTY_H_

View File

@@ -0,0 +1,153 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATE_NEUTRAL_H_
#define _QX_DATE_NEUTRAL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDateNeutral.h
* \author XDL Team
* \ingroup QxDao
* \brief Helper class to store a date value into database under neutral format (YYYYMMDD) => cross database compatibility
*/
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#include <QtCore/qdatetime.h>
#include <QtCore/qdatastream.h>
#include <QxSerialize/Qt/QxSerialize_QString.h>
#include <QxTraits/get_class_name.h>
namespace qx
{
class QxDateNeutral;
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::QxDateNeutral &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::QxDateNeutral &t) QX_USED;
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxDateNeutral : helper class to store a date value into database under neutral format (YYYYMMDD) => cross database compatibility
*/
class QxDateNeutral
{
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
friend class boost::serialization::access;
#endif // _QX_ENABLE_BOOST_SERIALIZATION
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::QxDateNeutral &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::QxDateNeutral &t);
private:
QDate m_date; //!< Data value under QDate format from Qt library
QString m_neutral; //!< Data value under neutral format 'yyyyMMdd'
public:
QxDateNeutral() { ; }
explicit QxDateNeutral(const QDate &date) : m_date(date) { update(); }
explicit QxDateNeutral(const QString &neutral) : m_neutral(neutral) { update(); }
virtual ~QxDateNeutral() { ; }
inline QDate toDate() const { return m_date; }
inline QString toNeutral() const { return m_neutral; }
inline bool isValid() const { return m_date.isValid(); }
inline void setDate(const QDate &date)
{
m_neutral = "";
m_date = date;
update();
}
inline void setNeutral(const QString &neutral)
{
m_date = QDate();
m_neutral = neutral;
update();
}
static QxDateNeutral fromDate(const QDate &date) { return QxDateNeutral(date); }
static QxDateNeutral fromNeutral(const QString &neutral) { return QxDateNeutral(neutral); }
private:
static inline const char *format() { return "yyyyMMdd"; }
void update()
{
if (m_neutral.isEmpty() && !m_date.isValid())
{
return;
}
else if (m_date.isValid())
{
m_neutral = m_date.toString(format());
}
else
{
qAssert(m_neutral.size() == QString(format()).size());
m_date = QDate::fromString(m_neutral, format());
qAssert(m_date.isValid());
}
}
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
Q_UNUSED(file_version);
ar &boost::serialization::make_nvp("date_neutral", m_neutral);
if (Archive::is_loading::value)
{
m_date = QDate();
update();
}
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
} // namespace qx
QX_REGISTER_CLASS_NAME(qx::QxDateNeutral)
#endif // _QX_DATE_NEUTRAL_H_

View File

@@ -0,0 +1,153 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATE_TIME_NEUTRAL_H_
#define _QX_DATE_TIME_NEUTRAL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDateTimeNeutral.h
* \author XDL Team
* \ingroup QxDao
* \brief Helper class to store a date-time value into database under neutral format (YYYYMMDDHHMMSS) => cross database compatibility
*/
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#include <QtCore/qdatetime.h>
#include <QtCore/qdatastream.h>
#include <QxSerialize/Qt/QxSerialize_QString.h>
#include <QxTraits/get_class_name.h>
namespace qx
{
class QxDateTimeNeutral;
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::QxDateTimeNeutral &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::QxDateTimeNeutral &t) QX_USED;
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxDateTimeNeutral : helper class to store a date-time value into database under neutral format (YYYYMMDDHHMMSS) => cross database compatibility
*/
class QxDateTimeNeutral
{
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
friend class boost::serialization::access;
#endif // _QX_ENABLE_BOOST_SERIALIZATION
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::QxDateTimeNeutral &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::QxDateTimeNeutral &t);
private:
QDateTime m_dt; //!< Data value under QDateTime format from Qt library
QString m_neutral; //!< Data value under neutral format 'yyyyMMddhhmmss'
public:
QxDateTimeNeutral() { ; }
explicit QxDateTimeNeutral(const QDateTime &dt) : m_dt(dt) { update(); }
explicit QxDateTimeNeutral(const QString &neutral) : m_neutral(neutral) { update(); }
virtual ~QxDateTimeNeutral() { ; }
inline QDateTime toDateTime() const { return m_dt; }
inline QString toNeutral() const { return m_neutral; }
inline bool isValid() const { return m_dt.isValid(); }
inline void setDateTime(const QDateTime &dt)
{
m_neutral = "";
m_dt = dt;
update();
}
inline void setNeutral(const QString &neutral)
{
m_dt = QDateTime();
m_neutral = neutral;
update();
}
static QxDateTimeNeutral fromDateTime(const QDateTime &dt) { return QxDateTimeNeutral(dt); }
static QxDateTimeNeutral fromNeutral(const QString &neutral) { return QxDateTimeNeutral(neutral); }
private:
static inline const char *format() { return "yyyyMMddhhmmss"; }
void update()
{
if (m_neutral.isEmpty() && !m_dt.isValid())
{
return;
}
else if (m_dt.isValid())
{
m_neutral = m_dt.toString(format());
}
else
{
qAssert(m_neutral.size() == QString(format()).size());
m_dt = QDateTime::fromString(m_neutral, format());
qAssert(m_dt.isValid());
}
}
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
Q_UNUSED(file_version);
ar &boost::serialization::make_nvp("dt_neutral", m_neutral);
if (Archive::is_loading::value)
{
m_dt = QDateTime();
update();
}
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
} // namespace qx
QX_REGISTER_CLASS_NAME(qx::QxDateTimeNeutral)
#endif // _QX_DATE_TIME_NEUTRAL_H_

View File

@@ -0,0 +1,155 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifdef _QX_ENABLE_MONGODB
#ifndef _QX_DAO_MONGODB_HELPER_H_
#define _QX_DAO_MONGODB_HELPER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxMongoDB_Helper.h
* \author XDL Team
* \ingroup QxDao
* \brief Helper class to store all QxOrm registered classes in a MongoDB database : qx::QxSqlDatabase::getSingleton()->setDriverName("QXMONGODB");
*/
#include <QtSql/qsqlerror.h>
#include <QxSingleton/QxSingleton.h>
namespace qx
{
class IxClass;
class QxSqlQuery;
} // namespace qx
namespace qx
{
namespace dao
{
namespace detail
{
class IxDao_Helper;
} // namespace detail
} // namespace dao
} // namespace qx
namespace qx
{
namespace dao
{
namespace mongodb
{
struct QxMongoDB_Fetcher;
/*!
* \ingroup QxDao
* \brief qx::dao::mongodb::QxMongoDB_Helper : helper class to store all QxOrm registered classes in a MongoDB database : qx::QxSqlDatabase::getSingleton()->setDriverName("QXMONGODB");
*/
class QX_DLL_EXPORT QxMongoDB_Helper : public QxSingleton<QxMongoDB_Helper>
{
friend class QxSingleton<QxMongoDB_Helper>;
public:
enum opts
{
opts_collection_insert_one,
opts_collection_insert_many,
opts_collection_update_one,
opts_collection_update_many,
opts_collection_delete_one,
opts_collection_delete_many,
opts_collection_find,
opts_collection_command,
opts_collection_count,
opts_collection_create_bulk_operation,
opts_bulk_operation_update_one,
opts_bulk_operation_remove_one,
opts_collection_aggregate
};
private:
struct QxMongoDB_HelperImpl;
std::unique_ptr<QxMongoDB_HelperImpl> m_pImpl; //!< Private implementation idiom
QxMongoDB_Helper();
virtual ~QxMongoDB_Helper();
public:
static QSqlError insertOne(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, const QString &json, QString &insertedId);
static QSqlError insertMany(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, const QStringList &json, QStringList &insertedId);
static QSqlError updateOne(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, const QString &json, const qx::QxSqlQuery *query = NULL);
static QSqlError updateMany(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, const QStringList &json, const qx::QxSqlQuery *query = NULL);
static QSqlError deleteOne(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, const QString &json, const qx::QxSqlQuery *query = NULL);
static QSqlError deleteMany(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, const QStringList &json, const qx::QxSqlQuery *query = NULL);
static QSqlError findOne(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, QString &json, const qx::QxSqlQuery *query = NULL);
static QSqlError findMany(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, QStringList &json, const qx::QxSqlQuery *query = NULL, QxMongoDB_Fetcher *pFetcher = NULL);
static QSqlError aggregate(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, QStringList &json, const qx::QxSqlQuery *query = NULL, const QString &lookup = QString(), QxMongoDB_Fetcher *pFetcher = NULL);
static QSqlError count(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, long &cnt, const qx::QxSqlQuery *query = NULL);
static QSqlError executeCommand(qx::dao::detail::IxDao_Helper *pDaoHelper, qx::IxClass *pClass, qx::QxSqlQuery *query);
static QSqlError autoCreateIndexes(bool log = true);
static bool setOptions(opts e, const QString &optsAsJson);
static void setLogDatabaseReply(bool b);
static void setLogDatabaseInfo(bool b);
static void clearPoolConnection();
};
/*!
* \ingroup QxDao
* \brief qx::dao::mongodb::QxMongoDB_Fetcher : used to fetch a list of items from MongoDB database without having to put them in a buffer before fetching
*/
struct QX_DLL_EXPORT QxMongoDB_Fetcher
{
QxMongoDB_Fetcher();
virtual ~QxMongoDB_Fetcher();
virtual void fetch(const QString &json) = 0;
};
} // namespace mongodb
} // namespace dao
} // namespace qx
QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::dao::mongodb::QxMongoDB_Helper)
#endif // _QX_DAO_MONGODB_HELPER_H_
#endif // _QX_ENABLE_MONGODB

View File

@@ -0,0 +1,128 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_REPOSITORY_H_
#define _IX_REPOSITORY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxRepository.h
* \author XDL Team
* \ingroup QxDao
* \brief Common interface for all repositories to provide access to database by introspection using QObject class or qx::IxCollection class
*/
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlquery.h>
#include <QtSql/qsqlerror.h>
#include <QtSql/qsqldriver.h>
#include <QxCommon/QxBool.h>
#include <QxDao/QxSqlQuery.h>
#include <QxCollection/IxCollection.h>
namespace qx
{
class IxClass;
class QxSession;
/*!
* \ingroup QxDao
* \brief qx::IxRepository : common interface for all repositories to provide access to database by introspection using QObject class or qx::IxCollection class
*
* There is a type verification at runtime using <i>dynamic_cast</i> function.
* For example, if you are working with a class named <i>MyType</i>, you can call all methods of <i>qx::IxRepository</i> interface using :
* - <i>MyType *</i> for a single object, if <i>MyType</i> inherits from <i>QObject</i> ;
* - <i>qx::QxCollection< Key, QSharedPointer<MyType> > *</i> for a list of objects, where <i>Key</i> is the primary key type defined for <i>MyType</i> class (<i>long</i> by default).
*
* Note : if a bad type is detected at runtime, an exception of type <i>qx::dao::sql_error</i> is thrown.
*/
class QX_DLL_EXPORT IxRepository
{
protected:
bool m_bRegister; //!< Register repository into QxRepositoryX collection
QString m_sKeyRepository; //!< Repository key used by QxRepositoryX collection
QSqlDatabase m_database; //!< Database connection associated to the repository
QxSession *m_pSession; //!< Session associated to the repository
public:
IxRepository(bool bRegister, const QString &sKey);
IxRepository(bool bRegister, const QString &sKey, const QSqlDatabase &database);
IxRepository(bool bRegister, const QString &sKey, QxSession *pSession);
virtual ~IxRepository();
QSqlDatabase *database();
QxSession *session() const;
virtual long _count(const qx::QxSqlQuery &query = qx::QxSqlQuery()) = 0;
virtual void *_fetchById(const QVariant &id, const QStringList &columns = QStringList(), const QStringList &relation = QStringList()) = 0;
virtual QSqlError _fetchById(QObject *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList()) = 0;
virtual QSqlError _fetchById(qx::IxCollection *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList()) = 0;
virtual QSqlError _fetchAll(QObject *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList()) = 0;
virtual QSqlError _fetchAll(qx::IxCollection *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList()) = 0;
virtual QSqlError _fetchByQuery(const qx::QxSqlQuery &query, QObject *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList()) = 0;
virtual QSqlError _fetchByQuery(const qx::QxSqlQuery &query, qx::IxCollection *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList()) = 0;
virtual QSqlError _insert(QObject *p, const QStringList &relation = QStringList()) = 0;
virtual QSqlError _insert(qx::IxCollection *p, const QStringList &relation = QStringList()) = 0;
virtual QSqlError _update(QObject *p, const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList()) = 0;
virtual QSqlError _update(qx::IxCollection *p, const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList()) = 0;
virtual QSqlError _save(QObject *p, const QStringList &relation = QStringList()) = 0;
virtual QSqlError _save(qx::IxCollection *p, const QStringList &relation = QStringList()) = 0;
virtual QSqlError _deleteById(const QVariant &id) = 0;
virtual QSqlError _deleteById(QObject *p) = 0;
virtual QSqlError _deleteById(qx::IxCollection *p) = 0;
virtual QSqlError _deleteAll() = 0;
virtual QSqlError _deleteByQuery(const qx::QxSqlQuery &query) = 0;
virtual QSqlError _destroyById(const QVariant &id) = 0;
virtual QSqlError _destroyById(QObject *p) = 0;
virtual QSqlError _destroyById(qx::IxCollection *p) = 0;
virtual QSqlError _destroyAll() = 0;
virtual QSqlError _destroyByQuery(const qx::QxSqlQuery &query) = 0;
virtual qx_bool _exist(QObject *p) = 0;
virtual qx_bool _exist(qx::IxCollection *p) = 0;
virtual qx::IxCollection_ptr _newCollection() const = 0;
virtual qx::IxClass *_getClass() const = 0;
public:
static qx::IxCollection_ptr _fetchAll(const QString &repositoryKey, const QStringList &columns = QStringList(), const QStringList &relation = QStringList());
static qx::IxCollection_ptr _fetchByQuery(const QString &repositoryKey, const qx::QxSqlQuery &query, const QStringList &columns = QStringList(), const QStringList &relation = QStringList());
};
} // namespace qx
#endif // _IX_REPOSITORY_H_

View File

@@ -0,0 +1,606 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_REPOSITORY_H_
#define _QX_REPOSITORY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxRepository.h
* \author XDL Team
* \ingroup QxDao
* \brief Repository to provide a common interface to communicate with database
*/
#include <QxDao/QxRepository/IxRepository.h>
#include <QxDao/QxRepository/QxRepositoryX.h>
#include <QxDao/QxDao.h>
#include <QxDao/QxSession.h>
#include <QxDao/QxSqlError.h>
#include <QxRegister/QxClass.h>
#include <QxCollection/QxCollection.h>
#include <QxTraits/get_primary_key.h>
#define QX_REPOSITORY_COLLECTION_DYNAMIC_CAST_ERROR QSqlError("[QxOrm] qx::QxRepository<T> : 'invalid collection pointer, dynamic_cast failed'", "", QSqlError::UnknownError)
#define QX_REPOSITORY_POINTER_DYNAMIC_CAST_ERROR QSqlError("[QxOrm] qx::QxRepository<T> : 'invalid pointer, dynamic_cast failed'", "", QSqlError::UnknownError)
#define QX_REPOSITORY_QOBJECT_BASE_CLASS_ERROR QSqlError("[QxOrm] qx::QxRepository<T> : 'invalid pointer, need to inherit from QObject class to use qx::IxRepository interface'", "", QSqlError::UnknownError)
#ifndef _QX_NO_RTTI
#define QX_REPOSITORY_CAST_COLLECTION \
type_collection_qt *x = dynamic_cast<type_collection_qt *>(p); \
type_collection_boost *y = (x ? NULL : dynamic_cast<type_collection_boost *>(p)); \
if (!x && !y) \
{ \
throw qx::dao::sql_error(QX_REPOSITORY_COLLECTION_DYNAMIC_CAST_ERROR); \
}
#else // _QX_NO_RTTI
#define QX_REPOSITORY_CAST_COLLECTION \
type_collection_qt *x = NULL; \
type_collection_boost *y = static_cast<type_collection_boost *>(p);
#endif // _QX_NO_RTTI
namespace qx
{
template <class T>
inline void register_repository(const QString &sKey);
/*!
* \ingroup QxDao
* \brief qx::QxRepository<T> : repository to provide a common interface to communicate with database
*/
template <class T>
class QxRepository : public IxRepository
{
template <class U>
friend inline void register_repository(const QString &sKey);
private:
QxRepository(const QString &sKey) : IxRepository(true, sKey) { ; }
public:
QxRepository() : IxRepository(false, QString("")) { ; }
QxRepository(const QSqlDatabase &database) : IxRepository(false, QString(""), database) { ; }
QxRepository(QxSession *pSession) : IxRepository(false, QString(""), pSession) { ; }
virtual ~QxRepository() { ; }
long count(const qx::QxSqlQuery &query = qx::QxSqlQuery())
{
return qx::dao::count<T>(query, this->database());
}
T *fetchById(const QVariant &id, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
IxDataMemberX *pDataMemberX = QxClass<T>::getSingleton()->getDataMemberX();
IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL);
if (!pDataMemberId)
{
qAssert(false);
return NULL;
}
T *t = new T();
QSqlError err;
pDataMemberId->fromVariant(t, id, -1, qx::cvt::context::e_database);
if (relation.count() == 0)
{
err = qx::dao::fetch_by_id((*t), this->database(), columns);
}
else
{
err = qx::dao::fetch_by_id_with_relation(relation, (*t), this->database());
}
if (err.isValid() && m_pSession)
{
delete t;
t = NULL;
(*m_pSession) += err;
}
else if (err.isValid())
{
delete t;
t = NULL;
}
return t;
}
template <class U>
QSqlError fetchById(U &u, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::fetch_by_id(u, this->database(), columns);
}
else
{
err = qx::dao::fetch_by_id_with_relation(relation, u, this->database());
}
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
template <class U>
QSqlError fetchAll(U &u, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::fetch_all(u, this->database(), columns);
}
else
{
err = qx::dao::fetch_all_with_relation(relation, u, this->database());
}
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
template <class U>
QSqlError fetchByQuery(const qx::QxSqlQuery &query, U &u, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::fetch_by_query(query, u, this->database(), columns);
}
else
{
err = qx::dao::fetch_by_query_with_relation(relation, query, u, this->database());
}
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
template <class U>
QSqlError insert(U &u, const QStringList &relation = QStringList(), bool bUseExecBatch = false)
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::insert(u, this->database(), bUseExecBatch);
}
else
{
err = qx::dao::insert_with_relation(relation, u, this->database());
}
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
template <class U>
QSqlError update(U &u, const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), bool bUseExecBatch = false)
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::update_by_query(query, u, this->database(), columns, bUseExecBatch);
}
else
{
err = qx::dao::update_by_query_with_relation(relation, query, u, this->database());
}
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
template <class U>
QSqlError save(U &u, const QStringList &relation = QStringList())
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::save(u, this->database());
}
else
{
err = qx::dao::save_with_relation(relation, u, this->database());
}
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
QSqlError deleteById(const QVariant &id)
{
IxDataMemberX *pDataMemberX = QxClass<T>::getSingleton()->getDataMemberX();
IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL);
if (!pDataMemberId)
{
qAssert(false);
return QSqlError();
}
std::shared_ptr<T> t = std::make_shared<T>();
pDataMemberId->fromVariant(t.get(), id, -1, qx::cvt::context::e_database);
QSqlError err = qx::dao::delete_by_id((*t), this->database());
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
template <class U>
QSqlError deleteById(U &u, bool bUseExecBatch = false)
{
QSqlError err = qx::dao::delete_by_id(u, this->database(), bUseExecBatch);
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
QSqlError deleteAll()
{
QSqlError err = qx::dao::delete_all<T>(this->database());
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
QSqlError deleteByQuery(const qx::QxSqlQuery &query)
{
QSqlError err = qx::dao::delete_by_query<T>(query, this->database());
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
QSqlError destroyById(const QVariant &id)
{
IxDataMemberX *pDataMemberX = QxClass<T>::getSingleton()->getDataMemberX();
IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL);
if (!pDataMemberId)
{
qAssert(false);
return QSqlError();
}
std::shared_ptr<T> t = std::make_shared<T>();
pDataMemberId->fromVariant(t.get(), id, -1, qx::cvt::context::e_database);
QSqlError err = qx::dao::destroy_by_id((*t), this->database());
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
template <class U>
QSqlError destroyById(U &u, bool bUseExecBatch = false)
{
QSqlError err = qx::dao::destroy_by_id(u, this->database(), bUseExecBatch);
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
QSqlError destroyAll()
{
QSqlError err = qx::dao::destroy_all<T>(this->database());
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
QSqlError destroyByQuery(const qx::QxSqlQuery &query)
{
QSqlError err = qx::dao::destroy_by_query<T>(query, this->database());
if (err.isValid() && m_pSession)
{
(*m_pSession) += err;
}
return err;
}
template <class U>
qx_bool exist(U &u)
{
return qx::dao::exist(u, this->database());
}
private:
typedef typename qx::trait::get_primary_key<T>::type type_primary_key;
typedef qx::QxCollection<type_primary_key, QSharedPointer<T>> type_collection_qt;
typedef qx::QxCollection<type_primary_key, std::shared_ptr<T>> type_collection_boost;
template <bool bIsQObject /* = false */, int dummy>
struct qxVerifyPointer
{
static inline T *get(QObject *p)
{
Q_UNUSED(p);
throw qx::dao::sql_error(QX_REPOSITORY_QOBJECT_BASE_CLASS_ERROR);
return NULL;
}
};
template <int dummy>
struct qxVerifyPointer<true, dummy>
#ifdef _QX_NO_RTTI
{
static inline T *get(QObject *p)
{
T *t = qobject_cast<T *>(p);
if (!t)
{
throw qx::dao::sql_error(QX_REPOSITORY_POINTER_DYNAMIC_CAST_ERROR);
};
return t;
}
};
#else // _QX_NO_RTTI
{
static inline T *get(QObject *p)
{
T *t = dynamic_cast<T *>(p);
if (!t)
{
throw qx::dao::sql_error(QX_REPOSITORY_POINTER_DYNAMIC_CAST_ERROR);
};
return t;
}
};
#endif // _QX_NO_RTTI
public:
virtual long _count(const qx::QxSqlQuery &query = qx::QxSqlQuery())
{
return this->count(query);
}
virtual void *_fetchById(const QVariant &id, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
return static_cast<void *>(this->fetchById(id, columns, relation));
}
virtual QSqlError _fetchById(QObject *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
T *t = qxVerifyPointer<std::is_base_of<QObject, T>::value, 0>::get(p);
return this->fetchById((*t), columns, relation);
}
virtual QSqlError _fetchById(qx::IxCollection *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QX_REPOSITORY_CAST_COLLECTION
return (x ? this->fetchById((*x), columns, relation) : this->fetchById((*y), columns, relation));
}
virtual QSqlError _fetchAll(QObject *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
T *t = qxVerifyPointer<std::is_base_of<QObject, T>::value, 0>::get(p);
return this->fetchAll((*t), columns, relation);
}
virtual QSqlError _fetchAll(qx::IxCollection *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QX_REPOSITORY_CAST_COLLECTION
return (x ? this->fetchAll((*x), columns, relation) : this->fetchAll((*y), columns, relation));
}
virtual QSqlError _fetchByQuery(const qx::QxSqlQuery &query, QObject *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
T *t = qxVerifyPointer<std::is_base_of<QObject, T>::value, 0>::get(p);
return this->fetchByQuery(query, (*t), columns, relation);
}
virtual QSqlError _fetchByQuery(const qx::QxSqlQuery &query, qx::IxCollection *p, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QX_REPOSITORY_CAST_COLLECTION
return (x ? this->fetchByQuery(query, (*x), columns, relation) : this->fetchByQuery(query, (*y), columns, relation));
}
virtual QSqlError _insert(QObject *p, const QStringList &relation = QStringList())
{
T *t = qxVerifyPointer<std::is_base_of<QObject, T>::value, 0>::get(p);
return this->insert((*t), relation);
}
virtual QSqlError _insert(qx::IxCollection *p, const QStringList &relation = QStringList())
{
QX_REPOSITORY_CAST_COLLECTION
return (x ? this->insert((*x), relation) : this->insert((*y), relation));
}
virtual QSqlError _update(QObject *p, const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
T *t = qxVerifyPointer<std::is_base_of<QObject, T>::value, 0>::get(p);
return this->update((*t), query, columns, relation);
}
virtual QSqlError _update(qx::IxCollection *p, const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QX_REPOSITORY_CAST_COLLECTION
return (x ? this->update((*x), query, columns, relation) : this->update((*y), query, columns, relation));
}
virtual QSqlError _save(QObject *p, const QStringList &relation = QStringList())
{
T *t = qxVerifyPointer<std::is_base_of<QObject, T>::value, 0>::get(p);
return this->save((*t), relation);
}
virtual QSqlError _save(qx::IxCollection *p, const QStringList &relation = QStringList())
{
QX_REPOSITORY_CAST_COLLECTION
return (x ? this->save((*x), relation) : this->save((*y), relation));
}
virtual QSqlError _deleteById(const QVariant &id)
{
return this->deleteById(id);
}
virtual QSqlError _deleteById(QObject *p)
{
T *t = qxVerifyPointer<std::is_base_of<QObject, T>::value, 0>::get(p);
return this->deleteById(*t);
}
virtual QSqlError _deleteById(qx::IxCollection *p)
{
QX_REPOSITORY_CAST_COLLECTION
return (x ? this->deleteById(*x) : this->deleteById(*y));
}
virtual QSqlError _deleteAll()
{
return this->deleteAll();
}
virtual QSqlError _deleteByQuery(const qx::QxSqlQuery &query)
{
return this->deleteByQuery(query);
}
virtual QSqlError _destroyById(const QVariant &id)
{
return this->destroyById(id);
}
virtual QSqlError _destroyById(QObject *p)
{
T *t = qxVerifyPointer<std::is_base_of<QObject, T>::value, 0>::get(p);
return this->destroyById(*t);
}
virtual QSqlError _destroyById(qx::IxCollection *p)
{
QX_REPOSITORY_CAST_COLLECTION
return (x ? this->destroyById(*x) : this->destroyById(*y));
}
virtual QSqlError _destroyAll()
{
return this->destroyAll();
}
virtual QSqlError _destroyByQuery(const qx::QxSqlQuery &query)
{
return this->destroyByQuery(query);
}
virtual qx_bool _exist(QObject *p)
{
T *t = qxVerifyPointer<std::is_base_of<QObject, T>::value, 0>::get(p);
return this->exist(*t);
}
virtual qx_bool _exist(qx::IxCollection *p)
{
QX_REPOSITORY_CAST_COLLECTION
return (x ? this->exist(*x) : this->exist(*y));
}
virtual qx::IxCollection_ptr _newCollection() const
{
qx::IxCollection_ptr lst = std::make_shared<type_collection_boost>();
return lst;
}
virtual qx::IxClass *_getClass() const
{
return qx::QxClass<T>::getSingleton();
}
public:
static T *getById(const QVariant &id, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
IxDataMemberX *pDataMemberX = QxClass<T>::getSingleton()->getDataMemberX();
IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL);
if (!pDataMemberId)
{
qAssert(false);
return NULL;
}
T *t = new T();
QSqlError err;
pDataMemberId->fromVariant(t, id, -1, qx::cvt::context::e_database);
if (relation.count() == 0)
{
err = qx::dao::fetch_by_id((*t), NULL, columns);
}
else
{
err = qx::dao::fetch_by_id_with_relation(relation, (*t), NULL);
}
if (err.isValid())
{
delete t;
t = NULL;
}
return t;
}
};
template <class T>
inline void register_repository(const QString &sKey)
{
// 'pNewRepository' instance will be destroyed by 'qx::QxRepositoryX::unregisterRepository()' method
qx::QxRepository<T> *pNewRepository = new qx::QxRepository<T>(sKey);
Q_UNUSED(pNewRepository);
}
} // namespace qx
#endif // _QX_REPOSITORY_H_

View File

@@ -0,0 +1,89 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_REPOSITORY_X_H_
#define _QX_REPOSITORY_X_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxRepositoryX.h
* \author XDL Team
* \ingroup QxDao
* \brief List of all repositories registered using qx::register_repository<T> function
*/
#include <QtCore/qhash.h>
#include <QtCore/qmutex.h>
#include <QxDao/QxRepository/IxRepository.h>
#include <QxSingleton/QxSingleton.h>
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxRepositoryX : list of all repositories registered using qx::register_repository<T> function
*
* Note : you can register automatically all repositories using the macro <i>_QX_AUTO_REGISTER_REPOSITORY</i> into <i>QxConfig.h</i> file.
*/
class QX_DLL_EXPORT QxRepositoryX : public QxSingleton<QxRepositoryX>
{
friend class IxRepository;
friend class QxSingleton<QxRepositoryX>;
protected:
QHash<QString, IxRepository *> m_mapRepositoryX; //!< Collection of all 'IxRepository' pointer
QMutex m_oMutexRepositoryX; //!< Mutex -> 'QxRepositoryX' is thread-safe
bool m_bUnregisterAllRepository; //!< Flag to know if collection is clearing
private:
QxRepositoryX() : QxSingleton<QxRepositoryX>("qx::QxRepositoryX"), m_bUnregisterAllRepository(false) { ; }
virtual ~QxRepositoryX() { unregisterAllRepository(); }
void registerRepository(const QString &sKey, IxRepository *pRepository);
void unregisterRepository(const QString &sKey);
void unregisterAllRepository();
public:
static IxRepository *get(const QString &sKey);
};
} // namespace qx
QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::QxRepositoryX)
#endif // _QX_REPOSITORY_X_H_

457
include/QxDao/QxSession.h Normal file
View File

@@ -0,0 +1,457 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DAO_SESSION_H_
#define _QX_DAO_SESSION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSession.h
* \author XDL Team
* \ingroup QxDao
* \brief Define a session to manage automatically database transactions (using C++ RAII)
*/
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlquery.h>
#include <QtSql/qsqlerror.h>
#include <QtSql/qsqldriver.h>
#include <QtCore/qlist.h>
#include <QxCommon/QxBool.h>
#include <QxDao/QxDao.h>
#include <QxDao/QxSqlQuery.h>
#include <QxDao/QxSqlError.h>
#include <QxRegister/QxClass.h>
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxSession : define a session to manage automatically database transactions (using C++ RAII)
*
* A database <b>transaction</b> is a sequence of operations performed as a single logical unit of work.
* If no errors occurred during the execution of the transaction then the system <b>commits</b> the transaction.
* If an error occurs during the transaction, or if the user specifies a <b>rollback</b> operation, the data manipulations within the transaction are not persisted to the database.
*
* The <i>qx::QxSession</i> class of QxOrm library is designed to manage automatically database transactions (using <i>C++ RAII</i>) :
* \code
{ // Start a scope where a new session is instantiated
// Create a session : a valid database connexion by thread is automatically assigned to the session and a transaction is opened
qx::QxSession session;
// Execute some operations with database (using += operator of qx::QxSession class and session database connexion)
session += qx::dao::insert(my_object, session.database());
session += qx::dao::update(my_object, session.database());
session += qx::dao::fetch_by_id(my_object, session.database());
session += qx::dao::delete_by_id(my_object, session.database());
// If the session is not valid (so an error occured) => display first error
if (! session.isValid()) { qDebug("[QxOrm] session error : '%s'", qPrintable(session.firstError().text())); }
} // End of scope : session is destroyed (transaction => automatically commit or rollback if there is an error)
* \endcode
*
* <i>Note :</i> a session can throw a <i>qx::dao::sql_error</i> exception when a SQL error occured (by default, there is no exception).
* You can setup this feature using :
* - <i>qx::QxSession</i> constructor (for a specific session) ;
* - <i>qx::QxSqlDatabase::getSingleton()->setSessionThrowable(bool b)</i> parameter (for all sessions).
*
* <i>Other note :</i> don't forget to pass the session database connexion to each <i>qx::dao::xxx</i> functions (using <i>session.database()</i> method).
* Moreover, you can manage your own database connexion (from a connexion pool for example) using constructor of <i>qx::QxSession</i> class.
*
* <i>qx::QxSession</i> class provides also persistent methods (CRUD) to make easier to write C++ code.
* Here is the same example using methods of <i>qx::QxSession</i> class instead of functions into namespace <i>qx::dao</i> :
* \code
{ // Start a scope where a new session is instantiated
// Create a session : a valid database connexion by thread is automatically assigned to the session and a transaction is opened
qx::QxSession session;
// Execute some operations with database
session.insert(my_object);
session.update(my_object);
session.fetchById(my_object);
session.deleteById(my_object);
// If the session is not valid (so an error occured) => display first error
if (! session.isValid()) { qDebug("[QxOrm] session error : '%s'", qPrintable(session.firstError().text())); }
} // End of scope : session is destroyed (transaction => automatically commit or rollback if there is an error)
* \endcode
*/
class QX_DLL_EXPORT QxSession
{
private:
struct QxSessionImpl;
std::shared_ptr<QxSessionImpl> m_pImpl; //!< Private implementation idiom (use std::shared_ptr instead of std::unique_ptr because of incomplete type)
public:
QxSession();
QxSession(const QSqlDatabase &database);
QxSession(const QSqlDatabase &database, bool bOpenTransaction);
QxSession(const QSqlDatabase &database, bool bOpenTransaction, bool bThrowable, bool bAutoRollbackWhenDestroyed = false);
virtual ~QxSession();
bool isThrowable() const;
bool isOpened() const;
bool isValid() const;
bool isAutoRollbackWhenDestroyed() const;
void setAutoRollbackWhenDestroyed(bool b);
QSqlError firstError() const;
QSqlError lastError() const;
QList<QSqlError> allErrors() const;
const QSqlDatabase *database() const;
QSqlDatabase *database();
bool open();
bool close();
bool commit();
bool rollback();
QxSession &operator+=(const QSqlError &err);
static QxSession *getActiveSession(QSqlDatabase *db);
void ignoreSoftDelete(bool bIgnoreSoftDelete = true, const QStringList &classesToIgnore = QStringList());
bool checkIgnoreSoftDelete(const QString &classKey) const;
QString getIgnoreSoftDeleteHash() const;
template <class T>
long count(const qx::QxSqlQuery &query = qx::QxSqlQuery())
{
return qx::dao::count<T>(query, this->database());
}
template <class T>
QSqlError count(long &lCount, const qx::QxSqlQuery &query = qx::QxSqlQuery())
{
return qx::dao::count<T>(lCount, query, this->database());
}
template <class T>
T *fetchById(const QVariant &id, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
IxDataMemberX *pDataMemberX = QxClass<T>::getSingleton()->getDataMemberX();
IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL);
if (!pDataMemberId)
{
qAssert(false);
return NULL;
}
T *t = new T();
QSqlError err;
pDataMemberId->fromVariant(t, id, -1, qx::cvt::context::e_database);
if (relation.count() == 0)
{
err = qx::dao::fetch_by_id((*t), this->database(), columns);
}
else
{
err = qx::dao::fetch_by_id_with_relation(relation, (*t), this->database());
}
if (err.isValid())
{
delete t;
t = NULL;
(*this) += err;
}
return t;
}
template <class T>
QSqlError fetchById(T &t, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::fetch_by_id(t, this->database(), columns);
}
else
{
err = qx::dao::fetch_by_id_with_relation(relation, t, this->database());
}
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError fetchAll(T &t, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::fetch_all(t, this->database(), columns);
}
else
{
err = qx::dao::fetch_all_with_relation(relation, t, this->database());
}
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError fetchByQuery(const qx::QxSqlQuery &query, T &t, const QStringList &columns = QStringList(), const QStringList &relation = QStringList())
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::fetch_by_query(query, t, this->database(), columns);
}
else
{
err = qx::dao::fetch_by_query_with_relation(relation, query, t, this->database());
}
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError insert(T &t, const QStringList &relation = QStringList(), bool bUseExecBatch = false)
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::insert(t, this->database(), bUseExecBatch);
}
else
{
err = qx::dao::insert_with_relation(relation, t, this->database());
}
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError update(T &t, const qx::QxSqlQuery &query = qx::QxSqlQuery(), const QStringList &columns = QStringList(), const QStringList &relation = QStringList(), bool bUseExecBatch = false)
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::update_by_query(query, t, this->database(), columns, bUseExecBatch);
}
else
{
err = qx::dao::update_by_query_with_relation(relation, query, t, this->database());
}
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError save(T &t, const QStringList &relation = QStringList())
{
QSqlError err;
if (relation.count() == 0)
{
err = qx::dao::save(t, this->database());
}
else
{
err = qx::dao::save_with_relation(relation, t, this->database());
}
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError deleteById(const QVariant &id)
{
IxDataMemberX *pDataMemberX = QxClass<T>::getSingleton()->getDataMemberX();
IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL);
if (!pDataMemberId)
{
qAssert(false);
return QSqlError();
}
std::shared_ptr<T> t = std::make_shared<T>();
pDataMemberId->fromVariant(t.get(), id, -1, qx::cvt::context::e_database);
QSqlError err = qx::dao::delete_by_id((*t), this->database());
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError deleteById(T &t, bool bUseExecBatch = false)
{
QSqlError err = qx::dao::delete_by_id(t, this->database(), bUseExecBatch);
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError deleteAll()
{
QSqlError err = qx::dao::delete_all<T>(this->database());
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError deleteByQuery(const qx::QxSqlQuery &query)
{
QSqlError err = qx::dao::delete_by_query<T>(query, this->database());
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError destroyById(const QVariant &id)
{
IxDataMemberX *pDataMemberX = QxClass<T>::getSingleton()->getDataMemberX();
IxDataMember *pDataMemberId = (pDataMemberX ? pDataMemberX->getId_WithDaoStrategy() : NULL);
if (!pDataMemberId)
{
qAssert(false);
return QSqlError();
}
std::shared_ptr<T> t = std::make_shared<T>();
pDataMemberId->fromVariant(t.get(), id, -1, qx::cvt::context::e_database);
QSqlError err = qx::dao::destroy_by_id((*t), this->database());
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError destroyById(T &t, bool bUseExecBatch = false)
{
QSqlError err = qx::dao::destroy_by_id(t, this->database(), bUseExecBatch);
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError destroyAll()
{
QSqlError err = qx::dao::destroy_all<T>(this->database());
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError destroyByQuery(const qx::QxSqlQuery &query)
{
QSqlError err = qx::dao::destroy_by_query<T>(query, this->database());
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
QSqlError executeQuery(qx::QxSqlQuery &query, T &t)
{
QSqlError err = qx::dao::execute_query<T>(query, t, this->database());
if (err.isValid())
{
(*this) += err;
}
return err;
}
QSqlError callQuery(qx::QxSqlQuery &query)
{
QSqlError err = qx::dao::call_query(query, this->database());
if (err.isValid())
{
(*this) += err;
}
return err;
}
template <class T>
qx_bool exist(T &t)
{
return qx::dao::exist(t, this->database());
}
private:
QxSession(const QxSession &other) { Q_UNUSED(other); }
QxSession &operator=(const QxSession &other)
{
Q_UNUSED(other);
return (*this);
}
};
} // namespace qx
#endif // _QX_DAO_SESSION_H_

View File

@@ -0,0 +1,148 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SOFT_DELETE_H_
#define _QX_SOFT_DELETE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSoftDelete.h
* \author XDL Team
* \ingroup QxDao
* \brief Soft delete (or logical delete) behavior to update a row into database (flag it as deleted) instead of delete it from database
*/
#define QX_DAO_SOFT_DELETE_QDATETIME_FORMAT "yyyyMMddhhmmsszzz"
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxSoftDelete : soft delete (or logical delete) behavior to update a row into database (flag it as deleted) instead of delete it from database
*
* A soft delete doesn't remove rows from database (this is not a physical delete) : a new column is added to the table definition to flag a row as deleted or not.
* This column can contain a boolean (1 means row deleted, 0 or NULL means row not deleted), or can contain deletion date-time (if empty or NULL, row is not deleted).
* So you can reactivate a deleted row by setting NULL or empty value into database.
*
* To define a soft delete behavior with QxOrm library, you have to use the class qx::QxSoftDelete in function mapping by class qx::register_class<T>.
* Here is an example with the class <i>Bar</i> containing 2 properties <i>m_id</i> and <i>m_desc</i> :
* \code
namespace qx {
template <> void register_class(QxClass<Bar> & t)
{
t.setSoftDelete(qx::QxSoftDelete("deleted_at"));
t.id(& Bar::m_id, "id");
t.data(& Bar::m_desc, "desc");
}}
* \endcode
*
* SQL queries builded by QxOrm library will take into account this soft delete parameter to add conditions (don't fetch deleted item, don't delete physically a row, etc.).
* For example, if you execute this code with the class <i>Bar</i> :
* \code
Bar_ptr pBar; pBar.reset(new Bar());
pBar->setId(5);
QSqlError daoError = qx::dao::delete_by_id(pBar); qAssert(! daoError.isValid());
qx_bool bDaoExist = qx::dao::exist(pBar); qAssert(! bDaoExist);
daoError = qx::dao::delete_all<Bar>(); qAssert(! daoError.isValid());
long lBarCount = qx::dao::count<Bar>(); qAssert(lBarCount == 0);
daoError = qx::dao::destroy_all<Bar>(); qAssert(! daoError.isValid());
* \endcode
*
* You will obtain following output trace :
* \code
[QxOrm] sql query (93 ms) : UPDATE Bar SET deleted_at = '20110617115148615' WHERE id = :id
[QxOrm] sql query (0 ms) : SELECT Bar.id AS Bar_id_0, Bar.deleted_at FROM Bar WHERE Bar.id = :id AND (Bar.deleted_at IS NULL OR Bar.deleted_at = '')
[QxOrm] sql query (78 ms) : UPDATE Bar SET deleted_at = '20110617115148724'
[QxOrm] sql query (0 ms) : SELECT COUNT(*) FROM Bar WHERE (Bar.deleted_at IS NULL OR Bar.deleted_at = '')
[QxOrm] sql query (110 ms) : DELETE FROM Bar
* \endcode
*
* <i>Note :</i> To delete physically a row from database, you have to use followings functions : qx::dao::destroy_by_id() and qx::dao::destroy_all().
*
* <i>Other note :</i> it is recommended to define into database an index on column <i>deleted_at</i> to optimize execution of SQL queries.
*/
class QX_DLL_EXPORT QxSoftDelete
{
public:
enum mode
{
mode_flag,
mode_date_time
};
private:
QString m_sTable; //!< Table name where soft delete behavior is applied
QString m_sColumn; //!< Column name to store soft delete information
QString m_sSqlQueryToFetch; //!< Overrided user SQL query to fetch an item, if empty QxOrm library builds a default SQL query
QString m_sSqlQueryToUpdate; //!< Overrided user SQL query to update an item, if empty QxOrm library builds a default SQL query
QString m_sSqlQueryToCreateTable; //!< Overrided user SQL query to create table, if empty QxOrm library builds a default SQL query
mode m_eMode; //!< Soft delete mode : 'mode_flag' with a boolean column, 'mode_date_time' with a date-time column containing deletion date-time
bool m_bFetchInJoin; //!< Add SQL condition to fetch in the JOIN part (default value), for backward compatibility with previous versions of QxOrm library set this value to false (means fetch in the WHERE part)
public:
QxSoftDelete();
QxSoftDelete(const QString &sColumn);
QxSoftDelete(const QString &sColumn, mode eMode);
~QxSoftDelete();
QString getTableName() const;
QString getColumnName() const;
QString getSqlQueryToFetch() const;
QString getSqlQueryToUpdate() const;
QString getSqlQueryToCreateTable() const;
mode getMode() const;
bool getSqlFetchInJoin() const;
void setTableName(const QString &sTable);
void setColumnName(const QString &sColumn);
void setSqlQueryToFetch(const QString &s);
void setSqlQueryToUpdate(const QString &s);
void setSqlQueryToCreateTable(const QString &s);
void setMode(mode eMode);
void setSqlFetchInJoin(bool b);
bool isEmpty() const;
QString buildSqlTablePointName(const QString &sTable = QString()) const;
QString buildSqlQueryToFetch(const QString &sTable = QString()) const;
QString buildSqlQueryToUpdate() const;
QString buildSqlQueryToCreateTable() const;
};
} // namespace qx
#endif // _QX_SOFT_DELETE_H_

View File

@@ -0,0 +1,189 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_DATABASE_H_
#define _QX_SQL_DATABASE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlDatabase.h
* \author XDL Team
* \ingroup QxDao
* \brief Define all parameters to connect to database and retrieve a valid connection by thread
*/
#include <QtCore/qhash.h>
#include <QtCore/qmutex.h>
#include <QtCore/qthread.h>
#include <QtCore/quuid.h>
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlquery.h>
#include <QtSql/qsqlerror.h>
#include <QxSingleton/QxSingleton.h>
#include <QxDao/QxSqlGenerator/IxSqlGenerator.h>
namespace qx
{
namespace dao
{
namespace detail
{
class IxDao_Helper;
} // namespace detail
} // namespace dao
} // namespace qx
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxSqlDatabase : define all parameters to connect to database and retrieve a valid connection by thread (this class is a singleton and is thread-safe)
*/
class QX_DLL_EXPORT QxSqlDatabase : public QxSingleton<QxSqlDatabase>
{
friend class QxSingleton<QxSqlDatabase>;
friend class qx::dao::detail::IxDao_Helper;
public:
enum ph_style
{
ph_style_question_mark,
ph_style_2_point_name,
ph_style_at_name
};
typedef std::function<void(QSqlDatabase &)> type_fct_db_open;
private:
struct QxSqlDatabaseImpl;
std::unique_ptr<QxSqlDatabaseImpl> m_pImpl; //!< Private implementation idiom
QxSqlDatabase();
virtual ~QxSqlDatabase();
public:
QString getDriverName() const;
QString getConnectOptions() const;
QString getDatabaseName() const;
QString getUserName() const;
QString getPassword() const;
QString getHostName() const;
int getPort() const;
bool getTraceSqlQuery() const;
bool getTraceSqlRecord() const;
bool getTraceSqlBoundValues() const;
bool getTraceSqlBoundValuesOnError() const;
ph_style getSqlPlaceHolderStyle() const;
bool getSessionThrowable() const;
bool getSessionAutoTransaction() const;
bool getValidatorThrowable() const;
bool getAutoReplaceSqlAliasIntoQuery() const;
bool getVerifyOffsetRelation() const;
bool getAddAutoIncrementIdToUpdateQuery() const;
bool getForceParentIdToAllChildren() const;
type_fct_db_open getFctDatabaseOpen() const;
bool getAddSqlSquareBracketsForTableName() const;
bool getAddSqlSquareBracketsForColumnName() const;
bool getFormatSqlQueryBeforeLogging() const;
QStringList getSqlDelimiterForTableName() const;
QStringList getSqlDelimiterForColumnName() const;
QStringList getSqlDelimiterForTableNameAlias() const;
QStringList getSqlDelimiterForColumnNameAlias() const;
int getTraceSqlOnlySlowQueriesDatabase() const;
int getTraceSqlOnlySlowQueriesTotal() const;
bool getDisplayTimerDetails() const;
void setDriverName(const QString &s, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setConnectOptions(const QString &s, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setDatabaseName(const QString &s, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setUserName(const QString &s, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setPassword(const QString &s, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setHostName(const QString &s, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setPort(int i, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setTraceSqlQuery(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setTraceSqlRecord(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setTraceSqlBoundValues(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setTraceSqlBoundValuesOnError(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setSqlPlaceHolderStyle(ph_style e, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setSessionThrowable(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setSessionAutoTransaction(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setValidatorThrowable(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setSqlGenerator(qx::dao::detail::IxSqlGenerator_ptr p, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setAutoReplaceSqlAliasIntoQuery(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setVerifyOffsetRelation(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setAddAutoIncrementIdToUpdateQuery(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setForceParentIdToAllChildren(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setFctDatabaseOpen(type_fct_db_open fct, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setAddSqlSquareBracketsForTableName(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setAddSqlSquareBracketsForColumnName(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setFormatSqlQueryBeforeLogging(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setSqlDelimiterForTableName(const QStringList &lst, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setSqlDelimiterForColumnName(const QStringList &lst, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setSqlDelimiterForTableNameAlias(const QStringList &lst, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setSqlDelimiterForColumnNameAlias(const QStringList &lst, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setTraceSqlOnlySlowQueriesDatabase(int i, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setTraceSqlOnlySlowQueriesTotal(int i, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
void setDisplayTimerDetails(bool b, bool bJustForCurrentThread = false, QSqlDatabase *pJustForThisDatabase = NULL);
static QSqlDatabase getDatabase();
static QSqlDatabase getDatabase(QSqlError &dbError);
static QSqlDatabase getDatabaseCloned();
static QSqlDatabase checkDatabaseByThread();
static void removeDatabaseByThread();
static void closeAllDatabases();
static void clearAllDatabases();
static bool isEmpty();
qx::dao::detail::IxSqlGenerator *getSqlGenerator();
void clearAllSettingsForCurrentThread();
void clearAllSettingsForDatabase(QSqlDatabase *p);
protected:
bool setCurrentDatabaseByThread(QSqlDatabase *p);
void clearCurrentDatabaseByThread();
};
} // namespace qx
QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::QxSqlDatabase)
#endif // _QX_SQL_DATABASE_H_

View File

@@ -0,0 +1,208 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_SQL_ELEMENT_H_
#define _IX_SQL_ELEMENT_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxSqlElement.h
* \author XDL Team
* \ingroup QxDao
* \brief Common interface for all SQL elements to build SQL query
*/
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#include <QtCore/qdatastream.h>
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#endif // _QX_NO_JSON
#include <QtSql/qsqlquery.h>
#include <QxCollection/QxCollection.h>
#include <QxDao/QxSqlGenerator/IxSqlGenerator.h>
#include <QxSerialize/Qt/QxSerialize_QList.h>
#include <QxSerialize/Qt/QxSerialize_QStringList.h>
#include <QxSerialize/Qt/QxSerialize_QVariant.h>
#include <QxConvert/QxConvert.h>
namespace qx
{
namespace dao
{
namespace detail
{
class IxSqlElement;
} // namespace detail
} // namespace dao
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::dao::detail::IxSqlElement &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::dao::detail::IxSqlElement &t) QX_USED;
#ifndef _QX_NO_JSON
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_ToJson<qx::dao::detail::IxSqlElement>;
template <>
struct QxConvert_FromJson<qx::dao::detail::IxSqlElement>;
QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::dao::detail::IxSqlElement &t, const QString &format) QX_USED;
QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue &j, qx::dao::detail::IxSqlElement &t, const QString &format) QX_USED;
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_NO_JSON
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::IxSqlElement : common interface for all SQL elements to build SQL query
*/
class QX_DLL_EXPORT IxSqlElement
{
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::dao::detail::IxSqlElement &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::dao::detail::IxSqlElement &t);
#ifndef _QX_NO_JSON
friend struct qx::cvt::detail::QxConvert_ToJson<qx::dao::detail::IxSqlElement>;
friend struct qx::cvt::detail::QxConvert_FromJson<qx::dao::detail::IxSqlElement>;
friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::dao::detail::IxSqlElement &t, const QString &format);
friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue &j, qx::dao::detail::IxSqlElement &t, const QString &format);
#endif // _QX_NO_JSON
public:
enum type_class
{
_no_type,
_sql_compare,
_sql_element_temp,
_sql_expression,
_sql_free_text,
_sql_in,
_sql_is_between,
_sql_is_null,
_sql_limit,
_sql_sort,
_sql_embed_query
};
protected:
int m_iIndex; //!< Index of SQL element to build unique string
QStringList m_lstColumns; //!< List of columns associated to SQL element
QStringList m_lstKeys; //!< List of keys associated to SQL element
QList<QVariant> m_lstValues; //!< List of values associated to SQL element
IxSqlGenerator *m_pSqlGenerator; //!< SQL generator to build SQL query specific for each database
public:
IxSqlElement(int index);
virtual ~IxSqlElement();
void setColumn(const QString &column);
void setColumns(const QStringList &columns);
void setValue(const QVariant &val);
void setValues(const QVariantList &values);
virtual IxSqlElement::type_class getTypeClass() const = 0;
virtual QString toString() const = 0;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const = 0;
virtual void postProcess(QString &sql) const = 0;
virtual void clone(IxSqlElement *other);
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void qxSave(Archive &ar) const
{
QString sExtraSettings = getExtraSettings();
ar << boost::serialization::make_nvp("index", m_iIndex);
ar << boost::serialization::make_nvp("list_columns", m_lstColumns);
ar << boost::serialization::make_nvp("list_keys", m_lstKeys);
ar << boost::serialization::make_nvp("list_values", m_lstValues);
ar << boost::serialization::make_nvp("extra_settings", sExtraSettings);
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void qxLoad(Archive &ar)
{
QString sExtraSettings;
ar >> boost::serialization::make_nvp("index", m_iIndex);
ar >> boost::serialization::make_nvp("list_columns", m_lstColumns);
ar >> boost::serialization::make_nvp("list_keys", m_lstKeys);
ar >> boost::serialization::make_nvp("list_values", m_lstValues);
ar >> boost::serialization::make_nvp("extra_settings", sExtraSettings);
setExtraSettings(sExtraSettings);
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
protected:
void updateKeys();
virtual QString getExtraSettings() const = 0;
virtual void setExtraSettings(const QString &s) = 0;
};
typedef std::shared_ptr<IxSqlElement> IxSqlElement_ptr;
QX_DLL_EXPORT IxSqlElement_ptr create_sql_element(IxSqlElement::type_class e) QX_USED;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _IX_SQL_ELEMENT_H_

View File

@@ -0,0 +1,107 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_COMPARE_H_
#define _QX_SQL_COMPARE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlCompare.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL element to compare value (==, <, >, <=, >=, LIKE, NOT LIKE, etc.)
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlCompare : SQL element to compare value (==, <, >, <=, >=, LIKE, NOT LIKE, etc.)
*/
class QX_DLL_EXPORT QxSqlCompare : public IxSqlElement
{
public:
enum type
{
_is_equal_to,
_is_not_equal_to,
_is_greater_than,
_is_greater_than_or_equal_to,
_is_less_than,
_is_less_than_or_equal_to,
_like,
_not_like,
_starts_with,
_ends_with,
_contains_string,
_custom_operator,
_is_equal_to_select,
_is_not_equal_to_select
};
protected:
QxSqlCompare::type m_type; //!< Compare type
QString m_sCustomOperator; //!< Possibility to define a custom operator with enum _custom_operator (for example <@ for PostgreSQL ltree type)
public:
QxSqlCompare();
QxSqlCompare(int index, QxSqlCompare::type t, const QString &sCustomOperator = QString());
virtual ~QxSqlCompare();
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
virtual IxSqlElement::type_class getTypeClass() const;
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlCompare> QxSqlCompare_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_COMPARE_H_

View File

@@ -0,0 +1,52 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_ELEMENT_H_
#define _QX_SQL_ELEMENT_H_
#ifdef _MSC_VER
#pragma once
#endif
#include <QxDao/QxSqlElement/IxSqlElement.h>
#include <QxDao/QxSqlElement/QxSqlCompare.h>
#include <QxDao/QxSqlElement/QxSqlElementTemp.h>
#include <QxDao/QxSqlElement/QxSqlEmbedQuery.h>
#include <QxDao/QxSqlElement/QxSqlExpression.h>
#include <QxDao/QxSqlElement/QxSqlFreeText.h>
#include <QxDao/QxSqlElement/QxSqlIn.h>
#include <QxDao/QxSqlElement/QxSqlIsBetween.h>
#include <QxDao/QxSqlElement/QxSqlIsNull.h>
#include <QxDao/QxSqlElement/QxSqlLimit.h>
#include <QxDao/QxSqlElement/QxSqlSort.h>
#endif // _QX_SQL_ELEMENT_H_

View File

@@ -0,0 +1,83 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_ELEMENT_TEMP_H_
#define _QX_SQL_ELEMENT_TEMP_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlElementTemp.h
* \author XDL Team
* \ingroup QxDao
* \brief Temporary SQL element (need to be cloned to be used)
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlElementTemp : temporary SQL element (need to be cloned to be used)
*/
class QX_DLL_EXPORT QxSqlElementTemp : public IxSqlElement
{
public:
QxSqlElementTemp();
virtual ~QxSqlElementTemp();
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
virtual IxSqlElement::type_class getTypeClass() const;
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlElementTemp> QxSqlElementTemp_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_ELEMENT_TEMP_H_

View File

@@ -0,0 +1,105 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_EMBED_QUERY_H_
#define _QX_SQL_EMBED_QUERY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlEmbedQuery.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL element to embed a SQL sub-query inside a parent SQL query
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
class QxSqlQuery;
} // namespace qx
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlEmbedQuery : SQL element to embed a SQL sub-query inside a parent SQL query
*/
class QX_DLL_EXPORT QxSqlEmbedQuery : public IxSqlElement
{
public:
enum type
{
_none,
_in,
_not_in,
_is_equal_to,
_is_not_equal_to
};
private:
struct QxSqlEmbedQueryImpl;
std::unique_ptr<QxSqlEmbedQueryImpl> m_pImpl; //!< Private implementation idiom
public:
QxSqlEmbedQuery(QxSqlEmbedQuery::type type = QxSqlEmbedQuery::_none);
QxSqlEmbedQuery(int index, QxSqlEmbedQuery::type type = QxSqlEmbedQuery::_none);
virtual ~QxSqlEmbedQuery();
void setQuery(const qx::QxSqlQuery &query);
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
virtual IxSqlElement::type_class getTypeClass() const;
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlEmbedQuery> QxSqlEmbedQuery_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_EMBED_QUERY_H_

View File

@@ -0,0 +1,97 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_EXPRESSION_H_
#define _QX_SQL_EXPRESSION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlExpression.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL element to build a SQL expression (WHERE, AND, OR, etc.)
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlExpression : SQL element to build a SQL expression (WHERE, AND, OR, etc.)
*/
class QX_DLL_EXPORT QxSqlExpression : public IxSqlElement
{
public:
enum type
{
_where,
_and,
_or,
_open_parenthesis,
_close_parenthesis
};
protected:
QxSqlExpression::type m_type;
public:
QxSqlExpression();
QxSqlExpression(int index, QxSqlExpression::type t);
virtual ~QxSqlExpression();
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
virtual IxSqlElement::type_class getTypeClass() const;
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlExpression> QxSqlExpression_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_EXPRESSION_H_

View File

@@ -0,0 +1,89 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_FREE_TEXT_H_
#define _QX_SQL_FREE_TEXT_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlFreeText.h
* \author XDL Team
* \ingroup QxDao
* \brief Possibility to add free text to SQL query
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlFreeText : possibility to add free text to SQL query
*/
class QX_DLL_EXPORT QxSqlFreeText : public IxSqlElement
{
protected:
QString m_sText; //!< Custom SQL text to insert to SQL query
public:
QxSqlFreeText();
QxSqlFreeText(int index);
virtual ~QxSqlFreeText();
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
virtual IxSqlElement::type_class getTypeClass() const;
void setText(const QString &txt);
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlFreeText> QxSqlFreeText_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_FREE_TEXT_H_

View File

@@ -0,0 +1,96 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_IN_H_
#define _QX_SQL_IN_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlIn.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL element to verify a list of values (IN, NOT IN, etc.)
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlIn : SQL element to verify a list of values (IN, NOT IN, etc.)
*/
class QX_DLL_EXPORT QxSqlIn : public IxSqlElement
{
public:
enum type
{
_in,
_not_in,
_in_select,
_not_in_select
};
protected:
QxSqlIn::type m_type;
public:
QxSqlIn();
QxSqlIn(int index, QxSqlIn::type t);
virtual ~QxSqlIn();
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
virtual IxSqlElement::type_class getTypeClass() const;
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlIn> QxSqlIn_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_IN_H_

View File

@@ -0,0 +1,94 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_IS_BETWEEN_H_
#define _QX_SQL_IS_BETWEEN_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlIsBetween.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL element to verify if a value is included into 2 other values
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlIsBetween : SQL element to verify if a value is included into 2 other values
*/
class QX_DLL_EXPORT QxSqlIsBetween : public IxSqlElement
{
public:
enum type
{
_is_between,
_is_not_between
};
protected:
QxSqlIsBetween::type m_type;
public:
QxSqlIsBetween();
QxSqlIsBetween(int index, QxSqlIsBetween::type t);
virtual ~QxSqlIsBetween();
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
virtual IxSqlElement::type_class getTypeClass() const;
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlIsBetween> QxSqlIsBetween_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_IS_BETWEEN_H_

View File

@@ -0,0 +1,94 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_IS_NULL_H_
#define _QX_SQL_IS_NULL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlIsNull.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL element to verify if a value is null or not null (IS NULL, IS NOT NULL)
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlIsNull : SQL element to verify if a value is null or not null (IS NULL, IS NOT NULL)
*/
class QX_DLL_EXPORT QxSqlIsNull : public IxSqlElement
{
public:
enum type
{
_is_null,
_is_not_null
};
protected:
QxSqlIsNull::type m_type;
public:
QxSqlIsNull();
QxSqlIsNull(int index, QxSqlIsNull::type t);
virtual ~QxSqlIsNull();
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
virtual IxSqlElement::type_class getTypeClass() const;
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlIsNull> QxSqlIsNull_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_IS_NULL_H_

View File

@@ -0,0 +1,93 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_LIMIT_H_
#define _QX_SQL_LIMIT_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlLimit.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL element to limit rows count fetched from database
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlLimit : SQL element to limit rows count fetched from database
*/
class QX_DLL_EXPORT QxSqlLimit : public IxSqlElement
{
public:
QxSqlLimit();
QxSqlLimit(int index);
virtual ~QxSqlLimit();
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
int getStartRow() const;
int getRowsCount() const;
int getMaxRow() const;
bool getWithTies() const;
QString getStartRow_ParamKey() const;
QString getRowsCount_ParamKey() const;
QString getMaxRow_ParamKey() const;
virtual IxSqlElement::type_class getTypeClass() const;
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlLimit> QxSqlLimit_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_LIMIT_H_

View File

@@ -0,0 +1,95 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_SORT_H_
#define _QX_SQL_SORT_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlSort.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL element to sort or to group list of elements fetched from database (ORDER BY, GROUP BY)
*/
#include <QxDao/QxSqlElement/IxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlSort : SQL element to sort or to group list of elements fetched from database (ORDER BY, GROUP BY)
*/
class QX_DLL_EXPORT QxSqlSort : public IxSqlElement
{
public:
enum type
{
_order_asc,
_order_desc,
_group_by
};
protected:
QxSqlSort::type m_type;
public:
QxSqlSort();
QxSqlSort(int index, QxSqlSort::type t);
virtual ~QxSqlSort();
virtual QString toString() const;
virtual void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql) const;
virtual IxSqlElement::type_class getTypeClass() const;
protected:
virtual QString getExtraSettings() const;
virtual void setExtraSettings(const QString &s);
};
typedef std::shared_ptr<QxSqlSort> QxSqlSort_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_SORT_H_

108
include/QxDao/QxSqlError.h Normal file
View File

@@ -0,0 +1,108 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_ERROR_H_
#define _QX_SQL_ERROR_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlError.h
* \author XDL Team
* \ingroup QxDao
* \brief Define a SQL error exception and retrieve QSqlError type of Qt library
*/
#include <iostream>
#include <exception>
#include <QtCore/qbytearray.h>
#include <QtSql/qsqlerror.h>
namespace qx
{
namespace dao
{
/*!
* \ingroup QxDao
* \brief qx::dao::sql_error : define a SQL error exception and retrieve QSqlError type of Qt library
*/
class sql_error : public std::exception
{
private:
QSqlError m_error;
QByteArray m_errorMessage;
public:
#if (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
sql_error(const QSqlError &err) : std::exception(), m_error(err)
{
if (!m_error.text().isEmpty() && (m_error.type() == QSqlError::NoError))
{
m_error = QSqlError(m_error.driverText(), m_error.databaseText(), QSqlError::UnknownError, m_error.nativeErrorCode());
};
m_errorMessage = m_error.text().toLocal8Bit();
}
#else // (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
sql_error(const QSqlError &err) : std::exception(), m_error(err)
{
if (!m_error.text().isEmpty() && (m_error.type() == QSqlError::NoError))
{
m_error.setType(QSqlError::UnknownError);
};
m_errorMessage = m_error.text().toLocal8Bit();
}
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 3, 0))
virtual ~sql_error() throw() { ; }
virtual const char *what() const throw()
{
if (m_error.isValid())
{
return m_errorMessage.constData();
}
else
{
return "";
}
}
QSqlError get() const { return m_error; }
};
} // namespace dao
} // namespace qx
#endif // _QX_SQL_ERROR_H_

View File

@@ -0,0 +1,105 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_SQL_GENERATOR_H_
#define _IX_SQL_GENERATOR_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxSqlGenerator.h
* \author XDL Team
* \ingroup QxDao
* \brief Common interface for all SQL generators to build SQL query specific for each database
*/
#include <QtSql/qsqlquery.h>
#include <QxCollection/QxCollection.h>
namespace qx
{
namespace dao
{
namespace detail
{
class IxDao_Helper;
class IxSqlElement;
class QxSqlCompare;
class QxSqlElementTemp;
class QxSqlEmbedQuery;
class QxSqlExpression;
class QxSqlFreeText;
class QxSqlIn;
class QxSqlIsBetween;
class QxSqlIsNull;
class QxSqlLimit;
class QxSqlSort;
/*!
* \ingroup QxDao
* \brief qx::dao::detail::IxSqlGenerator : common interface for all SQL generators to build SQL query specific for each database
*/
class QX_DLL_EXPORT IxSqlGenerator
{
public:
IxSqlGenerator();
virtual ~IxSqlGenerator();
virtual void init() = 0;
virtual QString getAutoIncrement() const = 0;
virtual QString getWildCard() const = 0;
virtual QString getTableAliasSep() const = 0;
virtual QString getLimit(const QxSqlLimit *pLimit) const = 0;
virtual void resolveLimit(QSqlQuery &query, const QxSqlLimit *pLimit, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const = 0;
virtual void postProcess(QString &sql, const QxSqlLimit *pLimit) const = 0;
virtual void onBeforeInsert(IxDao_Helper *pDaoHelper, void *pOwner) const = 0;
virtual void onAfterInsert(IxDao_Helper *pDaoHelper, void *pOwner) const = 0;
virtual void onBeforeUpdate(IxDao_Helper *pDaoHelper, void *pOwner) const = 0;
virtual void onAfterUpdate(IxDao_Helper *pDaoHelper, void *pOwner) const = 0;
virtual void onBeforeDelete(IxDao_Helper *pDaoHelper, void *pOwner) const = 0;
virtual void onAfterDelete(IxDao_Helper *pDaoHelper, void *pOwner) const = 0;
virtual void checkSqlInsert(IxDao_Helper *pDaoHelper, QString &sql) const = 0;
virtual void onBeforeSqlPrepare(IxDao_Helper *pDaoHelper, QString &sql) const = 0;
virtual void formatSqlQuery(IxDao_Helper *pDaoHelper, QString &sql) const = 0;
};
typedef std::shared_ptr<IxSqlGenerator> IxSqlGenerator_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _IX_SQL_GENERATOR_H_

View File

@@ -0,0 +1,48 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_GENERATOR_H_
#define _QX_SQL_GENERATOR_H_
#ifdef _MSC_VER
#pragma once
#endif
#include <QxDao/QxSqlGenerator/IxSqlGenerator.h>
#include <QxDao/QxSqlGenerator/QxSqlGenerator_Standard.h>
#include <QxDao/QxSqlGenerator/QxSqlGenerator_MySQL.h>
#include <QxDao/QxSqlGenerator/QxSqlGenerator_Oracle.h>
#include <QxDao/QxSqlGenerator/QxSqlGenerator_PostgreSQL.h>
#include <QxDao/QxSqlGenerator/QxSqlGenerator_SQLite.h>
#include <QxDao/QxSqlGenerator/QxSqlGenerator_MSSQLServer.h>
#endif // _QX_SQL_GENERATOR_H_

View File

@@ -0,0 +1,81 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_GENERATOR_MSSQLSERVER_H_
#define _QX_SQL_GENERATOR_MSSQLSERVER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlGenerator_MSSQLServer.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL generator for Microsoft SQL Server database
*/
#include <QxDao/QxSqlGenerator/QxSqlGenerator_Standard.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlGenerator_MSSQLServer : SQL generator for Microsoft SQL Server database
*/
class QX_DLL_EXPORT QxSqlGenerator_MSSQLServer : public QxSqlGenerator_Standard
{
public:
QxSqlGenerator_MSSQLServer();
virtual ~QxSqlGenerator_MSSQLServer();
virtual void init();
virtual QString getLimit(const QxSqlLimit *pLimit) const;
virtual void resolveLimit(QSqlQuery &query, const QxSqlLimit *pLimit, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql, const QxSqlLimit *pLimit) const;
private:
void initSqlTypeByClassName() const;
};
typedef std::shared_ptr<QxSqlGenerator_MSSQLServer> QxSqlGenerator_MSSQLServer_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_GENERATOR_MSSQLSERVER_H_

View File

@@ -0,0 +1,78 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_GENERATOR_MYSQL_H_
#define _QX_SQL_GENERATOR_MYSQL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlGenerator_MySQL.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL generator for MySQL database
*/
#include <QxDao/QxSqlGenerator/QxSqlGenerator_Standard.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlGenerator_MySQL : SQL generator for MySQL database
*/
class QX_DLL_EXPORT QxSqlGenerator_MySQL : public QxSqlGenerator_Standard
{
public:
QxSqlGenerator_MySQL();
virtual ~QxSqlGenerator_MySQL();
virtual QString getAutoIncrement() const;
private:
void initSqlTypeByClassName() const;
};
typedef std::shared_ptr<QxSqlGenerator_MySQL> QxSqlGenerator_MySQL_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_GENERATOR_MYSQL_H_

View File

@@ -0,0 +1,95 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_GENERATOR_ORACLE_H_
#define _QX_SQL_GENERATOR_ORACLE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlGenerator_Oracle.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL generator for Oracle database
*/
#include <QxDao/QxSqlGenerator/QxSqlGenerator_Standard.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlGenerator_Oracle : SQL generator for Oracle database
*/
class QX_DLL_EXPORT QxSqlGenerator_Oracle : public QxSqlGenerator_Standard
{
protected:
bool m_bOldLimitSyntax; //!< Use old limit syntax (for Oracle version < 12.1), more details here : https://stackoverflow.com/questions/470542/how-do-i-limit-the-number-of-rows-returned-by-an-oracle-query-after-ordering
bool m_bManageLastInsertId; //!< Manage last insert id using RETURNING INTO syntax (thx to Romain Macureau and Abdennour Boutrig)
public:
QxSqlGenerator_Oracle();
QxSqlGenerator_Oracle(bool bManageLastInsertId);
virtual ~QxSqlGenerator_Oracle();
virtual QString getTableAliasSep() const;
virtual QString getLimit(const QxSqlLimit *pLimit) const;
virtual void resolveLimit(QSqlQuery &query, const QxSqlLimit *pLimit, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql, const QxSqlLimit *pLimit) const;
virtual void checkSqlInsert(IxDao_Helper *pDaoHelper, QString &sql) const;
virtual void onBeforeInsert(IxDao_Helper *pDaoHelper, void *pOwner) const;
virtual void onAfterInsert(IxDao_Helper *pDaoHelper, void *pOwner) const;
bool getOldLimitSyntax() const;
void setOldLimitSyntax(bool b);
bool getManageLastInsertId() const;
void setManageLastInsertId(bool b);
private:
void initSqlTypeByClassName() const;
};
typedef std::shared_ptr<QxSqlGenerator_Oracle> QxSqlGenerator_Oracle_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_GENERATOR_ORACLE_H_

View File

@@ -0,0 +1,79 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_GENERATOR_POSTGRESQL_H_
#define _QX_SQL_GENERATOR_POSTGRESQL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlGenerator_PostgreSQL.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL generator for PostgreSQL database
*/
#include <QxDao/QxSqlGenerator/QxSqlGenerator_Standard.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlGenerator_PostgreSQL : SQL generator for PostgreSQL database
*/
class QX_DLL_EXPORT QxSqlGenerator_PostgreSQL : public QxSqlGenerator_Standard
{
public:
QxSqlGenerator_PostgreSQL();
virtual ~QxSqlGenerator_PostgreSQL();
virtual void checkSqlInsert(IxDao_Helper *pDaoHelper, QString &sql) const;
virtual void onAfterInsert(IxDao_Helper *pDaoHelper, void *pOwner) const;
private:
void initSqlTypeByClassName() const;
};
typedef std::shared_ptr<QxSqlGenerator_PostgreSQL> QxSqlGenerator_PostgreSQL_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_GENERATOR_POSTGRESQL_H_

View File

@@ -0,0 +1,76 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_GENERATOR_SQLITE_H_
#define _QX_SQL_GENERATOR_SQLITE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlGenerator_SQLite.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL generator for SQLite database
*/
#include <QxDao/QxSqlGenerator/QxSqlGenerator_Standard.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlGenerator_SQLite : SQL generator for SQLite database
*/
class QX_DLL_EXPORT QxSqlGenerator_SQLite : public QxSqlGenerator_Standard
{
public:
QxSqlGenerator_SQLite();
virtual ~QxSqlGenerator_SQLite();
private:
void initSqlTypeByClassName() const;
};
typedef std::shared_ptr<QxSqlGenerator_SQLite> QxSqlGenerator_SQLite_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_GENERATOR_SQLITE_H_

View File

@@ -0,0 +1,92 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_GENERATOR_STANDARD_H_
#define _QX_SQL_GENERATOR_STANDARD_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlGenerator_Standard.h
* \author XDL Team
* \ingroup QxDao
* \brief SQL generator to build standard SQL query
*/
#include <QxDao/QxSqlGenerator/IxSqlGenerator.h>
#include <QxDao/QxSqlElement/QxSqlElement.h>
namespace qx
{
namespace dao
{
namespace detail
{
/*!
* \ingroup QxDao
* \brief qx::dao::detail::QxSqlGenerator_Standard : SQL generator to build standard SQL query
*/
class QX_DLL_EXPORT QxSqlGenerator_Standard : public IxSqlGenerator
{
public:
QxSqlGenerator_Standard();
virtual ~QxSqlGenerator_Standard();
virtual void init();
virtual QString getAutoIncrement() const;
virtual QString getWildCard() const;
virtual QString getTableAliasSep() const;
virtual QString getLimit(const QxSqlLimit *pLimit) const;
virtual void resolveLimit(QSqlQuery &query, const QxSqlLimit *pLimit, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
virtual void postProcess(QString &sql, const QxSqlLimit *pLimit) const;
virtual void onBeforeInsert(IxDao_Helper *pDaoHelper, void *pOwner) const;
virtual void onAfterInsert(IxDao_Helper *pDaoHelper, void *pOwner) const;
virtual void onBeforeUpdate(IxDao_Helper *pDaoHelper, void *pOwner) const;
virtual void onAfterUpdate(IxDao_Helper *pDaoHelper, void *pOwner) const;
virtual void onBeforeDelete(IxDao_Helper *pDaoHelper, void *pOwner) const;
virtual void onAfterDelete(IxDao_Helper *pDaoHelper, void *pOwner) const;
virtual void checkSqlInsert(IxDao_Helper *pDaoHelper, QString &sql) const;
virtual void onBeforeSqlPrepare(IxDao_Helper *pDaoHelper, QString &sql) const;
virtual void formatSqlQuery(IxDao_Helper *pDaoHelper, QString &sql) const;
};
typedef std::shared_ptr<QxSqlGenerator_Standard> QxSqlGenerator_Standard_ptr;
} // namespace detail
} // namespace dao
} // namespace qx
#endif // _QX_SQL_GENERATOR_STANDARD_H_

72
include/QxDao/QxSqlJoin.h Normal file
View File

@@ -0,0 +1,72 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_JOIN_H_
#define _QX_SQL_JOIN_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlJoin.h
* \author XDL Team
* \ingroup QxDao
* \brief Define how to join 2 tables into SQL query (LEFT OUTER JOIN, INNER JOIN, etc...)
*/
#define QX_LEFT_OUTER_JOIN QString("->")
#define QX_INNER_JOIN QString(">>")
namespace qx
{
namespace dao
{
/*!
* \ingroup QxDao
* \brief qx::dao::sql_join : define how to join 2 tables into SQL query (LEFT OUTER JOIN, INNER JOIN, etc...)
*/
struct sql_join
{
enum join_type
{
no_join,
left_outer_join,
inner_join
};
};
} // namespace dao
} // namespace qx
#endif // _QX_SQL_JOIN_H_

729
include/QxDao/QxSqlQuery.h Normal file
View File

@@ -0,0 +1,729 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_QUERY_H_
#define _QX_SQL_QUERY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlQuery.h
* \author XDL Team
* \ingroup QxDao
* \brief Define a user SQL query added to default SQL query builded by QxOrm library, and used by qx::dao::xxx functions to filter elements fetched from database
*/
#ifdef Q_COMPILER_INITIALIZER_LISTS
#include <initializer_list>
#endif // Q_COMPILER_INITIALIZER_LISTS
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/split_free.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#include <QtCore/qdatastream.h>
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#include <QtCore/qjsonobject.h>
#include <QtCore/qjsonarray.h>
#include <QtCore/qjsondocument.h>
#endif // _QX_NO_JSON
#include <QtSql/qsqlquery.h>
#include <QxCollection/QxCollection.h>
#include <QxDao/QxSqlElement/QxSqlElement.h>
#include <QxSerialize/QxSerializeFastCompil.h>
#include <QxTraits/get_class_name.h>
#include <QxRegister/QxVersion.h>
#include <QxConvert/QxConvert.h>
namespace qx
{
class QxSqlQuery;
} // namespace qx
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
namespace boost
{
namespace serialization
{
template <class Archive>
inline void qx_save(Archive &ar, const qx::QxSqlQuery &t, const unsigned int file_version);
template <class Archive>
inline void qx_load(Archive &ar, qx::QxSqlQuery &t, const unsigned int file_version);
} // namespace serialization
} // namespace boost
#endif // _QX_ENABLE_BOOST_SERIALIZATION
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::QxSqlQuery &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::QxSqlQuery &t) QX_USED;
#ifndef _QX_NO_JSON
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_ToJson<qx::QxSqlQuery>;
template <>
struct QxConvert_FromJson<qx::QxSqlQuery>;
QX_DLL_EXPORT QJsonValue QxConvert_ToJson_Helper(const qx::QxSqlQuery &t, const QString &format) QX_USED;
QX_DLL_EXPORT qx_bool QxConvert_FromJson_Helper(const QJsonValue &j, qx::QxSqlQuery &t, const QString &format) QX_USED;
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_NO_JSON
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxSqlQuery : define a user SQL query added to default SQL query builded by QxOrm library, and used by qx::dao::xxx functions to filter elements fetched from database
*
* The class <i>qx::QxSqlQuery</i> (or its typedef <i>qx_query</i>) is used to communicate with database (to filter, to sort, etc.) in two different ways :
* - writing manually SQL query ;
* - using C++ methods with a syntax similar to SQL (same concept than the great library <i>SubSonic</i> for .Net).
*
* With the first method (writing manually SQL query), you can use some optimizations specific for each database.
* The second method (using C++ code to build SQL query) binds automatically SQL parameters without using <i>qx::QxSqlQuery::bind()</i> function.
*
* Here is an example with <i>qx::QxSqlQuery</i> class writing manually a SQL query :
* \code
// Build a SQL query to fetch only 'author' of type 'female'
qx::QxSqlQuery query("WHERE author.sex = :sex");
query.bind(":sex", author::female);
QList<author> list_of_female;
QSqlError daoError = qx::dao::fetch_by_query(query, list_of_female);
// Here we can work with the collection provided by database
for (long l = 0; l < list_of_female.count(); l++) { ; }
* \endcode
*
* QxOrm library provides 3 styles to write SQL parameters.
* This style can be modified for a project using the following method <i>qx::QxSqlDatabase::getSingleton()->setSqlPlaceHolderStyle()</i> :
* - <i>ph_style_2_point_name</i> : "WHERE author.sex = :sex" (default style) ;
* - <i>ph_style_at_name</i> : "WHERE author.sex = @sex" ;
* - <i>ph_style_question_mark</i> : "WHERE author.sex = ?".
*
* Here is the same example using C++ code of the class <i>qx::QxSqlQuery</i> (or its typedef <i>qx_query</i>) to build query automatically :
* \code
// Build a SQL query to fetch only 'author' of type 'female'
qx_query query;
query.where("author.sex").isEqualTo(author::female);
QList<author> list_of_female;
QSqlError daoError = qx::dao::fetch_by_query(query, list_of_female);
// Here we can work with the collection provided by database
for (long l = 0; l < list_of_female.count(); l++) { ; }
* \endcode
*
* With C++ methods of <i>qx::QxSqlQuery</i> class, you don't have to bind any SQL parameter, and the syntax is similar to real SQL.
* All SQL parameters will be provided to database automatically with the following style : <i>qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle()</i>.
*
* Here is an example with many methods of <i>qx::QxSqlQuery</i> class (or its typedef <i>qx_query</i>) :
* \code
qx_query query;
query.where("sex").isEqualTo(author::female)
.and_("age").isGreaterThan(38)
.or_("last_name").isNotEqualTo("Dupont")
.or_("first_name").like("Alfred")
.and_OpenParenthesis("id").isLessThanOrEqualTo(999)
.and_("birth_date").isBetween(date1, date2)
.closeParenthesis()
.or_("id").in(50, 999, 11, 23, 78945)
.and_("is_deleted").isNotNull()
.orderAsc("last_name", "first_name", "sex")
.limit(50, 150);
* \endcode
*
* This code will produce following SQL for <i>MySQL</i>, <i>PostgreSQL</i> and <i>SQLite</i> databases (for <i>Oracle</i> and <i>SQLServer</i>, there is a specific process for <i>limit()</i> method) :
* \code
WHERE sex = :sex_1_0
AND age > :age_3_0
OR last_name <> :last_name_5_0
OR first_name LIKE :first_name_7_0
AND ( id <= :id_10_0 AND birth_date BETWEEN :birth_date_12_0_1 AND :birth_date_12_0_2 )
OR id IN (:id_15_0_0, :id_15_0_1, :id_15_0_2, :id_15_0_3, :id_15_0_4)
AND is_deleted IS NOT NULL
ORDER BY last_name ASC, first_name ASC, sex ASC
LIMIT :limit_rows_count_19_0 OFFSET :offset_start_row_19_0
* \endcode
*
* Here is the list of all functions available to use <i>qx::QxSqlQuery</i> class (or its typedef <i>qx_query</i>) :
* \code
// with functions into namespace qx::dao
qx::dao::count<T>()
qx::dao::fetch_by_query<T>()
qx::dao::update_by_query<T>()
qx::dao::delete_by_query<T>()
qx::dao::destroy_by_query<T>()
qx::dao::fetch_by_query_with_relation<T>()
qx::dao::fetch_by_query_with_all_relation<T>()
qx::dao::update_by_query_with_relation<T>()
qx::dao::update_by_query_with_all_relation<T>()
qx::dao::update_optimized_by_query<T>()
// with qx::QxSession class
qx::QxSession::count<T>()
qx::QxSession::fetchByQuery<T>()
qx::QxSession::update<T>()
qx::QxSession::deleteByQuery<T>()
qx::QxSession::destroyByQuery<T>()
// with qx::QxRepository<T> class
qx::QxRepository<T>::count()
qx::QxRepository<T>::fetchByQuery()
qx::QxRepository<T>::update()
qx::QxRepository<T>::deleteByQuery()
qx::QxRepository<T>::destroyByQuery()
* \endcode
*
* <i>Note :</i> those functions have 2 other optionals parameters :
* - <i>const QStringList & columns</i> : to indicate columns to fetch (by default, all columns are fetched) ;
* - <i>const QStringList & relation</i> : to indicate relations to fetch (<i>one-to-one</i>, <i>one-to-many</i>, <i>many-to-one</i> and <i>many-to-many</i> defined into <i>void qx::register_class<T>()</i> mapping function by class), by default there is no relation fetched.
*
* <i>Other note :</i> it's possible to call a stored procedure using <i>qx::QxSqlQuery</i> class, for example :
* \code
qx_query query("CALL MyStoredProc(:param1, :param2)");
query.bind(":param1", "myValue1");
query.bind(":param2", 5024, QSql::InOut);
QSqlError daoError = qx::dao::call_query(query);
QVariant vNewValue = query.boundValue(":param2");
query.dumpSqlResult();
* \endcode
*
* If the stored procedure returns a resultset, you can iterate over each rows and fields using the following methods (after calling <i>qx::dao::call_query()</i> function) :
* - <i>long qx::QxSqlQuery::getSqlResultRowCount() const;</i>
* - <i>long qx::QxSqlQuery::getSqlResultColumnCount() const;</i>
* - <i>QVariant qx::QxSqlQuery::getSqlResultAt(long row, long column) const;</i>
* - <i>QVariant qx::QxSqlQuery::getSqlResultAt(long row, const QString & column) const;</i>
* - <i>QVector qx::QxSqlQuery::getSqlResultAllColumns() const;</i>
* - <i>void qx::QxSqlQuery::dumpSqlResult();</i>
*
* <i>Other note :</i> to add your own SQL query methods (for example, some databases provide non-standard specifics SQL functions) :
* - create a derived class based on <i>qx::QxSqlQuery</i> class ;
* - if your C++ compiler supports covariant return type, add the macro <i>QX_SQL_QUERY_DERIVED_IMPL_COVARIANT_RETURN_TYPE_HPP(myClass)</i> in the definition of your class (<i>myClass.h</i>) ;
* - if your C++ compiler supports covariant return type, add the macro <i>QX_SQL_QUERY_DERIVED_IMPL_COVARIANT_RETURN_TYPE_CPP(myClass)</i> in the implementation of your class (<i>myClass.cpp</i>) ;
* - add all SQL specifics functions in your derived class.
*/
class QX_DLL_EXPORT QxSqlQuery
{
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
friend inline void boost::serialization::qx_save(Archive &ar, const qx::QxSqlQuery &t, const unsigned int file_version);
template <class Archive>
friend inline void boost::serialization::qx_load(Archive &ar, qx::QxSqlQuery &t, const unsigned int file_version);
#endif // _QX_ENABLE_BOOST_SERIALIZATION
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::QxSqlQuery &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::QxSqlQuery &t);
#ifndef _QX_NO_JSON
friend struct qx::cvt::detail::QxConvert_ToJson<qx::QxSqlQuery>;
friend struct qx::cvt::detail::QxConvert_FromJson<qx::QxSqlQuery>;
friend QX_DLL_EXPORT QJsonValue qx::cvt::detail::QxConvert_ToJson_Helper(const qx::QxSqlQuery &t, const QString &format);
friend QX_DLL_EXPORT qx_bool qx::cvt::detail::QxConvert_FromJson_Helper(const QJsonValue &j, qx::QxSqlQuery &t, const QString &format);
#endif // _QX_NO_JSON
public:
typedef std::function<void(QString &)> type_fct_on_before_sql_prepare;
protected:
struct QxSqlResult
{
QHash<QString, int> positionByKey;
QHash<QString, int> positionByKeyUpper;
QVector<QVector<QVariant>> values;
};
typedef std::tuple<QVariant, QSql::ParamType> type_bind_value;
QStringList m_sQuery; //!< Query SQL with place-holder
QxCollection<QString, type_bind_value> m_lstValue; //!< Bind value in this array
qx::dao::detail::IxSqlElement_ptr m_pSqlElementTemp; //!< Temporary SQL element
QList<qx::dao::detail::IxSqlElement_ptr> m_lstSqlElement; //!< List of all SQL elements to build SQL query
int m_iSqlElementIndex; //!< Current index of SQL element
int m_iParenthesisCount; //!< Current parenthesis count
bool m_bDistinct; //!< Replace SELECT by SELECT DISTINCT in SQL query
std::shared_ptr<QxSqlResult> m_pSqlResult; //!< All results returning by SQL query or stored procedure (after calling qx::dao::call_query function)
QVariant m_vResponse; //!< Can be used to store some responses (from MongoDB database for example in JSON format)
QString m_sType; //!< Query type (for example : 'aggregate' or 'cursor' for MongoDB database)
QHash<QString, std::shared_ptr<QxSqlQuery>> m_lstJoinQueryUser; //!< List of SQL queries defined by user to add inside relationships joins (LEFT OUTER JOIN, INNER JOIN), for example : INNER JOIN my_table2 m2 ON (m1.id = m2.parent_id AND (XXX))
QList<std::shared_ptr<QxSqlQuery>> m_lstJoinQueryToResolve; //!< List of SQL queries to resolve (in the right order) to add inside relationships joins (LEFT OUTER JOIN, INNER JOIN), for example : INNER JOIN my_table2 m2 ON (m1.id = m2.parent_id AND (XXX))
type_fct_on_before_sql_prepare m_fctOnBeforeSqlPrepare; //!< Custom callback function to modify SQL query before preparing in database
public:
QxSqlQuery();
QxSqlQuery(const char *query, const QVariantList &values = QVariantList());
QxSqlQuery(const QString &query, const QVariantList &values = QVariantList());
QxSqlQuery(const QStringList &query);
QxSqlQuery(const QString &type, const QString &query);
QxSqlQuery(const QString &type, const QStringList &query);
virtual ~QxSqlQuery();
#ifndef _QX_NO_JSON
#ifdef Q_COMPILER_INITIALIZER_LISTS
QxSqlQuery(std::initializer_list<QPair<QString, QJsonValue>> json);
QxSqlQuery(std::initializer_list<QPair<QString, QJsonValue>> json, std::initializer_list<QPair<QString, QJsonValue>> opts);
QxSqlQuery(const QString &type, std::initializer_list<QPair<QString, QJsonValue>> json);
QxSqlQuery(const QString &type, std::initializer_list<QPair<QString, QJsonValue>> json, std::initializer_list<QPair<QString, QJsonValue>> opts);
#endif // Q_COMPILER_INITIALIZER_LISTS
#endif // _QX_NO_JSON
QString query();
QString queryAt(int idx) const;
void queryAt(int idx, const QString &query);
QVariant response() const;
QString type() const;
bool isEmpty() const;
bool isDistinct() const;
void clear();
void resolve(QSqlQuery &query, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
void resolveOutput(QSqlQuery &query, bool bFetchSqlResult);
void postProcess(QString &sql) const;
void setResponse(const QVariant &v);
void setType(const QString &s);
QString getJoinQuery(const QString &relationKey, const QString &relationAlias);
QString getJoinQueryHash();
QxSqlQuery &query(const QString &sQuery);
QxSqlQuery &bind(const QVariant &vValue, QSql::ParamType paramType = QSql::In);
QxSqlQuery &bind(const QString &sKey, const QVariant &vValue, QSql::ParamType paramType = QSql::In);
QVariant boundValue(const QString &sKey) const;
QVariant boundValue(int iPosition) const;
long getSqlResultRowCount() const;
long getSqlResultColumnCount() const;
QVariant getSqlResultAt(long row, long column) const;
QVariant getSqlResultAt(long row, const QString &column, bool caseSensitive = false) const;
QVector<QVariant> getSqlResultAt(long row) const;
QVector<QString> getSqlResultAllColumns() const;
void dumpSqlResult();
static void dumpBoundValues(const QSqlQuery &query);
QxSqlQuery &setFctOnBeforeSqlPrepare(type_fct_on_before_sql_prepare fct);
void onBeforeSqlPrepare(QString &sql);
private:
void verifyQuery() const QX_USED;
void fetchSqlResult(QSqlQuery &query);
public:
/* -- All methods to build SQL query using C++ syntax -- */
virtual QxSqlQuery &distinct();
virtual QxSqlQuery &where(const QString &column);
virtual QxSqlQuery &where_OpenParenthesis(const QString &column);
virtual QxSqlQuery &and_(const QString &column);
virtual QxSqlQuery &and_OpenParenthesis(const QString &column);
virtual QxSqlQuery &or_(const QString &column);
virtual QxSqlQuery &or_OpenParenthesis(const QString &column);
virtual QxSqlQuery &openParenthesis();
virtual QxSqlQuery &closeParenthesis();
virtual QxSqlQuery &orderAsc(const QStringList &columns);
virtual QxSqlQuery &orderAsc(const QString &col1);
virtual QxSqlQuery &orderAsc(const QString &col1, const QString &col2);
virtual QxSqlQuery &orderAsc(const QString &col1, const QString &col2, const QString &col3);
virtual QxSqlQuery &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4);
virtual QxSqlQuery &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5);
virtual QxSqlQuery &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6);
virtual QxSqlQuery &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7);
virtual QxSqlQuery &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8);
virtual QxSqlQuery &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8, const QString &col9);
virtual QxSqlQuery &orderDesc(const QStringList &columns);
virtual QxSqlQuery &orderDesc(const QString &col1);
virtual QxSqlQuery &orderDesc(const QString &col1, const QString &col2);
virtual QxSqlQuery &orderDesc(const QString &col1, const QString &col2, const QString &col3);
virtual QxSqlQuery &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4);
virtual QxSqlQuery &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5);
virtual QxSqlQuery &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6);
virtual QxSqlQuery &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7);
virtual QxSqlQuery &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8);
virtual QxSqlQuery &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8, const QString &col9);
virtual QxSqlQuery &groupBy(const QStringList &columns);
virtual QxSqlQuery &groupBy(const QString &col1);
virtual QxSqlQuery &groupBy(const QString &col1, const QString &col2);
virtual QxSqlQuery &groupBy(const QString &col1, const QString &col2, const QString &col3);
virtual QxSqlQuery &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4);
virtual QxSqlQuery &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5);
virtual QxSqlQuery &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6);
virtual QxSqlQuery &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7);
virtual QxSqlQuery &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8);
virtual QxSqlQuery &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8, const QString &col9);
virtual QxSqlQuery &limit(int rowsCount, int startRow = 0, bool withTies = false);
virtual QxSqlQuery &like(const QString &val);
virtual QxSqlQuery &notLike(const QString &val);
virtual QxSqlQuery &startsWith(const QString &val);
virtual QxSqlQuery &endsWith(const QString &val);
virtual QxSqlQuery &containsString(const QString &val);
virtual QxSqlQuery &isEqualTo(const QVariant &val);
virtual QxSqlQuery &isNotEqualTo(const QVariant &val);
virtual QxSqlQuery &isGreaterThan(const QVariant &val);
virtual QxSqlQuery &isGreaterThanOrEqualTo(const QVariant &val);
virtual QxSqlQuery &isLessThan(const QVariant &val);
virtual QxSqlQuery &isLessThanOrEqualTo(const QVariant &val);
virtual QxSqlQuery &customOperator(const QString &sCustomOperator, const QVariant &val);
virtual QxSqlQuery &in(const QVariantList &values);
virtual QxSqlQuery &in(const QVariant &val1);
virtual QxSqlQuery &in(const QVariant &val1, const QVariant &val2);
virtual QxSqlQuery &in(const QVariant &val1, const QVariant &val2, const QVariant &val3);
virtual QxSqlQuery &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4);
virtual QxSqlQuery &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5);
virtual QxSqlQuery &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6);
virtual QxSqlQuery &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7);
virtual QxSqlQuery &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8);
virtual QxSqlQuery &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8, const QVariant &val9);
virtual QxSqlQuery &notIn(const QVariantList &values);
virtual QxSqlQuery &notIn(const QVariant &val1);
virtual QxSqlQuery &notIn(const QVariant &val1, const QVariant &val2);
virtual QxSqlQuery &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3);
virtual QxSqlQuery &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4);
virtual QxSqlQuery &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5);
virtual QxSqlQuery &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6);
virtual QxSqlQuery &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7);
virtual QxSqlQuery &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8);
virtual QxSqlQuery &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8, const QVariant &val9);
virtual QxSqlQuery &in_Select(const QxSqlQuery &query);
virtual QxSqlQuery &notIn_Select(const QxSqlQuery &query);
virtual QxSqlQuery &isEqualTo_Select(const QxSqlQuery &query);
virtual QxSqlQuery &isNotEqualTo_Select(const QxSqlQuery &query);
virtual QxSqlQuery &isNull();
virtual QxSqlQuery &isNotNull();
virtual QxSqlQuery &isBetween(const QVariant &val1, const QVariant &val2);
virtual QxSqlQuery &isNotBetween(const QVariant &val1, const QVariant &val2);
virtual QxSqlQuery &freeText(const QString &text, const QVariantList &values = QVariantList());
virtual QxSqlQuery &addJoinQuery(const QString &relationKeyOrAlias, const QxSqlQuery &joinQuery);
private:
QxSqlQuery &addSqlExpression(const QString &column, qx::dao::detail::QxSqlExpression::type type);
QxSqlQuery &addSqlCompare(const QVariant &val, qx::dao::detail::QxSqlCompare::type type, const QString &sCustomOperator = QString());
QxSqlQuery &addSqlSort(const QStringList &columns, qx::dao::detail::QxSqlSort::type type);
QxSqlQuery &addSqlIn(const QVariantList &values, qx::dao::detail::QxSqlIn::type type);
QxSqlQuery &addSqlIsNull(qx::dao::detail::QxSqlIsNull::type type);
QxSqlQuery &addSqlIsBetween(const QVariant &val1, const QVariant &val2, qx::dao::detail::QxSqlIsBetween::type type);
QxSqlQuery &addFreeText(const QString &text, const QVariantList &values);
QxSqlQuery &addEmbedQuery(const QxSqlQuery &query, qx::dao::detail::QxSqlEmbedQuery::type type, bool requirePreviousElement);
};
} // namespace qx
typedef qx::QxSqlQuery qx_query;
namespace qx
{
namespace dao
{
/*!
* \ingroup QxDao
* \brief qx::dao::call_query function can be used to call a custom SQL query or a stored procedure
*
* To get an output value parameter (must be pass as <i>QSql::Out</i> or <i>QSql::InOut</i>) returned by a stored procedure, just call the following method : <i>QVariant qx::QxSqlQuery::boundValue(const QString & sKey) const;</i>.<br/>
* To iterate over all resultset, just use the following methods :
* - <i>long qx::QxSqlQuery::getSqlResultRowCount() const;</i>
* - <i>long qx::QxSqlQuery::getSqlResultColumnCount() const;</i>
* - <i>QVariant qx::QxSqlQuery::getSqlResultAt(long row, long column) const;</i>
* - <i>QVariant qx::QxSqlQuery::getSqlResultAt(long row, const QString & column) const;</i>
* - <i>QVector qx::QxSqlQuery::getSqlResultAllColumns() const;</i>
* - <i>void qx::QxSqlQuery::dumpSqlResult();</i>
*
* Here is an example of code using <i>qx::dao::call_query</i> function :
* \code
qx_query query("CALL MyStoredProc(:param1, :param2)");
query.bind(":param1", "myValue1");
query.bind(":param2", 5024, QSql::InOut);
QSqlError daoError = qx::dao::call_query(query);
QVariant vNewValue = query.boundValue(":param2");
query.dumpSqlResult();
* \endcode
*/
QX_DLL_EXPORT QSqlError call_query(qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL);
/*!
* \ingroup QxDao
* \brief qx::dao::call_query_without_prepare function can be used to call a custom SQL query or a stored procedure : same as qx::dao::call_query() function without calling prepare() QSqlQuery class method (can be useful to execute some specific SQL queries)
*/
QX_DLL_EXPORT QSqlError call_query_without_prepare(qx::QxSqlQuery &query, QSqlDatabase *pDatabase = NULL);
namespace helper
{
QX_DLL_EXPORT QSqlError call_query_helper(qx::QxSqlQuery &query, QSqlDatabase *pDatabase, bool bPrepare);
} // namespace helper
} // namespace dao
} // namespace qx
QX_REGISTER_CLASS_NAME(qx_query)
QX_CLASS_VERSION(qx::QxSqlQuery, 0)
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
QX_SERIALIZE_FAST_COMPIL_SAVE_LOAD_HPP(QX_DLL_EXPORT, qx::QxSqlQuery)
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#define QX_SQL_QUERY_DERIVED_IMPL_COVARIANT_RETURN_TYPE_HPP(className) \
public: \
virtual className &distinct(); \
\
virtual className &where(const QString &column); \
virtual className &where_OpenParenthesis(const QString &column); \
virtual className &and_(const QString &column); \
virtual className &and_OpenParenthesis(const QString &column); \
virtual className &or_(const QString &column); \
virtual className &or_OpenParenthesis(const QString &column); \
\
virtual className &openParenthesis(); \
virtual className &closeParenthesis(); \
\
virtual className &orderAsc(const QStringList &columns); \
virtual className &orderAsc(const QString &col1); \
virtual className &orderAsc(const QString &col1, const QString &col2); \
virtual className &orderAsc(const QString &col1, const QString &col2, const QString &col3); \
virtual className &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4); \
virtual className &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5); \
virtual className &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6); \
virtual className &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7); \
virtual className &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8); \
virtual className &orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8, const QString &col9); \
\
virtual className &orderDesc(const QStringList &columns); \
virtual className &orderDesc(const QString &col1); \
virtual className &orderDesc(const QString &col1, const QString &col2); \
virtual className &orderDesc(const QString &col1, const QString &col2, const QString &col3); \
virtual className &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4); \
virtual className &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5); \
virtual className &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6); \
virtual className &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7); \
virtual className &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8); \
virtual className &orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8, const QString &col9); \
\
virtual className &groupBy(const QStringList &columns); \
virtual className &groupBy(const QString &col1); \
virtual className &groupBy(const QString &col1, const QString &col2); \
virtual className &groupBy(const QString &col1, const QString &col2, const QString &col3); \
virtual className &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4); \
virtual className &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5); \
virtual className &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6); \
virtual className &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7); \
virtual className &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8); \
virtual className &groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8, const QString &col9); \
\
virtual className &limit(int rowsCount, int startRow = 0, bool withTies = false); \
\
virtual className &like(const QString &val); \
virtual className &notLike(const QString &val); \
virtual className &startsWith(const QString &val); \
virtual className &endsWith(const QString &val); \
virtual className &containsString(const QString &val); \
\
virtual className &isEqualTo(const QVariant &val); \
virtual className &isNotEqualTo(const QVariant &val); \
virtual className &isGreaterThan(const QVariant &val); \
virtual className &isGreaterThanOrEqualTo(const QVariant &val); \
virtual className &isLessThan(const QVariant &val); \
virtual className &isLessThanOrEqualTo(const QVariant &val); \
virtual className &customOperator(const QString &sCustomOperator, const QVariant &val); \
\
virtual className &in(const QVariantList &values); \
virtual className &in(const QVariant &val1); \
virtual className &in(const QVariant &val1, const QVariant &val2); \
virtual className &in(const QVariant &val1, const QVariant &val2, const QVariant &val3); \
virtual className &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4); \
virtual className &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5); \
virtual className &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6); \
virtual className &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7); \
virtual className &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8); \
virtual className &in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8, const QVariant &val9); \
\
virtual className &notIn(const QVariantList &values); \
virtual className &notIn(const QVariant &val1); \
virtual className &notIn(const QVariant &val1, const QVariant &val2); \
virtual className &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3); \
virtual className &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4); \
virtual className &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5); \
virtual className &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6); \
virtual className &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7); \
virtual className &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8); \
virtual className &notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8, const QVariant &val9); \
\
virtual className &in_Select(const QxSqlQuery &query); \
virtual className &notIn_Select(const QxSqlQuery &query); \
virtual className &isEqualTo_Select(const QxSqlQuery &query); \
virtual className &isNotEqualTo_Select(const QxSqlQuery &query); \
\
virtual className &isNull(); \
virtual className &isNotNull(); \
\
virtual className &isBetween(const QVariant &val1, const QVariant &val2); \
virtual className &isNotBetween(const QVariant &val1, const QVariant &val2); \
\
virtual className &freeText(const QString &text, const QVariantList &values = QVariantList()); \
\
virtual className &addJoinQuery(const QString &relationKeyOrAlias, const QxSqlQuery &joinQuery);
#define QX_SQL_QUERY_DERIVED_IMPL_COVARIANT_RETURN_TYPE_CPP(className) \
\
className &className::distinct() { return static_cast<className &>(qx::QxSqlQuery::distinct()); } \
\
className &className::where(const QString &column) { return static_cast<className &>(qx::QxSqlQuery::where(column)); } \
className &className::where_OpenParenthesis(const QString &column) { return static_cast<className &>(qx::QxSqlQuery::where_OpenParenthesis(column)); } \
className &className::and_(const QString &column) { return static_cast<className &>(qx::QxSqlQuery::and_(column)); } \
className &className::and_OpenParenthesis(const QString &column) { return static_cast<className &>(qx::QxSqlQuery::and_OpenParenthesis(column)); } \
className &className::or_(const QString &column) { return static_cast<className &>(qx::QxSqlQuery::or_(column)); } \
className &className::or_OpenParenthesis(const QString &column) { return static_cast<className &>(qx::QxSqlQuery::or_OpenParenthesis(column)); } \
\
className &className::openParenthesis() { return static_cast<className &>(qx::QxSqlQuery::openParenthesis()); } \
className &className::closeParenthesis() { return static_cast<className &>(qx::QxSqlQuery::closeParenthesis()); } \
\
className &className::orderAsc(const QStringList &columns) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(columns)); } \
className &className::orderAsc(const QString &col1) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(col1)); } \
className &className::orderAsc(const QString &col1, const QString &col2) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(col1, col2)); } \
className &className::orderAsc(const QString &col1, const QString &col2, const QString &col3) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(col1, col2, col3)); } \
className &className::orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(col1, col2, col3, col4)); } \
className &className::orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(col1, col2, col3, col4, col5)); } \
className &className::orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(col1, col2, col3, col4, col5, col6)); } \
className &className::orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(col1, col2, col3, col4, col5, col6, col7)); } \
className &className::orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(col1, col2, col3, col4, col5, col6, col7, col8)); } \
className &className::orderAsc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8, const QString &col9) { return static_cast<className &>(qx::QxSqlQuery::orderAsc(col1, col2, col3, col4, col5, col6, col7, col8, col9)); } \
\
className &className::orderDesc(const QStringList &columns) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(columns)); } \
className &className::orderDesc(const QString &col1) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(col1)); } \
className &className::orderDesc(const QString &col1, const QString &col2) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(col1, col2)); } \
className &className::orderDesc(const QString &col1, const QString &col2, const QString &col3) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(col1, col2, col3)); } \
className &className::orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(col1, col2, col3, col4)); } \
className &className::orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(col1, col2, col3, col4, col5)); } \
className &className::orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(col1, col2, col3, col4, col5, col6)); } \
className &className::orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(col1, col2, col3, col4, col5, col6, col7)); } \
className &className::orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(col1, col2, col3, col4, col5, col6, col7, col8)); } \
className &className::orderDesc(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8, const QString &col9) { return static_cast<className &>(qx::QxSqlQuery::orderDesc(col1, col2, col3, col4, col5, col6, col7, col8, col9)); } \
\
className &className::groupBy(const QStringList &columns) { return static_cast<className &>(qx::QxSqlQuery::groupBy(columns)); } \
className &className::groupBy(const QString &col1) { return static_cast<className &>(qx::QxSqlQuery::groupBy(col1)); } \
className &className::groupBy(const QString &col1, const QString &col2) { return static_cast<className &>(qx::QxSqlQuery::groupBy(col1, col2)); } \
className &className::groupBy(const QString &col1, const QString &col2, const QString &col3) { return static_cast<className &>(qx::QxSqlQuery::groupBy(col1, col2, col3)); } \
className &className::groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4) { return static_cast<className &>(qx::QxSqlQuery::groupBy(col1, col2, col3, col4)); } \
className &className::groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5) { return static_cast<className &>(qx::QxSqlQuery::groupBy(col1, col2, col3, col4, col5)); } \
className &className::groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6) { return static_cast<className &>(qx::QxSqlQuery::groupBy(col1, col2, col3, col4, col5, col6)); } \
className &className::groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7) { return static_cast<className &>(qx::QxSqlQuery::groupBy(col1, col2, col3, col4, col5, col6, col7)); } \
className &className::groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8) { return static_cast<className &>(qx::QxSqlQuery::groupBy(col1, col2, col3, col4, col5, col6, col7, col8)); } \
className &className::groupBy(const QString &col1, const QString &col2, const QString &col3, const QString &col4, const QString &col5, const QString &col6, const QString &col7, const QString &col8, const QString &col9) { return static_cast<className &>(qx::QxSqlQuery::groupBy(col1, col2, col3, col4, col5, col6, col7, col8, col9)); } \
\
className &className::limit(int rowsCount, int startRow, bool withTies) { return static_cast<className &>(qx::QxSqlQuery::limit(rowsCount, startRow, withTies)); } \
\
className &className::like(const QString &val) { return static_cast<className &>(qx::QxSqlQuery::like(val)); } \
className &className::notLike(const QString &val) { return static_cast<className &>(qx::QxSqlQuery::notLike(val)); } \
className &className::startsWith(const QString &val) { return static_cast<className &>(qx::QxSqlQuery::startsWith(val)); } \
className &className::endsWith(const QString &val) { return static_cast<className &>(qx::QxSqlQuery::endsWith(val)); } \
className &className::containsString(const QString &val) { return static_cast<className &>(qx::QxSqlQuery::containsString(val)); } \
\
className &className::isEqualTo(const QVariant &val) { return static_cast<className &>(qx::QxSqlQuery::isEqualTo(val)); } \
className &className::isNotEqualTo(const QVariant &val) { return static_cast<className &>(qx::QxSqlQuery::isNotEqualTo(val)); } \
className &className::isGreaterThan(const QVariant &val) { return static_cast<className &>(qx::QxSqlQuery::isGreaterThan(val)); } \
className &className::isGreaterThanOrEqualTo(const QVariant &val) { return static_cast<className &>(qx::QxSqlQuery::isGreaterThanOrEqualTo(val)); } \
className &className::isLessThan(const QVariant &val) { return static_cast<className &>(qx::QxSqlQuery::isLessThan(val)); } \
className &className::isLessThanOrEqualTo(const QVariant &val) { return static_cast<className &>(qx::QxSqlQuery::isLessThanOrEqualTo(val)); } \
className &className::customOperator(const QString &sCustomOperator, const QVariant &val) { return static_cast<className &>(qx::QxSqlQuery::customOperator(sCustomOperator, val)); } \
\
className &className::in(const QVariantList &values) { return static_cast<className &>(qx::QxSqlQuery::in(values)); } \
className &className::in(const QVariant &val1) { return static_cast<className &>(qx::QxSqlQuery::in(val1)); } \
className &className::in(const QVariant &val1, const QVariant &val2) { return static_cast<className &>(qx::QxSqlQuery::in(val1, val2)); } \
className &className::in(const QVariant &val1, const QVariant &val2, const QVariant &val3) { return static_cast<className &>(qx::QxSqlQuery::in(val1, val2, val3)); } \
className &className::in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4) { return static_cast<className &>(qx::QxSqlQuery::in(val1, val2, val3, val4)); } \
className &className::in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5) { return static_cast<className &>(qx::QxSqlQuery::in(val1, val2, val3, val4, val5)); } \
className &className::in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6) { return static_cast<className &>(qx::QxSqlQuery::in(val1, val2, val3, val4, val5, val6)); } \
className &className::in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7) { return static_cast<className &>(qx::QxSqlQuery::in(val1, val2, val3, val4, val5, val6, val7)); } \
className &className::in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8) { return static_cast<className &>(qx::QxSqlQuery::in(val1, val2, val3, val4, val5, val6, val7, val8)); } \
className &className::in(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8, const QVariant &val9) { return static_cast<className &>(qx::QxSqlQuery::in(val1, val2, val3, val4, val5, val6, val7, val8, val9)); } \
\
className &className::notIn(const QVariantList &values) { return static_cast<className &>(qx::QxSqlQuery::notIn(values)); } \
className &className::notIn(const QVariant &val1) { return static_cast<className &>(qx::QxSqlQuery::notIn(val1)); } \
className &className::notIn(const QVariant &val1, const QVariant &val2) { return static_cast<className &>(qx::QxSqlQuery::notIn(val1, val2)); } \
className &className::notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3) { return static_cast<className &>(qx::QxSqlQuery::notIn(val1, val2, val3)); } \
className &className::notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4) { return static_cast<className &>(qx::QxSqlQuery::notIn(val1, val2, val3, val4)); } \
className &className::notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5) { return static_cast<className &>(qx::QxSqlQuery::notIn(val1, val2, val3, val4, val5)); } \
className &className::notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6) { return static_cast<className &>(qx::QxSqlQuery::notIn(val1, val2, val3, val4, val5, val6)); } \
className &className::notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7) { return static_cast<className &>(qx::QxSqlQuery::notIn(val1, val2, val3, val4, val5, val6, val7)); } \
className &className::notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8) { return static_cast<className &>(qx::QxSqlQuery::notIn(val1, val2, val3, val4, val5, val6, val7, val8)); } \
className &className::notIn(const QVariant &val1, const QVariant &val2, const QVariant &val3, const QVariant &val4, const QVariant &val5, const QVariant &val6, const QVariant &val7, const QVariant &val8, const QVariant &val9) { return static_cast<className &>(qx::QxSqlQuery::notIn(val1, val2, val3, val4, val5, val6, val7, val8, val9)); } \
\
className &className::in_Select(const QxSqlQuery &query) { return static_cast<className &>(qx::QxSqlQuery::in_Select(query)); } \
className &className::notIn_Select(const QxSqlQuery &query) { return static_cast<className &>(qx::QxSqlQuery::notIn_Select(query)); } \
className &className::isEqualTo_Select(const QxSqlQuery &query) { return static_cast<className &>(qx::QxSqlQuery::isEqualTo_Select(query)); } \
className &className::isNotEqualTo_Select(const QxSqlQuery &query) { return static_cast<className &>(qx::QxSqlQuery::isNotEqualTo_Select(query)); } \
\
className &className::isNull() { return static_cast<className &>(qx::QxSqlQuery::isNull()); } \
className &className::isNotNull() { return static_cast<className &>(qx::QxSqlQuery::isNotNull()); } \
\
className &className::isBetween(const QVariant &val1, const QVariant &val2) { return static_cast<className &>(qx::QxSqlQuery::isBetween(val1, val2)); } \
className &className::isNotBetween(const QVariant &val1, const QVariant &val2) { return static_cast<className &>(qx::QxSqlQuery::isNotBetween(val1, val2)); } \
\
className &className::freeText(const QString &text, const QVariantList &values) { return static_cast<className &>(qx::QxSqlQuery::freeText(text, values)); } \
\
className &className::addJoinQuery(const QString &relationKeyOrAlias, const QxSqlQuery &joinQuery) { return static_cast<className &>(qx::QxSqlQuery::addJoinQuery(relationKeyOrAlias, joinQuery)); }
#endif // _QX_SQL_QUERY_H_

View File

@@ -0,0 +1,567 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_QUERY_BUILDER_H_
#define _QX_SQL_QUERY_BUILDER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlQueryBuilder.h
* \author XDL Team
* \ingroup QxDao
* \brief Concrete SQL query builder by class with a cache mechanism to backup and restore queries already built by the program
*/
#include <QxDao/IxSqlQueryBuilder.h>
#include <QxDao/QxSqlQueryHelper.h>
#include <QxRegister/QxClass.h>
#include <QxTraits/remove_attr.h>
#include <QxTraits/remove_smart_ptr.h>
#include <QxTraits/is_qx_registered.h>
#define QX_SQL_ERR_NO_DATA_MEMBER_REGISTERED "'QxSqlQueryBuilder<T>' error : 'qx::register_class()' not called or no data member registered"
#define QX_SQL_ERR_NO_ID_REGISTERED "'QxSqlQueryBuilder<T>' error : no id registered"
#define QX_SQL_BUILDER_INIT_FCT(oper) \
qx::dao::detail::IxDao_Timer timer(this->getDaoHelper(), qx::dao::detail::IxDao_Helper::timer_build_sql); \
QString joinQueryHash = (this->getDaoHelper() ? this->getDaoHelper()->qxQuery().getJoinQueryHash() : QString()); \
QString ignoreSoftDeleteHash = (this->getDaoHelper() ? this->getDaoHelper()->getIgnoreSoftDeleteHash() : QString()); \
QString key = QxClass<type_sql>::getSingleton()->getKey() + joinQueryHash + ignoreSoftDeleteHash + oper; \
if ((joinQueryHash.isEmpty()) && (this->findSqlQuery(key))) \
{ \
return (*this); \
} \
QString &sql = this->getCurrentBuildingSql(); \
sql = "";
#define QX_SQL_BUILDER_INIT_FCT_WITH_RELATION(oper) \
qx::dao::detail::IxDao_Timer timer(this->getDaoHelper(), qx::dao::detail::IxDao_Helper::timer_build_sql); \
QString joinQueryHash = (this->getDaoHelper() ? this->getDaoHelper()->qxQuery().getJoinQueryHash() : QString()); \
QString ignoreSoftDeleteHash = (this->getDaoHelper() ? this->getDaoHelper()->getIgnoreSoftDeleteHash() : QString()); \
QString key = QxClass<type_sql>::getSingleton()->getKey() + joinQueryHash + this->getHashRelation() + ignoreSoftDeleteHash + oper; \
if ((joinQueryHash.isEmpty()) && (this->findSqlQuery(key))) \
{ \
this->findSqlAlias(key); \
return (*this); \
} \
QString &sql = this->getCurrentBuildingSql(); \
sql = "";
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder<T> : concrete SQL query builder for class T with a cache mechanism to backup and restore queries already built by the program
*/
template <class T>
class QxSqlQueryBuilder : public IxSqlQueryBuilder
{
private:
typedef typename qx::trait::remove_attr<T>::type type_sql_tmp_1;
typedef typename qx::trait::remove_smart_ptr<type_sql_tmp_1>::type type_sql_tmp_2;
public:
typedef typename qx::QxSqlQueryBuilder<T>::type_sql_tmp_2 type_sql;
public:
QxSqlQueryBuilder() : IxSqlQueryBuilder() { ; }
virtual ~QxSqlQueryBuilder() { static_assert(qx::trait::is_qx_registered<type_sql>::value, "qx::trait::is_qx_registered<type_sql>::value"); }
virtual void init()
{
if (isInitDone())
{
return;
}
setDataMemberX(QxClass<type_sql>::getSingleton()->dataMemberX());
setSoftDelete(QxClass<type_sql>::getSingleton()->getSoftDelete());
IxSqlQueryBuilder::init();
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_Count<T> : concrete SQL query builder for class T to build a COUNT SQL query
*/
template <class T>
class QxSqlQueryBuilder_Count : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_Count() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_Count() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
Q_UNUSED(pRelationX);
QX_SQL_BUILDER_INIT_FCT("Count")
sql = "SELECT COUNT(*) FROM " + qx::IxDataMember::getSqlFromTable(this->table());
if (!this->softDelete().isEmpty())
{
sql += " WHERE " + this->softDelete().buildSqlQueryToFetch();
}
this->setSqlQuery(sql, key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_Exist<T> : concrete SQL query builder for class T to build an EXIST SQL query
*/
template <class T>
class QxSqlQueryBuilder_Exist : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_Exist() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_Exist() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
Q_UNUSED(pRelationX);
QX_SQL_BUILDER_INIT_FCT("Exist")
if (!this->getDataId())
{
qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED);
qAssert(false);
return (*this);
}
qx::dao::detail::QxSqlQueryHelper_Exist<type_sql>::sql(sql, (*this));
this->setSqlQuery(sql, key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_FetchAll<T> : concrete SQL query builder for class T to build a FETCH ALL SQL query
*/
template <class T>
class QxSqlQueryBuilder_FetchAll : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_FetchAll() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_FetchAll() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(pRelationX);
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QX_SQL_BUILDER_INIT_FCT("FetchAll")
qx::dao::detail::QxSqlQueryHelper_FetchAll<type_sql>::sql(sql, (*this));
this->setSqlQuery(sql, key);
}
else
{
QString sql;
if (!this->verifyColumns(columns))
{
return (*this);
}
qx::dao::detail::QxSqlQueryHelper_FetchAll<type_sql>::sql(sql, (*this), columns);
this->setSqlQuery(sql);
}
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_FetchById<T> : concrete SQL query builder for class T to build a FETCH BY ID SQL query
*/
template <class T>
class QxSqlQueryBuilder_FetchById : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_FetchById() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_FetchById() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(pRelationX);
if (!this->getDataId())
{
qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED);
qAssert(false);
return (*this);
}
QxSqlQueryBuilder_FetchAll<type_sql> builder;
builder.clone(*this);
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QX_SQL_BUILDER_INIT_FCT("FetchById")
qx::dao::detail::QxSqlQueryHelper_FetchById<type_sql>::sql(sql, builder);
this->setSqlQuery(sql, key);
}
else
{
QString sql;
if (!this->verifyColumns(columns))
{
return (*this);
}
qx::dao::detail::QxSqlQueryHelper_FetchById<type_sql>::sql(sql, builder, columns);
this->setSqlQuery(sql);
}
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_Insert<T> : concrete SQL query builder for class T to build an INSERT SQL query
*/
template <class T>
class QxSqlQueryBuilder_Insert : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_Insert() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_Insert() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
Q_UNUSED(pRelationX);
QX_SQL_BUILDER_INIT_FCT("Insert")
qx::dao::detail::QxSqlQueryHelper_Insert<type_sql>::sql(sql, (*this));
this->setSqlQuery(sql, key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_Update<T> : concrete SQL query builder for class T to build an UPDATE SQL query
*/
template <class T>
class QxSqlQueryBuilder_Update : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_Update() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_Update() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(pRelationX);
if (!this->getDataId())
{
qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED);
qAssert(false);
return (*this);
}
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QX_SQL_BUILDER_INIT_FCT("Update")
qx::dao::detail::QxSqlQueryHelper_Update<type_sql>::sql(sql, (*this));
this->setSqlQuery(sql, key);
}
else
{
QString sql;
if (!this->verifyColumns(columns))
{
return (*this);
}
qx::dao::detail::QxSqlQueryHelper_Update<type_sql>::sql(sql, (*this), columns);
this->setSqlQuery(sql);
}
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_DeleteAll<T> : concrete SQL query builder for class T to build a DELETE ALL SQL query
*/
template <class T>
class QxSqlQueryBuilder_DeleteAll : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_DeleteAll() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_DeleteAll() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
Q_UNUSED(pRelationX);
QX_SQL_BUILDER_INIT_FCT("DeleteAll")
sql = "DELETE FROM " + this->table();
this->setSqlQuery(sql, key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_SoftDeleteAll<T> : concrete SQL query builder for class T to build a SOFT DELETE ALL SQL query
*/
template <class T>
class QxSqlQueryBuilder_SoftDeleteAll : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_SoftDeleteAll() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_SoftDeleteAll() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
Q_UNUSED(pRelationX);
QX_SQL_BUILDER_INIT_FCT("SoftDeleteAll")
if (!this->softDelete().isEmpty())
{
sql = "UPDATE " + this->table() + " SET " + this->softDelete().buildSqlQueryToUpdate();
}
else
{
qAssert(false);
}
this->setSqlQuery(sql, key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_DeleteById<T> : concrete SQL query builder for class T to build a DELETE BY ID SQL query
*/
template <class T>
class QxSqlQueryBuilder_DeleteById : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_DeleteById() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_DeleteById() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
Q_UNUSED(pRelationX);
QX_SQL_BUILDER_INIT_FCT("DeleteById")
if (!this->getDataId())
{
qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED);
qAssert(false);
return (*this);
}
qx::dao::detail::QxSqlQueryHelper_DeleteById<type_sql>::sql(sql, (*this), false);
this->setSqlQuery(sql, key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_SoftDeleteById<T> : concrete SQL query builder for class T to build a SOFT DELETE BY ID SQL query
*/
template <class T>
class QxSqlQueryBuilder_SoftDeleteById : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_SoftDeleteById() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_SoftDeleteById() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
Q_UNUSED(pRelationX);
QX_SQL_BUILDER_INIT_FCT("SoftDeleteById")
if (!this->getDataId())
{
qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED);
qAssert(false);
return (*this);
}
if (this->softDelete().isEmpty())
{
qAssert(false);
return (*this);
}
qx::dao::detail::QxSqlQueryHelper_DeleteById<type_sql>::sql(sql, (*this), true);
this->setSqlQuery(sql, key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_CreateTable<T> : concrete SQL query builder for class T to build a CREATE TABLE SQL query
*/
template <class T>
class QxSqlQueryBuilder_CreateTable : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_CreateTable() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_CreateTable() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
Q_UNUSED(pRelationX);
QX_SQL_BUILDER_INIT_FCT("CreateTable")
qx::dao::detail::QxSqlQueryHelper_CreateTable<type_sql>::sql(sql, (*this));
this->setSqlQuery(sql, key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_Count_WithRelation<T> : concrete SQL query builder for class T to build a COUNT WITH RELATION SQL query
*/
template <class T>
class QxSqlQueryBuilder_Count_WithRelation : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_Count_WithRelation() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_Count_WithRelation() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
QX_SQL_BUILDER_INIT_FCT_WITH_RELATION("Count_WithRelation")
IxSqlQueryBuilder::sql_Count_WithRelation(pRelationX, sql, (*this));
this->setSqlQuery(sql, key);
this->insertSqlAlias(key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_FetchAll_WithRelation<T> : concrete SQL query builder for class T to build a FETCH ALL WITH RELATION SQL query
*/
template <class T>
class QxSqlQueryBuilder_FetchAll_WithRelation : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_FetchAll_WithRelation() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_FetchAll_WithRelation() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
QX_SQL_BUILDER_INIT_FCT_WITH_RELATION("FetchAll_WithRelation")
qx::dao::detail::QxSqlQueryHelper_FetchAll_WithRelation<type_sql>::sql(pRelationX, sql, (*this));
this->setSqlQuery(sql, key);
this->insertSqlAlias(key);
return (*this);
}
};
/*!
* \ingroup QxDao
* \brief qx::QxSqlQueryBuilder_FetchById_WithRelation<T> : concrete SQL query builder for class T to build a FETCH BY ID WITH RELATION SQL query
*/
template <class T>
class QxSqlQueryBuilder_FetchById_WithRelation : public QxSqlQueryBuilder<T>
{
public:
typedef typename QxSqlQueryBuilder<T>::type_sql type_sql;
QxSqlQueryBuilder_FetchById_WithRelation() : QxSqlQueryBuilder<T>() { ; }
virtual ~QxSqlQueryBuilder_FetchById_WithRelation() { ; }
virtual IxSqlQueryBuilder &buildSql(const QStringList &columns = QStringList(), QxSqlRelationLinked *pRelationX = NULL)
{
Q_UNUSED(columns);
QX_SQL_BUILDER_INIT_FCT_WITH_RELATION("FetchById_WithRelation")
if (!this->getDataId())
{
qDebug("[QxOrm] %s", QX_SQL_ERR_NO_ID_REGISTERED);
qAssert(false);
return (*this);
}
QxSqlQueryBuilder_FetchAll_WithRelation<type_sql> builder;
builder.clone(*this);
qx::dao::detail::QxSqlQueryHelper_FetchById_WithRelation<type_sql>::sql(pRelationX, sql, builder);
this->setSqlQuery(sql, key);
this->insertSqlAlias(key);
return (*this);
}
};
} // namespace qx
#endif // _QX_SQL_QUERY_BUILDER_H_

View File

@@ -0,0 +1,87 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_QUERY_HELPER_H_
#define _QX_SQL_QUERY_HELPER_H_
#ifdef _MSC_VER
#pragma once
#endif
#include <QtSql/qsqlquery.h>
#include <QxDao/IxSqlQueryBuilder.h>
#include <QxDataMember/IxDataMember.h>
#include <QxTraits/is_qx_registered.h>
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_CreateTable;
template <class T>
struct QxSqlQueryHelper_DeleteById;
template <class T>
struct QxSqlQueryHelper_Exist;
template <class T>
struct QxSqlQueryHelper_FetchAll;
template <class T>
struct QxSqlQueryHelper_FetchAll_WithRelation;
template <class T>
struct QxSqlQueryHelper_FetchById;
template <class T>
struct QxSqlQueryHelper_FetchById_WithRelation;
template <class T>
struct QxSqlQueryHelper_Insert;
template <class T>
struct QxSqlQueryHelper_Update;
} // namespace detail
} // namespace dao
} // namespace qx
#include "../../inl/QxDao/QxSqlQueryHelper_CreateTable.inl"
#include "../../inl/QxDao/QxSqlQueryHelper_DeleteById.inl"
#include "../../inl/QxDao/QxSqlQueryHelper_Exist.inl"
#include "../../inl/QxDao/QxSqlQueryHelper_FetchAll.inl"
#include "../../inl/QxDao/QxSqlQueryHelper_FetchAll_WithRelation.inl"
#include "../../inl/QxDao/QxSqlQueryHelper_FetchById.inl"
#include "../../inl/QxDao/QxSqlQueryHelper_FetchById_WithRelation.inl"
#include "../../inl/QxDao/QxSqlQueryHelper_Insert.inl"
#include "../../inl/QxDao/QxSqlQueryHelper_Update.inl"
#endif // _QX_SQL_QUERY_HELPER_H_

View File

@@ -0,0 +1,296 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_RELATION_H_
#define _QX_SQL_RELATION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlRelation.h
* \author XDL Team
* \ingroup QxDao
* \brief Base class for all relationships defined between 2 classes (or between 2 tables in database)
*/
#include <QxDao/QxDao.h>
#include <QxDao/IxSqlRelation.h>
#include <QxDao/IxSqlQueryBuilder.h>
#include <QxTraits/remove_attr.h>
#include <QxTraits/remove_smart_ptr.h>
#include <QxTraits/generic_container.h>
#include <QxTraits/is_container.h>
#include <QxTraits/is_valid_primary_key.h>
#include <QxTraits/is_qx_registered.h>
#include <QxRegister/IxClass.h>
namespace qx
{
template <class T>
class QxClass;
/*!
* \ingroup QxDao
* \brief qx::QxSqlRelation<DataType, Owner> : base class for all relationships defined between 2 classes (or between 2 tables in database)
*/
template <class DataType, class Owner>
class QxSqlRelation : public IxSqlRelation
{
protected:
typedef typename qx::trait::remove_attr<DataType>::type type_tmp_1;
typedef typename qx::trait::remove_smart_ptr<type_tmp_1>::type type_tmp_2;
typedef type_tmp_2 type_container;
typedef qx::trait::generic_container<type_container> type_generic_container;
typedef typename type_generic_container::type_item type_item;
typedef typename std::conditional<qx::trait::is_container<type_container>::value, typename type_generic_container::type_value_qx, type_container>::type type_tmp_3;
typedef typename QxSqlRelation<DataType, Owner>::type_tmp_3 type_data;
typedef Owner type_owner;
enum
{
is_valid = (qx::trait::is_qx_registered<type_data>::value && qx::trait::is_qx_registered<type_owner>::value)
};
enum
{
is_data_pointer = (std::is_pointer<DataType>::value || qx::trait::is_smart_ptr<DataType>::value)
};
enum
{
is_data_container = qx::trait::is_container<type_container>::value
};
enum
{
is_same_data_owner = std::is_same<type_data, type_owner>::value
};
public:
QxSqlRelation(IxDataMember *p) : IxSqlRelation(p) { this->setIsSameDataOwner(static_cast<int>(is_same_data_owner)); }
virtual ~QxSqlRelation() { static_assert(is_valid, "is_valid"); }
virtual void init()
{
if (!this->canInit())
{
return;
}
this->setClass(QxClass<type_data>::getSingleton(), QxClass<type_owner>::getSingleton());
IxSqlRelation::init();
}
protected:
DataType *getDataTypePtr(QxSqlRelationParams &params) const
{
qAssert(params.owner() && this->getDataMember());
return static_cast<DataType *>(this->getDataMember()->getValueVoidPtr(params.owner()));
}
type_owner &getOwner(QxSqlRelationParams &params) const
{
qAssert(params.owner());
return (*static_cast<type_owner *>(params.owner()));
}
type_data &getData(QxSqlRelationParams &params) const
{
return getData_Helper<is_data_pointer, is_data_container, 0>::get(getDataTypePtr(params));
}
type_container &getContainer(QxSqlRelationParams &params) const
{
return getContainer_Helper<is_data_pointer, is_data_container, 0>::get(getDataTypePtr(params));
}
type_item createItem() const
{
return createItem_Helper<is_data_container, 0>::get();
}
bool isNullData(QxSqlRelationParams &params) const
{
return isNullData_Helper<is_data_pointer, 0>::get(getDataTypePtr(params));
}
bool callTriggerBeforeFetch(type_data &t, QxSqlRelationParams &params) const
{
if (!params.builder().getDaoHelper())
{
return true;
}
qx::dao::on_before_fetch<type_data>((&t), params.builder().getDaoHelper());
return params.builder().getDaoHelper()->isValid();
}
bool callTriggerAfterFetch(type_data &t, QxSqlRelationParams &params) const
{
if (!params.builder().getDaoHelper())
{
return true;
}
qx::dao::on_after_fetch<type_data>((&t), params.builder().getDaoHelper());
return params.builder().getDaoHelper()->isValid();
}
private:
template <bool bIsPointer /* = false */, bool bIsContainer /* = false */, int dummy>
struct getData_Helper
{
static type_data &get(DataType *t) { return (*t); }
};
template <int dummy>
struct getData_Helper<true, false, dummy>
{
static type_data &get(DataType *t)
{
if (!(*t))
{
qx::trait::construct_ptr<DataType>::get(*t);
};
return (**t);
}
};
template <int dummy>
struct getData_Helper<false, true, dummy>
{
static type_data &get(DataType *t)
{
qAssert(false);
Q_UNUSED(t);
type_data *pDummy(NULL);
return (*pDummy);
}
};
template <int dummy>
struct getData_Helper<true, true, dummy>
{
static type_data &get(DataType *t)
{
qAssert(false);
Q_UNUSED(t);
type_data *pDummy(NULL);
return (*pDummy);
}
};
template <bool bIsPointer /* = false */, bool bIsContainer /* = false */, int dummy>
struct getContainer_Helper
{
static type_container &get(DataType *t)
{
qAssert(false);
Q_UNUSED(t);
type_container *pDummy(NULL);
return (*pDummy);
}
};
template <int dummy>
struct getContainer_Helper<true, false, dummy>
{
static type_container &get(DataType *t)
{
qAssert(false);
Q_UNUSED(t);
type_container *pDummy(NULL);
return (*pDummy);
}
};
template <int dummy>
struct getContainer_Helper<false, true, dummy>
{
static type_container &get(DataType *t) { return (*t); }
};
template <int dummy>
struct getContainer_Helper<true, true, dummy>
{
static type_container &get(DataType *t)
{
if (!(*t))
{
qx::trait::construct_ptr<DataType>::get(*t);
};
return (**t);
}
};
template <bool bIsContainer /* = false */, int dummy>
struct createItem_Helper
{
static type_item get()
{
qAssert(false);
type_item *pDummy(NULL);
return (*pDummy);
}
};
template <int dummy>
struct createItem_Helper<true, dummy>
{
static type_item get() { return type_generic_container::createItem(); }
};
template <bool bIsPointer /* = false */, int dummy>
struct isNullData_Helper
{
static bool get(DataType *t)
{
Q_UNUSED(t);
return false;
}
};
template <int dummy>
struct isNullData_Helper<true, dummy>
{
static bool get(DataType *t) { return ((!(*t)) ? true : false); }
};
};
} // namespace qx
#include <QxDao/QxSqlRelation_OneToOne.h>
#include <QxDao/QxSqlRelation_OneToMany.h>
#include <QxDao/QxSqlRelation_ManyToOne.h>
#include <QxDao/QxSqlRelation_ManyToMany.h>
#include <QxDao/QxSqlRelation_RawData.h>
#endif // _QX_SQL_RELATION_H_

View File

@@ -0,0 +1,149 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_RELATION_LINKED_H_
#define _QX_SQL_RELATION_LINKED_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlRelationLinked.h
* \author XDL Team
* \ingroup QxDao
* \brief Hierarchy of relationships to build SQL query
*/
#include <QtSql/qsqlerror.h>
#include <QxCommon/QxBool.h>
#include <QxDao/IxSqlRelation.h>
#include <QxCollection/QxCollection.h>
namespace qx
{
namespace dao
{
namespace detail
{
class IxDao_Helper;
} // namespace detail
} // namespace dao
} // namespace qx
namespace qx
{
class IxClass;
/*!
* \ingroup QxDao
* \brief qx::QxSqlRelationLinked : hierarchy of relationships to build SQL query
*
* Here is the structure, each real relation has a relation linked associated to build the hierarchy, like this :
* \code
(<root>, <relation_linked>)
("blog", blog_relation)
("blog", <relation_linked>)
("author", author_relation)
("author", <relation_linked>)
("list_blog", list_blog_relation)
("list_blog", <relation_linked>)
(etc...)
("comment", comment_relation)
("comment", <relation_linked>)
("blog_id", blog_id_relation)
("blog_id", <relation_linked>)
(etc...)
("category", category_relation)
("category", <relation_linked>)
("list_blog", list_blog_relation)
("list_blog", <relation_linked>)
(etc...)
* \endcode
*/
class QX_DLL_EXPORT QxSqlRelationLinked
{
public:
typedef std::shared_ptr<QxSqlRelationLinked> type_ptr;
typedef std::tuple<qx::dao::sql_join::join_type, IxSqlRelation *, QPair<QSet<QString>, long>, QString, bool> type_relation;
typedef qx::QxCollection<QString, type_relation> type_lst_relation;
typedef QHash<QString, type_ptr> type_lst_relation_linked;
private:
struct QxSqlRelationLinkedImpl;
std::unique_ptr<QxSqlRelationLinkedImpl> m_pImpl; //!< Private implementation idiom
public:
QxSqlRelationLinked();
QxSqlRelationLinked(bool bRoot);
virtual ~QxSqlRelationLinked();
static type_ptr getHierarchy(IxClass *pClass, const QStringList &sRelationX, qx_bool &bOk, qx::dao::detail::IxDao_Helper *pDaoHelper = NULL);
void hierarchySelect(QxSqlRelationParams &params);
void hierarchyFrom(QxSqlRelationParams &params);
void hierarchyJoin(QxSqlRelationParams &params);
void hierarchyWhereSoftDelete(QxSqlRelationParams &params);
void hierarchyResolveOutput(QxSqlRelationParams &params);
QSqlError hierarchyOnBeforeSave(QxSqlRelationParams &params);
QSqlError hierarchyOnAfterSave(QxSqlRelationParams &params);
void updateOffset(QxSqlRelationParams &params);
bool getCartesianProduct() const;
long getAllRelationCount() const;
long getRelationCount() const;
bool existRelation(const QString &sKey) const;
type_lst_relation_linked getRelationLinkedX() const;
type_lst_relation getRelationX() const;
bool isRoot() const;
bool checkRootColumns(const QString &s) const;
long getRootColumnsCount() const;
long getRootColumnsOffset() const;
void setRootColumnsOffset(long l);
QString getRootCustomAlias() const;
protected:
bool isValidDaoHelper(QxSqlRelationParams &params) const;
};
typedef std::shared_ptr<QxSqlRelationLinked> QxSqlRelationLinked_ptr;
} // namespace qx
#endif // _QX_SQL_RELATION_LINKED_H_

View File

@@ -0,0 +1,195 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_RELATION_PARAMS_H_
#define _QX_SQL_RELATION_PARAMS_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlRelationParams.h
* \author XDL Team
* \ingroup QxDao
* \brief Define list of parameters to transfer to relationships to manage SQL queries builded by QxOrm library
*/
#include <QtSql/qsqldatabase.h>
#include <QtSql/qsqlquery.h>
#include <QxDao/QxSqlJoin.h>
#include <QxDao/QxSqlSaveMode.h>
#include <QxCollection/QxCollection.h>
namespace qx
{
class QxSqlRelationLinked;
class IxSqlQueryBuilder;
class IxSqlRelation;
/*!
* \ingroup QxDao
* \brief qx::QxSqlRelationParams : define list of parameters to transfer to relationships to manage SQL queries builded by QxOrm library
*/
class QX_DLL_EXPORT QxSqlRelationParams
{
public:
typedef std::shared_ptr<QxSqlRelationLinked> type_relation_linked_ptr;
typedef QHash<QString, type_relation_linked_ptr> type_lst_relation_linked;
protected:
QVariant m_vId; //!< Current id
long m_lIndex; //!< Current SQL relation index
long m_lIndexOwner; //!< Current SQL relation owner index
long m_lOffset; //!< Current SQL query offset
QString *m_sql; //!< Current SQL query
IxSqlQueryBuilder *m_builder; //!< Current SQL query builder
QSqlQuery *m_query; //!< Current SQL query connected to database
QSqlDatabase *m_database; //!< Current SQL database connexion
void *m_pOwner; //!< Owner to current object to resolve input/output
qx::dao::sql_join::join_type m_eJoinType; //!< Current join type to build SQL query : LEFT OUTER JOIN, INNER JOIN, etc...
type_lst_relation_linked *m_pRelationX; //!< Current list of relations used by qx::QxSqlRelationLinked class
QString m_sTableAlias; //!< Current SQL table alias : useful for relationships defined in base class
qx::dao::save_mode::e_save_mode m_eSaveMode; //!< Used to improve performance, if you know that you are just inserting or updating items in database
bool m_bRecursiveMode; //!< Recursive mode to iterate over each level of relationship
QSet<void *> m_lstRecursiveItems; //!< Used by recursive process to avoid infinite loop
QPair<QSet<QString>, long> *m_pColumns; //!< List of relation columns to fetch (syntax : my_relation { column_1, column_2, etc... }), if empty then fetch all columns
QString m_sCustomAlias; //!< Custom SQL table alias instead of generating a new one automatically
QString m_sCustomAliasOwner; //!< Custom SQL table alias owner instead of generating a new one automatically
qx::QxCollection<QString, QVariantList> *m_pLstExecBatch; //!< List of data to send to database when QSqlQuery::execBatch() method is used
bool m_bIsDistinct; //!< SQL query of type SELECT DISTINCT
public:
QxSqlRelationParams();
QxSqlRelationParams(long lIndex, long lOffset, QString *sql, IxSqlQueryBuilder *builder, QSqlQuery *query, void *pOwner, const QVariant &vId = QVariant(), qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL);
virtual ~QxSqlRelationParams();
inline QVariant id() const { return m_vId; }
inline long index() const { return m_lIndex; }
inline long indexOwner() const { return m_lIndexOwner; }
inline long offset() const { return m_lOffset; }
inline QString &sql()
{
qAssert(m_sql);
return (*m_sql);
}
inline const QString &sql() const
{
qAssert(m_sql);
return (*m_sql);
}
inline QSqlQuery &query()
{
qAssert(m_query);
return (*m_query);
}
inline const QSqlQuery &query() const
{
qAssert(m_query);
return (*m_query);
}
inline QSqlDatabase &database()
{
qAssert(m_database);
return (*m_database);
}
inline const QSqlDatabase &database() const
{
qAssert(m_database);
return (*m_database);
}
inline IxSqlQueryBuilder &builder()
{
qAssert(m_builder);
return (*m_builder);
}
inline const IxSqlQueryBuilder &builder() const
{
qAssert(m_builder);
return (*m_builder);
}
inline void *owner() const { return m_pOwner; }
inline qx::dao::sql_join::join_type joinType() const { return m_eJoinType; }
inline type_lst_relation_linked *relationX() const { return m_pRelationX; }
inline QString getTableAlias() const { return m_sTableAlias; }
inline qx::dao::save_mode::e_save_mode saveMode() const { return m_eSaveMode; }
inline bool recursiveMode() const { return m_bRecursiveMode; }
inline bool existRecursiveItem(void *p) const { return m_lstRecursiveItems.contains(p); }
inline QSet<QString> getColumns() const { return (m_pColumns ? m_pColumns->first : QSet<QString>()); }
inline bool checkColumns(const QString &s) const { return (!m_pColumns || m_pColumns->first.isEmpty() || m_pColumns->first.contains(s)); }
inline long getColumnsCount() const { return (m_pColumns ? m_pColumns->first.count() : 0); }
inline long getColumnsOffset() const { return (m_pColumns ? m_pColumns->second : 0); }
inline QString getCustomAlias() const { return m_sCustomAlias; }
inline QString getCustomAliasOwner() const { return m_sCustomAliasOwner; }
inline qx::QxCollection<QString, QVariantList> *getLstExecBatch() const { return m_pLstExecBatch; }
inline bool isDistinct() const { return m_bIsDistinct; }
inline void setId(const QVariant &vId) { m_vId = vId; }
inline void setIndex(long lIndex) { m_lIndex = lIndex; }
inline void setIndexOwner(long lIndex) { m_lIndexOwner = lIndex; }
inline void setOffset(long lOffset) { m_lOffset = lOffset; }
inline void setSql(QString *sql) { m_sql = sql; }
inline void setQuery(QSqlQuery *query) { m_query = query; }
inline void setDatabase(QSqlDatabase *database) { m_database = database; }
inline void setOwner(void *pOwner) { m_pOwner = pOwner; }
inline void setJoinType(qx::dao::sql_join::join_type e) { m_eJoinType = e; }
inline void setRelationX(type_lst_relation_linked *p) { m_pRelationX = p; }
inline void setTableAlias(const QString &s) { m_sTableAlias = s; }
inline void setSaveMode(qx::dao::save_mode::e_save_mode e) { m_eSaveMode = e; }
inline void setRecursiveMode(bool b) { m_bRecursiveMode = b; }
inline void insertRecursiveItem(void *p)
{
if (p)
{
m_lstRecursiveItems.insert(p);
}
}
inline void setColumns(QPair<QSet<QString>, long> *p) { m_pColumns = p; }
inline void setColumnsOffset(long l)
{
if (m_pColumns)
{
m_pColumns->second = l;
}
}
inline void setCustomAlias(const QString &s) { m_sCustomAlias = s; }
inline void setCustomAliasOwner(const QString &s) { m_sCustomAliasOwner = s; }
inline void setLstExecBatch(qx::QxCollection<QString, QVariantList> *p) { m_pLstExecBatch = p; }
void setBuilder(IxSqlQueryBuilder *builder);
};
} // namespace qx
#endif // _QX_SQL_RELATION_PARAMS_H_

View File

@@ -0,0 +1,341 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_RELATION_MANY_TO_MANY_H_
#define _QX_SQL_RELATION_MANY_TO_MANY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlRelation_ManyToMany.h
* \author XDL Team
* \ingroup QxDao
* \brief Manage a relationship many-to-many defined between 2 classes (or between 2 tables in database)
*/
#include <QxDao/QxSqlRelation.h>
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxSqlRelation_ManyToMany<DataType, Owner> : manage a relationship many-to-many defined between 2 classes (or between 2 tables in database)
*/
template <class DataType, class Owner>
class QxSqlRelation_ManyToMany : public QxSqlRelation<DataType, Owner>
{
private:
typedef typename QxSqlRelation<DataType, Owner>::type_owner type_owner;
typedef typename QxSqlRelation<DataType, Owner>::type_data type_data;
typedef typename QxSqlRelation<DataType, Owner>::type_container type_container;
typedef typename QxSqlRelation<DataType, Owner>::type_generic_container type_generic_container;
typedef typename QxSqlRelation<DataType, Owner>::type_item type_item;
typedef typename type_generic_container::type_iterator type_iterator;
typedef typename type_item::type_value type_value;
enum
{
is_data_container = QxSqlRelation<DataType, Owner>::is_data_container
};
public:
QxSqlRelation_ManyToMany(IxDataMember *p, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType) : QxSqlRelation<DataType, Owner>(p)
{
this->setRelationType(qx::IxSqlRelation::many_to_many);
this->setExtraTable(sExtraTable);
this->setForeignKeyOwner(sForeignKeyOwner);
this->setForeignKeyDataType(sForeignKeyDataType);
this->verifyParameters();
}
virtual ~QxSqlRelation_ManyToMany() { static_assert(is_data_container, "is_data_container"); }
virtual QString getDescription() const { return "relation many-to-many"; }
virtual bool getCartesianProduct() const { return true; }
virtual void createTable(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazySelect(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFrom(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerFrom(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyJoin(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyWhere(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerWhere(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyWhereSoftDelete(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFetch_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerFetch_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFetch_ResolveOutput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyInsert(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyInsert_Values(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyUpdate(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyInsert_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyUpdate_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual QSqlError onBeforeSave(QxSqlRelationParams &params) const
{
Q_UNUSED(params);
return QSqlError();
}
virtual QVariant getIdFromQuery(bool bEager, QxSqlRelationParams &params, int iOffset, int iNameIndex) const
{
return this->getIdFromQuery_ManyToMany(bEager, params, iOffset, iNameIndex);
}
virtual void updateOffset(bool bEager, QxSqlRelationParams &params) const
{
this->updateOffset_ManyToMany(bEager, params);
}
virtual void eagerSelect(QxSqlRelationParams &params) const
{
this->eagerSelect_ManyToMany(params);
}
virtual void eagerJoin(QxSqlRelationParams &params) const
{
this->eagerJoin_ManyToMany(params);
}
virtual void eagerWhereSoftDelete(QxSqlRelationParams &params) const
{
this->eagerWhereSoftDelete_ManyToMany(params);
}
virtual void *eagerFetch_ResolveOutput(QxSqlRelationParams &params) const
{
if (!this->verifyOffset(params, true))
{
return NULL;
}
QSqlQuery &query = params.query();
IxDataMember *p = NULL;
IxDataMember *pId = this->getDataId();
qAssert(pId);
long lIndex = 0;
long lOffsetId = ((pId && (!params.isDistinct())) ? pId->getNameCount() : 0);
bool bValidId(false);
long lOffsetOld = params.offset();
this->updateOffset(true, params);
long lRelation = 0;
IxSqlRelation *pRelation = NULL;
if (!params.isDistinct())
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = query.value(lOffsetOld + i);
bValidId = (bValidId || qx::trait::is_valid_primary_key(v));
}
if (!bValidId)
{
return NULL;
}
}
type_item item = this->createItem();
type_data &item_val = item.value_qx();
if (!this->callTriggerBeforeFetch(item_val, params))
{
return NULL;
}
if (!params.isDistinct())
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = query.value(lOffsetOld + i);
qx::cvt::from_variant(v, item.key(), "", i, qx::cvt::context::e_database);
}
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = query.value(lOffsetOld + i);
pId->fromVariant((&item_val), v, "", i, qx::cvt::context::e_database);
}
}
else
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = this->getIdFromQuery(true, params, (lOffsetOld + i), i);
qx::cvt::from_variant(v, item.key(), "", i, qx::cvt::context::e_database);
}
}
long lOffsetRelation = (lOffsetOld + lOffsetId);
long lCurrIndex = 0;
while ((p = this->nextData(lIndex)))
{
if (params.checkColumns(p->getKey()))
{
p->fromVariant((&item_val), query.value(lCurrIndex + lOffsetRelation), -1, qx::cvt::context::e_database);
lCurrIndex++;
}
}
if (params.relationX())
{
long lOffsetCurrent = (lCurrIndex + lOffsetRelation);
QString sOldCustomAliasOwner = params.getCustomAliasOwner();
params.setCustomAliasOwner(params.getCustomAlias());
long lIndexOwnerOld = params.indexOwner();
params.setIndexOwner(params.index());
void *pOwnerOld = params.owner();
params.setOwner(&item_val);
lOffsetOld = params.offset();
params.setOffset(lOffsetCurrent);
while ((pRelation = this->nextRelation(lRelation)))
{
if (this->addLazyRelation(params, pRelation))
{
pRelation->lazyFetch_ResolveOutput(params);
}
}
params.setOwner(pOwnerOld);
params.setOffset(lOffsetOld);
params.setCustomAliasOwner(sOldCustomAliasOwner);
params.setIndexOwner(lIndexOwnerOld);
}
if (!this->callTriggerAfterFetch(item_val, params))
{
return NULL;
}
type_value *pValue = type_generic_container::insertItem(this->getContainer(params), item);
if (!type_item::is_value_pointer && pValue)
{
return pValue;
}
return (&item_val);
}
virtual QSqlError onAfterSave(QxSqlRelationParams &params) const
{
QSqlError daoError;
if (this->isNullData(params))
{
return this->deleteFromExtraTable(params);
}
if (!params.recursiveMode())
{
daoError = qx::dao::save(this->getContainer(params), (&params.database()));
}
else
{
daoError = qx::dao::save_with_relation_recursive(this->getContainer(params), params.saveMode(), (&params.database()), (&params));
}
if (daoError.isValid())
{
return daoError;
}
daoError = this->deleteFromExtraTable(params);
if (daoError.isValid())
{
return daoError;
}
daoError = this->insertIntoExtraTable(params);
if (daoError.isValid())
{
return daoError;
}
return QSqlError();
}
virtual QString createExtraTable() const
{
return this->createExtraTable_ManyToMany();
}
private:
void verifyParameters()
{
qAssert(!this->getExtraTable().isEmpty() && !this->getForeignKeyOwner().isEmpty() && !this->getForeignKeyDataType().isEmpty() && (this->getForeignKeyOwner() != this->getForeignKeyDataType()));
}
QSqlError deleteFromExtraTable(QxSqlRelationParams &params) const
{
return this->deleteFromExtraTable_ManyToMany(params);
}
QSqlError insertIntoExtraTable(QxSqlRelationParams &params) const
{
IxDataMember *pIdOwner = this->getDataIdOwner();
qAssert(pIdOwner);
IxDataMember *pIdData = this->getDataId();
qAssert(pIdData);
if (!pIdOwner || !pIdData)
{
return QSqlError();
}
QStringList lstForeignKeyOwner = this->getForeignKeyOwner().split("|");
QStringList lstForeignKeyDataType = this->getForeignKeyDataType().split("|");
qAssert(pIdOwner->getNameCount() == lstForeignKeyOwner.count());
qAssert(pIdData->getNameCount() == lstForeignKeyDataType.count());
QString sql = "INSERT INTO " + this->getExtraTable() + " (";
sql += pIdOwner->getSqlName(", ", this->getForeignKeyOwner(), false, (&params.builder()));
sql += ", ";
sql += pIdData->getSqlName(", ", this->getForeignKeyDataType(), false, (&params.builder()));
sql += ") VALUES (";
sql += pIdOwner->getSqlPlaceHolder("", -1, ", ", this->getForeignKeyOwner()) + ", " + pIdData->getSqlPlaceHolder("", -1, ", ", this->getForeignKeyDataType()) + ")";
if (this->traceSqlQuery())
{
qDebug("[QxOrm] sql query (extra-table) : %s", qPrintable(sql));
}
type_item item;
type_container &container = this->getContainer(params);
type_iterator itr = type_generic_container::begin(container, item);
type_iterator itr_end = type_generic_container::end(container);
QSqlQuery queryInsert(params.database());
if (!queryInsert.prepare(sql))
{
return queryInsert.lastError();
}
while (itr != itr_end)
{
pIdOwner->setSqlPlaceHolder(queryInsert, params.owner(), "", this->getForeignKeyOwner());
pIdData->setSqlPlaceHolder(queryInsert, (&item.value_qx()), "", this->getForeignKeyDataType());
if (!queryInsert.exec())
{
return queryInsert.lastError();
}
itr = type_generic_container::next(container, itr, item);
}
return QSqlError();
}
};
} // namespace qx
#endif // _QX_SQL_RELATION_MANY_TO_MANY_H_

View File

@@ -0,0 +1,300 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_RELATION_MANY_TO_ONE_H_
#define _QX_SQL_RELATION_MANY_TO_ONE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlRelation_ManyToOne.h
* \author XDL Team
* \ingroup QxDao
* \brief Manage a relationship many-to-one defined between 2 classes (or between 2 tables in database)
*/
#include <QxDao/QxSqlRelation.h>
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxSqlRelation_ManyToOne<DataType, Owner> : manage a relationship many-to-one defined between 2 classes (or between 2 tables in database)
*/
template <class DataType, class Owner>
class QxSqlRelation_ManyToOne : public QxSqlRelation<DataType, Owner>
{
private:
typedef typename QxSqlRelation<DataType, Owner>::type_owner type_owner;
typedef typename QxSqlRelation<DataType, Owner>::type_data type_data;
public:
QxSqlRelation_ManyToOne(IxDataMember *p) : QxSqlRelation<DataType, Owner>(p) { this->setRelationType(qx::IxSqlRelation::many_to_one); }
virtual ~QxSqlRelation_ManyToOne() { ; }
virtual QString getDescription() const { return "relation many-to-one"; }
virtual QString createExtraTable() const { return ""; }
virtual bool getCartesianProduct() const { return false; }
virtual void lazyFrom(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerFrom(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyJoin(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyWhere(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerWhere(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyWhereSoftDelete(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFetch_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerFetch_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual QSqlError onAfterSave(QxSqlRelationParams &params) const
{
Q_UNUSED(params);
return QSqlError();
}
virtual QSqlError onBeforeSave(QxSqlRelationParams &params) const
{
if (this->isNullData(params) || params.recursiveMode())
{
return QSqlError();
}
return qx::dao::save(this->getData(params), (&params.database()));
}
virtual void lazyUpdate_ResolveInput(QxSqlRelationParams &params) const
{
this->lazyInsert_ResolveInput(params);
}
virtual QVariant getIdFromQuery(bool bEager, QxSqlRelationParams &params, int iOffset, int iNameIndex) const
{
return this->getIdFromQuery_ManyToOne(bEager, params, iOffset, iNameIndex);
}
virtual void updateOffset(bool bEager, QxSqlRelationParams &params) const
{
this->updateOffset_ManyToOne(bEager, params);
}
virtual void createTable(QxSqlRelationParams &params) const
{
this->createTable_ManyToOne(params);
}
virtual void lazySelect(QxSqlRelationParams &params) const
{
this->lazySelect_ManyToOne(params);
}
virtual void eagerSelect(QxSqlRelationParams &params) const
{
this->eagerSelect_ManyToOne(params);
}
virtual void eagerJoin(QxSqlRelationParams &params) const
{
this->eagerJoin_ManyToOne(params);
}
virtual void eagerWhereSoftDelete(QxSqlRelationParams &params) const
{
this->eagerWhereSoftDelete_ManyToOne(params);
}
virtual void lazyFetch_ResolveOutput(QxSqlRelationParams &params) const
{
if (!this->verifyOffset(params, false))
{
return;
}
QSqlQuery &query = params.query();
typename QxSqlRelation<DataType, Owner>::type_owner &currOwner = this->getOwner(params);
IxDataMember *pData = this->getDataMember();
qAssert(pData);
if (!pData)
{
return;
}
bool bValidId(false);
for (int i = 0; i < pData->getNameCount(); i++)
{
QVariant vId = query.value(params.offset() + i);
bValidId = (bValidId || qx::trait::is_valid_primary_key(vId));
}
if (pData && bValidId)
{
for (int i = 0; i < pData->getNameCount(); i++)
{
pData->fromVariant((&currOwner), query.value(params.offset() + i), i, qx::cvt::context::e_database);
}
}
this->updateOffset(false, params);
}
virtual void *eagerFetch_ResolveOutput(QxSqlRelationParams &params) const
{
if (!this->verifyOffset(params, false))
{
return NULL;
}
QSqlQuery &query = params.query();
typename QxSqlRelation<DataType, Owner>::type_owner &currOwner = this->getOwner(params);
IxDataMember *pData = this->getDataMember();
qAssert(pData);
if (!pData)
{
return NULL;
}
IxDataMember *p = NULL;
IxDataMember *pId = this->getDataId();
qAssert(pId);
if (!pId)
{
return NULL;
}
long lIndex = 0;
long lOffsetId = ((pId && (!params.isDistinct())) ? pId->getNameCount() : 0);
long lOffsetData = ((pData && (!params.isDistinct())) ? pData->getNameCount() : 0);
long lOffsetOld = params.offset();
this->updateOffset(true, params);
long lOffsetRelation = (lOffsetOld + lOffsetId + lOffsetData);
long lRelation = 0;
IxSqlRelation *pRelation = NULL;
bool bValidId(false), bValidIdBis(false);
if (!params.isDistinct())
{
for (int i = 0; i < pData->getNameCount(); i++)
{
QVariant vId = query.value(lOffsetOld + i);
bValidId = (bValidId || qx::trait::is_valid_primary_key(vId));
}
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant vIdBis = query.value(lOffsetOld + lOffsetData + i);
bValidIdBis = (bValidIdBis || qx::trait::is_valid_primary_key(vIdBis));
}
if (pData && bValidId)
{
for (int i = 0; i < pData->getNameCount(); i++)
{
pData->fromVariant((&currOwner), query.value(lOffsetOld + i), i, qx::cvt::context::e_database);
}
}
if (!bValidIdBis)
{
return NULL;
}
}
type_data &currData = this->getData(params);
if (!this->callTriggerBeforeFetch(currData, params))
{
return NULL;
}
if (pId && (!params.isDistinct()))
{
for (int i = 0; i < pId->getNameCount(); i++)
{
pId->fromVariant((&currData), query.value(lOffsetOld + lOffsetData + i), i, qx::cvt::context::e_database);
}
}
while ((p = this->nextData(lIndex)))
{
if (params.checkColumns(p->getKey()))
{
p->fromVariant((&currData), query.value(lOffsetRelation++), -1, qx::cvt::context::e_database);
}
}
if (params.relationX())
{
QString sOldCustomAliasOwner = params.getCustomAliasOwner();
params.setCustomAliasOwner(params.getCustomAlias());
long lIndexOwnerOld = params.indexOwner();
params.setIndexOwner(params.index());
void *pOwnerOld = params.owner();
params.setOwner(&currData);
lOffsetOld = params.offset();
params.setOffset(lOffsetRelation++);
while ((pRelation = this->nextRelation(lRelation)))
{
if (this->addLazyRelation(params, pRelation))
{
pRelation->lazyFetch_ResolveOutput(params);
}
}
params.setOwner(pOwnerOld);
params.setOffset(lOffsetOld);
params.setCustomAliasOwner(sOldCustomAliasOwner);
params.setIndexOwner(lIndexOwnerOld);
}
if (!this->callTriggerAfterFetch(currData, params))
{
return NULL;
}
return (&currData);
}
virtual void lazyInsert(QxSqlRelationParams &params) const
{
this->lazyInsert_ManyToOne(params);
}
virtual void lazyInsert_Values(QxSqlRelationParams &params) const
{
this->lazyInsert_Values_ManyToOne(params);
}
virtual void lazyUpdate(QxSqlRelationParams &params) const
{
this->lazyUpdate_ManyToOne(params);
}
virtual void lazyInsert_ResolveInput(QxSqlRelationParams &params) const
{
QSqlQuery &query = params.query();
typename QxSqlRelation<DataType, Owner>::type_owner &currOwner = this->getOwner(params);
IxDataMember *pData = this->getDataMember();
qAssert(pData);
if (pData)
{
pData->setSqlPlaceHolder(query, (&currOwner), "", "", false, params.getLstExecBatch());
}
}
};
} // namespace qx
#endif // _QX_SQL_RELATION_MANY_TO_ONE_H_

View File

@@ -0,0 +1,322 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_RELATION_ONE_TO_MANY_H_
#define _QX_SQL_RELATION_ONE_TO_MANY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlRelation_OneToMany.h
* \author XDL Team
* \ingroup QxDao
* \brief Manage a relationship one-to-many defined between 2 classes (or between 2 tables in database)
*/
#include <QxDao/QxSqlRelation.h>
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxSqlRelation_OneToMany<DataType, Owner> : manage a relationship one-to-many defined between 2 classes (or between 2 tables in database)
*/
template <class DataType, class Owner>
class QxSqlRelation_OneToMany : public QxSqlRelation<DataType, Owner>
{
private:
typedef typename QxSqlRelation<DataType, Owner>::type_owner type_owner;
typedef typename QxSqlRelation<DataType, Owner>::type_data type_data;
typedef typename QxSqlRelation<DataType, Owner>::type_container type_container;
typedef typename QxSqlRelation<DataType, Owner>::type_generic_container type_generic_container;
typedef typename QxSqlRelation<DataType, Owner>::type_item type_item;
typedef typename type_generic_container::type_iterator type_iterator;
typedef typename type_item::type_value type_value;
enum
{
is_data_container = QxSqlRelation<DataType, Owner>::is_data_container
};
public:
QxSqlRelation_OneToMany(IxDataMember *p, const QString &sForeignKey) : QxSqlRelation<DataType, Owner>(p)
{
this->setRelationType(qx::IxSqlRelation::one_to_many);
this->setForeignKey(sForeignKey);
qAssert(!this->getForeignKey().isEmpty());
}
virtual ~QxSqlRelation_OneToMany() { static_assert(is_data_container, "is_data_container"); }
virtual QString getDescription() const { return "relation one-to-many"; }
virtual QString createExtraTable() const { return ""; }
virtual bool getCartesianProduct() const { return true; }
virtual void createTable(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazySelect(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFrom(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerFrom(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyJoin(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyWhere(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerWhere(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyWhereSoftDelete(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFetch_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerFetch_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFetch_ResolveOutput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyInsert(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyInsert_Values(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyUpdate(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyInsert_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyUpdate_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual QSqlError onBeforeSave(QxSqlRelationParams &params) const
{
Q_UNUSED(params);
return QSqlError();
}
virtual QSqlError onAfterSave(QxSqlRelationParams &params) const
{
if (this->isNullData(params))
{
return QSqlError();
}
this->forceParentIdToAllChildren(params);
if (!params.recursiveMode())
{
return qx::dao::save(this->getContainer(params), (&params.database()));
}
else
{
return qx::dao::save_with_relation_recursive(this->getContainer(params), params.saveMode(), (&params.database()), (&params));
}
}
virtual QVariant getIdFromQuery(bool bEager, QxSqlRelationParams &params, int iOffset, int iNameIndex) const
{
return this->getIdFromQuery_OneToMany(bEager, params, iOffset, iNameIndex);
}
virtual void updateOffset(bool bEager, QxSqlRelationParams &params) const
{
this->updateOffset_OneToMany(bEager, params);
}
virtual void eagerSelect(QxSqlRelationParams &params) const
{
this->eagerSelect_OneToMany(params);
}
virtual void eagerJoin(QxSqlRelationParams &params) const
{
this->eagerJoin_OneToMany(params);
}
virtual void eagerWhereSoftDelete(QxSqlRelationParams &params) const
{
this->eagerWhereSoftDelete_OneToMany(params);
}
virtual void *eagerFetch_ResolveOutput(QxSqlRelationParams &params) const
{
if (!this->verifyOffset(params, true))
{
return NULL;
}
QSqlQuery &query = params.query();
IxDataMember *p = NULL;
IxDataMember *pId = this->getDataId();
qAssert(pId);
if (!pId)
{
return NULL;
}
IxDataMember *pForeign = this->getDataByKey(this->getForeignKey());
qAssert(pForeign);
if (!pForeign)
{
return NULL;
}
long lIndex = 0;
long lOffsetId = ((pId && (!params.isDistinct())) ? pId->getNameCount() : 0);
long lOffsetForeign = ((pForeign && (!params.isDistinct())) ? pForeign->getNameCount() : 0);
long lOffsetOld = params.offset();
this->updateOffset(true, params);
long lOffsetRelation = (lOffsetOld + lOffsetId + lOffsetForeign);
long lRelation = 0;
IxSqlRelation *pRelation = NULL;
bool bValidId(false), bValidForeign(false);
if (!params.isDistinct())
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant vId = query.value(lOffsetOld + i);
bValidId = (bValidId || qx::trait::is_valid_primary_key(vId));
}
for (int i = 0; i < pForeign->getNameCount(); i++)
{
QVariant vForeign = query.value(lOffsetOld + lOffsetId + i);
bValidForeign = (bValidForeign || qx::trait::is_valid_primary_key(vForeign));
}
if (!bValidId || !bValidForeign)
{
return NULL;
}
}
type_item item = this->createItem();
type_data &item_val = item.value_qx();
if (!this->callTriggerBeforeFetch(item_val, params))
{
return NULL;
}
if (!params.isDistinct())
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = query.value(lOffsetOld + i);
qx::cvt::from_variant(v, item.key(), "", i, qx::cvt::context::e_database);
}
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = query.value(lOffsetOld + i);
pId->fromVariant((&item_val), v, "", i, qx::cvt::context::e_database);
}
for (int i = 0; i < pForeign->getNameCount(); i++)
{
QVariant v = query.value(lOffsetOld + lOffsetId + i);
pForeign->fromVariant((&item_val), v, "", i, qx::cvt::context::e_database);
}
}
else
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = this->getIdFromQuery(true, params, (lOffsetOld + i), i);
qx::cvt::from_variant(v, item.key(), "", i, qx::cvt::context::e_database);
}
}
while ((p = this->nextData(lIndex)))
{
if ((p != pForeign) && (params.checkColumns(p->getKey())))
{
p->fromVariant((&item_val), query.value(lOffsetRelation++), -1, qx::cvt::context::e_database);
}
}
if (params.relationX())
{
QString sOldCustomAliasOwner = params.getCustomAliasOwner();
params.setCustomAliasOwner(params.getCustomAlias());
long lIndexOwnerOld = params.indexOwner();
params.setIndexOwner(params.index());
void *pOwnerOld = params.owner();
params.setOwner(&item_val);
lOffsetOld = params.offset();
params.setOffset(lOffsetRelation++);
while ((pRelation = this->nextRelation(lRelation)))
{
if (this->addLazyRelation(params, pRelation))
{
pRelation->lazyFetch_ResolveOutput(params);
}
}
params.setOwner(pOwnerOld);
params.setOffset(lOffsetOld);
params.setCustomAliasOwner(sOldCustomAliasOwner);
params.setIndexOwner(lIndexOwnerOld);
}
if (!this->callTriggerAfterFetch(item_val, params))
{
return NULL;
}
type_value *pValue = type_generic_container::insertItem(this->getContainer(params), item);
if (!type_item::is_value_pointer && pValue)
{
return pValue;
}
return (&item_val);
}
private:
void forceParentIdToAllChildren(QxSqlRelationParams &params) const
{
bool bForce = qx::QxSqlDatabase::getSingleton()->getForceParentIdToAllChildren();
if (!bForce || !params.owner())
{
return;
}
IxDataMember *pIdOwner = this->getDataIdOwner();
if (!pIdOwner)
{
return;
}
IxDataMember *pForeign = this->getDataByKey(this->getForeignKey());
if (!pForeign)
{
return;
}
if (pIdOwner->getNameCount() != pForeign->getNameCount())
{
return;
}
QList<QVariant> vIdOwner;
for (int i = 0; i < pIdOwner->getNameCount(); i++)
{
vIdOwner.append(pIdOwner->toVariant(params.owner(), i, qx::cvt::context::e_database));
}
type_item item;
type_container &container = this->getContainer(params);
type_iterator itr = type_generic_container::begin(container, item);
type_iterator itr_end = type_generic_container::end(container);
while (itr != itr_end)
{
type_data &item_val = item.value_qx();
for (int i = 0; i < vIdOwner.count(); i++)
{
pForeign->fromVariant((&item_val), vIdOwner.at(i), "", i, qx::cvt::context::e_database);
}
itr = type_generic_container::next(container, itr, item);
}
}
};
} // namespace qx
#endif // _QX_SQL_RELATION_ONE_TO_MANY_H_

View File

@@ -0,0 +1,228 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_RELATION_ONE_TO_ONE_H_
#define _QX_SQL_RELATION_ONE_TO_ONE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlRelation_OneToOne.h
* \author XDL Team
* \ingroup QxDao
* \brief Manage a relationship one-to-one defined between 2 classes (or between 2 tables in database)
*/
#include <QxDao/QxSqlRelation.h>
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxSqlRelation_OneToOne<DataType, Owner> : manage a relationship one-to-one defined between 2 classes (or between 2 tables in database)
*/
template <class DataType, class Owner>
class QxSqlRelation_OneToOne : public QxSqlRelation<DataType, Owner>
{
private:
typedef typename QxSqlRelation<DataType, Owner>::type_owner type_owner;
typedef typename QxSqlRelation<DataType, Owner>::type_data type_data;
public:
QxSqlRelation_OneToOne(IxDataMember *p) : QxSqlRelation<DataType, Owner>(p) { this->setRelationType(qx::IxSqlRelation::one_to_one); }
virtual ~QxSqlRelation_OneToOne() { ; }
virtual QString getDescription() const { return "relation one-to-one"; }
virtual QString createExtraTable() const { return ""; }
virtual bool getCartesianProduct() const { return false; }
virtual void createTable(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazySelect(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFrom(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerFrom(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyJoin(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyWhere(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerWhere(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyWhereSoftDelete(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFetch_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void eagerFetch_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyFetch_ResolveOutput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyInsert(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyInsert_Values(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyUpdate(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyInsert_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual void lazyUpdate_ResolveInput(QxSqlRelationParams &params) const { Q_UNUSED(params); }
virtual QSqlError onBeforeSave(QxSqlRelationParams &params) const
{
Q_UNUSED(params);
return QSqlError();
}
virtual QSqlError onAfterSave(QxSqlRelationParams &params) const
{
if (this->isNullData(params))
{
return QSqlError();
}
if (!params.recursiveMode())
{
return qx::dao::save(this->getData(params), (&params.database()));
}
else
{
return qx::dao::save_with_relation_recursive(this->getData(params), params.saveMode(), (&params.database()), (&params));
}
}
virtual QVariant getIdFromQuery(bool bEager, QxSqlRelationParams &params, int iOffset, int iNameIndex) const
{
return this->getIdFromQuery_OneToOne(bEager, params, iOffset, iNameIndex);
}
virtual void updateOffset(bool bEager, QxSqlRelationParams &params) const
{
this->updateOffset_OneToOne(bEager, params);
}
virtual void eagerSelect(QxSqlRelationParams &params) const
{
this->eagerSelect_OneToOne(params);
}
virtual void eagerJoin(QxSqlRelationParams &params) const
{
this->eagerJoin_OneToOne(params);
}
virtual void eagerWhereSoftDelete(QxSqlRelationParams &params) const
{
this->eagerWhereSoftDelete_OneToOne(params);
}
virtual void *eagerFetch_ResolveOutput(QxSqlRelationParams &params) const
{
if (!this->verifyOffset(params, true))
{
return NULL;
}
QSqlQuery &query = params.query();
IxDataMember *p = NULL;
IxDataMember *pId = this->getDataId();
qAssert(pId);
if (!pId)
{
return NULL;
}
long lIndex = 0;
long lOffsetId = ((pId && (!params.isDistinct())) ? pId->getNameCount() : 0);
bool bValidId(false);
long lOffsetOld = params.offset();
this->updateOffset(true, params);
long lRelation = 0;
IxSqlRelation *pRelation = NULL;
if (!params.isDistinct())
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = query.value(lOffsetOld + i);
bValidId = (bValidId || qx::trait::is_valid_primary_key(v));
}
if (!bValidId)
{
return NULL;
}
}
type_data &currData = this->getData(params);
if (!this->callTriggerBeforeFetch(currData, params))
{
return NULL;
}
if (!params.isDistinct())
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = query.value(lOffsetOld + i);
pId->fromVariant((&currData), v, i, qx::cvt::context::e_database);
}
}
long lOffsetRelation = (lOffsetOld + lOffsetId);
long lCurrIndex = 0;
while ((p = this->nextData(lIndex)))
{
if (params.checkColumns(p->getKey()))
{
p->fromVariant((&currData), query.value(lCurrIndex + lOffsetRelation), -1, qx::cvt::context::e_database);
lCurrIndex++;
}
}
if (params.relationX())
{
long lOffsetCurrent = (lCurrIndex + lOffsetRelation);
QString sOldCustomAliasOwner = params.getCustomAliasOwner();
params.setCustomAliasOwner(params.getCustomAlias());
long lIndexOwnerOld = params.indexOwner();
params.setIndexOwner(params.index());
void *pOwnerOld = params.owner();
params.setOwner(&currData);
lOffsetOld = params.offset();
params.setOffset(lOffsetCurrent);
while ((pRelation = this->nextRelation(lRelation)))
{
if (this->addLazyRelation(params, pRelation))
{
pRelation->lazyFetch_ResolveOutput(params);
}
}
params.setOwner(pOwnerOld);
params.setOffset(lOffsetOld);
params.setCustomAliasOwner(sOldCustomAliasOwner);
params.setIndexOwner(lIndexOwnerOld);
}
if (!this->callTriggerAfterFetch(currData, params))
{
return NULL;
}
return (&currData);
}
};
} // namespace qx
#endif // _QX_SQL_RELATION_ONE_TO_ONE_H_

View File

@@ -0,0 +1,30 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/

View File

@@ -0,0 +1,70 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_SQL_SAVE_MODE_H_
#define _QX_SQL_SAVE_MODE_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxSqlSaveMode.h
* \author XDL Team
* \ingroup QxDao
* \brief To improve performance, if you know that you are just inserting or updating items in database
*/
namespace qx
{
namespace dao
{
/*!
* \ingroup QxDao
* \brief qx::dao::save_mode : to improve performance, if you know that you are just inserting or updating items in database
*/
struct save_mode
{
enum e_save_mode
{
e_none,
e_check_insert_or_update,
e_insert_only,
e_update_only
};
};
} // namespace dao
} // namespace qx
#endif // _QX_SQL_SAVE_MODE_H_

View File

@@ -0,0 +1,153 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_TIME_NEUTRAL_H_
#define _QX_TIME_NEUTRAL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxTimeNeutral.h
* \author XDL Team
* \ingroup QxDao
* \brief Helper class to store a time value into database under neutral format (HHMMSS) => cross database compatibility
*/
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#include <QtCore/qdatetime.h>
#include <QtCore/qdatastream.h>
#include <QxSerialize/Qt/QxSerialize_QString.h>
#include <QxTraits/get_class_name.h>
namespace qx
{
class QxTimeNeutral;
} // namespace qx
QX_DLL_EXPORT QDataStream &operator<<(QDataStream &stream, const qx::QxTimeNeutral &t) QX_USED;
QX_DLL_EXPORT QDataStream &operator>>(QDataStream &stream, qx::QxTimeNeutral &t) QX_USED;
namespace qx
{
/*!
* \ingroup QxDao
* \brief qx::QxTimeNeutral : helper class to store a time value into database under neutral format (HHMMSS) => cross database compatibility
*/
class QxTimeNeutral
{
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
friend class boost::serialization::access;
#endif // _QX_ENABLE_BOOST_SERIALIZATION
friend QX_DLL_EXPORT QDataStream & ::operator<<(QDataStream &stream, const qx::QxTimeNeutral &t);
friend QX_DLL_EXPORT QDataStream & ::operator>>(QDataStream &stream, qx::QxTimeNeutral &t);
private:
QTime m_time; //!< Data value under QTime format from Qt library
QString m_neutral; //!< Data value under neutral format 'hhmmss'
public:
QxTimeNeutral() { ; }
explicit QxTimeNeutral(const QTime &time) : m_time(time) { update(); }
explicit QxTimeNeutral(const QString &neutral) : m_neutral(neutral) { update(); }
virtual ~QxTimeNeutral() { ; }
inline QTime toTime() const { return m_time; }
inline QString toNeutral() const { return m_neutral; }
inline bool isValid() const { return m_time.isValid(); }
inline void setTime(const QTime &time)
{
m_neutral = "";
m_time = time;
update();
}
inline void setNeutral(const QString &neutral)
{
m_time = QTime();
m_neutral = neutral;
update();
}
static QxTimeNeutral fromTime(const QTime &time) { return QxTimeNeutral(time); }
static QxTimeNeutral fromNeutral(const QString &neutral) { return QxTimeNeutral(neutral); }
private:
static inline const char *format() { return "hhmmss"; }
void update()
{
if (m_neutral.isEmpty() && !m_time.isValid())
{
return;
}
else if (m_time.isValid())
{
m_neutral = m_time.toString(format());
}
else
{
qAssert(m_neutral.size() == QString(format()).size());
m_time = QTime::fromString(m_neutral, format());
qAssert(m_time.isValid());
}
}
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void serialize(Archive &ar, const unsigned int file_version)
{
Q_UNUSED(file_version);
ar &boost::serialization::make_nvp("time_neutral", m_neutral);
if (Archive::is_loading::value)
{
m_time = QTime();
update();
}
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
} // namespace qx
QX_REGISTER_CLASS_NAME(qx::QxTimeNeutral)
#endif // _QX_TIME_NEUTRAL_H_

52
include/QxDaoRepository.h Normal file
View File

@@ -0,0 +1,52 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DAO_REPOSITORY_H_
#define _QX_DAO_REPOSITORY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDaoRepository.h
* \author XDL Team
* \ingroup QxDao
* \brief Include all headers required to use repository pattern
*/
#include <QxOrm.h>
#include <QxDao/QxRepository/IxRepository.h>
#include <QxDao/QxRepository/QxRepository.h>
#include <QxDao/QxRepository/QxRepositoryX.h>
#endif // _QX_DAO_REPOSITORY_H_

View File

@@ -0,0 +1,430 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_DATA_MEMBER_H_
#define _IX_DATA_MEMBER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxDataMember.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Common interface for all class properties registered into QxOrm context
*/
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#endif // _MSC_VER
#include <QtCore/qmutex.h>
#include <QtSql/qsqlquery.h>
#ifndef _QX_NO_JSON
#include <QtCore/qjsonvalue.h>
#endif // _QX_NO_JSON
#include <QxCommon/QxAny.h>
#include <QxCommon/QxBool.h>
#include <QxCommon/QxPropertyBag.h>
#include <QxCollection/QxCollection.h>
#include <QxSerialize/boost/QxSerializeInclude.h>
#include <QxConvert/QxConvert.h>
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER
#define QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(ArchiveInput, ArchiveOutput) \
virtual void toArchive(const void *pOwner, ArchiveOutput &ar) const = 0; \
virtual void fromArchive(void *pOwner, ArchiveInput &ar) = 0;
namespace qx
{
class IxDataMemberX;
class IxSqlRelation;
class IxSqlQueryBuilder;
struct IxDataMemberSqlCallbackParams;
namespace dao
{
namespace detail
{
class IxDao_Helper;
} // namespace detail
} // namespace dao
/*!
* \ingroup QxDataMember
* \brief qx::IxDataMember : common interface for all class properties registered into QxOrm context
*/
class QX_DLL_EXPORT IxDataMember : public qx::QxPropertyBag
{
template <typename DataType, class Owner>
friend class QxDataMember;
public:
typedef std::function<void(IxDataMemberSqlCallbackParams &)> type_fct_sql_callback;
private:
struct IxDataMemberImpl;
std::unique_ptr<IxDataMemberImpl> m_pImpl; //!< Private implementation idiom
static QMutex m_mutex; //!< Mutex => qx::IxDataMember is thread-safe
public:
IxDataMember(const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl);
virtual ~IxDataMember() = 0;
QString getKey() const;
QString getName() const;
int getNameCount() const;
QString getNameParent() const;
const char *getNamePtr() const;
QString getDescription() const;
QString getFormat() const;
long getVersion() const;
bool getSerialize() const;
bool getDao() const;
QVariant getDefaultValue() const;
QVariant getMinValue() const;
QVariant getMaxValue() const;
int getPrecision() const;
int getMinLength() const;
int getMaxLength() const;
bool getRequired() const;
bool getReadOnly() const;
bool getAutoIncrement() const;
bool getNotNull() const;
bool getIsPrimaryKey() const;
bool getIsIndex() const;
bool getIsUnique() const;
IxDataMemberX *getParent() const;
IxSqlRelation *getSqlRelation() const;
bool hasSqlRelation() const;
bool getAccessDataPointer() const;
virtual QString getType() const;
QString getTypeParent() const;
IxDataMember *getPImpl() const;
void setName(const QString &s);
void setNameParent(const QString &s);
void setDescription(const QString &s);
void setFormat(const QString &s);
void setSqlType(const QString &s);
void setSqlAlias(const QString &s);
void setVersion(long l);
void setSerialize(bool b);
void setDao(bool b);
void setDefaultValue(const QVariant &v);
void setPrecision(int i);
void setRequired(bool b);
void setReadOnly(bool b);
void setAutoIncrement(bool b);
void setIsPrimaryKey(bool b);
void setIsIndex(bool b);
void setIsUnique(bool b);
void setParent(IxDataMemberX *p);
void setSqlRelation(IxSqlRelation *p);
void setAccessDataPointer(bool b);
void setMinValue(long lMinValue, const QString &sMessage = QString());
void setMinValue(double dMinValue, const QString &sMessage = QString());
void setMaxValue(long lMaxValue, const QString &sMessage = QString());
void setMaxValue(double dMaxValue, const QString &sMessage = QString());
void setMinLength(int iMinLength, const QString &sMessage = QString());
void setMaxLength(int iMaxLength, const QString &sMessage = QString());
void setNotNull(bool bNotNull, const QString &sMessage = QString());
bool isThereRelationPartOfPrimaryKey(int iIndexNamePK, IxSqlRelation *&pRelation, int &iIndexNameFK) const;
bool isPartOfPrimaryKey(int iIndexNameFK, IxDataMember *&pPrimaryKey, int &iIndexNamePK) const;
void setRelationPartOfPrimaryKey(int iIndexNamePK, IxSqlRelation *pRelation, int iIndexNameFK);
void setPartOfPrimaryKey(int iIndexNameFK, IxDataMember *pPrimaryKey, int iIndexNamePK);
QString getName(int iIndex, const QString &sOtherName = QString()) const;
QString getSqlAlias(const QString &sTable = QString(), bool bClauseWhere = false, int iIndexName = 0, qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlType(int iIndexName = -1) const;
QString getSqlTypeAndParams(int iIndexName = -1) const;
QString getSqlPlaceHolder(const QString &sAppend = QString(), int iIndexName = 0, const QString &sSep = QString(", "), const QString &sOtherName = QString(), bool bCheckFKPartOfPK = false) const;
void setSqlPlaceHolder(QSqlQuery &query, void *pOwner, const QString &sAppend = QString(), const QString &sOtherName = QString(), bool bCheckFKPartOfPK = false, qx::QxCollection<QString, QVariantList> *pLstExecBatch = NULL) const;
QString getSqlAliasEqualToPlaceHolder(const QString &sTable = QString(), bool bClauseWhere = false, const QString &sAppend = QString(), const QString &sSep = QString(" AND "), bool bCheckFKPartOfPK = false, qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlNameEqualToPlaceHolder(const QString &sAppend = QString(), const QString &sSep = QString(" AND "), bool bCheckFKPartOfPK = false, qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlTablePointNameAsAlias(const QString &sTable, const QString &sSep = QString(", "), const QString &sSuffixAlias = QString(), bool bCheckFKPartOfPK = false, const QString &sCustomAlias = QString(), qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlName(const QString &sSep = QString(", "), const QString &sOtherName = QString(), bool bCheckFKPartOfPK = false, qx::IxSqlQueryBuilder *pSqlQueryBuilder = NULL) const;
QString getSqlNameAndTypeAndParams(const QString &sSep = QString(", "), const QString &sOtherName = QString(), bool bCheckFKPartOfPK = false) const;
void customGetSqlName(type_fct_sql_callback fct);
void customGetSqlTablePointNameAsAlias(type_fct_sql_callback fct);
void customGetSqlNameEqualToPlaceHolder(type_fct_sql_callback fct);
void customGetSqlAliasEqualToPlaceHolder(type_fct_sql_callback fct);
void customGetSqlAlias(type_fct_sql_callback fct);
static QString getSqlFromTable(const QString &sTable, const QString &sCustomAlias = QString());
static QString getSqlTableName(const QString &sTable);
static QString getSqlColumnName(const QString &sColumn);
static QString getSqlTableNameAlias(const QString &sTable);
static QString getSqlColumnNameAlias(const QString &sColumn);
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const = 0;
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const = 0;
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) = 0;
QVariant toVariant(const void *pOwner, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const;
qx_bool fromVariant(void *pOwner, const QVariant &v, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context);
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const = 0;
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) = 0;
QJsonValue toJson(const void *pOwner) const;
qx_bool fromJson(void *pOwner, const QJsonValue &j);
#endif // _QX_NO_JSON
protected:
virtual qx::any getDataPtr(const void *pOwner) const = 0;
virtual qx::any getDataPtr(void *pOwner) = 0;
virtual void *getDataVoidPtr(const void *pOwner) const = 0;
virtual void *getDataVoidPtr(void *pOwner) = 0;
public:
qx::any getValueAnyPtr(const void *pOwner) const { return this->getDataPtr(pOwner); }
qx::any getValueAnyPtr(void *pOwner) { return this->getDataPtr(pOwner); }
void *getValueVoidPtr(const void *pOwner) const { return this->getDataVoidPtr(pOwner); }
void *getValueVoidPtr(void *pOwner) { return this->getDataVoidPtr(pOwner); }
template <typename T>
T *getValuePtr(void *pOwner, bool *bOk = NULL)
{
if (bOk)
{
(*bOk) = false;
}
if (!getAccessDataPointer())
{
qDebug("[QxOrm] qx::IxDataMember::getValuePtr<T>() : '%s'", "cannot access data-member pointer");
return NULL;
}
qx::any a = this->getDataPtr(pOwner);
try
{
T *t = qx::any_cast<T *>(a);
if (bOk)
{
(*bOk) = (t != NULL);
};
return t;
}
catch (const qx::bad_any_cast &err)
{
Q_UNUSED(err);
qDebug("[QxOrm] qx::IxDataMember::getValuePtr<T>() : '%s'", "bad any cast exception");
return NULL;
}
catch (...)
{
qDebug("[QxOrm] qx::IxDataMember::getValuePtr<T>() : '%s'", "unknown cast exception");
return NULL;
}
}
template <typename T>
T getValue(void *pOwner, bool *bOk = NULL)
{
if (!getAccessDataPointer())
{
return qxCannotAccessDataPointer<T, 0>::getValue(this, pOwner, bOk);
}
T *t = this->getValuePtr<T>(pOwner, bOk);
return (t ? (*t) : T());
}
template <typename T>
bool setValue(void *pOwner, const T &val)
{
if (!getAccessDataPointer())
{
return qxCannotAccessDataPointer<T, 0>::setValue(this, pOwner, val);
}
T *t = this->getValuePtr<T>(pOwner);
if (t)
{
(*t) = val;
}
return (t != NULL);
}
private:
template <typename T, int dummy>
struct qxCannotAccessDataPointer
{
static T getValue(IxDataMember *pData, void *pOwner, bool *bOk)
{
Q_UNUSED(pData);
Q_UNUSED(pOwner);
qDebug("[QxOrm] qx::IxDataMember::qxCannotAccessDataPointer<T>::getValue() : '%s'", "type T not supported");
if (bOk)
{
(*bOk) = false;
};
return T();
}
static bool setValue(IxDataMember *pData, void *pOwner, const T &val)
{
Q_UNUSED(pData);
Q_UNUSED(pOwner);
Q_UNUSED(val);
qDebug("[QxOrm] qx::IxDataMember::qxCannotAccessDataPointer<T>::setValue() : '%s'", "type T not supported");
return false;
}
};
template <int dummy>
struct qxCannotAccessDataPointer<QVariant, dummy>
{
static QVariant getValue(IxDataMember *pData, void *pOwner, bool *bOk)
{
if (bOk)
{
(*bOk) = (pData != NULL);
};
return (pData ? pData->toVariant(pOwner, "") : QVariant());
}
static bool setValue(IxDataMember *pData, void *pOwner, const QVariant &val)
{
return (pData ? pData->fromVariant(pOwner, val, "").getValue() : false);
}
};
template <int dummy>
struct qxCannotAccessDataPointer<QString, dummy>
{
static QString getValue(IxDataMember *pData, void *pOwner, bool *bOk)
{
if (bOk)
{
(*bOk) = (pData != NULL);
};
return (pData ? pData->toVariant(pOwner, "").toString() : QString());
}
static bool setValue(IxDataMember *pData, void *pOwner, const QString &val)
{
QVariant tmp(val);
return (pData ? pData->fromVariant(pOwner, tmp, "").getValue() : false);
}
};
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
private:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
void serialize(Archive &ar, const unsigned int version);
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
typedef std::shared_ptr<IxDataMember> IxDataMember_ptr;
/*!
* \ingroup QxDataMember
* \brief qx::IxDataMemberSqlCallbackParams : list of parameters used by custom callback functions to override SQL queries generated by QxOrm library
*/
struct IxDataMemberSqlCallbackParams
{
const IxDataMember *pDataMember; //!< The data member instance which calls custom callback function
QString &sSQL; //!< Default value is the SQL generated by QxOrm library for this data member, can be changed by the custom callback function
QString sTable; //!< SQL table name (not always provided)
QString sSep; //!< SQL separator (not always provided)
QString sCustomAlias; //!< SQL custom alias (not always provided)
QString sSuffixAlias; //!< SQL suffix alias (not always provided)
QString sAppend; //!< String to append to SQL query (not always provided)
QString sOtherName; //!< SQL other name for this data member (not always provided)
bool bClauseWhere; //!< Define if we are building SQL in the clause WHERE or not (not always provided)
bool bCheckFKPartOfPK; //!< Check if foreign key is part of primary key (not always provided)
int iIndexName; //!< Index name for composite primary key (not always provided)
qx::dao::detail::IxDao_Helper *pDaoHelper; //!< DAO helper instance
qx::IxSqlQueryBuilder *pSqlQueryBuilder; //!< SQL query builder instance
IxDataMemberSqlCallbackParams(const IxDataMember *p, QString &sql);
~IxDataMemberSqlCallbackParams();
};
} // namespace qx
QX_DLL_EXPORT_INLINE_FCT bool operator<(const qx::IxDataMember &i1, const qx::IxDataMember &i2);
QX_DLL_EXPORT_INLINE_FCT bool operator>(const qx::IxDataMember &i1, const qx::IxDataMember &i2);
#endif // _IX_DATA_MEMBER_H_

View File

@@ -0,0 +1,107 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_DATA_MEMBER_X_H_
#define _IX_DATA_MEMBER_X_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxDataMemberX.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Common interface for a list of IxDataMember class properties registered into QxOrm context (for example, list of data member of a class)
*/
#include <QxDataMember/IxDataMember.h>
#include <QxDao/QxDaoStrategy.h>
#include <QxCollection/QxCollection.h>
namespace qx
{
class IxClass;
/*!
* \ingroup QxDataMember
* \brief qx::IxDataMemberX : common interface for a list of IxDataMember class properties registered into QxOrm context (for example, list of data member of a class)
*/
class QX_DLL_EXPORT IxDataMemberX
{
private:
struct IxDataMemberXImpl;
std::unique_ptr<IxDataMemberXImpl> m_pImpl; //!< Private implementation idiom
protected:
IxDataMemberX();
virtual ~IxDataMemberX();
public:
IxClass *getClass() const;
void setClass(IxClass *p);
QString getName() const;
const char *getNamePtr() const;
QString getDescription() const;
long getVersion() const;
qx::dao::strategy::inheritance getDaoStrategy() const;
long count() const;
long size() const;
bool exist(const QString &sKey) const;
IxDataMember *get(long l) const;
IxDataMember *get(const QString &s) const;
IxDataMember *getId() const;
virtual long count_WithDaoStrategy() const = 0;
virtual bool exist_WithDaoStrategy(const QString &sKey) const = 0;
virtual IxDataMember *get_WithDaoStrategy(long lIndex) const = 0;
virtual IxDataMember *get_WithDaoStrategy(const QString &sKey) const = 0;
virtual IxDataMember *getId_WithDaoStrategy() const = 0;
protected:
void setId(IxDataMember *p);
QxCollection<QString, IxDataMember *> &getListDataMemberRef();
const QxCollection<QString, IxDataMember *> &getListDataMemberRef() const;
QxCollection<QString, IxDataMember *> &getListPImplRef();
const QxCollection<QString, IxDataMember *> &getListPImplRef() const;
};
typedef std::shared_ptr<IxDataMemberX> IxDataMemberX_ptr;
} // namespace qx
#endif // _IX_DATA_MEMBER_X_H_

View File

@@ -0,0 +1,202 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATA_MEMBER_H_
#define _QX_DATA_MEMBER_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDataMember.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Concrete class property registered into QxOrm context
*/
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/serialization.hpp>
#include <boost/serialization/nvp.hpp>
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#include <QxDataMember/IxDataMember.h>
#include <QxTraits/is_equal.h>
#include <QxTraits/get_class_name.h>
#define QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(ArchiveInput, ArchiveOutput) \
virtual void toArchive(const void *pOwner, ArchiveOutput &ar) const { QxDataMember::toArchive(ar, getNamePtr(), getData(pOwner)); } \
virtual void fromArchive(void *pOwner, ArchiveInput &ar) { QxDataMember::fromArchive(ar, getNamePtr(), getData(pOwner)); }
namespace qx
{
/*!
* \ingroup QxDataMember
* \brief qx::QxDataMember<DataType, Owner> : concrete property of type DataType registered into QxOrm context for the class Owner
*/
template <typename DataType, class Owner>
class QxDataMember : public IxDataMember
{
protected:
typedef DataType Owner::*type_data_member_ptr;
type_data_member_ptr m_pData; //!< Data member under format "& Owner::DataMember"
IxDataMember *m_pImpl_; //!< If not NULL then this data member is owned by a private implementation idiom instance
public:
QxDataMember(type_data_member_ptr pData, const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl = NULL) : IxDataMember(sKey, lVersion, bSerialize, bDao, pImpl), m_pData(pData), m_pImpl_(pImpl) { this->setAccessDataPointer(true); }
virtual ~QxDataMember() { ; }
inline DataType *getData(void *pOwner) const
{
void *pOwner_ = (m_pImpl_ ? m_pImpl_->getDataVoidPtr(pOwner) : pOwner);
return (pOwner_ ? (&((static_cast<Owner *>(pOwner_))->*m_pData)) : NULL);
}
inline const DataType *getData(const void *pOwner) const
{
const void *pOwner_ = (m_pImpl_ ? m_pImpl_->getDataVoidPtr(pOwner) : pOwner);
return (pOwner_ ? (&((static_cast<const Owner *>(pOwner_))->*m_pData)) : NULL);
}
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const { return qx::cvt::to_variant((*getData(pOwner)), sFormat, iIndexName, ctx); }
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) { return qx::cvt::from_variant(v, (*getData(pOwner)), sFormat, iIndexName, ctx); }
virtual QString getType() const
{
QMutexLocker locker(&IxDataMember::m_mutex);
return QString(qx::trait::get_class_name<DataType>::get());
}
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const { return qx::cvt::to_json((*getData(pOwner)), sFormat); }
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) { return qx::cvt::from_json(j, (*getData(pOwner)), sFormat); }
#endif // _QX_NO_JSON
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const
{
if ((pOwner1 == NULL) || (pOwner2 == NULL))
{
return false;
}
if (pOwner1 == pOwner2)
{
return true;
}
return qxCompareDataMember<qx::trait::has_operator_equal_equal<DataType>::value, 0>::isEqual((*this), pOwner1, pOwner2);
}
protected:
virtual qx::any getDataPtr(const void *pOwner) const { return qx::any(getData(pOwner)); }
virtual qx::any getDataPtr(void *pOwner) { return qx::any(getData(pOwner)); }
virtual void *getDataVoidPtr(const void *pOwner) const { return static_cast<void *>(const_cast<DataType *>(getData(pOwner))); }
virtual void *getDataVoidPtr(void *pOwner) { return static_cast<void *>(getData(pOwner)); }
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_IMPL_VIRTUAL_ARCHIVE(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
private:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
static inline void toArchive(Archive &ar, const char *sName, const DataType *pData)
{
ar << boost::serialization::make_nvp(sName, (*pData));
}
template <class Archive>
static inline void fromArchive(Archive &ar, const char *sName, DataType *pData)
{
ar >> boost::serialization::make_nvp(sName, (*pData));
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
private:
template <bool bCanCompare /* = false */, int dummy>
struct qxCompareDataMember
{
static inline bool isEqual(const QxDataMember<DataType, Owner> &dataMember, const void *pOwner1, const void *pOwner2)
{
return (dataMember.toVariant(pOwner1, "") == dataMember.toVariant(pOwner2, ""));
}
};
template <int dummy>
struct qxCompareDataMember<true, dummy>
{
static inline bool isEqual(const QxDataMember<DataType, Owner> &dataMember, const void *pOwner1, const void *pOwner2)
{
return ((*dataMember.getData(pOwner1)) == (*dataMember.getData(pOwner2)));
}
};
};
} // namespace qx
#include "../../inl/QxDataMember/QxDataMember.inl"
#endif // _QX_DATA_MEMBER_H_

View File

@@ -0,0 +1,229 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATA_MEMBER_X_H_
#define _QX_DATA_MEMBER_X_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDataMemberX.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Concrete list of class properties registered into QxOrm context
*/
#include <QxDataMember/IxDataMemberX.h>
#include <QxDataMember/QxDataMember.h>
#include <QxDataMember/QxDataMember_QObject.h>
#include <QxDataMember/QxDataMember_PImpl.h>
#include <QxDao/QxSqlRelation.h>
#include <QxSingleton/QxSingleton.h>
#include <QxFactory/QxFactory.h>
#include <QxTraits/get_base_class.h>
#include <QxTraits/get_primary_key.h>
#include <QxTraits/get_sql_type.h>
#include <QxTraits/qt_meta_object.h>
namespace qx
{
/*!
* \ingroup QxDataMember
* \brief qx::QxDataMemberX<T> : concrete list of properties registered into QxOrm context for the class T
*/
template <class T>
class QxDataMemberX : public IxDataMemberX, public QxSingleton<QxDataMemberX<T>>
{
friend class QxSingleton<QxDataMemberX<T>>;
public:
typedef typename qx::trait::get_primary_key<T>::type type_primary_key;
typedef typename qx::trait::get_base_class<T>::type type_base_class;
protected:
QxDataMemberX() : IxDataMemberX(), QxSingleton<QxDataMemberX<T>>(QString("qx::QxDataMemberX_") + qx::trait::get_class_name<T>::get_xml_tag()) { ; }
virtual ~QxDataMemberX() { ; }
public:
virtual long count_WithDaoStrategy() const { return count_WithDaoStrategy_Helper(); }
virtual bool exist_WithDaoStrategy(const QString &sKey) const { return exist_WithDaoStrategy_Helper(sKey); }
virtual IxDataMember *get_WithDaoStrategy(long lIndex) const { return get_WithDaoStrategy_Helper(lIndex); }
virtual IxDataMember *get_WithDaoStrategy(const QString &sKey) const { return get_WithDaoStrategy_Helper(sKey); }
virtual IxDataMember *getId_WithDaoStrategy() const { return getId_WithDaoStrategy_Helper(); }
IxDataMember *id(type_primary_key T::*pDataMemberId, const QString &sKey, long lVersion = 0);
IxDataMember *id(const QString &sKey, long lVersion);
IxDataMember *add(const QString &sKey, long lVersion);
template <typename V, typename U>
IxDataMember *add(V U::*pData, const QString &sKey, long lVersion = 0, bool bSerialize = true, bool bDao = true);
template <typename V, typename U>
IxSqlRelation *relationOneToOne(V U::*pData, const QString &sKey, long lVersion = 0);
template <typename V, typename U>
IxSqlRelation *relationManyToOne(V U::*pData, const QString &sKey, long lVersion = 0);
template <typename V, typename U>
IxSqlRelation *relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion = 0);
template <typename V, typename U>
IxSqlRelation *relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion = 0);
template <typename V, typename U>
IxDataMember *pimpl(V U::*pData, const QString &sKey);
template <typename U>
IxDataMember *id(type_primary_key U::*pDataMemberId, const QString &sKey, long lVersion, IxDataMember *pImpl);
template <typename V, typename U>
IxDataMember *add(V U::*pData, const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl);
template <typename V, typename U>
IxSqlRelation *relationOneToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl);
template <typename V, typename U>
IxSqlRelation *relationManyToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl);
template <typename V, typename U>
IxSqlRelation *relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion, IxDataMember *pImpl);
template <typename V, typename U>
IxSqlRelation *relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion, IxDataMember *pImpl);
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class Archive>
inline void toArchive(const T *pOwner, Archive &ar, const unsigned int file_version) const;
template <class Archive>
inline void fromArchive(T *pOwner, Archive &ar, const unsigned int file_version);
#endif // _QX_ENABLE_BOOST_SERIALIZATION
private:
IxDataMember *initId(IxDataMember *pId, long lVersion);
IxDataMember *initData(IxDataMember *pData, long lVersion);
IxDataMember *initPImpl(IxDataMember *pImpl);
inline IxDataMemberX *getBaseClass_Helper() const { return QxDataMemberX<type_base_class>::getSingleton(); }
long count_WithDaoStrategy_Helper() const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? count() : getBaseClass_Helper()->count_WithDaoStrategy());
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return (count() + ((!getId() && getId_WithDaoStrategy()) ? 1 : 0));
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (count() + getBaseClass_Helper()->count_WithDaoStrategy());
}
qAssert(false);
return 0;
}
bool exist_WithDaoStrategy_Helper(const QString &sKey) const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? exist(sKey) : getBaseClass_Helper()->exist_WithDaoStrategy(sKey));
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return (exist(sKey) || (getId_WithDaoStrategy() ? (getId_WithDaoStrategy()->getKey() == sKey) : false));
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (exist(sKey) || getBaseClass_Helper()->exist_WithDaoStrategy(sKey));
}
qAssert(false);
return false;
}
IxDataMember *get_WithDaoStrategy_Helper(long lIndex) const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? get(lIndex) : getBaseClass_Helper()->get_WithDaoStrategy(lIndex));
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return ((!getId() && (lIndex == count())) ? getId_WithDaoStrategy() : get(lIndex));
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (((lIndex >= 0) && (lIndex < count())) ? get(lIndex) : getBaseClass_Helper()->get_WithDaoStrategy(lIndex - count()));
}
qAssert(false);
return NULL;
}
IxDataMember *get_WithDaoStrategy_Helper(const QString &sKey) const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? get(sKey) : getBaseClass_Helper()->get_WithDaoStrategy(sKey));
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return ((getId_WithDaoStrategy() && (getId_WithDaoStrategy()->getKey() == sKey)) ? getId_WithDaoStrategy() : get(sKey));
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (exist(sKey) ? get(sKey) : getBaseClass_Helper()->get_WithDaoStrategy(sKey));
}
qAssert(false);
return NULL;
}
IxDataMember *getId_WithDaoStrategy_Helper() const
{
if (getDaoStrategy() == qx::dao::strategy::single_table_inheritance)
{
return ((getBaseClass_Helper()->getDaoStrategy() != getDaoStrategy()) ? getId() : getBaseClass_Helper()->getId_WithDaoStrategy());
}
else if (getDaoStrategy() == qx::dao::strategy::class_table_inheritance)
{
return (getId() ? getId() : getBaseClass_Helper()->getId_WithDaoStrategy());
}
else if (getDaoStrategy() == qx::dao::strategy::concrete_table_inheritance)
{
return (getId() ? getId() : getBaseClass_Helper()->getId_WithDaoStrategy());
}
qAssert(false);
return NULL;
}
};
} // namespace qx
#include "../../inl/QxDataMember/QxDataMemberX.inl"
#endif // _QX_DATA_MEMBER_X_H_

View File

@@ -0,0 +1,376 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATA_MEMBER_PIMPL_H_
#define _QX_DATA_MEMBER_PIMPL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDataMember_PImpl.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Concrete class property registered into QxOrm context (using private implementation idiom)
*/
#include <QxDataMember/IxDataMember.h>
#define QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(ArchiveInput, ArchiveOutput) \
virtual void toArchive(const void *pOwner, ArchiveOutput &ar) const Q_DECL_OVERRIDE \
{ \
Q_UNUSED(pOwner); \
Q_UNUSED(ar); \
} \
virtual void fromArchive(void *pOwner, ArchiveInput &ar) Q_DECL_OVERRIDE \
{ \
Q_UNUSED(pOwner); \
Q_UNUSED(ar); \
}
namespace qx
{
/*!
* \ingroup QxDataMember
* \brief qx::QxDataMember_PImpl<DataType, Owner> : concrete property of type DataType registered into QxOrm context for the class Owner (using private implementation idiom)
*/
template <typename DataType, class Owner>
class QxDataMember_PImpl : public IxDataMember
{
protected:
typedef DataType Owner::*type_data_member_ptr;
type_data_member_ptr m_pData; //!< Data member under format "& Owner::DataMember"
public:
QxDataMember_PImpl(type_data_member_ptr pData, const QString &sKey) : IxDataMember(sKey, 0, false, false, NULL), m_pData(pData)
{
static_assert(std::is_pointer<DataType>::value, "std::is_pointer<DataType>::value");
this->setAccessDataPointer(true);
}
virtual ~QxDataMember_PImpl() { ; }
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner1);
Q_UNUSED(pOwner2);
return false;
}
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return QVariant();
}
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(v);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return qx_bool(true);
}
virtual QString getType() const Q_DECL_OVERRIDE { return QString(); }
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
return QJsonValue();
}
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(j);
Q_UNUSED(sFormat);
return qx_bool(true);
}
#endif // _QX_NO_JSON
protected:
inline DataType *getData(void *pOwner) const { return (&((static_cast<Owner *>(pOwner))->*m_pData)); }
inline const DataType *getData(const void *pOwner) const { return (&((static_cast<const Owner *>(pOwner))->*m_pData)); }
virtual qx::any getDataPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? qx::any(*getData(pOwner)) : qx::any()); }
virtual qx::any getDataPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? qx::any(*getData(pOwner)) : qx::any()); }
virtual void *getDataVoidPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? static_cast<void *>(const_cast<DataType>(*getData(pOwner))) : NULL); }
virtual void *getDataVoidPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? static_cast<void *>(*getData(pOwner)) : NULL); }
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
template <typename DataType, class Owner>
class QxDataMember_PImpl<std::unique_ptr<DataType>, Owner> : public IxDataMember
{
protected:
typedef std::unique_ptr<DataType> Owner::*type_data_member_ptr;
type_data_member_ptr m_pData; //!< Data member under format "& Owner::DataMember"
public:
QxDataMember_PImpl(type_data_member_ptr pData, const QString &sKey) : IxDataMember(sKey, 0, false, false, NULL), m_pData(pData) { this->setAccessDataPointer(true); }
virtual ~QxDataMember_PImpl() { ; }
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner1);
Q_UNUSED(pOwner2);
return false;
}
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return QVariant();
}
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(v);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return qx_bool(true);
}
virtual QString getType() const Q_DECL_OVERRIDE { return QString(); }
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
return QJsonValue();
}
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(j);
Q_UNUSED(sFormat);
return qx_bool(true);
}
#endif // _QX_NO_JSON
protected:
inline std::unique_ptr<DataType> *getData(void *pOwner) const { return (&((static_cast<Owner *>(pOwner))->*m_pData)); }
inline const std::unique_ptr<DataType> *getData(const void *pOwner) const { return (&((static_cast<const Owner *>(pOwner))->*m_pData)); }
virtual qx::any getDataPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
virtual qx::any getDataPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
virtual void *getDataVoidPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? static_cast<void *>(const_cast<DataType *>(getData(pOwner)->get())) : NULL); }
virtual void *getDataVoidPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? static_cast<void *>(getData(pOwner)->get()) : NULL); }
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
template <typename DataType, class Owner>
class QxDataMember_PImpl<std::shared_ptr<DataType>, Owner> : public IxDataMember
{
protected:
typedef std::shared_ptr<DataType> Owner::*type_data_member_ptr;
type_data_member_ptr m_pData; //!< Data member under format "& Owner::DataMember"
public:
QxDataMember_PImpl(type_data_member_ptr pData, const QString &sKey) : IxDataMember(sKey, 0, false, false, NULL), m_pData(pData) { this->setAccessDataPointer(true); }
virtual ~QxDataMember_PImpl() { ; }
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner1);
Q_UNUSED(pOwner2);
return false;
}
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return QVariant();
}
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(v);
Q_UNUSED(sFormat);
Q_UNUSED(iIndexName);
Q_UNUSED(ctx);
return qx_bool(true);
}
virtual QString getType() const Q_DECL_OVERRIDE { return QString(); }
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(sFormat);
return QJsonValue();
}
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat) Q_DECL_OVERRIDE
{
Q_UNUSED(pOwner);
Q_UNUSED(j);
Q_UNUSED(sFormat);
return qx_bool(true);
}
#endif // _QX_NO_JSON
protected:
inline std::shared_ptr<DataType> *getData(void *pOwner) const { return (&((static_cast<Owner *>(pOwner))->*m_pData)); }
inline const std::shared_ptr<DataType> *getData(const void *pOwner) const { return (&((static_cast<const Owner *>(pOwner))->*m_pData)); }
virtual qx::any getDataPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
virtual qx::any getDataPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? qx::any(getData(pOwner)->get()) : qx::any()); }
virtual void *getDataVoidPtr(const void *pOwner) const Q_DECL_FINAL { return (pOwner ? static_cast<void *>(const_cast<DataType *>(getData(pOwner)->get())) : NULL); }
virtual void *getDataVoidPtr(void *pOwner) Q_DECL_FINAL { return (pOwner ? static_cast<void *>(getData(pOwner)->get()) : NULL); }
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_PIMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
};
} // namespace qx
#endif // _QX_DATA_MEMBER_PIMPL_H_

View File

@@ -0,0 +1,132 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_DATA_MEMBER_QOBJECT_H_
#define _QX_DATA_MEMBER_QOBJECT_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxDataMember_QObject.h
* \author XDL Team
* \ingroup QxDataMember
* \brief Connect Qt introspection engine (based on QObject class, with QMetaObject type) to QxOrm library introspection engine
*/
#include <QtCore/qmetaobject.h>
#include <QtCore/qmetatype.h>
#include <QxDataMember/IxDataMember.h>
#include <QxSerialize/Qt/QxSerialize_QString.h>
#include <QxSerialize/Qt/QxSerialize_QVariant.h>
#define QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(ArchiveInput, ArchiveOutput) \
virtual void toArchive(const void *pOwner, ArchiveOutput &ar) const; \
virtual void fromArchive(void *pOwner, ArchiveInput &ar);
namespace qx
{
/*!
* \ingroup QxDataMember
* \brief qx::QxDataMember_QObject : connect Qt introspection engine (based on QObject class, with QMetaObject type) to QxOrm library introspection engine
*/
class QX_DLL_EXPORT QxDataMember_QObject : public IxDataMember
{
protected:
const QMetaObject *m_metaObject; //!< Meta-object from introspection engine of Qt library (& MyQObject::staticMetaObject)
QMetaProperty m_metaProperty; //!< Meta-property from introspection engine of Qt library
public:
QxDataMember_QObject(const QMetaObject *pMetaObject, const QString &sKey);
virtual ~QxDataMember_QObject() { ; }
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const;
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context) const;
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName = -1, qx::cvt::context::ctx_type ctx = qx::cvt::context::e_no_context);
virtual QString getType() const;
#ifndef _QX_NO_JSON
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const;
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat);
#endif // _QX_NO_JSON
public:
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
#if _QX_SERIALIZE_POLYMORPHIC
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::polymorphic_iarchive, boost::archive::polymorphic_oarchive)
#endif // _QX_SERIALIZE_POLYMORPHIC
#if _QX_SERIALIZE_BINARY
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_iarchive, boost::archive::binary_oarchive)
#endif // _QX_SERIALIZE_BINARY
#if _QX_SERIALIZE_TEXT
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_iarchive, boost::archive::text_oarchive)
#endif // _QX_SERIALIZE_TEXT
#if _QX_SERIALIZE_XML
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_iarchive, boost::archive::xml_oarchive)
#endif // _QX_SERIALIZE_XML
#if _QX_SERIALIZE_PORTABLE_BINARY
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(eos::portable_iarchive, eos::portable_oarchive)
#endif // _QX_SERIALIZE_PORTABLE_BINARY
#if _QX_SERIALIZE_WIDE_BINARY
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
#endif // _QX_SERIALIZE_WIDE_BINARY
#if _QX_SERIALIZE_WIDE_TEXT
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::text_wiarchive, boost::archive::text_woarchive)
#endif // _QX_SERIALIZE_WIDE_TEXT
#if _QX_SERIALIZE_WIDE_XML
QX_DATA_MEMBER_QOBJECT_IMPL_VIRTUAL_ARCHIVE_HPP(boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
#endif // _QX_SERIALIZE_WIDE_XML
#endif // _QX_ENABLE_BOOST_SERIALIZATION
protected:
virtual qx::any getDataPtr(const void *pOwner) const;
virtual qx::any getDataPtr(void *pOwner);
virtual void *getDataVoidPtr(const void *pOwner) const;
virtual void *getDataVoidPtr(void *pOwner);
};
} // namespace qx
#endif // _QX_DATA_MEMBER_QOBJECT_H_

View File

@@ -0,0 +1,178 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_ENABLE_BOOST
#ifndef _QX_BOOST_OPTIONAL_ONLY_H_
#define _QX_BOOST_OPTIONAL_ONLY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxBoostOptionalOnly.h
* \author XDL Team
* \ingroup QxExtras
* \brief Provides support for boost::optional<T> to manage NULL values even if _QX_ENABLE_BOOST compilation option is not defined : so this header file enables just boost::optional feature and should be included just after <QxOrm.h> header file (ideally in a precompiled header)
*/
#include <boost/optional.hpp>
#include <boost/none.hpp>
#include <QxOrm.h>
#define _QX_ENABLE_BOOST
#include <QxSerialize/QDataStream/QxSerializeQDataStream_boost_optional.h>
#undef _QX_ENABLE_BOOST
#include <QxTraits/construct_null_qvariant.h>
QX_REGISTER_CLASS_NAME_TEMPLATE_1(boost::optional)
namespace qx
{
namespace trait
{
template <typename T>
struct get_sql_type<boost::optional<T>>
{
static inline const char *get() { return qx::trait::get_sql_type<T>::get(); }
};
} // namespace trait
} // namespace qx
namespace qx
{
namespace cvt
{
namespace detail
{
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvert_ToJson<boost::optional<T>>
{
static inline QJsonValue toJson(const boost::optional<T> &t, const QString &format)
{
if (t)
{
return qx::cvt::to_json((*t), format);
};
return QJsonValue();
}
};
template <typename T>
struct QxConvert_FromJson<boost::optional<T>>
{
static inline qx_bool fromJson(const QJsonValue &j, boost::optional<T> &t, const QString &format)
{
if (j.isNull())
{
t = boost::none;
return qx_bool(true);
}
else if (!t)
{
t = T();
}
return qx::cvt::from_json(j, (*t), format);
}
};
#endif // _QX_NO_JSON
template <typename T>
struct QxConvert_ToString<boost::optional<T>>
{
static inline QString toString(const boost::optional<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (t)
{
return qx::cvt::to_string((*t), format, index, ctx);
};
return QString();
}
};
template <typename T>
struct QxConvert_FromString<boost::optional<T>>
{
static inline qx_bool fromString(const QString &s, boost::optional<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (!t)
{
t = T();
};
return qx::cvt::from_string(s, (*t), format, index, ctx);
}
};
template <typename T>
struct QxConvert_ToVariant<boost::optional<T>>
{
static inline QVariant toVariant(const boost::optional<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (t)
{
return qx::cvt::to_variant((*t), format, index, ctx);
};
return qx::trait::construct_null_qvariant<T>::get();
}
};
template <typename T>
struct QxConvert_FromVariant<boost::optional<T>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::optional<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (v.isNull())
{
t = boost::none;
return qx_bool(true);
}
else if (!t)
{
t = T();
}
return qx::cvt::from_variant(v, (*t), format, index, ctx);
}
};
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_BOOST_OPTIONAL_ONLY_H_
#endif // _QX_ENABLE_BOOST

View File

@@ -0,0 +1,202 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_STD_OPTIONAL_H_
#define _QX_STD_OPTIONAL_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxStdOptional.h
* \author XDL Team
* \ingroup QxExtras
* \brief Support std::optional<T> class (requires a C++17 compiler) to manage NULL database value, this header should be included just after <QxOrm.h> header file (ideally in a precompiled header)
*/
#include <optional>
#include <QtCore/qdatastream.h>
#include <QxOrm.h>
#include <QxTraits/construct_null_qvariant.h>
template <typename T>
QDataStream &operator<<(QDataStream &stream, const std::optional<T> &t)
{
qint8 iHasData = (t ? 1 : 0);
stream << iHasData;
if (t)
{
stream << (*t);
}
return stream;
}
template <typename T>
QDataStream &operator>>(QDataStream &stream, std::optional<T> &t)
{
qint8 iHasData = 0;
stream >> iHasData;
if (iHasData)
{
t = T();
stream >> (*t);
}
else
{
t = std::optional<T>();
}
return stream;
}
QX_REGISTER_CLASS_NAME_TEMPLATE_1(std::optional)
namespace qx
{
namespace trait
{
template <typename T>
struct get_sql_type<std::optional<T>>
{
static inline const char *get() { return qx::trait::get_sql_type<T>::get(); }
};
} // namespace trait
} // namespace qx
namespace qx
{
namespace cvt
{
namespace detail
{
#ifndef _QX_NO_JSON
template <typename T>
struct QxConvert_ToJson<std::optional<T>>
{
static inline QJsonValue toJson(const std::optional<T> &t, const QString &format)
{
if (t)
{
return qx::cvt::to_json((*t), format);
};
return QJsonValue();
}
};
template <typename T>
struct QxConvert_FromJson<std::optional<T>>
{
static inline qx_bool fromJson(const QJsonValue &j, std::optional<T> &t, const QString &format)
{
if (j.isNull())
{
t = std::optional<T>();
return qx_bool(true);
}
else if (!t)
{
t = T();
}
return qx::cvt::from_json(j, (*t), format);
}
};
#endif // _QX_NO_JSON
template <typename T>
struct QxConvert_ToString<std::optional<T>>
{
static inline QString toString(const std::optional<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (t)
{
return qx::cvt::to_string((*t), format, index, ctx);
};
return QString();
}
};
template <typename T>
struct QxConvert_FromString<std::optional<T>>
{
static inline qx_bool fromString(const QString &s, std::optional<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (!t)
{
t = T();
};
return qx::cvt::from_string(s, (*t), format, index, ctx);
}
};
template <typename T>
struct QxConvert_ToVariant<std::optional<T>>
{
static inline QVariant toVariant(const std::optional<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (t)
{
return qx::cvt::to_variant((*t), format, index, ctx);
};
return qx::trait::construct_null_qvariant<T>::get();
}
};
template <typename T>
struct QxConvert_FromVariant<std::optional<T>>
{
static inline qx_bool fromVariant(const QVariant &v, std::optional<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (v.isNull())
{
t = std::optional<T>();
return qx_bool(true);
}
else if (!t)
{
t = T();
}
return qx::cvt::from_variant(v, (*t), format, index, ctx);
}
};
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_STD_OPTIONAL_H_

View File

@@ -0,0 +1,87 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_FACTORY_H_
#define _IX_FACTORY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxFactory.h
* \author XDL Team
* \ingroup QxFactory
* \brief Common interface for all classes that can be created dynamically using the class name
*/
#ifndef _QX_NO_RTTI
#include <typeinfo>
#endif // _QX_NO_RTTI
#include <QxCommon/QxAny.h>
namespace qx
{
/*!
* \ingroup QxFactory
* \brief qx::IxFactory : common interface for all classes that can be created dynamically using the class name
*/
class QX_DLL_EXPORT IxFactory
{
protected:
QString m_sKeyFactory; //!< Factory key used by the collection QxFactoryX
public:
IxFactory(const QString &sKey);
virtual ~IxFactory();
virtual qx::any createObject(bool bRawPointer = false) const = 0;
virtual void *createObjectNudePtr() const = 0;
#ifndef _QX_NO_RTTI
virtual const std::type_info &typeInfo() const = 0;
#endif // _QX_NO_RTTI
private:
IxFactory(const IxFactory &other) { Q_UNUSED(other); }
IxFactory &operator=(const IxFactory &other)
{
Q_UNUSED(other);
return (*this);
}
};
} // namespace qx
#endif // _IX_FACTORY_H_

View File

@@ -0,0 +1,231 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FACTORY_H_
#define _QX_FACTORY_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFactory.h
* \author XDL Team
* \ingroup QxFactory
* \brief Concrete factory class to create object dynamically using the class name
*/
#include <QtCore/qobject.h>
#include <QxFactory/IxFactory.h>
#include <QxTraits/get_base_class.h>
#include <QxTraits/get_class_name.h>
#include <QxTraits/get_primary_key.h>
#define QX_STR_CANNOT_INSTANTIATE_ABSTRACT_CLASS "[QxOrm] qx::QxFactory<T> ---> cannot instantiate abstract class '%s'"
#if _QX_AUTO_REGISTER_REPOSITORY
#define QX_AUTO_REGISTER_REPOSITORY(className, sKey) qx::register_repository<className>(sKey);
#else // _QX_AUTO_REGISTER_REPOSITORY
#define QX_AUTO_REGISTER_REPOSITORY(className, sKey) /* Nothing */
#endif // _QX_AUTO_REGISTER_REPOSITORY
namespace qx
{
class IxPersistable;
template <class T>
class QxClass;
#ifdef _QX_ENABLE_QT_NETWORK
namespace service
{
class IxService;
class IxParameter;
} // namespace service
#endif // _QX_ENABLE_QT_NETWORK
#if _QX_AUTO_REGISTER_REPOSITORY
template <class T>
inline void register_repository(const QString &sKey);
#endif // _QX_AUTO_REGISTER_REPOSITORY
/*!
* \ingroup QxFactory
* \brief qx::QxFactory<T> : concrete factory class to create object of type T dynamically using the class name
*/
template <class T>
class QxFactory : public IxFactory
{
public:
QxFactory(const QString &sKey) : IxFactory(sKey) { QX_AUTO_REGISTER_REPOSITORY(T, sKey); }
virtual ~QxFactory() { ; }
#ifdef _QX_ENABLE_QT_NETWORK
virtual qx::any createObject(bool bRawPointer = false) const
{
QxClass<T>::getSingleton();
return qxCreateInstance<std::is_abstract<T>::value, std::is_base_of<qx::IxPersistable, T>::value, std::is_base_of<qx::service::IxService, T>::value, std::is_base_of<qx::service::IxParameter, T>::value, std::is_base_of<QObject, T>::value, 0>::create(bRawPointer);
}
virtual void *createObjectNudePtr() const
{
QxClass<T>::getSingleton();
return qxCreateInstance<std::is_abstract<T>::value, std::is_base_of<qx::IxPersistable, T>::value, std::is_base_of<qx::service::IxService, T>::value, std::is_base_of<qx::service::IxParameter, T>::value, std::is_base_of<QObject, T>::value, 0>::createNudePtr();
}
#else // _QX_ENABLE_QT_NETWORK
virtual qx::any createObject(bool bRawPointer = false) const
{
QxClass<T>::getSingleton();
return qxCreateInstance<std::is_abstract<T>::value, std::is_base_of<qx::IxPersistable, T>::value, false, false, std::is_base_of<QObject, T>::value, 0>::create(bRawPointer);
}
virtual void *createObjectNudePtr() const
{
QxClass<T>::getSingleton();
return qxCreateInstance<std::is_abstract<T>::value, std::is_base_of<qx::IxPersistable, T>::value, false, false, std::is_base_of<QObject, T>::value, 0>::createNudePtr();
}
#endif // _QX_ENABLE_QT_NETWORK
#ifndef _QX_NO_RTTI
virtual const std::type_info &typeInfo() const
{
return typeid(T);
}
#endif // _QX_NO_RTTI
private:
template <bool bIsAbstract /* = false */, bool bIsIxPersistable /* = false */, bool bIsIxService /* = false */, bool bIsIxParameter /* = false */, bool bIsQObject /* = false */, int dummy>
struct qxCreateInstance
{
static inline qx::any create(bool bRawPointer)
{
if (bRawPointer)
{
T *p = new T();
return qx::any(p);
};
std::shared_ptr<T> ptr = std::make_shared<T>();
return qx::any(ptr);
}
static inline void *createNudePtr() { return static_cast<void *>(new T()); }
};
template <bool bIsIxPersistable, bool bIsIxService, bool bIsIxParameter, bool bIsQObject, int dummy>
struct qxCreateInstance<true, bIsIxPersistable, bIsIxService, bIsIxParameter, bIsQObject, dummy>
{
static inline qx::any create(bool bRawPointer)
{
Q_UNUSED(bRawPointer);
qDebug(QX_STR_CANNOT_INSTANTIATE_ABSTRACT_CLASS, qx::trait::get_class_name<T>::get());
return qx::any();
}
static inline void *createNudePtr()
{
qDebug(QX_STR_CANNOT_INSTANTIATE_ABSTRACT_CLASS, qx::trait::get_class_name<T>::get());
return NULL;
}
};
template <bool bIsQObject, int dummy>
struct qxCreateInstance<false, true, false, false, bIsQObject, dummy>
{
static inline qx::any create(bool bRawPointer)
{
if (bRawPointer)
{
T *p = new T();
return qx::any(p);
};
std::shared_ptr<T> ptr = std::make_shared<T>();
return qx::any(ptr);
}
static inline void *createNudePtr() { return static_cast<qx::IxPersistable *>(new T()); }
};
#ifdef _QX_ENABLE_QT_NETWORK
template <bool bIsQObject, int dummy>
struct qxCreateInstance<false, false, true, false, bIsQObject, dummy>
{
static inline qx::any create(bool bRawPointer)
{
if (bRawPointer)
{
T *p = new T();
return qx::any(p);
};
std::shared_ptr<T> ptr = std::make_shared<T>();
return qx::any(ptr);
}
static inline void *createNudePtr() { return static_cast<qx::service::IxService *>(new T()); }
};
template <bool bIsQObject, int dummy>
struct qxCreateInstance<false, false, false, true, bIsQObject, dummy>
{
static inline qx::any create(bool bRawPointer)
{
if (bRawPointer)
{
T *p = new T();
return qx::any(p);
};
std::shared_ptr<T> ptr = std::make_shared<T>();
return qx::any(ptr);
}
static inline void *createNudePtr() { return static_cast<qx::service::IxParameter *>(new T()); }
};
#endif // _QX_ENABLE_QT_NETWORK
template <int dummy>
struct qxCreateInstance<false, false, false, false, true, dummy>
{
static inline qx::any create(bool bRawPointer)
{
if (bRawPointer)
{
T *p = new T();
return qx::any(p);
};
std::shared_ptr<T> ptr = std::make_shared<T>();
return qx::any(ptr);
}
static inline void *createNudePtr() { return static_cast<QObject *>(new T()); }
};
};
} // namespace qx
#include "../../inl/QxFactory/QxFactory.inl"
#endif // _QX_FACTORY_H_

View File

@@ -0,0 +1,144 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FACTORY_X_H_
#define _QX_FACTORY_X_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFactoryX.h
* \author XDL Team
* \ingroup QxFactory
* \brief List of all classes registered with QxOrm library factory pattern to create object instance dynamically using the class name
*/
#include <QtCore/qhash.h>
#include <QtCore/qmutex.h>
#include <QxFactory/IxFactory.h>
#include <QxSingleton/QxSingleton.h>
namespace qx
{
inline qx::any create(const QString &sKey, bool bRawPointer = false);
template <typename T>
inline T *create_nude_ptr(const QString &sKey);
inline void *create_void_ptr(const QString &sKey);
class QxClassX;
/*!
* \ingroup QxFactory
* \brief qx::QxFactoryX : list of all classes registered with QxOrm library factory pattern to create object instance dynamically using the class name
*/
class QX_DLL_EXPORT QxFactoryX : public QxSingleton<QxFactoryX>
{
friend class QxClassX;
friend class IxFactory;
friend class QxSingleton<QxFactoryX>;
friend inline qx::any create(const QString &sKey, bool bRawPointer);
template <typename T>
friend inline T *create_nude_ptr(const QString &sKey);
friend inline void *create_void_ptr(const QString &sKey);
protected:
QHash<QString, IxFactory *> m_mapFactoryX; //!< Collection of all 'IxFactory' pointer
QMutex m_oMutexFactoryX; //!< Mutex -> 'QxFactoryX' is thread-safe
private:
QxFactoryX() : QxSingleton<QxFactoryX>("qx::QxFactoryX") { ; }
virtual ~QxFactoryX() { ; }
QHash<QString, IxFactory *> *getAllFactory() { return (&m_mapFactoryX); }
void registerFactory(const QString &sKey, IxFactory *pFactory);
void unregisterFactory(const QString &sKey);
qx::any createObject(const QString &sKey, bool bRawPointer = false) const;
void *createObjectNudePtr(const QString &sKey) const;
#ifndef _QX_NO_RTTI
const std::type_info &typeInfo(const QString &sKey) const;
#endif // _QX_NO_RTTI
static inline qx::any createInstance(const QString &sKey, bool bRawPointer = false) { return QxFactoryX::getSingleton()->createObject(sKey, bRawPointer); }
static inline void *createInstanceNudePtr(const QString &sKey) { return QxFactoryX::getSingleton()->createObjectNudePtr(sKey); }
#ifndef _QX_NO_RTTI
static inline const std::type_info &getTypeInfo(const QString &sKey) { return QxFactoryX::getSingleton()->typeInfo(sKey); }
#endif // _QX_NO_RTTI
};
/*!
* \ingroup QxFactory
* \brief Return a smart-pointer new instance of object (std::shared_ptr<T>) associated by key sKey using qx::any type (for example : qx::create("drug") return a new instance of smart-pointer drug class into qx::any type)
*/
inline qx::any create(const QString &sKey, bool bRawPointer /* = false */)
{
return qx::QxFactoryX::createInstance(sKey, bRawPointer);
}
/*!
* \ingroup QxFactory
* \brief Return a nude pointer (be careful with memory leak) of type T associated by key sKey, or return NULL if sKey is not registered into factory engine
*/
template <typename T>
inline T *create_nude_ptr(const QString &sKey)
#ifdef _QX_NO_RTTI
{
return static_cast<T *>(qx::QxFactoryX::createInstanceNudePtr(sKey));
}
#else // _QX_NO_RTTI
{
return dynamic_cast<T *>(static_cast<T *>(qx::QxFactoryX::createInstanceNudePtr(sKey)));
}
#endif // _QX_NO_RTTI
/*!
* \ingroup QxFactory
* \brief Return a void * pointer (be careful with memory leak) associated by key sKey, or return NULL if sKey is not registered into factory engine
*/
inline void *create_void_ptr(const QString &sKey)
{
return qx::QxFactoryX::createInstanceNudePtr(sKey);
}
} // namespace qx
QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::QxFactoryX)
#endif // _QX_FACTORY_X_H_

View File

@@ -0,0 +1,161 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _IX_FUNCTION_H_
#define _IX_FUNCTION_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file IxFunction.h
* \author XDL Team
* \ingroup QxFunction
* \brief Common interface for all functions registered into QxOrm context (used by introspection engine)
*/
#include <QxCommon/QxAny.h>
#include <QxCommon/QxBool.h>
#include <QxCommon/QxPropertyBag.h>
#include <QxCollection/QxCollection.h>
#include <QxFunction/QxFunctionError.h>
#include <QxFunction/QxFunctionMacro.h>
#include <QxTraits/remove_attr.h>
namespace qx
{
/*!
* \ingroup QxFunction
* \brief qx::IxFunction : common interface for all functions registered into QxOrm context (used by introspection engine)
*/
class IxFunction : public qx::QxPropertyBag
{
protected:
QString m_sKey; //!< Function key
QString m_sSeparator; //!< Separator character(s) for 'QString' parameters type
QString m_sDescription; //!< Function description
public:
typedef std::vector<qx::any> type_any_params;
IxFunction() : qx::QxPropertyBag(), m_sSeparator("|") { ; }
virtual ~IxFunction() { ; }
QString getKey() const { return m_sKey; }
QString getSeparator() const { return m_sSeparator; }
QString getDescription() const { return m_sDescription; }
void setKey(const QString &s) { m_sKey = s; }
void setSeparator(const QString &s) { m_sSeparator = s; }
void setDescription(const QString &s) { m_sDescription = s; }
virtual int getParamCount() const = 0;
virtual qx_bool invoke(const QString &params = QString(), qx::any *ret = NULL) const = 0;
virtual qx_bool invoke(const type_any_params &params, qx::any *ret = NULL) const = 0;
virtual qx_bool invoke(void *pOwner, const QString &params = QString(), qx::any *ret = NULL) const = 0;
virtual qx_bool invoke(void *pOwner, const type_any_params &params, qx::any *ret = NULL) const = 0;
virtual qx_bool isValidFct() const = 0;
virtual qx_bool isValidParams(const QString &params) const = 0;
virtual qx_bool isValidParams(const type_any_params &params) const = 0;
template <class T>
qx_bool isValidOwner(void *pOwner, T *dummy) const
{
Q_UNUSED(dummy);
typedef std::is_same<T, void> qx_verify_owner_tmp;
static_assert(!qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
if (!pOwner)
{
return qx_bool(false, 0, QX_FUNCTION_ERR_NULL_OWNER);
}
#ifndef _QX_NO_RTTI
if (!dynamic_cast<T *>(static_cast<T *>(pOwner)))
{
return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_OWNER);
}
#endif // _QX_NO_RTTI
return true;
}
template <class T>
qx_bool isValid(const T &params) const
{
qx_bool bValid = isValidFct();
if (!bValid)
{
return bValid;
};
bValid = isValidParams(params);
if (!bValid)
{
return bValid;
};
return true;
}
template <class T, class U>
qx_bool isValid(void *pOwner, const T &params, U *dummy) const
{
Q_UNUSED(dummy);
qx_bool bValid = isValidFct();
if (!bValid)
{
return bValid;
};
bValid = isValidParams(params);
if (!bValid)
{
return bValid;
};
bValid = isValidOwner<U>(pOwner, NULL);
if (!bValid)
{
return bValid;
};
return true;
}
};
typedef std::shared_ptr<IxFunction> IxFunction_ptr;
typedef QxCollection<QString, IxFunction_ptr> IxFunctionX;
typedef std::shared_ptr<IxFunctionX> IxFunctionX_ptr;
} // namespace qx
#endif // _IX_FUNCTION_H_

View File

@@ -0,0 +1,57 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_ERROR_H_
#define _QX_FUNCTION_ERROR_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFunctionError.h
* \author XDL Team
* \ingroup QxFunction
* \brief Define all messages when an error occured using QxFunction module of QxOrm library
*/
#define QX_FUNCTION_ERR_NUMBER_PARAMS "Incorrect parameters count"
#define QX_FUNCTION_ERR_INVALID_PARAM "Invalid parameter at position 'XXX'"
#define QX_FUNCTION_ERR_INVALID_FCT "Invalid function"
#define QX_FUNCTION_ERR_EMPTY_FCT "Empty function"
#define QX_FUNCTION_ERR_INVALID_MEMBER_FCT "Invalid member function"
#define QX_FUNCTION_ERR_EMPTY_MEMBER_FCT "Empty member function"
#define QX_FUNCTION_ERR_INVALID_OWNER "Invalid owner"
#define QX_FUNCTION_ERR_NULL_OWNER "NULL owner"
#define QX_FUNCTION_ERR_INVALID_INVOKE_CALL "Invalid 'invoke()' call"
#define QX_FUNCTION_ERR_UNKNOWN_ERROR "Unknown error calling function"
#endif // _QX_FUNCTION_ERROR_H_

View File

@@ -0,0 +1,51 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_INCLUDE_H_
#define _QX_FUNCTION_INCLUDE_H_
#ifdef _MSC_VER
#pragma once
#endif
#include <QxFunction/IxFunction.h>
#include <QxFunction/QxFunction_0.h>
#include <QxFunction/QxFunction_1.h>
#include <QxFunction/QxFunction_2.h>
#include <QxFunction/QxFunction_3.h>
#include <QxFunction/QxFunction_4.h>
#include <QxFunction/QxFunction_5.h>
#include <QxFunction/QxFunction_6.h>
#include <QxFunction/QxFunction_7.h>
#include <QxFunction/QxFunction_8.h>
#include <QxFunction/QxFunction_9.h>
#endif // _QX_FUNCTION_INCLUDE_H_

View File

@@ -0,0 +1,210 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_MACRO_H_
#define _QX_FUNCTION_MACRO_H_
#ifdef _MSC_VER
#pragma once
#endif
#include <QxConvert/QxConvert.h>
#define QX_FUNCTION_CLASS_FCT(className) \
public: \
type_fct m_fct; \
className(type_fct fct) : IxFunction(), m_fct(fct) { ; }; \
virtual ~className() { ; }; \
virtual qx_bool invoke(const QString &params = QString(), qx::any *ret = NULL) const \
{ \
return QxInvokerFct<QString, !std::is_same<R, void>::value>::invoke(params, ret, this); \
} \
virtual qx_bool invoke(const type_any_params &params, qx::any *ret = NULL) const \
{ \
return QxInvokerFct<type_any_params, !std::is_same<R, void>::value>::invoke(params, ret, this); \
} \
virtual qx_bool invoke(void *pOwner, const QString &params = QString(), qx::any *ret = NULL) const \
{ \
Q_UNUSED(pOwner); \
Q_UNUSED(params); \
Q_UNUSED(ret); \
qAssert(false); \
return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); \
} \
virtual qx_bool invoke(void *pOwner, const type_any_params &params, qx::any *ret = NULL) const \
{ \
Q_UNUSED(pOwner); \
Q_UNUSED(params); \
Q_UNUSED(ret); \
qAssert(false); \
return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); \
} \
virtual qx_bool isValidFct() const \
{ \
return ((!m_fct) ? qx_bool(false, 0, QX_FUNCTION_ERR_EMPTY_FCT) : qx_bool(true)); \
}
#define QX_FUNCTION_CLASS_MEMBER_FCT(className) \
public: \
type_fct m_fct; \
className(type_fct fct) : IxFunction(), m_fct(fct) { ; }; \
virtual ~className() { ; }; \
virtual qx_bool invoke(void *pOwner, const QString &params = QString(), qx::any *ret = NULL) const \
{ \
return QxInvokerFct<QString, !std::is_same<R, void>::value>::invoke(pOwner, params, ret, this); \
} \
virtual qx_bool invoke(void *pOwner, const type_any_params &params, qx::any *ret = NULL) const \
{ \
return QxInvokerFct<type_any_params, !std::is_same<R, void>::value>::invoke(pOwner, params, ret, this); \
} \
virtual qx_bool invoke(const QString &params = QString(), qx::any *ret = NULL) const \
{ \
Q_UNUSED(params); \
Q_UNUSED(ret); \
qAssert(false); \
return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); \
} \
virtual qx_bool invoke(const type_any_params &params, qx::any *ret = NULL) const \
{ \
Q_UNUSED(params); \
Q_UNUSED(ret); \
qAssert(false); \
return qx_bool(false, 0, QX_FUNCTION_ERR_INVALID_INVOKE_CALL); \
} \
virtual qx_bool isValidFct() const \
{ \
return ((!m_fct) ? qx_bool(false, 0, QX_FUNCTION_ERR_EMPTY_MEMBER_FCT) : qx_bool(true)); \
}
#define QX_FUNCTION_CATCH_AND_RETURN_INVOKE() \
catch (const std::exception &e) { bValid = qx_bool(false, 0, e.what()); } \
catch (...) { bValid = qx_bool(false, 0, QX_FUNCTION_ERR_UNKNOWN_ERROR); } \
if (!bValid) \
{ \
QString sMsgDebug = bValid.getDesc(); \
qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); \
qAssert(false); \
} \
return bValid;
#define QX_FUNCTION_INVOKE_START_WITH_OWNER() \
if (ret) \
{ \
(*ret) = qx::any(); \
} \
qx_bool bValid = pThis->isValid<T, Owner>(pOwner, params, NULL); \
if (!bValid) \
{ \
QString sMsgDebug = bValid.getDesc(); \
qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); \
qAssert(false); \
return bValid; \
}
#define QX_FUNCTION_INVOKE_START_WITHOUT_OWNER() \
if (ret) \
{ \
(*ret) = qx::any(); \
} \
qx_bool bValid = pThis->isValid(params); \
if (!bValid) \
{ \
QString sMsgDebug = bValid.getDesc(); \
qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); \
qAssert(false); \
return bValid; \
}
#define QX_FUNCTION_FETCH_PARAM(TYPE, VALUE, FCT) \
typename std::remove_const<TYPE>::type VALUE; \
{ \
qx_bool bTmp = qx::function::detail::FCT(params, VALUE, pThis); \
if (!bTmp) \
{ \
QString sMsgDebug = bTmp.getDesc(); \
qDebug("[QxOrm] %s", qPrintable(sMsgDebug)); \
qAssert(false); \
return bTmp; \
} \
}
#define QX_FUNCTION_GET_PARAM_TYPE_ANY(PARAMCOUNT) \
Q_UNUSED(qx_fct); \
if (params.size() < PARAMCOUNT) \
{ \
return qx_bool(false, 0, QX_FUNCTION_ERR_NUMBER_PARAMS); \
} \
qx_bool bValid = true; \
try \
{ \
p = qx::any_cast<P>(params[PARAMCOUNT - 1]); \
} \
catch (...) \
{ \
bValid = qx_bool(false, 0, QString(QX_FUNCTION_ERR_INVALID_PARAM).replace("XXX", QString::number(PARAMCOUNT))); \
} \
return bValid;
#define QX_FUNCTION_GET_PARAM_TYPE_STRING(PARAMCOUNT) \
if (!qx_fct) \
{ \
return qx_bool(false, 0, QX_FUNCTION_ERR_UNKNOWN_ERROR); \
} \
QStringList lst = params.split(qx_fct->getSeparator()); \
if (lst.size() < PARAMCOUNT) \
{ \
return qx_bool(false, 0, QX_FUNCTION_ERR_NUMBER_PARAMS); \
} \
qx_bool bValid = true; \
try \
{ \
bValid = qx::cvt::from_string(lst.at(PARAMCOUNT - 1), p); \
} \
catch (...) \
{ \
bValid = qx_bool(false, 0, QString(QX_FUNCTION_ERR_INVALID_PARAM).replace("XXX", QString::number(PARAMCOUNT))); \
} \
return bValid;
#define QX_FUNCTION_GET_PARAM_TYPE_STRING_TO_QSTRING(PARAMCOUNT) \
if (!qx_fct) \
{ \
return qx_bool(false, 0, QX_FUNCTION_ERR_UNKNOWN_ERROR); \
} \
QStringList lst = params.split(qx_fct->getSeparator()); \
if (lst.size() < PARAMCOUNT) \
{ \
return qx_bool(false, 0, QX_FUNCTION_ERR_NUMBER_PARAMS); \
} \
p = lst.at(PARAMCOUNT - 1); \
return true;
#endif // _QX_FUNCTION_MACRO_H_

View File

@@ -0,0 +1,188 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_0_H_
#define _QX_FUNCTION_0_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFunction_0.h
* \author XDL Team
* \ingroup QxFunction
* \brief Concrete function class registered into QxOrm context without parameter
*/
#include <QxFunction/IxFunction.h>
#include <QxFunction/QxParameters.h>
namespace qx
{
/*!
* \ingroup QxFunction
* \brief qx::QxFunction_0<Owner, R> : concrete function registered into QxOrm context defined into class Owner, returning an object of type R and without parameter
*/
template <class Owner, typename R>
class QxFunction_0 : public IxFunction
{
public:
typedef std::function<R(Owner *)> type_fct;
QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_0);
virtual int getParamCount() const { return 0; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_0 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
try
{
pThis->m_fct(static_cast<Owner *>(pOwner));
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_0 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
try
{
R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner));
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
template <typename R>
class QxFunction_0<void, R> : public IxFunction
{
public:
typedef std::function<R()> type_fct;
QX_FUNCTION_CLASS_FCT(QxFunction_0);
virtual int getParamCount() const { return 0; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_0 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
try
{
pThis->m_fct();
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_0 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
try
{
R retTmp = pThis->m_fct();
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
namespace function
{
template <class Owner, typename R>
IxFunction_ptr bind_fct_0(const typename QxFunction_0<Owner, R>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_0<void, R>>(fct);
return ptr;
}
template <class Owner, typename R>
IxFunction_ptr bind_member_fct_0(const typename QxFunction_0<Owner, R>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(!qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_0<Owner, R>>(fct);
return ptr;
}
} // namespace function
} // namespace qx
#endif // _QX_FUNCTION_0_H_

View File

@@ -0,0 +1,194 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_1_H_
#define _QX_FUNCTION_1_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFunction_1.h
* \author XDL Team
* \ingroup QxFunction
* \brief Concrete function class registered into QxOrm context with 1 parameter
*/
#include <QxFunction/IxFunction.h>
#include <QxFunction/QxParameters.h>
namespace qx
{
/*!
* \ingroup QxFunction
* \brief qx::QxFunction_1<Owner, R, P1> : concrete function registered into QxOrm context defined into class Owner, returning an object of type R and with 1 parameter P1
*/
template <class Owner, typename R, typename P1>
class QxFunction_1 : public IxFunction
{
public:
typedef std::function<R(Owner *, P1)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_1);
virtual int getParamCount() const { return 1; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_1 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
try
{
pThis->m_fct(static_cast<Owner *>(pOwner), p1);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_1 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
try
{
R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
template <typename R, typename P1>
class QxFunction_1<void, R, P1> : public IxFunction
{
public:
typedef std::function<R(P1)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
QX_FUNCTION_CLASS_FCT(QxFunction_1);
virtual int getParamCount() const { return 1; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_1 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
try
{
pThis->m_fct(p1);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_1 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
try
{
R retTmp = pThis->m_fct(p1);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
namespace function
{
template <class Owner, typename R, typename P1>
IxFunction_ptr bind_fct_1(const typename QxFunction_1<Owner, R, P1>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_1<void, R, P1>>(fct);
return ptr;
}
template <class Owner, typename R, typename P1>
IxFunction_ptr bind_member_fct_1(const typename QxFunction_1<Owner, R, P1>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(!qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_1<Owner, R, P1>>(fct);
return ptr;
}
} // namespace function
} // namespace qx
#endif // _QX_FUNCTION_1_H_

View File

@@ -0,0 +1,200 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_2_H_
#define _QX_FUNCTION_2_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFunction_2.h
* \author XDL Team
* \ingroup QxFunction
* \brief Concrete function class registered into QxOrm context with 2 parameters
*/
#include <QxFunction/IxFunction.h>
#include <QxFunction/QxParameters.h>
namespace qx
{
/*!
* \ingroup QxFunction
* \brief qx::QxFunction_2<Owner, R, P1, P2> : concrete function registered into QxOrm context defined into class Owner, returning an object of type R and with 2 parameters P1, P2
*/
template <class Owner, typename R, typename P1, typename P2>
class QxFunction_2 : public IxFunction
{
public:
typedef std::function<R(Owner *, P1, P2)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_2);
virtual int getParamCount() const { return 2; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_2 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
try
{
pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_2 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
try
{
R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
template <typename R, typename P1, typename P2>
class QxFunction_2<void, R, P1, P2> : public IxFunction
{
public:
typedef std::function<R(P1, P2)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
QX_FUNCTION_CLASS_FCT(QxFunction_2);
virtual int getParamCount() const { return 2; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_2 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
try
{
pThis->m_fct(p1, p2);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_2 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
try
{
R retTmp = pThis->m_fct(p1, p2);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
namespace function
{
template <class Owner, typename R, typename P1, typename P2>
IxFunction_ptr bind_fct_2(const typename QxFunction_2<Owner, R, P1, P2>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_2<void, R, P1, P2>>(fct);
return ptr;
}
template <class Owner, typename R, typename P1, typename P2>
IxFunction_ptr bind_member_fct_2(const typename QxFunction_2<Owner, R, P1, P2>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(!qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_2<Owner, R, P1, P2>>(fct);
return ptr;
}
} // namespace function
} // namespace qx
#endif // _QX_FUNCTION_2_H_

View File

@@ -0,0 +1,206 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_3_H_
#define _QX_FUNCTION_3_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFunction_3.h
* \author XDL Team
* \ingroup QxFunction
* \brief Concrete function class registered into QxOrm context with 3 parameters
*/
#include <QxFunction/IxFunction.h>
#include <QxFunction/QxParameters.h>
namespace qx
{
/*!
* \ingroup QxFunction
* \brief qx::QxFunction_3<Owner, R, P1, P2, P3> : concrete function registered into QxOrm context defined into class Owner, returning an object of type R and with 3 parameters P1, P2, P3
*/
template <class Owner, typename R, typename P1, typename P2, typename P3>
class QxFunction_3 : public IxFunction
{
public:
typedef std::function<R(Owner *, P1, P2, P3)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_3);
virtual int getParamCount() const { return 3; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_3 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
try
{
pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_3 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
try
{
R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
template <typename R, typename P1, typename P2, typename P3>
class QxFunction_3<void, R, P1, P2, P3> : public IxFunction
{
public:
typedef std::function<R(P1, P2, P3)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
QX_FUNCTION_CLASS_FCT(QxFunction_3);
virtual int getParamCount() const { return 3; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_3 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
try
{
pThis->m_fct(p1, p2, p3);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_3 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
try
{
R retTmp = pThis->m_fct(p1, p2, p3);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
namespace function
{
template <class Owner, typename R, typename P1, typename P2, typename P3>
IxFunction_ptr bind_fct_3(const typename QxFunction_3<Owner, R, P1, P2, P3>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_3<void, R, P1, P2, P3>>(fct);
return ptr;
}
template <class Owner, typename R, typename P1, typename P2, typename P3>
IxFunction_ptr bind_member_fct_3(const typename QxFunction_3<Owner, R, P1, P2, P3>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(!qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_3<Owner, R, P1, P2, P3>>(fct);
return ptr;
}
} // namespace function
} // namespace qx
#endif // _QX_FUNCTION_3_H_

View File

@@ -0,0 +1,212 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_4_H_
#define _QX_FUNCTION_4_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFunction_4.h
* \author XDL Team
* \ingroup QxFunction
* \brief Concrete function class registered into QxOrm context with 4 parameters
*/
#include <QxFunction/IxFunction.h>
#include <QxFunction/QxParameters.h>
namespace qx
{
/*!
* \ingroup QxFunction
* \brief qx::QxFunction_4<Owner, R, P1, P2, P3, P4> : concrete function registered into QxOrm context defined into class Owner, returning an object of type R and with 4 parameters P1, P2, P3, P4
*/
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4>
class QxFunction_4 : public IxFunction
{
public:
typedef std::function<R(Owner *, P1, P2, P3, P4)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_4);
virtual int getParamCount() const { return 4; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_4 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
try
{
pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_4 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
try
{
R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
template <typename R, typename P1, typename P2, typename P3, typename P4>
class QxFunction_4<void, R, P1, P2, P3, P4> : public IxFunction
{
public:
typedef std::function<R(P1, P2, P3, P4)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
QX_FUNCTION_CLASS_FCT(QxFunction_4);
virtual int getParamCount() const { return 4; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_4 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
try
{
pThis->m_fct(p1, p2, p3, p4);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_4 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
try
{
R retTmp = pThis->m_fct(p1, p2, p3, p4);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
namespace function
{
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4>
IxFunction_ptr bind_fct_4(const typename QxFunction_4<Owner, R, P1, P2, P3, P4>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_4<void, R, P1, P2, P3, P4>>(fct);
return ptr;
}
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4>
IxFunction_ptr bind_member_fct_4(const typename QxFunction_4<Owner, R, P1, P2, P3, P4>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(!qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_4<Owner, R, P1, P2, P3, P4>>(fct);
return ptr;
}
} // namespace function
} // namespace qx
#endif // _QX_FUNCTION_4_H_

View File

@@ -0,0 +1,218 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_5_H_
#define _QX_FUNCTION_5_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFunction_5.h
* \author XDL Team
* \ingroup QxFunction
* \brief Concrete function class registered into QxOrm context with 5 parameters
*/
#include <QxFunction/IxFunction.h>
#include <QxFunction/QxParameters.h>
namespace qx
{
/*!
* \ingroup QxFunction
* \brief qx::QxFunction_5<Owner, R, P1, P2, P3, P4, P5> : concrete function registered into QxOrm context defined into class Owner, returning an object of type R and with 5 parameters P1, P2, P3, P4, P5
*/
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
class QxFunction_5 : public IxFunction
{
public:
typedef std::function<R(Owner *, P1, P2, P3, P4, P5)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
typedef typename qx::trait::remove_attr<P5, false>::type type_P5;
QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_5);
virtual int getParamCount() const { return 5; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_5 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
try
{
pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4, p5);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_5 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
try
{
R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4, p5);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
class QxFunction_5<void, R, P1, P2, P3, P4, P5> : public IxFunction
{
public:
typedef std::function<R(P1, P2, P3, P4, P5)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
typedef typename qx::trait::remove_attr<P5, false>::type type_P5;
QX_FUNCTION_CLASS_FCT(QxFunction_5);
virtual int getParamCount() const { return 5; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_5 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
try
{
pThis->m_fct(p1, p2, p3, p4, p5);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_5 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
try
{
R retTmp = pThis->m_fct(p1, p2, p3, p4, p5);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
namespace function
{
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
IxFunction_ptr bind_fct_5(const typename QxFunction_5<Owner, R, P1, P2, P3, P4, P5>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_5<void, R, P1, P2, P3, P4, P5>>(fct);
return ptr;
}
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
IxFunction_ptr bind_member_fct_5(const typename QxFunction_5<Owner, R, P1, P2, P3, P4, P5>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(!qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_5<Owner, R, P1, P2, P3, P4, P5>>(fct);
return ptr;
}
} // namespace function
} // namespace qx
#endif // _QX_FUNCTION_5_H_

View File

@@ -0,0 +1,224 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_6_H_
#define _QX_FUNCTION_6_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFunction_6.h
* \author XDL Team
* \ingroup QxFunction
* \brief Concrete function class registered into QxOrm context with 6 parameters
*/
#include <QxFunction/IxFunction.h>
#include <QxFunction/QxParameters.h>
namespace qx
{
/*!
* \ingroup QxFunction
* \brief qx::QxFunction_6<Owner, R, P1, P2, P3, P4, P5, P6> : concrete function registered into QxOrm context defined into class Owner, returning an object of type R and with 6 parameters P1, P2, P3, P4, P5, P6
*/
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
class QxFunction_6 : public IxFunction
{
public:
typedef std::function<R(Owner *, P1, P2, P3, P4, P5, P6)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
typedef typename qx::trait::remove_attr<P5, false>::type type_P5;
typedef typename qx::trait::remove_attr<P6, false>::type type_P6;
QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_6);
virtual int getParamCount() const { return 6; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_6 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
QX_FUNCTION_FETCH_PARAM(type_P6, p6, get_param_6);
try
{
pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4, p5, p6);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_6 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
QX_FUNCTION_FETCH_PARAM(type_P6, p6, get_param_6);
try
{
R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4, p5, p6);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
class QxFunction_6<void, R, P1, P2, P3, P4, P5, P6> : public IxFunction
{
public:
typedef std::function<R(P1, P2, P3, P4, P5, P6)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
typedef typename qx::trait::remove_attr<P5, false>::type type_P5;
typedef typename qx::trait::remove_attr<P6, false>::type type_P6;
QX_FUNCTION_CLASS_FCT(QxFunction_6);
virtual int getParamCount() const { return 6; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_6 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
QX_FUNCTION_FETCH_PARAM(type_P6, p6, get_param_6);
try
{
pThis->m_fct(p1, p2, p3, p4, p5, p6);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_6 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
QX_FUNCTION_FETCH_PARAM(type_P6, p6, get_param_6);
try
{
R retTmp = pThis->m_fct(p1, p2, p3, p4, p5, p6);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
namespace function
{
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
IxFunction_ptr bind_fct_6(const typename QxFunction_6<Owner, R, P1, P2, P3, P4, P5, P6>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_6<void, R, P1, P2, P3, P4, P5, P6>>(fct);
return ptr;
}
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
IxFunction_ptr bind_member_fct_6(const typename QxFunction_6<Owner, R, P1, P2, P3, P4, P5, P6>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(!qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_6<Owner, R, P1, P2, P3, P4, P5, P6>>(fct);
return ptr;
}
} // namespace function
} // namespace qx
#endif // _QX_FUNCTION_6_H_

View File

@@ -0,0 +1,230 @@
/****************************************************************************
**
** https://www.qxorm.com/
** Copyright (C) 2013 XDL Team (ic-east.com)
**
** This file is part of the QxOrm library
**
** This software is provided 'as-is', without any express or implied
** warranty. In no event will the authors be held liable for any
** damages arising from the use of this software
**
** Commercial Usage
** Licensees holding valid commercial QxOrm licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and XDL Team
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file 'license.gpl3.txt' included in the
** packaging of this file. Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met : http://www.gnu.org/copyleft/gpl.html
**
** If you are unsure which license is appropriate for your use, or
** if you have questions regarding the use of this file, please contact :
** ic-east.com
**
****************************************************************************/
#ifndef _QX_FUNCTION_7_H_
#define _QX_FUNCTION_7_H_
#ifdef _MSC_VER
#pragma once
#endif
/*!
* \file QxFunction_7.h
* \author XDL Team
* \ingroup QxFunction
* \brief Concrete function class registered into QxOrm context with 7 parameters
*/
#include <QxFunction/IxFunction.h>
#include <QxFunction/QxParameters.h>
namespace qx
{
/*!
* \ingroup QxFunction
* \brief qx::QxFunction_7<Owner, R, P1, P2, P3, P4, P5, P6, P7> : concrete function registered into QxOrm context defined into class Owner, returning an object of type R and with 7 parameters P1, P2, P3, P4, P5, P6, P7
*/
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
class QxFunction_7 : public IxFunction
{
public:
typedef std::function<R(Owner *, P1, P2, P3, P4, P5, P6, P7)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
typedef typename qx::trait::remove_attr<P5, false>::type type_P5;
typedef typename qx::trait::remove_attr<P6, false>::type type_P6;
typedef typename qx::trait::remove_attr<P7, false>::type type_P7;
QX_FUNCTION_CLASS_MEMBER_FCT(QxFunction_7);
virtual int getParamCount() const { return 7; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_7 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
QX_FUNCTION_FETCH_PARAM(type_P6, p6, get_param_6);
QX_FUNCTION_FETCH_PARAM(type_P7, p7, get_param_7);
try
{
pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4, p5, p6, p7);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(void *pOwner, const T &params, qx::any *ret, const QxFunction_7 *pThis)
{
QX_FUNCTION_INVOKE_START_WITH_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
QX_FUNCTION_FETCH_PARAM(type_P6, p6, get_param_6);
QX_FUNCTION_FETCH_PARAM(type_P7, p7, get_param_7);
try
{
R retTmp = pThis->m_fct(static_cast<Owner *>(pOwner), p1, p2, p3, p4, p5, p6, p7);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
class QxFunction_7<void, R, P1, P2, P3, P4, P5, P6, P7> : public IxFunction
{
public:
typedef std::function<R(P1, P2, P3, P4, P5, P6, P7)> type_fct;
typedef typename qx::trait::remove_attr<P1, false>::type type_P1;
typedef typename qx::trait::remove_attr<P2, false>::type type_P2;
typedef typename qx::trait::remove_attr<P3, false>::type type_P3;
typedef typename qx::trait::remove_attr<P4, false>::type type_P4;
typedef typename qx::trait::remove_attr<P5, false>::type type_P5;
typedef typename qx::trait::remove_attr<P6, false>::type type_P6;
typedef typename qx::trait::remove_attr<P7, false>::type type_P7;
QX_FUNCTION_CLASS_FCT(QxFunction_7);
virtual int getParamCount() const { return 7; }
virtual qx_bool isValidParams(const QString &params) const
{
Q_UNUSED(params);
return true;
}
virtual qx_bool isValidParams(const type_any_params &params) const
{
Q_UNUSED(params);
return true;
}
private:
template <class T, bool bReturnValue /* = false */>
struct QxInvokerFct
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_7 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
QX_FUNCTION_FETCH_PARAM(type_P6, p6, get_param_6);
QX_FUNCTION_FETCH_PARAM(type_P7, p7, get_param_7);
try
{
pThis->m_fct(p1, p2, p3, p4, p5, p6, p7);
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
template <class T>
struct QxInvokerFct<T, true>
{
static inline qx_bool invoke(const T &params, qx::any *ret, const QxFunction_7 *pThis)
{
QX_FUNCTION_INVOKE_START_WITHOUT_OWNER();
QX_FUNCTION_FETCH_PARAM(type_P1, p1, get_param_1);
QX_FUNCTION_FETCH_PARAM(type_P2, p2, get_param_2);
QX_FUNCTION_FETCH_PARAM(type_P3, p3, get_param_3);
QX_FUNCTION_FETCH_PARAM(type_P4, p4, get_param_4);
QX_FUNCTION_FETCH_PARAM(type_P5, p5, get_param_5);
QX_FUNCTION_FETCH_PARAM(type_P6, p6, get_param_6);
QX_FUNCTION_FETCH_PARAM(type_P7, p7, get_param_7);
try
{
R retTmp = pThis->m_fct(p1, p2, p3, p4, p5, p6, p7);
if (ret)
{
(*ret) = qx::any(retTmp);
}
}
QX_FUNCTION_CATCH_AND_RETURN_INVOKE();
}
};
};
namespace function
{
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
IxFunction_ptr bind_fct_7(const typename QxFunction_7<Owner, R, P1, P2, P3, P4, P5, P6, P7>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(qx_verify_owner_tmp::value, "qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_7<void, R, P1, P2, P3, P4, P5, P6, P7>>(fct);
return ptr;
}
template <class Owner, typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
IxFunction_ptr bind_member_fct_7(const typename QxFunction_7<Owner, R, P1, P2, P3, P4, P5, P6, P7>::type_fct &fct)
{
typedef std::is_same<Owner, void> qx_verify_owner_tmp;
static_assert(!qx_verify_owner_tmp::value, "! qx_verify_owner_tmp::value");
IxFunction_ptr ptr = std::make_shared<QxFunction_7<Owner, R, P1, P2, P3, P4, P5, P6, P7>>(fct);
return ptr;
}
} // namespace function
} // namespace qx
#endif // _QX_FUNCTION_7_H_

Some files were not shown because too many files have changed in this diff Show More