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,615 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
template <typename Key, typename Value>
QxCollection<Key, Value>::QxCollection() : IxCollection(), m_batch(false)
{
}
template <typename Key, typename Value>
QxCollection<Key, Value>::QxCollection(const QxCollection<Key, Value> &other) : IxCollection(), m_batch(false)
{
cloneCollection(this, other);
}
template <typename Key, typename Value>
QxCollection<Key, Value>::~QxCollection()
{
}
template <typename Key, typename Value>
QxCollection<Key, Value> &QxCollection<Key, Value>::operator=(const QxCollection<Key, Value> &other)
{
if (this != (&other))
{
cloneCollection(this, other);
}
return (*this);
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::operator==(const QxCollection<Key, Value> &other) const
{
return isSameCollection(this, other);
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::operator!=(const QxCollection<Key, Value> &other) const
{
return (!isSameCollection(this, other));
}
template <typename Key, typename Value>
void QxCollection<Key, Value>::cloneCollection(QxCollection<Key, Value> *pClone, const QxCollection<Key, Value> &pRef)
{
if (!pClone)
{
return;
}
if (pClone == (&pRef))
{
return;
}
QMutexLocker locker1(&pRef.m_mutex);
QMutexLocker locker2(&pClone->m_mutex);
qAssert(pRef.m_list.size() == pRef.m_hash.size());
pClone->m_list = pRef.m_list;
pClone->m_hash = pRef.m_hash;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::isSameCollection(const QxCollection<Key, Value> *p1, const QxCollection<Key, Value> &p2) const
{
if (!p1)
{
return false;
}
if (p1 == (&p2))
{
return true;
}
if (p1->size() != p2.size())
{
return false;
}
QMutexLocker locker1(&p2.m_mutex);
QMutexLocker locker2(&p1->m_mutex);
qAssert(p2.m_list.size() == p2.m_hash.size());
return ((p1->m_list == p2.m_list) && (p1->m_hash == p2.m_hash));
}
template <typename Key, typename Value>
void QxCollection<Key, Value>::updateHashPosition(long from /* = 0 */, long to /* = -1 */, bool check /* = false */)
{
if (m_batch)
{
return;
}
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
if (to == -1)
{
to = (m_list.size() - 1);
}
if ((from < 0) || (to >= m_list.size()) || (from > to))
{
return;
}
for (long idx = from; idx <= to; idx++)
{
const Key &key = m_list.at(idx).first;
m_hash.insert(key, idx);
}
if (check)
{
qAssert(m_list.size() == m_hash.size());
}
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::iterator QxCollection<Key, Value>::begin()
{
QMutexLocker locker(&m_mutex);
return m_list.begin();
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::iterator QxCollection<Key, Value>::end()
{
QMutexLocker locker(&m_mutex);
return m_list.end();
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::const_iterator QxCollection<Key, Value>::begin() const
{
QMutexLocker locker(&m_mutex);
return m_list.begin();
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::const_iterator QxCollection<Key, Value>::end() const
{
QMutexLocker locker(&m_mutex);
return m_list.end();
}
#if (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
template <typename Key, typename Value>
typename QxCollection<Key, Value>::reverse_iterator QxCollection<Key, Value>::rbegin()
{
QMutexLocker locker(&m_mutex);
return m_list.rbegin();
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::reverse_iterator QxCollection<Key, Value>::rend()
{
QMutexLocker locker(&m_mutex);
return m_list.rend();
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::const_reverse_iterator QxCollection<Key, Value>::rbegin() const
{
QMutexLocker locker(&m_mutex);
return m_list.rbegin();
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::const_reverse_iterator QxCollection<Key, Value>::rend() const
{
QMutexLocker locker(&m_mutex);
return m_list.rend();
}
#endif // (QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
template <typename Key, typename Value>
void QxCollection<Key, Value>::reserve(long size)
{
if (size <= 0)
{
return;
}
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
m_list.reserve(size);
m_hash.reserve(size);
}
template <typename Key, typename Value>
void QxCollection<Key, Value>::reverse()
{
{
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
std::reverse(m_list.begin(), m_list.end());
}
updateHashPosition();
}
template <typename Key, typename Value>
void QxCollection<Key, Value>::clear()
{
QMutexLocker locker(&m_mutex);
m_hash.clear();
m_list.clear();
}
template <typename Key, typename Value>
long QxCollection<Key, Value>::count() const
{
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
return static_cast<long>(m_list.size());
}
template <typename Key, typename Value>
long QxCollection<Key, Value>::size() const
{
return this->count();
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::contains(const Key &key) const
{
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
return (m_hash.contains(key));
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::exist(const Key &key) const
{
return this->contains(key);
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::empty() const
{
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
return m_list.isEmpty();
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::push_back(const Key &key, const Value &value)
{
return this->insert(key, value);
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::push_front(const Key &key, const Value &value)
{
return this->insert(0, key, value);
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::insert(const Key &key, const Value &value)
{
qAssert(!exist(key));
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
m_list.append(qMakePair(key, value));
m_hash.insert(key, (m_list.size() - 1));
return true;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::insert(long index, const Key &key, const Value &value)
{
qAssert(!exist(key));
if (index < 0)
{
index = 0;
}
if (index >= size())
{
return this->insert(key, value);
}
{
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
m_list.insert(index, qMakePair(key, value));
m_hash.insert(key, index);
}
updateHashPosition(index);
return true;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::insert(const QxCollection<Key, Value> &other)
{
{
if (this == (&other))
{
return false;
}
QMutexLocker locker1(&m_mutex);
QMutexLocker locker2(&other.m_mutex);
m_list.append(other.m_list);
m_hash.unite(other.m_hash);
}
updateHashPosition(0, -1, true);
return true;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::insert(long index, const QxCollection<Key, Value> &other)
{
if (index < 0)
{
index = 0;
}
if ((index >= size()) && (index != 0))
{
index = (size() - 1);
}
if (this == (&other))
{
return false;
}
QMutexLocker locker1(&other.m_mutex);
{
QMutexLocker locker2(&m_mutex);
qAssert(m_list.size() == m_hash.size());
m_batch = true;
}
for (long l = 0; l < other.size(); l++)
{
const type_pair_key_value &pair = other.m_list.at(l);
this->insert((index + l), pair.first, pair.second);
}
{
QMutexLocker locker3(&m_mutex);
m_batch = false;
}
updateHashPosition(index);
return true;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::replace(long index, const Key &key, const Value &value)
{
qAssert(!exist(key));
QMutexLocker locker(&m_mutex);
m_hash.remove(m_list.at(index).first);
m_list.replace(index, qMakePair(key, value));
m_hash.insert(key, index);
qAssert(m_list.size() == m_hash.size());
return true;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::swap(long index1, long index2)
{
if (index1 < 0 || index1 >= size())
{
return false;
}
if (index2 < 0 || index2 >= size())
{
return false;
}
if (index1 == index2)
{
return true;
}
QMutexLocker locker(&m_mutex);
const Key &key1 = m_list.at(index1).first;
const Key &key2 = m_list.at(index2).first;
m_hash.insert(key1, index2);
m_hash.insert(key2, index1);
m_list.swap(index1, index2);
qAssert(m_list.size() == m_hash.size());
return true;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::move(long indexFrom, long indexTo)
{
return swap(indexFrom, indexTo);
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::removeByKey(const Key &key)
{
qAssert(exist(key));
long pos = 0;
{
QMutexLocker locker(&m_mutex);
pos = m_hash.value(key, -1);
if ((pos < 0) || (pos >= m_list.size()))
{
return false;
}
qAssert(m_list.at(pos).first == key);
m_hash.remove(key);
m_list.removeAt(pos);
}
updateHashPosition(pos, -1, true);
return true;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::removeByIndex(long index)
{
if (index < 0 || index >= size())
{
return false;
}
{
QMutexLocker locker(&m_mutex);
const Key &key = m_list.at(index).first;
qAssert(m_hash.value(key, -1) == index);
m_hash.remove(key);
m_list.removeAt(index);
}
updateHashPosition(index, -1, true);
return true;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::removeByIndex(long first, long last)
{
if (first < 0 || first >= size())
{
return false;
}
if (last < 0 || last >= size())
{
return false;
}
if (first > last)
{
return false;
}
{
QMutexLocker locker(&m_mutex);
m_batch = true;
}
for (long idx = first; idx <= last; idx++)
{
removeByIndex(idx);
}
{
QMutexLocker locker(&m_mutex);
m_batch = false;
}
updateHashPosition(first);
return true;
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::removeFirst()
{
return this->removeByIndex(0);
}
template <typename Key, typename Value>
bool QxCollection<Key, Value>::removeLast()
{
return this->removeByIndex(size() - 1);
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::const_reference_value QxCollection<Key, Value>::getByKey(const Key &key) const
{
qAssert(exist(key));
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
const type_pair_key_value &pair = m_list.at(m_hash.value(key, -1));
qAssert(pair.first == key);
return pair.second;
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::const_reference_value QxCollection<Key, Value>::getByIndex(long index) const
{
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
qAssert((index >= 0) && (index < static_cast<long>(m_list.size())));
qAssert(m_hash.value(m_list.at(index).first, -1) == index);
return m_list.at(index).second;
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::const_reference_value QxCollection<Key, Value>::getFirst() const
{
qAssert(!empty());
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
return m_list.at(0).second;
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::const_reference_value QxCollection<Key, Value>::getLast() const
{
qAssert(!empty());
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
return m_list.at(m_list.size() - 1).second;
}
template <typename Key, typename Value>
typename QxCollection<Key, Value>::const_reference_key QxCollection<Key, Value>::getKeyByIndex(long index) const
{
QMutexLocker locker(&m_mutex);
qAssert(m_list.size() == m_hash.size());
qAssert((index >= 0) && (index < static_cast<long>(m_list.size())));
qAssert(m_hash.value(m_list.at(index).first, -1) == index);
return m_list.at(index).first;
}
template <typename Key, typename Value>
void QxCollection<Key, Value>::sortByKey(bool bAscending /* = true */)
{
if (bAscending)
{
QMutexLocker locker(&m_mutex);
std::sort(m_list.begin(), m_list.end(), (&compareKeyValue < std::is_pointer<Key>::value || qx::trait::is_smart_ptr<Key>::value, 0 > ::compareByKeyAscending));
}
else
{
QMutexLocker locker(&m_mutex);
std::sort(m_list.begin(), m_list.end(), (&compareKeyValue < std::is_pointer<Key>::value || qx::trait::is_smart_ptr<Key>::value, 0 > ::compareByKeyDescending));
}
updateHashPosition(0, -1, true);
}
template <typename Key, typename Value>
void QxCollection<Key, Value>::sortByValue(bool bAscending /* = true */)
{
if (bAscending)
{
QMutexLocker locker(&m_mutex);
std::sort(m_list.begin(), m_list.end(), (&compareKeyValue < std::is_pointer<Value>::value || qx::trait::is_smart_ptr<Value>::value, 0 > ::compareByValueAscending));
}
else
{
QMutexLocker locker(&m_mutex);
std::sort(m_list.begin(), m_list.end(), (&compareKeyValue < std::is_pointer<Value>::value || qx::trait::is_smart_ptr<Value>::value, 0 > ::compareByValueDescending));
}
updateHashPosition(0, -1, true);
}
} // namespace qx
template <typename Key, typename Value>
QDataStream &operator<<(QDataStream &stream, const qx::QxCollection<Key, Value> &t)
{
long lCount = t.count();
stream << (qint32)(lCount);
for (long l = 0; l < lCount; l++)
{
stream << t.getKeyByIndex(l);
stream << t.getByIndex(l);
}
return stream;
}
template <typename Key, typename Value>
QDataStream &operator>>(QDataStream &stream, qx::QxCollection<Key, Value> &t)
{
qint32 lCount = 0;
stream >> lCount;
t.clear();
t.reserve(lCount);
for (qint32 l = 0; l < lCount; l++)
{
Key key;
stream >> key;
Value value;
stream >> value;
t.insert(key, value);
}
return stream;
}

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
**
****************************************************************************/
namespace qx
{
template <typename Key, typename Value>
QxCollectionIterator<Key, Value>::QxCollectionIterator(const QxCollection<Key, Value> &col) : m_pCollection(&col), m_lCurrIndex(-1)
{
}
template <typename Key, typename Value>
QxCollectionIterator<Key, Value>::~QxCollectionIterator()
{
}
template <typename Key, typename Value>
inline const Key &QxCollectionIterator<Key, Value>::key() const
{
qAssert(m_pCollection && (m_lCurrIndex >= 0) && (m_lCurrIndex < m_pCollection->size()));
return m_pCollection->getKeyByIndex(m_lCurrIndex);
}
template <typename Key, typename Value>
inline const Value &QxCollectionIterator<Key, Value>::value() const
{
qAssert(m_pCollection && (m_lCurrIndex >= 0) && (m_lCurrIndex < m_pCollection->size()));
return m_pCollection->getByIndex(m_lCurrIndex);
}
template <typename Key, typename Value>
inline void QxCollectionIterator<Key, Value>::toFirst()
{
m_lCurrIndex = -1;
}
template <typename Key, typename Value>
inline void QxCollectionIterator<Key, Value>::toLast()
{
m_lCurrIndex = m_pCollection->size();
}
template <typename Key, typename Value>
inline bool QxCollectionIterator<Key, Value>::next()
{
long lCurrIndex = m_lCurrIndex;
m_lCurrIndex = ((m_lCurrIndex < (m_pCollection->size() - 1)) ? (m_lCurrIndex + 1) : m_lCurrIndex);
return (m_lCurrIndex > lCurrIndex);
}
template <typename Key, typename Value>
inline bool QxCollectionIterator<Key, Value>::previous()
{
long lCurrIndex = m_lCurrIndex;
m_lCurrIndex = ((m_lCurrIndex > 0) ? (m_lCurrIndex - 1) : m_lCurrIndex);
return (m_lCurrIndex < lCurrIndex);
}
} // namespace qx

View File

@@ -0,0 +1,413 @@
/****************************************************************************
**
** 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_NO_JSON
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_FromJson<qx::trait::no_type>
{
static inline qx_bool fromJson(const QJsonValue &j, qx::trait::no_type &t, const QString &format)
{
Q_UNUSED(j);
Q_UNUSED(t);
Q_UNUSED(format);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<bool>
{
static inline qx_bool fromJson(const QJsonValue &j, bool &t, const QString &format)
{
Q_UNUSED(format);
t = j.toBool();
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<short>
{
static inline qx_bool fromJson(const QJsonValue &j, short &t, const QString &format)
{
Q_UNUSED(format);
t = static_cast<short>(qRound(j.toDouble()));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<int>
{
static inline qx_bool fromJson(const QJsonValue &j, int &t, const QString &format)
{
Q_UNUSED(format);
t = qRound(j.toDouble());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<long>
{
static inline qx_bool fromJson(const QJsonValue &j, long &t, const QString &format)
{
Q_UNUSED(format);
t = static_cast<long>(qRound64(j.toDouble()));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<long long>
{
static inline qx_bool fromJson(const QJsonValue &j, long long &t, const QString &format)
{
Q_UNUSED(format);
t = static_cast<long long>(qRound64(j.toDouble()));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<float>
{
static inline qx_bool fromJson(const QJsonValue &j, float &t, const QString &format)
{
Q_UNUSED(format);
t = static_cast<float>(j.toDouble());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<double>
{
static inline qx_bool fromJson(const QJsonValue &j, double &t, const QString &format)
{
Q_UNUSED(format);
t = j.toDouble();
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<unsigned short>
{
static inline qx_bool fromJson(const QJsonValue &j, unsigned short &t, const QString &format)
{
Q_UNUSED(format);
t = static_cast<unsigned short>(qRound(j.toDouble()));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<unsigned int>
{
static inline qx_bool fromJson(const QJsonValue &j, unsigned int &t, const QString &format)
{
Q_UNUSED(format);
t = static_cast<unsigned int>(qRound(j.toDouble()));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<unsigned long>
{
static inline qx_bool fromJson(const QJsonValue &j, unsigned long &t, const QString &format)
{
Q_UNUSED(format);
t = static_cast<unsigned long>(qRound64(j.toDouble()));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<unsigned long long>
{
static inline qx_bool fromJson(const QJsonValue &j, unsigned long long &t, const QString &format)
{
Q_UNUSED(format);
t = static_cast<unsigned long long>(qRound64(j.toDouble()));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<QDateTime>
{
static inline qx_bool fromJson(const QJsonValue &j, QDateTime &t, const QString &format)
{
#ifdef _QX_ENABLE_MONGODB
if (j.isObject() && format.startsWith("mongodb"))
{
QJsonObject obj = j.toObject();
QString dt;
if (obj.contains("$date"))
{
dt = obj.value("$date").toString();
}
if (!dt.isEmpty())
{
t = QDateTime::fromString(dt, QX_JSON_DATE_TIME_FORMAT);
return qx_bool(true);
}
}
#endif // _QX_ENABLE_MONGODB
Q_UNUSED(format);
t = (j.isNull() ? QDateTime() : QDateTime::fromString(j.toString(), QX_JSON_DATE_TIME_FORMAT));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<QDate>
{
static inline qx_bool fromJson(const QJsonValue &j, QDate &t, const QString &format)
{
#ifdef _QX_ENABLE_MONGODB
if (j.isObject() && format.startsWith("mongodb"))
{
QDateTime dt;
QxConvert_FromJson<QDateTime>::fromJson(j, dt, format);
t = dt.date();
return qx_bool(true);
}
#endif // _QX_ENABLE_MONGODB
Q_UNUSED(format);
t = (j.isNull() ? QDate() : QDate::fromString(j.toString(), Qt::ISODate));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<QTime>
{
static inline qx_bool fromJson(const QJsonValue &j, QTime &t, const QString &format)
{
Q_UNUSED(format);
t = (j.isNull() ? QTime() : QTime::fromString(j.toString(), QX_JSON_DATE_TIME_FORMAT));
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<QByteArray>
{
static inline qx_bool fromJson(const QJsonValue &j, QByteArray &t, const QString &format)
{
Q_UNUSED(format);
t = QByteArray::fromBase64(j.toString().toLatin1());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<QString>
{
static inline qx_bool fromJson(const QJsonValue &j, QString &t, const QString &format)
{
Q_UNUSED(format);
t = j.toString();
#ifdef _QX_ENABLE_MONGODB
if (t.isEmpty() && j.isObject() && format.startsWith("mongodb"))
{
QJsonObject obj = j.toObject();
if (obj.contains("$oid"))
{
t = obj.value("$oid").toString();
}
if (!t.isEmpty())
{
t = "qx_oid:" + t;
}
}
#endif // _QX_ENABLE_MONGODB
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<QVariant>
{
static inline qx_bool fromJson(const QJsonValue &j, QVariant &t, const QString &format)
{
Q_UNUSED(format);
t = j.toVariant();
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<QUuid>
{
static inline qx_bool fromJson(const QJsonValue &j, QUuid &t, const QString &format)
{
Q_UNUSED(format);
t = QUuid(j.toString());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<qx::QxDateNeutral>
{
static inline qx_bool fromJson(const QJsonValue &j, qx::QxDateNeutral &t, const QString &format)
{
Q_UNUSED(format);
t = qx::QxDateNeutral::fromNeutral(j.toString());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<qx::QxTimeNeutral>
{
static inline qx_bool fromJson(const QJsonValue &j, qx::QxTimeNeutral &t, const QString &format)
{
Q_UNUSED(format);
t = qx::QxTimeNeutral::fromNeutral(j.toString());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<qx::QxDateTimeNeutral>
{
static inline qx_bool fromJson(const QJsonValue &j, qx::QxDateTimeNeutral &t, const QString &format)
{
Q_UNUSED(format);
t = qx::QxDateTimeNeutral::fromNeutral(j.toString());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromJson<std::string>
{
static inline qx_bool fromJson(const QJsonValue &j, std::string &t, const QString &format)
#ifndef QT_NO_STL
{
Q_UNUSED(format);
t = j.toString().toStdString();
return qx_bool(true);
}
};
#else // QT_NO_STL
{
Q_UNUSED(format);
t = j.toString().toLatin1().constData();
return qx_bool(true);
}
};
#endif // QT_NO_STL
template <>
struct QxConvert_FromJson<std::wstring>
{
static inline qx_bool fromJson(const QJsonValue &j, std::wstring &t, const QString &format)
#if ((!defined(QT_NO_STL)) && (!defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
t = j.toString().toStdWString();
return qx_bool(true);
}
};
#else // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(t);
Q_UNUSED(j);
qAssert(false); /* Need STL compatibility ! */
return qx_bool(true);
}
};
#endif // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
template <>
struct QxConvert_FromJson<qx_bool>
{
static inline qx_bool fromJson(const QJsonValue &j, qx_bool &t, const QString &format)
{
Q_UNUSED(format);
t = qx_bool();
if (j.isObject())
{
QJsonObject obj = j.toObject();
t.setValue(obj["value"].toBool());
t.setCode(static_cast<long>(qRound64(obj["code"].toDouble())));
t.setDesc(obj["desc"].toString());
}
return qx_bool(true);
}
};
#ifdef _QX_ENABLE_BOOST
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_ENABLE_BOOST
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_NO_JSON

View File

@@ -0,0 +1,979 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_FromString<qx::trait::no_type>
{
static inline qx_bool fromString(const QString &s, qx::trait::no_type &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);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<QString>
{
static inline qx_bool fromString(const QString &s, QString &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = s;
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<QUuid>
{
static inline qx_bool fromString(const QString &s, QUuid &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = QUuid(s);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<QDate>
{
static inline qx_bool fromString(const QString &s, QDate &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
t = QDate::fromString(s, (format.isEmpty() ? QString(QX_STR_CVT_QDATE_FORMAT) : format));
return t.isValid();
}
};
template <>
struct QxConvert_FromString<QTime>
{
static inline qx_bool fromString(const QString &s, QTime &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
t = QTime::fromString(s, (format.isEmpty() ? QString(QX_STR_CVT_QTIME_FORMAT) : format));
return t.isValid();
}
};
template <>
struct QxConvert_FromString<QDateTime>
{
static inline qx_bool fromString(const QString &s, QDateTime &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
t = QDateTime::fromString(s, (format.isEmpty() ? QString(QX_STR_CVT_QDATETIME_FORMAT) : format));
return t.isValid();
}
};
template <>
struct QxConvert_FromString<QByteArray>
{
static inline qx_bool fromString(const QString &s, QByteArray &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = s.toLatin1();
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<QVariant>
{
static inline qx_bool fromString(const QString &s, QVariant &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
#ifndef _QX_NO_JSON
if (s.startsWith("$$JSON$$"))
{
QJsonParseError err;
QString stream = s.right(s.size() - 16); // $$JSON$$0000XX$$
QJsonDocument doc = QJsonDocument::fromJson(stream.toUtf8(), (&err));
if (err.error == QJsonParseError::NoError)
{
QJsonValue json = (doc.isArray() ? QJsonValue(doc.array()) : QJsonValue(doc.object()));
t = json.toVariant();
return qx_bool(true);
}
}
#endif // _QX_NO_JSON
t = QVariant(s);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<qx_bool>
{
static inline qx_bool fromString(const QString &s, qx_bool &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t.fromString(s);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<bool>
{
static inline qx_bool fromString(const QString &s, bool &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = (((s == "0") || s.trimmed().isEmpty()) ? false : true);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<char>
{
static inline qx_bool fromString(const QString &s, char &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = (s.isEmpty() ? ' ' : s.toLatin1().at(0));
return (!s.isEmpty());
}
};
template <>
struct QxConvert_FromString<short>
{
static inline qx_bool fromString(const QString &s, short &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 = s.toShort(&bOk);
return bOk;
}
};
template <>
struct QxConvert_FromString<int>
{
static inline qx_bool fromString(const QString &s, int &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 = s.toInt(&bOk);
return bOk;
}
};
template <>
struct QxConvert_FromString<long>
{
static inline qx_bool fromString(const QString &s, long &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<long>(s.toLongLong(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromString<long long>
{
static inline qx_bool fromString(const QString &s, long long &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<long long>(s.toLongLong(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromString<float>
{
static inline qx_bool fromString(const QString &s, float &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<float>(s.toDouble(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromString<double>
{
static inline qx_bool fromString(const QString &s, double &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 = s.toDouble(&bOk);
return bOk;
}
};
template <>
struct QxConvert_FromString<unsigned short>
{
static inline qx_bool fromString(const QString &s, unsigned short &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<unsigned short>(s.toUShort(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromString<unsigned int>
{
static inline qx_bool fromString(const QString &s, unsigned int &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<unsigned int>(s.toUInt(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromString<unsigned long>
{
static inline qx_bool fromString(const QString &s, unsigned long &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<unsigned long>(s.toULongLong(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromString<unsigned long long>
{
static inline qx_bool fromString(const QString &s, unsigned long long &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<unsigned long long>(s.toULongLong(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromString<qx::QxDateNeutral>
{
static inline qx_bool fromString(const QString &s, qx::QxDateNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = qx::QxDateNeutral::fromNeutral(s);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<qx::QxTimeNeutral>
{
static inline qx_bool fromString(const QString &s, qx::QxTimeNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = qx::QxTimeNeutral::fromNeutral(s);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<qx::QxDateTimeNeutral>
{
static inline qx_bool fromString(const QString &s, qx::QxDateTimeNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = qx::QxDateTimeNeutral::fromNeutral(s);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromString<std::string>
{
static inline qx_bool fromString(const QString &s, std::string &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
#ifndef QT_NO_STL
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = s.toStdString();
return qx_bool(true);
}
};
#else // QT_NO_STL
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = s.toLatin1().constData();
return qx_bool(true);
}
};
#endif // QT_NO_STL
template <>
struct QxConvert_FromString<std::wstring>
{
static inline qx_bool fromString(const QString &s, std::wstring &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
#if ((!defined(QT_NO_STL)) && (!defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = s.toStdWString();
return qx_bool(true);
}
};
#else // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
Q_UNUSED(t);
Q_UNUSED(s);
qAssert(false); /* Need STL compatibility ! */
return qx_bool(true);
}
};
#endif // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
#ifndef _QX_NO_JSON
template <>
struct QxConvert_FromString<QJsonValue>
{
static inline qx_bool fromString(const QString &s, QJsonValue &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
QJsonParseError jsonError;
QByteArray dataAsByteArray = s.toUtf8();
QJsonDocument doc = QJsonDocument::fromJson(dataAsByteArray, (&jsonError));
if (jsonError.error != QJsonParseError::NoError)
{
return qx_bool(static_cast<long>(jsonError.error), jsonError.errorString());
}
t = (doc.isArray() ? QJsonValue(doc.array()) : QJsonValue(doc.object()));
return qx_bool(true);
}
};
#endif // _QX_NO_JSON
#ifdef _QX_ENABLE_BOOST
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);
}
};
#endif // _QX_ENABLE_BOOST
template <typename T1, typename T2>
struct QxConvert_FromString<std::pair<T1, T2>>
{
static inline qx_bool fromString(const QString &s, std::pair<T1, T2> &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);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T1, typename T2>
struct QxConvert_FromString<QPair<T1, T2>>
{
static inline qx_bool fromString(const QString &s, QPair<T1, T2> &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);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_FromString<std::vector<T>>
{
static inline qx_bool fromString(const QString &s, std::vector<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 QxConvert_FromString<std::list<T>>
{
static inline qx_bool fromString(const QString &s, std::list<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 QxConvert_FromString<std::set<T>>
{
static inline qx_bool fromString(const QString &s, std::set<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);
}
};
#ifdef _QX_ENABLE_BOOST
template <typename T>
struct QxConvert_FromString<boost::unordered_set<T>>
{
static inline qx_bool fromString(const QString &s, boost::unordered_set<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 QxConvert_FromString<boost::unordered_multiset<T>>
{
static inline qx_bool fromString(const QString &s, boost::unordered_multiset<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);
}
};
#endif // _QX_ENABLE_BOOST
template <typename T>
struct QxConvert_FromString<std::unordered_set<T>>
{
static inline qx_bool fromString(const QString &s, std::unordered_set<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 QxConvert_FromString<std::unordered_multiset<T>>
{
static inline qx_bool fromString(const QString &s, std::unordered_multiset<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);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_FromString<QVector<T>>
{
static inline qx_bool fromString(const QString &s, QVector<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);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_FromString<QList<T>>
{
static inline qx_bool fromString(const QString &s, QList<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);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
template <typename T>
struct QxConvert_FromString<QLinkedList<T>>
{
static inline qx_bool fromString(const QString &s, QLinkedList<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);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
template <typename T>
struct QxConvert_FromString<QFlags<T>>
{
static inline qx_bool fromString(const QString &s, QFlags<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = QFlags<T>(QFlag(s.toInt()));
return true;
}
};
template <typename Key, typename Value>
struct QxConvert_FromString<std::map<Key, Value>>
{
static inline qx_bool fromString(const QString &s, std::map<Key, Value> &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);
}
};
#ifdef _QX_ENABLE_BOOST
template <typename Key, typename Value>
struct QxConvert_FromString<boost::unordered_map<Key, Value>>
{
static inline qx_bool fromString(const QString &s, boost::unordered_map<Key, Value> &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 Key, typename Value>
struct QxConvert_FromString<boost::unordered_multimap<Key, Value>>
{
static inline qx_bool fromString(const QString &s, boost::unordered_multimap<Key, Value> &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);
}
};
#endif // _QX_ENABLE_BOOST
template <typename Key, typename Value>
struct QxConvert_FromString<std::unordered_map<Key, Value>>
{
static inline qx_bool fromString(const QString &s, std::unordered_map<Key, Value> &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 Key, typename Value>
struct QxConvert_FromString<std::unordered_multimap<Key, Value>>
{
static inline qx_bool fromString(const QString &s, std::unordered_multimap<Key, Value> &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 Key, typename Value>
struct QxConvert_FromString<QHash<Key, Value>>
{
static inline qx_bool fromString(const QString &s, QHash<Key, Value> &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 Key, typename Value>
struct QxConvert_FromString<QMultiHash<Key, Value>>
{
static inline qx_bool fromString(const QString &s, QMultiHash<Key, Value> &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 Key, typename Value>
struct QxConvert_FromString<QMap<Key, Value>>
{
static inline qx_bool fromString(const QString &s, QMap<Key, Value> &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 Key, typename Value>
struct QxConvert_FromString<QMultiMap<Key, Value>>
{
static inline qx_bool fromString(const QString &s, QMultiMap<Key, Value> &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 Key, typename Value>
struct QxConvert_FromString<qx::QxCollection<Key, Value>>
{
static inline qx_bool fromString(const QString &s, qx::QxCollection<Key, Value> &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);
}
};
#ifdef _QX_ENABLE_BOOST
template <typename T1>
struct QxConvert_FromString<boost::tuple<T1>>
{
static inline qx_bool fromString(const QString &s, boost::tuple<T1> &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 T1, typename T2>
struct QxConvert_FromString<boost::tuple<T1, T2>>
{
static inline qx_bool fromString(const QString &s, boost::tuple<T1, T2> &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 T1, typename T2, typename T3>
struct QxConvert_FromString<boost::tuple<T1, T2, T3>>
{
static inline qx_bool fromString(const QString &s, boost::tuple<T1, T2, T3> &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 T1, typename T2, typename T3, typename T4>
struct QxConvert_FromString<boost::tuple<T1, T2, T3, T4>>
{
static inline qx_bool fromString(const QString &s, boost::tuple<T1, T2, T3, T4> &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 T1, typename T2, typename T3, typename T4, typename T5>
struct QxConvert_FromString<boost::tuple<T1, T2, T3, T4, T5>>
{
static inline qx_bool fromString(const QString &s, boost::tuple<T1, T2, T3, T4, T5> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct QxConvert_FromString<boost::tuple<T1, T2, T3, T4, T5, T6>>
{
static inline qx_bool fromString(const QString &s, boost::tuple<T1, T2, T3, T4, T5, T6> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct QxConvert_FromString<boost::tuple<T1, T2, T3, T4, T5, T6, T7>>
{
static inline qx_bool fromString(const QString &s, boost::tuple<T1, T2, T3, T4, T5, T6, T7> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct QxConvert_FromString<boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8>>
{
static inline qx_bool fromString(const QString &s, boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct QxConvert_FromString<boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>>
{
static inline qx_bool fromString(const QString &s, boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> &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);
}
};
#endif // _QX_ENABLE_BOOST
template <typename T1>
struct QxConvert_FromString<std::tuple<T1>>
{
static inline qx_bool fromString(const QString &s, std::tuple<T1> &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 T1, typename T2>
struct QxConvert_FromString<std::tuple<T1, T2>>
{
static inline qx_bool fromString(const QString &s, std::tuple<T1, T2> &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 T1, typename T2, typename T3>
struct QxConvert_FromString<std::tuple<T1, T2, T3>>
{
static inline qx_bool fromString(const QString &s, std::tuple<T1, T2, T3> &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 T1, typename T2, typename T3, typename T4>
struct QxConvert_FromString<std::tuple<T1, T2, T3, T4>>
{
static inline qx_bool fromString(const QString &s, std::tuple<T1, T2, T3, T4> &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 T1, typename T2, typename T3, typename T4, typename T5>
struct QxConvert_FromString<std::tuple<T1, T2, T3, T4, T5>>
{
static inline qx_bool fromString(const QString &s, std::tuple<T1, T2, T3, T4, T5> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct QxConvert_FromString<std::tuple<T1, T2, T3, T4, T5, T6>>
{
static inline qx_bool fromString(const QString &s, std::tuple<T1, T2, T3, T4, T5, T6> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct QxConvert_FromString<std::tuple<T1, T2, T3, T4, T5, T6, T7>>
{
static inline qx_bool fromString(const QString &s, std::tuple<T1, T2, T3, T4, T5, T6, T7> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct QxConvert_FromString<std::tuple<T1, T2, T3, T4, T5, T6, T7, T8>>
{
static inline qx_bool fromString(const QString &s, std::tuple<T1, T2, T3, T4, T5, T6, T7, T8> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct QxConvert_FromString<std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>>
{
static inline qx_bool fromString(const QString &s, std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> &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);
}
};
} // namespace detail
} // namespace cvt
} // namespace qx

View File

@@ -0,0 +1,991 @@
/****************************************************************************
**
** 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_SERIALIZATION
#define QX_CVT_DEFAULT_ARCHIVE_FROM_VARIANT QX_CVT_DEFAULT_ARCHIVE::from_string(t, v.toString())
#else // _QX_ENABLE_BOOST_SERIALIZATION
#define QX_CVT_DEFAULT_ARCHIVE_FROM_VARIANT QX_CVT_DEFAULT_ARCHIVE::from_byte_array(t, v.toByteArray())
#endif // _QX_ENABLE_BOOST_SERIALIZATION
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_FromVariant<qx::trait::no_type>
{
static inline qx_bool fromVariant(const QVariant &v, qx::trait::no_type &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);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<bool>
{
static inline qx_bool fromVariant(const QVariant &v, bool &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toBool();
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<short>
{
static inline qx_bool fromVariant(const QVariant &v, short &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<short>(v.toInt(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromVariant<int>
{
static inline qx_bool fromVariant(const QVariant &v, int &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 = v.toInt(&bOk);
return bOk;
}
};
template <>
struct QxConvert_FromVariant<long>
{
static inline qx_bool fromVariant(const QVariant &v, long &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<long>(v.toLongLong(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromVariant<long long>
{
static inline qx_bool fromVariant(const QVariant &v, long long &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<long long>(v.toLongLong(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromVariant<float>
{
static inline qx_bool fromVariant(const QVariant &v, float &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<float>(v.toDouble(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromVariant<double>
{
static inline qx_bool fromVariant(const QVariant &v, double &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 = v.toDouble(&bOk);
return bOk;
}
};
template <>
struct QxConvert_FromVariant<unsigned short>
{
static inline qx_bool fromVariant(const QVariant &v, unsigned short &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<unsigned short>(v.toUInt(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromVariant<unsigned int>
{
static inline qx_bool fromVariant(const QVariant &v, unsigned int &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<unsigned int>(v.toUInt(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromVariant<unsigned long>
{
static inline qx_bool fromVariant(const QVariant &v, unsigned long &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<unsigned long>(v.toULongLong(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromVariant<unsigned long long>
{
static inline qx_bool fromVariant(const QVariant &v, unsigned long long &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<unsigned long long>(v.toULongLong(&bOk));
return bOk;
}
};
template <>
struct QxConvert_FromVariant<QDate>
{
static inline qx_bool fromVariant(const QVariant &v, QDate &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toDate();
return t.isValid();
}
};
template <>
struct QxConvert_FromVariant<QTime>
{
static inline qx_bool fromVariant(const QVariant &v, QTime &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toTime();
return t.isValid();
}
};
template <>
struct QxConvert_FromVariant<QDateTime>
{
static inline qx_bool fromVariant(const QVariant &v, QDateTime &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toDateTime();
return t.isValid();
}
};
template <>
struct QxConvert_FromVariant<QByteArray>
{
static inline qx_bool fromVariant(const QVariant &v, QByteArray &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toByteArray();
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<QString>
{
static inline qx_bool fromVariant(const QVariant &v, QString &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toString();
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<QVariant>
{
static inline qx_bool fromVariant(const QVariant &v, QVariant &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (ctx != qx::cvt::context::e_database)
{
t = v;
return qx_bool(true);
}
QString s = v.toString();
if (!s.startsWith("$$JSON$$"))
{
t = v;
return qx_bool(true);
}
return qx::cvt::detail::QxConvert_FromString<QVariant>::fromString(s, t, format, index, ctx);
}
};
template <>
struct QxConvert_FromVariant<QUuid>
{
static inline qx_bool fromVariant(const QVariant &v, QUuid &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = QUuid(v.toString());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<qx::QxDateNeutral>
{
static inline qx_bool fromVariant(const QVariant &v, qx::QxDateNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = qx::QxDateNeutral::fromNeutral(v.toString());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<qx::QxTimeNeutral>
{
static inline qx_bool fromVariant(const QVariant &v, qx::QxTimeNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = qx::QxTimeNeutral::fromNeutral(v.toString());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<qx::QxDateTimeNeutral>
{
static inline qx_bool fromVariant(const QVariant &v, qx::QxDateTimeNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = qx::QxDateTimeNeutral::fromNeutral(v.toString());
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<std::string>
{
static inline qx_bool fromVariant(const QVariant &v, std::string &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
#ifndef QT_NO_STL
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toString().toStdString();
return qx_bool(true);
}
};
#else // QT_NO_STL
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toString().toLatin1().constData();
return qx_bool(true);
}
};
#endif // QT_NO_STL
template <>
struct QxConvert_FromVariant<std::wstring>
{
static inline qx_bool fromVariant(const QVariant &v, std::wstring &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
#if ((!defined(QT_NO_STL)) && (!defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toString().toStdWString();
return qx_bool(true);
}
};
#else // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
Q_UNUSED(t);
Q_UNUSED(v);
qAssert(false); /* Need STL compatibility ! */
return qx_bool(true);
}
};
#endif // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
template <>
struct QxConvert_FromVariant<qx_bool>
{
static inline qx_bool fromVariant(const QVariant &v, qx_bool &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();
t.fromString(s);
return qx_bool(true);
}
};
#ifndef _QX_NO_JSON
template <>
struct QxConvert_FromVariant<QJsonValue>
{
static inline qx_bool fromVariant(const QVariant &v, QJsonValue &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = QJsonValue::fromVariant(v);
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<QJsonArray>
{
static inline qx_bool fromVariant(const QVariant &v, QJsonArray &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toJsonArray();
return qx_bool(true);
}
};
template <>
struct QxConvert_FromVariant<QJsonObject>
{
static inline qx_bool fromVariant(const QVariant &v, QJsonObject &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = v.toJsonObject();
return qx_bool(true);
}
};
#endif // _QX_NO_JSON
#ifdef _QX_ENABLE_BOOST
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);
}
};
#endif // _QX_ENABLE_BOOST
template <typename T1, typename T2>
struct QxConvert_FromVariant<std::pair<T1, T2>>
{
static inline qx_bool fromVariant(const QVariant &v, std::pair<T1, T2> &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_VARIANT;
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T1, typename T2>
struct QxConvert_FromVariant<QPair<T1, T2>>
{
static inline qx_bool fromVariant(const QVariant &v, QPair<T1, T2> &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_VARIANT;
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_FromVariant<std::vector<T>>
{
static inline qx_bool fromVariant(const QVariant &v, std::vector<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_VARIANT;
}
};
template <typename T>
struct QxConvert_FromVariant<std::list<T>>
{
static inline qx_bool fromVariant(const QVariant &v, std::list<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_VARIANT;
}
};
template <typename T>
struct QxConvert_FromVariant<std::set<T>>
{
static inline qx_bool fromVariant(const QVariant &v, std::set<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_VARIANT;
}
};
#ifdef _QX_ENABLE_BOOST
template <typename T>
struct QxConvert_FromVariant<boost::unordered_set<T>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::unordered_set<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_VARIANT;
}
};
template <typename T>
struct QxConvert_FromVariant<boost::unordered_multiset<T>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::unordered_multiset<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_VARIANT;
}
};
#endif // _QX_ENABLE_BOOST
template <typename T>
struct QxConvert_FromVariant<std::unordered_set<T>>
{
static inline qx_bool fromVariant(const QVariant &v, std::unordered_set<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_VARIANT;
}
};
template <typename T>
struct QxConvert_FromVariant<std::unordered_multiset<T>>
{
static inline qx_bool fromVariant(const QVariant &v, std::unordered_multiset<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_VARIANT;
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_FromVariant<QVector<T>>
{
static inline qx_bool fromVariant(const QVariant &v, QVector<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_VARIANT;
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_FromVariant<QList<T>>
{
static inline qx_bool fromVariant(const QVariant &v, QList<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_VARIANT;
}
};
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
template <typename T>
struct QxConvert_FromVariant<QLinkedList<T>>
{
static inline qx_bool fromVariant(const QVariant &v, QLinkedList<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_VARIANT;
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
template <typename T>
struct QxConvert_FromVariant<QFlags<T>>
{
static inline qx_bool fromVariant(const QVariant &v, QFlags<T> &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
t = QFlags<T>(QFlag(v.toInt()));
return true;
}
};
template <typename Key, typename Value>
struct QxConvert_FromVariant<std::map<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, std::map<Key, Value> &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_VARIANT;
}
};
#ifdef _QX_ENABLE_BOOST
template <typename Key, typename Value>
struct QxConvert_FromVariant<boost::unordered_map<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::unordered_map<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_FromVariant<boost::unordered_multimap<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::unordered_multimap<Key, Value> &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_VARIANT;
}
};
#endif // _QX_ENABLE_BOOST
template <typename Key, typename Value>
struct QxConvert_FromVariant<std::unordered_map<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, std::unordered_map<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_FromVariant<std::unordered_multimap<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, std::unordered_multimap<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_FromVariant<QHash<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, QHash<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_FromVariant<QMultiHash<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, QMultiHash<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_FromVariant<QMap<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, QMap<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_FromVariant<QMultiMap<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, QMultiMap<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_FromVariant<qx::QxCollection<Key, Value>>
{
static inline qx_bool fromVariant(const QVariant &v, qx::QxCollection<Key, Value> &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_VARIANT;
}
};
#ifdef _QX_ENABLE_BOOST
template <typename T1>
struct QxConvert_FromVariant<boost::tuple<T1>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::tuple<T1> &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_VARIANT;
}
};
template <typename T1, typename T2>
struct QxConvert_FromVariant<boost::tuple<T1, T2>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::tuple<T1, T2> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3>
struct QxConvert_FromVariant<boost::tuple<T1, T2, T3>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::tuple<T1, T2, T3> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4>
struct QxConvert_FromVariant<boost::tuple<T1, T2, T3, T4>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::tuple<T1, T2, T3, T4> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5>
struct QxConvert_FromVariant<boost::tuple<T1, T2, T3, T4, T5>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::tuple<T1, T2, T3, T4, T5> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct QxConvert_FromVariant<boost::tuple<T1, T2, T3, T4, T5, T6>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::tuple<T1, T2, T3, T4, T5, T6> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct QxConvert_FromVariant<boost::tuple<T1, T2, T3, T4, T5, T6, T7>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::tuple<T1, T2, T3, T4, T5, T6, T7> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct QxConvert_FromVariant<boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct QxConvert_FromVariant<boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>>
{
static inline qx_bool fromVariant(const QVariant &v, boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> &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_VARIANT;
}
};
#endif // _QX_ENABLE_BOOST
template <typename T1>
struct QxConvert_FromVariant<std::tuple<T1>>
{
static inline qx_bool fromVariant(const QVariant &v, std::tuple<T1> &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_VARIANT;
}
};
template <typename T1, typename T2>
struct QxConvert_FromVariant<std::tuple<T1, T2>>
{
static inline qx_bool fromVariant(const QVariant &v, std::tuple<T1, T2> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3>
struct QxConvert_FromVariant<std::tuple<T1, T2, T3>>
{
static inline qx_bool fromVariant(const QVariant &v, std::tuple<T1, T2, T3> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4>
struct QxConvert_FromVariant<std::tuple<T1, T2, T3, T4>>
{
static inline qx_bool fromVariant(const QVariant &v, std::tuple<T1, T2, T3, T4> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5>
struct QxConvert_FromVariant<std::tuple<T1, T2, T3, T4, T5>>
{
static inline qx_bool fromVariant(const QVariant &v, std::tuple<T1, T2, T3, T4, T5> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct QxConvert_FromVariant<std::tuple<T1, T2, T3, T4, T5, T6>>
{
static inline qx_bool fromVariant(const QVariant &v, std::tuple<T1, T2, T3, T4, T5, T6> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct QxConvert_FromVariant<std::tuple<T1, T2, T3, T4, T5, T6, T7>>
{
static inline qx_bool fromVariant(const QVariant &v, std::tuple<T1, T2, T3, T4, T5, T6, T7> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct QxConvert_FromVariant<std::tuple<T1, T2, T3, T4, T5, T6, T7, T8>>
{
static inline qx_bool fromVariant(const QVariant &v, std::tuple<T1, T2, T3, T4, T5, T6, T7, T8> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct QxConvert_FromVariant<std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>>
{
static inline qx_bool fromVariant(const QVariant &v, std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> &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_VARIANT;
}
};
} // namespace detail
} // namespace cvt
} // namespace qx

View File

@@ -0,0 +1,71 @@
/****************************************************************************
**
** 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_STRING_CVT_QT_H_
#define _QX_STRING_CVT_QT_H_
#ifdef _MSC_VER
#pragma once
#endif
#include <QxConvert/QxConvert.h>
#include <QxConvert/QxConvert_Impl.h>
QX_CVT_USING_ARCHIVE_IMPL(QObject)
QX_CVT_USING_ARCHIVE_IMPL(QPoint)
QX_CVT_USING_ARCHIVE_IMPL(QRect)
QX_CVT_USING_ARCHIVE_IMPL(QSize)
QX_CVT_USING_ARCHIVE_IMPL(QStringList)
QX_CVT_USING_ARCHIVE_IMPL(QUrl)
QX_CVT_USING_ARCHIVE_IMPL(QSqlError)
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_CVT_USING_ARCHIVE_IMPL(QRegExp)
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
#ifdef _QX_ENABLE_QT_GUI
QX_CVT_USING_ARCHIVE_IMPL(QBrush)
QX_CVT_USING_ARCHIVE_IMPL(QColor)
QX_CVT_USING_ARCHIVE_IMPL(QFont)
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_CVT_USING_ARCHIVE_IMPL(QMatrix)
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_CVT_USING_ARCHIVE_IMPL(QRegion)
QX_CVT_USING_ARCHIVE_IMPL(QImage)
QX_CVT_USING_ARCHIVE_IMPL(QPicture)
QX_CVT_USING_ARCHIVE_IMPL(QPixmap)
#endif // _QX_ENABLE_QT_GUI
QX_CVT_USING_ARCHIVE_IMPL(qx::QxSqlQuery)
QX_CVT_USING_ARCHIVE_IMPL(qx::QxInvalidValue)
QX_CVT_USING_ARCHIVE_IMPL(qx::QxInvalidValueX)
#endif // _QX_STRING_CVT_QT_H_

View File

@@ -0,0 +1,387 @@
/****************************************************************************
**
** 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_NO_JSON
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_ToJson<qx::trait::no_type>
{
static inline QJsonValue toJson(const qx::trait::no_type &t, const QString &format)
{
Q_UNUSED(t);
Q_UNUSED(format);
return QJsonValue();
}
};
template <>
struct QxConvert_ToJson<bool>
{
static inline QJsonValue toJson(const bool &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(t);
}
};
template <>
struct QxConvert_ToJson<short>
{
static inline QJsonValue toJson(const short &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(static_cast<int>(t));
}
};
template <>
struct QxConvert_ToJson<int>
{
static inline QJsonValue toJson(const int &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(t);
}
};
template <>
struct QxConvert_ToJson<long>
{
static inline QJsonValue toJson(const long &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(static_cast<double>(t));
}
};
template <>
struct QxConvert_ToJson<long long>
{
static inline QJsonValue toJson(const long long &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(static_cast<double>(t));
}
};
template <>
struct QxConvert_ToJson<float>
{
static inline QJsonValue toJson(const float &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(static_cast<double>(t));
}
};
template <>
struct QxConvert_ToJson<double>
{
static inline QJsonValue toJson(const double &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(t);
}
};
template <>
struct QxConvert_ToJson<unsigned short>
{
static inline QJsonValue toJson(const unsigned short &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(static_cast<int>(t));
}
};
template <>
struct QxConvert_ToJson<unsigned int>
{
static inline QJsonValue toJson(const unsigned int &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(static_cast<int>(t));
}
};
template <>
struct QxConvert_ToJson<unsigned long>
{
static inline QJsonValue toJson(const unsigned long &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(static_cast<double>(t));
}
};
template <>
struct QxConvert_ToJson<unsigned long long>
{
static inline QJsonValue toJson(const unsigned long long &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(static_cast<double>(t));
}
};
template <>
struct QxConvert_ToJson<QDateTime>
{
static inline QJsonValue toJson(const QDateTime &t, const QString &format)
{
#ifdef _QX_ENABLE_MONGODB
if (t.isValid() && format.startsWith("mongodb"))
{
QString dt = t.toString(QX_JSON_DATE_TIME_FORMAT);
if (dt.count() <= QX_JSON_DATE_TIME_FORMAT_SIZE)
{
dt += "Z";
}
QJsonObject obj;
obj.insert("$date", QJsonValue(dt));
return QJsonValue(obj);
}
#endif // _QX_ENABLE_MONGODB
Q_UNUSED(format);
if (t.isValid())
{
return QJsonValue(t.toString(QX_JSON_DATE_TIME_FORMAT));
};
return QJsonValue();
}
};
template <>
struct QxConvert_ToJson<QDate>
{
static inline QJsonValue toJson(const QDate &t, const QString &format)
{
#ifdef _QX_ENABLE_MONGODB
if (t.isValid() && format.startsWith("mongodb"))
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
{
QTime time = ((t.isValid()) ? QTime(0, 0) : QTime());
QDateTime dt(t, time);
return QxConvert_ToJson<QDateTime>::toJson(dt, format);
}
#else // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
{
QDateTime dt(t);
return QxConvert_ToJson<QDateTime>::toJson(dt, format);
}
#endif // (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
#endif // _QX_ENABLE_MONGODB
Q_UNUSED(format);
if (t.isValid())
{
return QJsonValue(t.toString(Qt::ISODate));
};
return QJsonValue();
}
};
template <>
struct QxConvert_ToJson<QTime>
{
static inline QJsonValue toJson(const QTime &t, const QString &format)
{
Q_UNUSED(format);
if (t.isValid())
{
return QJsonValue(t.toString(QX_JSON_DATE_TIME_FORMAT));
};
return QJsonValue();
}
};
template <>
struct QxConvert_ToJson<QByteArray>
{
static inline QJsonValue toJson(const QByteArray &t, const QString &format)
{
Q_UNUSED(format);
QString s = t.toBase64();
return QJsonValue(s);
}
};
template <>
struct QxConvert_ToJson<QString>
{
static inline QJsonValue toJson(const QString &t, const QString &format)
{
#ifdef _QX_ENABLE_MONGODB
if (t.startsWith("qx_oid:") && format.startsWith("mongodb"))
{
QJsonObject obj;
obj.insert("$oid", QJsonValue(t.right(t.size() - 7)));
return QJsonValue(obj);
}
#endif // _QX_ENABLE_MONGODB
Q_UNUSED(format);
return QJsonValue(t);
}
};
template <>
struct QxConvert_ToJson<QVariant>
{
static inline QJsonValue toJson(const QVariant &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue::fromVariant(t);
}
};
template <>
struct QxConvert_ToJson<QUuid>
{
static inline QJsonValue toJson(const QUuid &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(t.toString());
}
};
template <>
struct QxConvert_ToJson<qx::QxDateNeutral>
{
static inline QJsonValue toJson(const qx::QxDateNeutral &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(t.toNeutral());
}
};
template <>
struct QxConvert_ToJson<qx::QxTimeNeutral>
{
static inline QJsonValue toJson(const qx::QxTimeNeutral &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(t.toNeutral());
}
};
template <>
struct QxConvert_ToJson<qx::QxDateTimeNeutral>
{
static inline QJsonValue toJson(const qx::QxDateTimeNeutral &t, const QString &format)
{
Q_UNUSED(format);
return QJsonValue(t.toNeutral());
}
};
template <>
struct QxConvert_ToJson<std::string>
{
static inline QJsonValue toJson(const std::string &t, const QString &format)
#ifndef QT_NO_STL
{
Q_UNUSED(format);
return QJsonValue(QString::fromStdString(t));
}
};
#else // QT_NO_STL
{
Q_UNUSED(format);
return QJsonValue(QString::fromLatin1(t.data(), int(t.size())));
}
};
#endif // QT_NO_STL
template <>
struct QxConvert_ToJson<std::wstring>
{
static inline QJsonValue toJson(const std::wstring &t, const QString &format)
#if ((!defined(QT_NO_STL)) && (!defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
return QJsonValue(QString::fromStdWString(t));
}
};
#else // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(t);
qAssert(false); /* Need STL compatibility ! */
return QJsonValue();
}
};
#endif // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
template <>
struct QxConvert_ToJson<qx_bool>
{
static inline QJsonValue toJson(const qx_bool &t, const QString &format)
{
Q_UNUSED(format);
QJsonObject obj;
obj["value"] = t.getValue();
obj["code"] = static_cast<double>(t.getCode());
obj["desc"] = t.getDesc();
return QJsonValue(obj);
}
};
#ifdef _QX_ENABLE_BOOST
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();
}
};
#endif // _QX_ENABLE_BOOST
} // namespace detail
} // namespace cvt
} // namespace qx
#endif // _QX_NO_JSON

View File

@@ -0,0 +1,923 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_ToString<qx::trait::no_type>
{
static inline QString toString(const qx::trait::no_type &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return "";
}
};
template <>
struct QxConvert_ToString<QString>
{
static inline QString toString(const QString &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return t;
}
};
template <>
struct QxConvert_ToString<QUuid>
{
static inline QString toString(const QUuid &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toString();
}
};
template <>
struct QxConvert_ToString<QDate>
{
static inline QString toString(const QDate &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toString(format.isEmpty() ? QString(QX_STR_CVT_QDATE_FORMAT) : format);
}
};
template <>
struct QxConvert_ToString<QTime>
{
static inline QString toString(const QTime &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toString(format.isEmpty() ? QString(QX_STR_CVT_QTIME_FORMAT) : format);
}
};
template <>
struct QxConvert_ToString<QDateTime>
{
static inline QString toString(const QDateTime &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toString(format.isEmpty() ? QString(QX_STR_CVT_QDATETIME_FORMAT) : format);
}
};
template <>
struct QxConvert_ToString<QByteArray>
{
static inline QString toString(const QByteArray &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString(t);
}
};
template <>
struct QxConvert_ToString<QVariant>
{
static inline QString toString(const QVariant &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
#ifndef _QX_NO_JSON
if (qx::cvt::detail::helper::checkConvertQVariantToString(t))
{
QString type = QString("%1").arg(static_cast<int>(t.type()), 6, 10, QChar('0'));
QString val = "$$JSON$$" + type + "$$";
QJsonValue json = QJsonValue::fromVariant(t);
QJsonDocument doc = (json.isArray() ? QJsonDocument(json.toArray()) : QJsonDocument(json.toObject()));
return (val + QString::fromUtf8(doc.toJson()));
}
#endif // _QX_NO_JSON
return t.toString();
}
};
template <>
struct QxConvert_ToString<qx_bool>
{
static inline QString toString(const qx_bool &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toString();
}
};
template <>
struct QxConvert_ToString<bool>
{
static inline QString toString(const bool &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return (t ? "1" : "0");
}
};
template <>
struct QxConvert_ToString<char>
{
static inline QString toString(const char &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString(t);
}
};
template <>
struct QxConvert_ToString<short>
{
static inline QString toString(const short &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<int>
{
static inline QString toString(const int &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<long>
{
static inline QString toString(const long &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<long long>
{
static inline QString toString(const long long &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<float>
{
static inline QString toString(const float &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<double>
{
static inline QString toString(const double &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<unsigned short>
{
static inline QString toString(const unsigned short &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<unsigned int>
{
static inline QString toString(const unsigned int &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<unsigned long>
{
static inline QString toString(const unsigned long &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<unsigned long long>
{
static inline QString toString(const unsigned long long &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
return (format.isEmpty() ? QString::number(t) : QString(format).arg(t));
}
};
template <>
struct QxConvert_ToString<qx::QxDateNeutral>
{
static inline QString toString(const qx::QxDateNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toNeutral();
}
};
template <>
struct QxConvert_ToString<qx::QxTimeNeutral>
{
static inline QString toString(const qx::QxTimeNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toNeutral();
}
};
template <>
struct QxConvert_ToString<qx::QxDateTimeNeutral>
{
static inline QString toString(const qx::QxDateTimeNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toNeutral();
}
};
template <>
struct QxConvert_ToString<std::string>
{
static inline QString toString(const std::string &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
#ifndef QT_NO_STL
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString::fromStdString(t);
}
};
#else // QT_NO_STL
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString::fromLatin1(t.data(), int(t.size()));
}
};
#endif // QT_NO_STL
template <>
struct QxConvert_ToString<std::wstring>
{
static inline QString toString(const std::wstring &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
#if ((!defined(QT_NO_STL)) && (!defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString::fromStdWString(t);
}
};
#else // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
Q_UNUSED(t);
qAssert(false); /* Need STL compatibility ! */
return QString();
}
};
#endif // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
#ifndef _QX_NO_JSON
template <>
struct QxConvert_ToString<QJsonValue>
{
static inline QString toString(const QJsonValue &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(index);
Q_UNUSED(ctx);
QJsonDocument::JsonFormat jsonFormat = QJsonDocument::Compact;
if (!format.isEmpty())
{
jsonFormat = ((format == "indented") ? QJsonDocument::Indented : jsonFormat);
}
QJsonDocument doc = (t.isArray() ? QJsonDocument(t.toArray()) : QJsonDocument(t.toObject()));
return QString::fromUtf8(doc.toJson(jsonFormat));
}
};
#endif // _QX_NO_JSON
#ifdef _QX_ENABLE_BOOST
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();
}
};
#endif // _QX_ENABLE_BOOST
template <typename T1, typename T2>
struct QxConvert_ToString<std::pair<T1, T2>>
{
static inline QString toString(const std::pair<T1, T2> &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);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T1, typename T2>
struct QxConvert_ToString<QPair<T1, T2>>
{
static inline QString toString(const QPair<T1, T2> &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);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_ToString<std::vector<T>>
{
static inline QString toString(const std::vector<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 QxConvert_ToString<std::list<T>>
{
static inline QString toString(const std::list<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 QxConvert_ToString<std::set<T>>
{
static inline QString toString(const std::set<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);
}
};
#ifdef _QX_ENABLE_BOOST
template <typename T>
struct QxConvert_ToString<boost::unordered_set<T>>
{
static inline QString toString(const boost::unordered_set<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 QxConvert_ToString<boost::unordered_multiset<T>>
{
static inline QString toString(const boost::unordered_multiset<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);
}
};
#endif // _QX_ENABLE_BOOST
template <typename T>
struct QxConvert_ToString<std::unordered_set<T>>
{
static inline QString toString(const std::unordered_set<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 QxConvert_ToString<std::unordered_multiset<T>>
{
static inline QString toString(const std::unordered_multiset<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);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_ToString<QVector<T>>
{
static inline QString toString(const QVector<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);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_ToString<QList<T>>
{
static inline QString toString(const QList<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);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
template <typename T>
struct QxConvert_ToString<QLinkedList<T>>
{
static inline QString toString(const QLinkedList<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);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
template <typename T>
struct QxConvert_ToString<QFlags<T>>
{
static inline QString toString(const QFlags<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<int>(t));
}
};
template <typename Key, typename Value>
struct QxConvert_ToString<std::map<Key, Value>>
{
static inline QString toString(const std::map<Key, Value> &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);
}
};
#ifdef _QX_ENABLE_BOOST
template <typename Key, typename Value>
struct QxConvert_ToString<boost::unordered_map<Key, Value>>
{
static inline QString toString(const boost::unordered_map<Key, Value> &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 Key, typename Value>
struct QxConvert_ToString<boost::unordered_multimap<Key, Value>>
{
static inline QString toString(const boost::unordered_multimap<Key, Value> &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);
}
};
#endif // _QX_ENABLE_BOOST
template <typename Key, typename Value>
struct QxConvert_ToString<std::unordered_map<Key, Value>>
{
static inline QString toString(const std::unordered_map<Key, Value> &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 Key, typename Value>
struct QxConvert_ToString<std::unordered_multimap<Key, Value>>
{
static inline QString toString(const std::unordered_multimap<Key, Value> &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 Key, typename Value>
struct QxConvert_ToString<QHash<Key, Value>>
{
static inline QString toString(const QHash<Key, Value> &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 Key, typename Value>
struct QxConvert_ToString<QMultiHash<Key, Value>>
{
static inline QString toString(const QMultiHash<Key, Value> &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 Key, typename Value>
struct QxConvert_ToString<QMap<Key, Value>>
{
static inline QString toString(const QMap<Key, Value> &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 Key, typename Value>
struct QxConvert_ToString<QMultiMap<Key, Value>>
{
static inline QString toString(const QMultiMap<Key, Value> &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 Key, typename Value>
struct QxConvert_ToString<qx::QxCollection<Key, Value>>
{
static inline QString toString(const qx::QxCollection<Key, Value> &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);
}
};
#ifdef _QX_ENABLE_BOOST
template <typename T1>
struct QxConvert_ToString<boost::tuple<T1>>
{
static inline QString toString(const boost::tuple<T1> &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 T1, typename T2>
struct QxConvert_ToString<boost::tuple<T1, T2>>
{
static inline QString toString(const boost::tuple<T1, T2> &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 T1, typename T2, typename T3>
struct QxConvert_ToString<boost::tuple<T1, T2, T3>>
{
static inline QString toString(const boost::tuple<T1, T2, T3> &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 T1, typename T2, typename T3, typename T4>
struct QxConvert_ToString<boost::tuple<T1, T2, T3, T4>>
{
static inline QString toString(const boost::tuple<T1, T2, T3, T4> &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 T1, typename T2, typename T3, typename T4, typename T5>
struct QxConvert_ToString<boost::tuple<T1, T2, T3, T4, T5>>
{
static inline QString toString(const boost::tuple<T1, T2, T3, T4, T5> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct QxConvert_ToString<boost::tuple<T1, T2, T3, T4, T5, T6>>
{
static inline QString toString(const boost::tuple<T1, T2, T3, T4, T5, T6> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct QxConvert_ToString<boost::tuple<T1, T2, T3, T4, T5, T6, T7>>
{
static inline QString toString(const boost::tuple<T1, T2, T3, T4, T5, T6, T7> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct QxConvert_ToString<boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8>>
{
static inline QString toString(const boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct QxConvert_ToString<boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>>
{
static inline QString toString(const boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> &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);
}
};
#endif // _QX_ENABLE_BOOST
template <typename T1>
struct QxConvert_ToString<std::tuple<T1>>
{
static inline QString toString(const std::tuple<T1> &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 T1, typename T2>
struct QxConvert_ToString<std::tuple<T1, T2>>
{
static inline QString toString(const std::tuple<T1, T2> &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 T1, typename T2, typename T3>
struct QxConvert_ToString<std::tuple<T1, T2, T3>>
{
static inline QString toString(const std::tuple<T1, T2, T3> &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 T1, typename T2, typename T3, typename T4>
struct QxConvert_ToString<std::tuple<T1, T2, T3, T4>>
{
static inline QString toString(const std::tuple<T1, T2, T3, T4> &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 T1, typename T2, typename T3, typename T4, typename T5>
struct QxConvert_ToString<std::tuple<T1, T2, T3, T4, T5>>
{
static inline QString toString(const std::tuple<T1, T2, T3, T4, T5> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct QxConvert_ToString<std::tuple<T1, T2, T3, T4, T5, T6>>
{
static inline QString toString(const std::tuple<T1, T2, T3, T4, T5, T6> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct QxConvert_ToString<std::tuple<T1, T2, T3, T4, T5, T6, T7>>
{
static inline QString toString(const std::tuple<T1, T2, T3, T4, T5, T6, T7> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct QxConvert_ToString<std::tuple<T1, T2, T3, T4, T5, T6, T7, T8>>
{
static inline QString toString(const std::tuple<T1, T2, T3, T4, T5, T6, T7, T8> &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 T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct QxConvert_ToString<std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>>
{
static inline QString toString(const std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> &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);
}
};
} // namespace detail
} // namespace cvt
} // namespace qx

View File

@@ -0,0 +1,946 @@
/****************************************************************************
**
** 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_SERIALIZATION
#define QX_CVT_DEFAULT_ARCHIVE_TO_VARIANT QX_CVT_DEFAULT_ARCHIVE::to_string(t)
#else // _QX_ENABLE_BOOST_SERIALIZATION
#define QX_CVT_DEFAULT_ARCHIVE_TO_VARIANT QX_CVT_DEFAULT_ARCHIVE::to_byte_array(t)
#endif // _QX_ENABLE_BOOST_SERIALIZATION
#include <QxTraits/construct_null_qvariant.h>
namespace qx
{
namespace cvt
{
namespace detail
{
template <>
struct QxConvert_ToVariant<qx::trait::no_type>
{
static inline QVariant toVariant(const qx::trait::no_type &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(t);
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QVariant();
}
};
template <>
struct QxConvert_ToVariant<bool>
{
static inline QVariant toVariant(const bool &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 <>
struct QxConvert_ToVariant<short>
{
static inline QVariant toVariant(const short &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<int>(t));
}
};
template <>
struct QxConvert_ToVariant<int>
{
static inline QVariant toVariant(const int &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 <>
struct QxConvert_ToVariant<long>
{
static inline QVariant toVariant(const long &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 <>
struct QxConvert_ToVariant<long long>
{
static inline QVariant toVariant(const long long &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 <>
struct QxConvert_ToVariant<float>
{
static inline QVariant toVariant(const float &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<double>(t));
}
};
template <>
struct QxConvert_ToVariant<double>
{
static inline QVariant toVariant(const double &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 <>
struct QxConvert_ToVariant<unsigned short>
{
static inline QVariant toVariant(const unsigned short &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<unsigned int>(t));
}
};
template <>
struct QxConvert_ToVariant<unsigned int>
{
static inline QVariant toVariant(const unsigned int &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 <>
struct QxConvert_ToVariant<unsigned long>
{
static inline QVariant toVariant(const unsigned long &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<qulonglong>(t));
}
};
template <>
struct QxConvert_ToVariant<unsigned long long>
{
static inline QVariant toVariant(const unsigned long long &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<qulonglong>(t));
}
};
template <>
struct QxConvert_ToVariant<QDate>
{
static inline QVariant toVariant(const QDate &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 <>
struct QxConvert_ToVariant<QTime>
{
static inline QVariant toVariant(const QTime &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 <>
struct QxConvert_ToVariant<QDateTime>
{
static inline QVariant toVariant(const QDateTime &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 <>
struct QxConvert_ToVariant<QByteArray>
{
static inline QVariant toVariant(const QByteArray &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 <>
struct QxConvert_ToVariant<QString>
{
static inline QVariant toVariant(const QString &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 <>
struct QxConvert_ToVariant<QVariant>
{
static inline QVariant toVariant(const QVariant &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
if (ctx != qx::cvt::context::e_database)
{
return t;
}
if (!qx::cvt::detail::helper::checkConvertQVariantToString(t))
{
return t;
}
return QVariant(qx::cvt::detail::QxConvert_ToString<QVariant>::toString(t, format, index, ctx));
}
};
template <>
struct QxConvert_ToVariant<QUuid>
{
static inline QVariant toVariant(const QUuid &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QVariant(t.toString());
}
};
template <>
struct QxConvert_ToVariant<qx::QxDateNeutral>
{
static inline QVariant toVariant(const qx::QxDateNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QVariant(t.toNeutral());
}
};
template <>
struct QxConvert_ToVariant<qx::QxTimeNeutral>
{
static inline QVariant toVariant(const qx::QxTimeNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QVariant(t.toNeutral());
}
};
template <>
struct QxConvert_ToVariant<qx::QxDateTimeNeutral>
{
static inline QVariant toVariant(const qx::QxDateTimeNeutral &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QVariant(t.toNeutral());
}
};
template <>
struct QxConvert_ToVariant<std::string>
{
static inline QVariant toVariant(const std::string &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
#ifndef QT_NO_STL
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString::fromStdString(t);
}
};
#else // QT_NO_STL
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString::fromLatin1(t.data(), int(t.size()));
}
};
#endif // QT_NO_STL
template <>
struct QxConvert_ToVariant<std::wstring>
{
static inline QVariant toVariant(const std::wstring &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
#if ((!defined(QT_NO_STL)) && (!defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return QString::fromStdWString(t);
}
};
#else // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
Q_UNUSED(t);
qAssert(false); /* Need STL compatibility ! */
return QVariant();
}
};
#endif // ((! defined(QT_NO_STL)) && (! defined(QT_NO_STL_WCHAR)))
template <>
struct QxConvert_ToVariant<qx_bool>
{
static inline QVariant toVariant(const qx_bool &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toString();
}
};
#ifndef _QX_NO_JSON
template <>
struct QxConvert_ToVariant<QJsonValue>
{
static inline QVariant toVariant(const QJsonValue &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
return t.toVariant();
}
};
template <>
struct QxConvert_ToVariant<QJsonArray>
{
static inline QVariant toVariant(const QJsonArray &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
QVariant var(t);
return var;
}
};
template <>
struct QxConvert_ToVariant<QJsonObject>
{
static inline QVariant toVariant(const QJsonObject &t, const QString &format, int index, qx::cvt::context::ctx_type ctx)
{
Q_UNUSED(format);
Q_UNUSED(index);
Q_UNUSED(ctx);
QVariant var(t);
return var;
}
};
#endif // _QX_NO_JSON
#ifdef _QX_ENABLE_BOOST
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();
}
};
#endif // _QX_ENABLE_BOOST
template <typename T1, typename T2>
struct QxConvert_ToVariant<std::pair<T1, T2>>
{
static inline QVariant toVariant(const std::pair<T1, T2> &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_VARIANT;
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T1, typename T2>
struct QxConvert_ToVariant<QPair<T1, T2>>
{
static inline QVariant toVariant(const QPair<T1, T2> &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_VARIANT;
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_ToVariant<std::vector<T>>
{
static inline QVariant toVariant(const std::vector<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_VARIANT;
}
};
template <typename T>
struct QxConvert_ToVariant<std::list<T>>
{
static inline QVariant toVariant(const std::list<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_VARIANT;
}
};
template <typename T>
struct QxConvert_ToVariant<std::set<T>>
{
static inline QVariant toVariant(const std::set<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_VARIANT;
}
};
#ifdef _QX_ENABLE_BOOST
template <typename T>
struct QxConvert_ToVariant<boost::unordered_set<T>>
{
static inline QVariant toVariant(const boost::unordered_set<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_VARIANT;
}
};
template <typename T>
struct QxConvert_ToVariant<boost::unordered_multiset<T>>
{
static inline QVariant toVariant(const boost::unordered_multiset<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_VARIANT;
}
};
#endif // _QX_ENABLE_BOOST
template <typename T>
struct QxConvert_ToVariant<std::unordered_set<T>>
{
static inline QVariant toVariant(const std::unordered_set<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_VARIANT;
}
};
template <typename T>
struct QxConvert_ToVariant<std::unordered_multiset<T>>
{
static inline QVariant toVariant(const std::unordered_multiset<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_VARIANT;
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_ToVariant<QVector<T>>
{
static inline QVariant toVariant(const QVector<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_VARIANT;
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename T>
struct QxConvert_ToVariant<QList<T>>
{
static inline QVariant toVariant(const QList<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_VARIANT;
}
};
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
template <typename T>
struct QxConvert_ToVariant<QLinkedList<T>>
{
static inline QVariant toVariant(const QLinkedList<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_VARIANT;
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
template <typename T>
struct QxConvert_ToVariant<QFlags<T>>
{
static inline QVariant toVariant(const QFlags<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<int>(t));
}
};
template <typename Key, typename Value>
struct QxConvert_ToVariant<std::map<Key, Value>>
{
static inline QVariant toVariant(const std::map<Key, Value> &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_VARIANT;
}
};
#ifdef _QX_ENABLE_BOOST
template <typename Key, typename Value>
struct QxConvert_ToVariant<boost::unordered_map<Key, Value>>
{
static inline QVariant toVariant(const boost::unordered_map<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_ToVariant<boost::unordered_multimap<Key, Value>>
{
static inline QVariant toVariant(const boost::unordered_multimap<Key, Value> &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_VARIANT;
}
};
#endif // _QX_ENABLE_BOOST
template <typename Key, typename Value>
struct QxConvert_ToVariant<std::unordered_map<Key, Value>>
{
static inline QVariant toVariant(const std::unordered_map<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_ToVariant<std::unordered_multimap<Key, Value>>
{
static inline QVariant toVariant(const std::unordered_multimap<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_ToVariant<QHash<Key, Value>>
{
static inline QVariant toVariant(const QHash<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_ToVariant<QMultiHash<Key, Value>>
{
static inline QVariant toVariant(const QMultiHash<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_ToVariant<QMap<Key, Value>>
{
static inline QVariant toVariant(const QMap<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_ToVariant<QMultiMap<Key, Value>>
{
static inline QVariant toVariant(const QMultiMap<Key, Value> &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_VARIANT;
}
};
template <typename Key, typename Value>
struct QxConvert_ToVariant<qx::QxCollection<Key, Value>>
{
static inline QVariant toVariant(const qx::QxCollection<Key, Value> &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_VARIANT;
}
};
#ifdef _QX_ENABLE_BOOST
template <typename T1>
struct QxConvert_ToVariant<boost::tuple<T1>>
{
static inline QVariant toVariant(const boost::tuple<T1> &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_VARIANT;
}
};
template <typename T1, typename T2>
struct QxConvert_ToVariant<boost::tuple<T1, T2>>
{
static inline QVariant toVariant(const boost::tuple<T1, T2> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3>
struct QxConvert_ToVariant<boost::tuple<T1, T2, T3>>
{
static inline QVariant toVariant(const boost::tuple<T1, T2, T3> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4>
struct QxConvert_ToVariant<boost::tuple<T1, T2, T3, T4>>
{
static inline QVariant toVariant(const boost::tuple<T1, T2, T3, T4> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5>
struct QxConvert_ToVariant<boost::tuple<T1, T2, T3, T4, T5>>
{
static inline QVariant toVariant(const boost::tuple<T1, T2, T3, T4, T5> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct QxConvert_ToVariant<boost::tuple<T1, T2, T3, T4, T5, T6>>
{
static inline QVariant toVariant(const boost::tuple<T1, T2, T3, T4, T5, T6> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct QxConvert_ToVariant<boost::tuple<T1, T2, T3, T4, T5, T6, T7>>
{
static inline QVariant toVariant(const boost::tuple<T1, T2, T3, T4, T5, T6, T7> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct QxConvert_ToVariant<boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8>>
{
static inline QVariant toVariant(const boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct QxConvert_ToVariant<boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>>
{
static inline QVariant toVariant(const boost::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> &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_VARIANT;
}
};
#endif // _QX_ENABLE_BOOST
template <typename T1>
struct QxConvert_ToVariant<std::tuple<T1>>
{
static inline QVariant toVariant(const std::tuple<T1> &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_VARIANT;
}
};
template <typename T1, typename T2>
struct QxConvert_ToVariant<std::tuple<T1, T2>>
{
static inline QVariant toVariant(const std::tuple<T1, T2> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3>
struct QxConvert_ToVariant<std::tuple<T1, T2, T3>>
{
static inline QVariant toVariant(const std::tuple<T1, T2, T3> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4>
struct QxConvert_ToVariant<std::tuple<T1, T2, T3, T4>>
{
static inline QVariant toVariant(const std::tuple<T1, T2, T3, T4> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5>
struct QxConvert_ToVariant<std::tuple<T1, T2, T3, T4, T5>>
{
static inline QVariant toVariant(const std::tuple<T1, T2, T3, T4, T5> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6>
struct QxConvert_ToVariant<std::tuple<T1, T2, T3, T4, T5, T6>>
{
static inline QVariant toVariant(const std::tuple<T1, T2, T3, T4, T5, T6> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7>
struct QxConvert_ToVariant<std::tuple<T1, T2, T3, T4, T5, T6, T7>>
{
static inline QVariant toVariant(const std::tuple<T1, T2, T3, T4, T5, T6, T7> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8>
struct QxConvert_ToVariant<std::tuple<T1, T2, T3, T4, T5, T6, T7, T8>>
{
static inline QVariant toVariant(const std::tuple<T1, T2, T3, T4, T5, T6, T7, T8> &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_VARIANT;
}
};
template <typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9>
struct QxConvert_ToVariant<std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9>>
{
static inline QVariant toVariant(const std::tuple<T1, T2, T3, T4, T5, T6, T7, T8, T9> &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_VARIANT;
}
};
} // namespace detail
} // namespace cvt
} // namespace qx

File diff suppressed because it is too large Load Diff

196
inl/QxDao/QxDao_Count.inl Normal file
View File

@@ -0,0 +1,196 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Count
{
static long count(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase)
{
T t;
Q_UNUSED(t);
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "count", new qx::QxSqlQueryBuilder_Count<T>(), (&query));
if (!dao.isValid())
{
return 0;
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
long cnt = 0;
qx::dao::mongodb::QxMongoDB_Helper::count((&dao), dao.getDataMemberX()->getClass(), cnt, (&query));
if (!dao.isValid())
{
return 0;
}
return cnt;
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql().getSqlQuery();
if (sql.isEmpty())
{
dao.errEmpty();
return 0;
}
if (!query.isEmpty())
{
dao.addQuery(true);
sql = dao.builder().getSqlQuery();
}
if (!dao.exec())
{
dao.errFailed();
return 0;
}
if (!dao.nextRecord())
{
dao.errNoData();
return 0;
}
return static_cast<long>(dao.query().value(0).toLongLong());
}
static QSqlError count(long &lCount, const qx::QxSqlQuery &query, QSqlDatabase *pDatabase)
{
T t;
Q_UNUSED(t);
lCount = 0;
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "count", new qx::QxSqlQueryBuilder_Count<T>(), (&query));
if (!dao.isValid())
{
return dao.error();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::mongodb::QxMongoDB_Helper::count((&dao), dao.getDataMemberX()->getClass(), lCount, (&query));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql().getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!query.isEmpty())
{
dao.addQuery(true);
sql = dao.builder().getSqlQuery();
}
if (!dao.exec())
{
return dao.errFailed();
}
if (!dao.nextRecord())
{
return dao.errNoData();
}
lCount = static_cast<long>(dao.query().value(0).toLongLong());
return dao.error();
}
};
template <class T>
struct QxDao_Count_WithRelation
{
static QSqlError count(long &lCount, const QStringList &relation, const qx::QxSqlQuery &query, QSqlDatabase *pDatabase)
{
T t;
Q_UNUSED(t);
lCount = 0;
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "count with relation", new qx::QxSqlQueryBuilder_Count_WithRelation<T>(), (&query));
if (!dao.isValid())
{
return dao.error();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::mongodb::QxMongoDB_Helper::count((&dao), dao.getDataMemberX()->getClass(), lCount, (&query));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QStringList columns;
QString sql = dao.builder().buildSql(columns, dao.getSqlRelationLinked()).getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!query.isEmpty())
{
dao.addQuery(true);
sql = dao.builder().getSqlQuery();
}
if (!dao.exec())
{
return dao.errFailed();
}
if (!dao.nextRecord())
{
return dao.errNoData();
}
lCount = static_cast<long>(dao.query().value(0).toLongLong());
return dao.error();
}
};
} // namespace detail
} // namespace dao
} // namespace qx

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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_CreateTable
{
static QSqlError createTable(QSqlDatabase *pDatabase)
{
T t;
Q_UNUSED(t);
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "create table", new qx::QxSqlQueryBuilder_CreateTable<T>());
if (!dao.isValid())
{
return dao.error();
}
if (dao.database().driverName() != "QSQLITE")
{
QString sWarningMsg = "-- WARNING -- the function qx::dao::create_table<T>() can be used only with a SQLite database to create examples or prototypes, for other databases, it is recommended :";
sWarningMsg += "\n\t - to use QxEntityEditor application and its DDL SQL database schema export plugin ;";
sWarningMsg += "\n\t - 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...) ;";
sWarningMsg += "\n\t - or to generate database schema using the introspection engine of QxOrm library : go to 'https://www.qxorm.com/qxorm_en/faq.html#faq_230' web page for more details.";
qDebug("[QxOrm] %s", qPrintable(sWarningMsg));
}
QString sql = dao.builder().buildSql().getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!dao.query().exec(sql))
{
return dao.errFailed();
}
long index = 0;
qx::IxSqlRelation *pRelation = NULL;
while ((pRelation = dao.builder().nextRelation(index)))
{
QString sqlExtraTable = pRelation->createExtraTable();
if (sqlExtraTable.isEmpty())
{
continue;
}
QSqlQuery queryCreateTable(dao.database());
bool bExtraTable = queryCreateTable.exec(sqlExtraTable);
if (!bExtraTable)
{
dao.updateError(queryCreateTable.lastError());
break;
}
}
return dao.error();
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,103 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_DeleteAll
{
static QSqlError deleteAll(const qx::QxSqlQuery &query, QSqlDatabase *pDatabase, bool bVerifySoftDelete)
{
T t;
Q_UNUSED(t);
qx::IxSqlQueryBuilder *pBuilder = new qx::QxSqlQueryBuilder_DeleteAll<T>();
pBuilder->init();
qx::QxSoftDelete oSoftDelete = pBuilder->getSoftDelete();
if (bVerifySoftDelete && !oSoftDelete.isEmpty())
{
delete pBuilder;
pBuilder = new qx::QxSqlQueryBuilder_SoftDeleteAll<T>();
}
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "delete all", pBuilder, (&query));
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::mongodb::QxMongoDB_Helper::deleteMany((&dao), dao.getDataMemberX()->getClass(), QStringList(), (&query));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql().getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!pDatabase)
{
dao.transaction();
}
if (!query.isEmpty())
{
dao.addQuery(true);
sql = dao.builder().getSqlQuery();
}
if (!dao.exec())
{
return dao.errFailed();
}
return dao.error();
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,381 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_DeleteById_Generic
{
static QSqlError deleteById(T &t, QSqlDatabase *pDatabase, bool bVerifySoftDelete, bool bUseExecBatch)
{
Q_UNUSED(bUseExecBatch); // Useful only with containers
qx::IxSqlQueryBuilder *pBuilder = new qx::QxSqlQueryBuilder_DeleteById<T>();
pBuilder->init();
qx::QxSoftDelete oSoftDelete = pBuilder->getSoftDelete();
if (bVerifySoftDelete && !oSoftDelete.isEmpty())
{
delete pBuilder;
pBuilder = new qx::QxSqlQueryBuilder_SoftDeleteById<T>();
}
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "delete by id", pBuilder);
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.isValidPrimaryKey(t))
{
return dao.errInvalidId();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::on_before_delete<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
qx::dao::mongodb::QxMongoDB_Helper::deleteOne((&dao), dao.getDataMemberX()->getClass(), qx::serialization::json::to_string(t, 1, "mongodb:only_id"), NULL);
if (!dao.isValid())
{
return dao.error();
}
qx::dao::on_after_delete<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql().getSqlQuery();
if (!dao.getDataId() || sql.isEmpty())
{
return dao.errEmpty();
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
IxSqlGenerator *pSqlGenerator = dao.getSqlGenerator();
if (pSqlGenerator)
{
pSqlGenerator->onBeforeDelete((&dao), (&t));
}
qx::dao::on_before_delete<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_DeleteById<T>::resolveInput(t, dao.query(), dao.builder());
}
if (!dao.exec(true))
{
return dao.errFailed();
}
if (pSqlGenerator)
{
pSqlGenerator->onAfterDelete((&dao), (&t));
}
qx::dao::on_after_delete<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
};
template <class T>
struct QxDao_DeleteById_Container
{
static QSqlError deleteById(T &t, QSqlDatabase *pDatabase, bool bVerifySoftDelete, bool bUseExecBatch)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
qx::IxSqlQueryBuilder *pBuilder = new qx::QxSqlQueryBuilder_DeleteById<type_item>();
pBuilder->init();
qx::QxSoftDelete oSoftDelete = pBuilder->getSoftDelete();
if (bVerifySoftDelete && !oSoftDelete.isEmpty())
{
delete pBuilder;
pBuilder = new qx::QxSqlQueryBuilder_SoftDeleteById<type_item>();
}
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "delete by id", pBuilder);
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
dao.setUseExecBatch(bUseExecBatch);
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!deleteItem((*it), dao))
{
return dao.error();
}
}
QStringList &itemsAsJson = dao.itemsAsJson();
qx::dao::mongodb::QxMongoDB_Helper::deleteMany((&dao), dao.getDataMemberX()->getClass(), itemsAsJson, NULL);
if (!dao.isValid())
{
return dao.error();
}
dao.qxQuery().queryAt(2, "<done>");
dao.itemsAsJson().clear();
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!deleteItem((*it), dao))
{
return dao.error();
}
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql().getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!deleteItem((*it), dao))
{
return dao.error();
}
}
if (bUseExecBatch && (!dao.exec()))
{
return dao.errFailed();
}
return dao.error();
}
private:
template <typename U>
static inline bool deleteItem(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return deleteItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::deleteById(item, dao);
}
template <typename U, bool bIsPointer /* = true */>
struct deleteItem_Helper
{
static inline bool deleteById(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_DeleteById_Container<T>::deleteItem((*item), dao) : true);
}
};
template <typename U1, typename U2>
struct deleteItem_Helper<std::pair<U1, U2>, false>
{
static inline bool deleteById(std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_DeleteById_Container<T>::deleteItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct deleteItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool deleteById(const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_DeleteById_Container<T>::deleteItem(item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct deleteItem_Helper<QPair<U1, U2>, false>
{
static inline bool deleteById(QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_DeleteById_Container<T>::deleteItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct deleteItem_Helper<const QPair<U1, U2>, false>
{
static inline bool deleteById(const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_DeleteById_Container<T>::deleteItem(item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct deleteItem_Helper<U, false>
{
static bool deleteById(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
if (!dao.isValidPrimaryKey(item))
{
dao.errInvalidId();
return false;
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
if (dao.qxQuery().queryAt(2) == "<done>")
{
qx::dao::on_after_delete<U>((&item), (&dao));
return dao.isValid();
}
qx::dao::on_before_delete<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
QVariant id = (dao.getDataId() ? dao.getDataId()->toVariant(&item) : QVariant());
if (!id.isNull() && !id.toString().isEmpty())
{
dao.itemsAsJson().append(id.toString());
}
return dao.isValid();
}
#endif // _QX_ENABLE_MONGODB
IxSqlGenerator *pSqlGenerator = dao.getSqlGenerator();
if (pSqlGenerator)
{
pSqlGenerator->onBeforeDelete((&dao), (&item));
}
qx::dao::on_before_delete<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_DeleteById<U>::resolveInput(item, dao.query(), dao.builder());
}
if (dao.getUseExecBatch())
{
return dao.isValid();
}
if (!dao.exec(true))
{
dao.errFailed();
return false;
}
if (pSqlGenerator)
{
pSqlGenerator->onAfterDelete((&dao), (&item));
}
qx::dao::on_after_delete<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
return dao.isValid();
}
};
};
template <class T>
struct QxDao_DeleteById_Ptr
{
static inline QSqlError deleteById(T &t, QSqlDatabase *pDatabase, bool bVerifySoftDelete, bool bUseExecBatch)
{
if (!t)
{
return QSqlError();
}
if (bVerifySoftDelete)
{
return qx::dao::delete_by_id((*t), pDatabase, bUseExecBatch);
}
return qx::dao::destroy_by_id((*t), pDatabase, bUseExecBatch);
}
};
template <class T>
struct QxDao_DeleteById
{
static inline QSqlError deleteById(T &t, QSqlDatabase *pDatabase, bool bVerifySoftDelete, bool bUseExecBatch = false)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_DeleteById_Ptr<T>, qx::dao::detail::QxDao_DeleteById_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_DeleteById_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_DeleteById_Container<T>, type_dao_2>::type type_dao_3;
return type_dao_3::deleteById(t, pDatabase, bVerifySoftDelete, bUseExecBatch);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,295 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_ExecuteQuery_Generic
{
static QSqlError executeQuery(qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "execute custom sql query or stored procedure", new qx::QxSqlQueryBuilder_Count<T>());
if (!dao.isValid())
{
return dao.error();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
qx::dao::mongodb::QxMongoDB_Helper::executeCommand((&dao), dao.getDataMemberX()->getClass(), (&query));
if (!dao.isValid())
{
return dao.error();
}
QString json = query.response().toString();
qx::serialization::json::from_string(t, json, 1, "mongodb");
qx::dao::on_after_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = query.query();
if (sql.isEmpty())
{
return dao.errEmpty();
}
dao.builder().setSqlQuery(sql);
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
query.resolve(dao.query());
if (!dao.exec(true))
{
return dao.errFailed();
}
query.resolveOutput(dao.query(), false);
if (!dao.nextRecord())
{
return dao.error();
}
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
qx::IxDataMemberX *pDataMemberX = dao.builder().getDataMemberX();
if (!pDataMemberX)
{
qAssert(false);
return dao.error();
}
QSqlRecord record = dao.query().record();
for (int i = 0; i < record.count(); i++)
{
if (!pDataMemberX->exist_WithDaoStrategy(record.fieldName(i)))
{
continue;
}
qx::IxDataMember *pDataMember = pDataMemberX->get_WithDaoStrategy(record.fieldName(i));
if (pDataMember)
{
pDataMember->fromVariant((&t), record.value(i), -1, qx::cvt::context::e_database);
}
}
qx::dao::on_after_fetch<T>((&t), (&dao));
return dao.error();
}
};
template <class T>
struct QxDao_ExecuteQuery_Container
{
static QSqlError executeQuery(qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
qx::trait::generic_container<T>::clear(t);
qx::IxSqlQueryBuilder *pBuilder = new qx::QxSqlQueryBuilder_Count<type_item>();
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "execute custom sql query or stored procedure", pBuilder);
if (!dao.isValid())
{
return dao.error();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::mongodb::QxMongoDB_Helper::executeCommand((&dao), dao.getDataMemberX()->getClass(), (&query));
if (!dao.isValid())
{
return dao.error();
}
QString json = query.response().toString();
qx::serialization::json::from_string(t, json, 1, "mongodb");
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = query.query();
if (sql.isEmpty())
{
return dao.errEmpty();
}
dao.builder().setSqlQuery(sql);
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
query.resolve(dao.query());
if (!dao.exec(true))
{
return dao.errFailed();
}
query.resolveOutput(dao.query(), false);
QVector<QPair<int, qx::IxDataMember *>> vColumnToFetch;
bool bSize = (dao.hasFeature(QSqlDriver::QuerySize) && (dao.query().size() > 0));
if (bSize)
{
qx::trait::generic_container<T>::reserve(t, dao.query().size());
}
while (dao.nextRecord())
{
insertNewItem(t, dao, vColumnToFetch);
if (!dao.isValid())
{
return dao.error();
}
}
if (bSize)
{
qAssert(qx::trait::generic_container<T>::size(t) == static_cast<long>(dao.query().size()));
}
return dao.error();
}
private:
static void insertNewItem(T &t, qx::dao::detail::QxDao_Helper_Container<T> &dao, QVector<QPair<int, qx::IxDataMember *>> &vColumnToFetch)
{
typedef typename qx::trait::generic_container<T>::type_item type_item;
typedef typename type_item::type_value_qx type_value_qx;
type_item item = qx::trait::generic_container<T>::createItem();
type_value_qx &item_val = item.value_qx();
qx::IxDataMember *pId = dao.getDataId();
QVariant vId;
qx::dao::on_before_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
if (vColumnToFetch.count() <= 0)
{
qx::IxDataMemberX *pDataMemberX = dao.builder().getDataMemberX();
if (!pDataMemberX)
{
qAssert(false);
return;
}
QSqlRecord record = dao.query().record();
vColumnToFetch.reserve(record.count());
for (int i = 0; i < record.count(); i++)
{
if (!pDataMemberX->exist_WithDaoStrategy(record.fieldName(i)))
{
continue;
}
qx::IxDataMember *pDataMember = pDataMemberX->get_WithDaoStrategy(record.fieldName(i));
if (pDataMember)
{
vColumnToFetch.append(qMakePair(i, pDataMember));
}
}
}
for (int j = 0; j < vColumnToFetch.count(); j++)
{
QVariant vValue = dao.query().value(vColumnToFetch[j].first);
vColumnToFetch[j].second->fromVariant((&item_val), vValue, -1, qx::cvt::context::e_database);
if (pId == vColumnToFetch[j].second)
{
vId = vValue;
}
}
if (!vId.isValid())
{
vId = QVariant(static_cast<qlonglong>(qx::trait::generic_container<T>::size(t)));
}
qx::cvt::from_variant(vId, item.key(), "", -1, qx::cvt::context::e_database);
qx::dao::on_after_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
qx::dao::detail::QxDao_Keep_Original<type_item>::backup(item);
qx::trait::generic_container<T>::insertItem(t, item);
}
};
template <class T>
struct QxDao_ExecuteQuery_Ptr
{
static inline QSqlError executeQuery(qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
if (!t)
{
qx::trait::construct_ptr<T>::get(t);
};
return qx::dao::execute_query(query, (*t), pDatabase);
}
};
template <class T>
struct QxDao_ExecuteQuery
{
static inline QSqlError executeQuery(qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_ExecuteQuery_Ptr<T>, qx::dao::detail::QxDao_ExecuteQuery_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_ExecuteQuery_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_ExecuteQuery_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::executeQuery(query, t, pDatabase);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

261
inl/QxDao/QxDao_Exist.inl Normal file
View File

@@ -0,0 +1,261 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Exist_Generic
{
static qx_bool exist(T &t, QSqlDatabase *pDatabase)
{
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "exist", new qx::QxSqlQueryBuilder_Exist<T>());
if (!dao.isValid())
{
return qx_bool(false);
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
long cnt = 0;
QString json = qx::serialization::json::to_string(t, 1, "mongodb:only_id");
qx_query query(json);
qx::dao::mongodb::QxMongoDB_Helper::count((&dao), dao.getDataMemberX()->getClass(), cnt, (&query));
if (!dao.isValid())
{
return qx_bool(false);
}
return qx_bool(cnt >= 1);
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql().getSqlQuery();
if (!dao.getDataId() || sql.isEmpty())
{
dao.errEmpty();
return qx_bool(false);
}
if (!dao.prepare(sql))
{
dao.errFailed(true);
return qx_bool(false);
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_Exist<T>::resolveInput(t, dao.query(), dao.builder());
}
if (!dao.exec(true))
{
dao.errFailed();
return qx_bool(false);
}
return qx_bool(dao.nextRecord());
}
};
template <class T>
struct QxDao_Exist_Container
{
static qx_bool exist(T &t, QSqlDatabase *pDatabase)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return qx_bool(false);
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "exist", new qx::QxSqlQueryBuilder_Exist<type_item>());
if (!dao.isValid())
{
return qx_bool(false);
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!existItem((*it), dao))
{
return qx_bool(false);
}
}
return qx_bool(true);
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql().getSqlQuery();
if (sql.isEmpty())
{
dao.errEmpty();
return qx_bool(false);
}
if (!dao.prepare(sql))
{
dao.errFailed(true);
return qx_bool(false);
}
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!existItem((*it), dao))
{
return qx_bool(false);
}
}
return qx_bool(true);
}
private:
template <typename U>
static inline bool existItem(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return existItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::exist(item, dao);
}
template <typename U, bool bIsPointer /* = true */>
struct existItem_Helper
{
static inline bool exist(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Exist_Container<T>::existItem((*item), dao) : false);
}
};
template <typename U1, typename U2>
struct existItem_Helper<std::pair<U1, U2>, false>
{
static inline bool exist(std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Exist_Container<T>::existItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct existItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool exist(const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Exist_Container<T>::existItem(item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct existItem_Helper<QPair<U1, U2>, false>
{
static inline bool exist(QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Exist_Container<T>::existItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct existItem_Helper<const QPair<U1, U2>, false>
{
static inline bool exist(const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Exist_Container<T>::existItem(item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct existItem_Helper<U, false>
{
static bool exist(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
long cnt = 0;
QString json = qx::serialization::json::to_string(item, 1, "mongodb:only_id");
qx_query query(json);
qx::dao::mongodb::QxMongoDB_Helper::count((&dao), dao.getDataMemberX()->getClass(), cnt, (&query));
if (!dao.isValid())
{
return false;
}
return (cnt >= 1);
}
#endif // _QX_ENABLE_MONGODB
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_Exist<U>::resolveInput(item, dao.query(), dao.builder());
}
if (!dao.exec(true))
{
dao.errFailed();
return false;
}
return dao.nextRecord();
}
};
};
template <class T>
struct QxDao_Exist_Ptr
{
static inline qx_bool exist(T &t, QSqlDatabase *pDatabase)
{
return (t ? qx::dao::exist((*t), pDatabase) : qx_bool(false));
}
};
template <class T>
struct QxDao_Exist
{
static inline qx_bool exist(T &t, QSqlDatabase *pDatabase)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_Exist_Ptr<T>, qx::dao::detail::QxDao_Exist_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_Exist_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_Exist_Container<T>, type_dao_2>::type type_dao_3;
return type_dao_3::exist(t, pDatabase);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,291 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_FetchAll_Generic
{
static QSqlError fetchAll(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase, const QStringList &columns)
{
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "fetch all", new qx::QxSqlQueryBuilder_FetchAll<T>(), (&query));
if (!dao.isValid())
{
return dao.error();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
dao.setSqlColumns(columns);
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
QString json = qx::serialization::json::to_string(t, 1, "mongodb:only_id");
qx::dao::mongodb::QxMongoDB_Helper::findOne((&dao), dao.getDataMemberX()->getClass(), json, (&query));
if (!dao.isValid())
{
return dao.error();
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
QString ctx = QString("mongodb") + ((columns.count() > 0) ? (QString(":columns{,") + columns.join(",") + QString(",}")) : QString());
qx::serialization::json::from_string(t, json, 1, ctx);
qx::dao::on_after_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql(columns).getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!query.isEmpty())
{
dao.addQuery(true);
sql = dao.builder().getSqlQuery();
}
if (!dao.exec())
{
return dao.errFailed();
}
if (dao.nextRecord())
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
qx::dao::detail::QxSqlQueryHelper_FetchAll<T>::resolveOutput(t, dao.query(), dao.builder(), columns);
qx::dao::on_after_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
}
return dao.error();
}
};
#ifdef _QX_ENABLE_MONGODB
template <class T>
struct QxDao_FetchAll_MongoDB_Fetcher : public qx::dao::mongodb::QxMongoDB_Fetcher
{
T &m_t;
qx::dao::detail::QxDao_Helper_Container<T> &m_dao;
QxDao_FetchAll_MongoDB_Fetcher(T &t, qx::dao::detail::QxDao_Helper_Container<T> &dao) : qx::dao::mongodb::QxMongoDB_Fetcher(), m_t(t), m_dao(dao) { ; }
virtual ~QxDao_FetchAll_MongoDB_Fetcher() { ; }
virtual void fetch(const QString &json)
{
typedef typename qx::trait::generic_container<T>::type_item type_item;
typedef typename type_item::type_value_qx type_value_qx;
type_item item = qx::trait::generic_container<T>::createItem();
type_value_qx &item_val = item.value_qx();
qx::IxDataMember *pId = m_dao.getDataId();
QStringList columns = m_dao.getSqlColumns();
if (json.isEmpty())
{
return;
}
qx::dao::detail::IxDao_Timer timer((&m_dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
qx::dao::on_before_fetch<type_value_qx>((&item_val), (&m_dao));
if (!m_dao.isValid())
{
return;
}
QString ctx = QString("mongodb") + ((columns.count() > 0) ? (QString(":columns{,") + columns.join(",") + QString(",}")) : QString());
qx::serialization::json::from_string(item_val, json, 1, ctx);
for (int i = 0; i < (pId ? pId->getNameCount() : 0); i++)
{
QVariant id = pId->toVariant((&item_val), "", i, qx::cvt::context::e_database);
qx::cvt::from_variant(id, item.key(), "", i, qx::cvt::context::e_database);
}
qx::dao::on_after_fetch<type_value_qx>((&item_val), (&m_dao));
if (!m_dao.isValid())
{
return;
}
qx::dao::detail::QxDao_Keep_Original<type_item>::backup(item);
qx::trait::generic_container<T>::insertItem(m_t, item);
}
};
#endif // _QX_ENABLE_MONGODB
template <class T>
struct QxDao_FetchAll_Container
{
static QSqlError fetchAll(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase, const QStringList &columns)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
qx::trait::generic_container<T>::clear(t);
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "fetch all", new qx::QxSqlQueryBuilder_FetchAll<type_item>(), (&query));
if (!dao.isValid())
{
return dao.error();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
dao.setSqlColumns(columns);
QStringList &itemsAsJson = dao.itemsAsJson();
QxDao_FetchAll_MongoDB_Fetcher<T> fetcher(t, dao);
qx::dao::mongodb::QxMongoDB_Helper::findMany((&dao), dao.getDataMemberX()->getClass(), itemsAsJson, (&query), (&fetcher));
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql(columns).getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!query.isEmpty())
{
dao.addQuery(true);
sql = dao.builder().getSqlQuery();
}
if (!dao.exec())
{
return dao.errFailed();
}
dao.setSqlColumns(columns);
bool bSize = (dao.hasFeature(QSqlDriver::QuerySize) && (dao.query().size() > 0));
if (bSize)
{
qx::trait::generic_container<T>::reserve(t, dao.query().size());
}
while (dao.nextRecord())
{
insertNewItem(t, dao);
if (!dao.isValid())
{
return dao.error();
}
}
if (bSize)
{
qAssert(qx::trait::generic_container<T>::size(t) == static_cast<long>(dao.query().size()));
}
return dao.error();
}
private:
static void insertNewItem(T &t, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
typedef typename qx::trait::generic_container<T>::type_item type_item;
typedef typename type_item::type_value_qx type_value_qx;
type_item item = qx::trait::generic_container<T>::createItem();
type_value_qx &item_val = item.value_qx();
qx::IxDataMember *pId = dao.getDataId();
QStringList columns = dao.getSqlColumns();
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
if (pId)
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = dao.getIdFromQuery(i);
qx::cvt::from_variant(v, item.key(), "", i, qx::cvt::context::e_database);
}
}
qx::dao::on_before_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
qx::dao::detail::QxSqlQueryHelper_FetchAll<type_value_qx>::resolveOutput(item_val, dao.query(), dao.builder(), columns);
qx::dao::on_after_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
qx::dao::detail::QxDao_Keep_Original<type_item>::backup(item);
qx::trait::generic_container<T>::insertItem(t, item);
}
};
template <class T>
struct QxDao_FetchAll_Ptr
{
static inline QSqlError fetchAll(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase, const QStringList &columns)
{
return (t ? qx::dao::fetch_by_query(query, (*t), pDatabase, columns) : QSqlError());
}
};
template <class T>
struct QxDao_FetchAll
{
static inline QSqlError fetchAll(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase, const QStringList &columns)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_FetchAll_Ptr<T>, qx::dao::detail::QxDao_FetchAll_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_FetchAll_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_FetchAll_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::fetchAll(query, t, pDatabase, columns);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,451 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_FetchAll_WithRelation_Generic
{
typedef qx::dao::detail::QxDao_Helper<T> type_dao_helper;
typedef qx::dao::detail::QxSqlQueryHelper_FetchAll_WithRelation<T> type_query_helper;
static QSqlError fetchAll(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
type_dao_helper dao(t, pDatabase, "fetch all with relation", new qx::QxSqlQueryBuilder_FetchAll_WithRelation<T>(), (&query));
if (!dao.isValid())
{
return dao.error();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
QString json = qx::serialization::json::to_string(t, 1, "mongodb:only_id");
qx::dao::mongodb::QxMongoDB_Helper::findOne((&dao), dao.getDataMemberX()->getClass(), json, (&query));
if (!dao.isValid())
{
return dao.error();
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
qx::serialization::json::from_string(t, json, 1, "mongodb");
qx::dao::on_after_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QStringList columns;
QString sql = dao.builder().buildSql(columns, dao.getSqlRelationLinked()).getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!query.isEmpty())
{
dao.addQuery(true);
sql = dao.builder().getSqlQuery();
}
if (!dao.exec())
{
return dao.errFailed();
}
{
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
if (dao.getCartesianProduct())
{
fetchAll_Complex(t, dao);
}
else
{
fetchAll_Simple(t, dao);
}
if (!dao.isValid())
{
return dao.error();
}
qx::dao::on_after_fetch<T>((&t), (&dao));
}
return dao.error();
}
private:
static inline void fetchAll_Simple(T &t, type_dao_helper &dao)
{
if (!dao.nextRecord())
{
return;
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
type_query_helper::resolveOutput(dao.getSqlRelationLinked(), t, dao.query(), dao.builder());
}
static inline void fetchAll_Complex(T &t, type_dao_helper &dao)
{
while (dao.nextRecord())
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
type_query_helper::resolveOutput(dao.getSqlRelationLinked(), t, dao.query(), dao.builder());
if (!dao.isValid())
{
return;
}
}
}
};
#ifdef _QX_ENABLE_MONGODB
template <class T>
struct QxDao_FetchAll_WithRelation_MongoDB_Fetcher : public qx::dao::mongodb::QxMongoDB_Fetcher
{
typedef qx::dao::detail::QxDao_Helper_Container<T> type_dao_helper;
typedef qx::trait::generic_container<T> type_generic_container;
typedef typename type_generic_container::type_item type_item;
typedef typename type_item::type_value_qx type_value_qx;
typedef typename type_item::type_value type_value;
T &m_t;
type_dao_helper &m_dao;
QxDao_FetchAll_WithRelation_MongoDB_Fetcher(T &t, type_dao_helper &dao) : qx::dao::mongodb::QxMongoDB_Fetcher(), m_t(t), m_dao(dao) { ; }
virtual ~QxDao_FetchAll_WithRelation_MongoDB_Fetcher() { ; }
virtual void fetch(const QString &json)
{
fetcherHelper<type_item::is_value_pointer, 0>::insertNewItem(m_t, m_dao, json);
}
private:
template <bool bIsPointer /* = false */, int dummy>
struct fetcherHelper
{
static void insertNewItem(T &t, type_dao_helper &dao, const QString &json)
{
type_item item = type_generic_container::createItem();
qx::IxDataMember *pId = dao.getDataId();
qAssert(pId);
if (json.isEmpty())
{
return;
}
type_value_qx &item_val_tmp = item.value_qx();
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
qx::serialization::json::from_string(item_val_tmp, json, 1, "mongodb:columns{,_id," + pId->getKey() + ",}");
for (int i = 0; i < (pId ? pId->getNameCount() : 0); i++)
{
QVariant id = pId->toVariant((&item_val_tmp), "", i, qx::cvt::context::e_database);
qx::cvt::from_variant(id, item.key(), "", i, qx::cvt::context::e_database);
}
type_value *pValue = type_generic_container::insertItem(t, item);
type_value_qx &item_val = (pValue ? (*static_cast<type_value_qx *>(pValue)) : item.value_qx());
qx::dao::on_before_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
qx::serialization::json::from_string(item_val, json, 1, "mongodb");
qx::dao::on_after_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
qx::dao::detail::QxDao_Keep_Original<type_item>::backup(item);
}
};
template <int dummy>
struct fetcherHelper<true, dummy>
{
static void insertNewItem(T &t, type_dao_helper &dao, const QString &json)
{
type_item item = type_generic_container::createItem();
type_value_qx &item_val = item.value_qx();
qx::IxDataMember *pId = dao.getDataId();
qAssert(pId);
if (json.isEmpty())
{
return;
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
qx::dao::on_before_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
qx::serialization::json::from_string(item_val, json, 1, "mongodb");
for (int i = 0; i < (pId ? pId->getNameCount() : 0); i++)
{
QVariant id = pId->toVariant((&item_val), "", i, qx::cvt::context::e_database);
qx::cvt::from_variant(id, item.key(), "", i, qx::cvt::context::e_database);
}
qx::dao::on_after_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
qx::dao::detail::QxDao_Keep_Original<type_item>::backup(item);
qx::trait::generic_container<T>::insertItem(t, item);
}
};
};
#endif // _QX_ENABLE_MONGODB
template <class T>
struct QxDao_FetchAll_WithRelation_Container
{
typedef qx::dao::detail::QxDao_Helper_Container<T> type_dao_helper;
typedef qx::dao::detail::QxDao_FetchAll_WithRelation_Container<T> type_this;
typedef qx::trait::generic_container<T> type_generic_container;
typedef typename type_generic_container::type_item type_item;
typedef typename type_item::type_value_qx type_value_qx;
typedef typename type_item::type_value type_value;
typedef qx::dao::detail::QxSqlQueryHelper_FetchAll_WithRelation<type_value_qx> type_query_helper;
static QSqlError fetchAll(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
type_generic_container::clear(t);
type_dao_helper dao(t, pDatabase, "fetch all with relation", new qx::QxSqlQueryBuilder_FetchAll_WithRelation<type_value_qx>(), (&query));
if (!dao.isValid())
{
return dao.error();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
QStringList &itemsAsJson = dao.itemsAsJson();
QxDao_FetchAll_WithRelation_MongoDB_Fetcher<T> fetcher(t, dao);
qx::dao::mongodb::QxMongoDB_Helper::findMany((&dao), dao.getDataMemberX()->getClass(), itemsAsJson, (&query), (&fetcher));
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
bool bComplex = dao.getCartesianProduct();
QVariant vId;
QStringList columns;
QString sql = dao.builder().buildSql(columns, dao.getSqlRelationLinked()).getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!query.isEmpty())
{
dao.addQuery(true);
sql = dao.builder().getSqlQuery();
}
if (!dao.exec())
{
return dao.errFailed();
}
bool bSize = (dao.hasFeature(QSqlDriver::QuerySize) && (dao.query().size() > 0));
if (bSize)
{
type_generic_container::reserve(t, dao.query().size());
}
while (dao.nextRecord())
{
if (!dao.isValid())
{
return dao.error();
}
vId = dao.getIdFromQuery(-1);
void *pItemTmp = (bComplex ? dao.builder().existIdX(0, vId, vId) : NULL);
if (!pItemTmp)
{
insertHelper<type_item::is_value_pointer, 0>::insertNewItem(t, dao);
continue;
}
type_value_qx *pItem = static_cast<type_value_qx *>(pItemTmp);
type_query_helper::resolveOutput(dao.getSqlRelationLinked(), (*pItem), dao.query(), dao.builder());
}
if (bSize)
{
type_generic_container::reserve(t, type_generic_container::size(t));
}
return dao.error();
}
private:
template <bool bIsPointer /* = false */, int dummy>
struct insertHelper
{
static void insertNewItem(T &t, type_dao_helper &dao)
{
type_item item = type_generic_container::createItem();
qx::IxDataMember *pId = dao.getDataId();
qAssert(pId);
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
if (pId)
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = dao.getIdFromQuery(i);
qx::cvt::from_variant(v, item.key(), "", i, qx::cvt::context::e_database);
}
}
type_value *pValue = type_generic_container::insertItem(t, item);
type_value_qx &item_val = (pValue ? (*static_cast<type_value_qx *>(pValue)) : item.value_qx());
qx::dao::on_before_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
type_query_helper::resolveOutput(dao.getSqlRelationLinked(), item_val, dao.query(), dao.builder());
if (!dao.isValid())
{
return;
}
qx::dao::on_after_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
qx::dao::detail::QxDao_Keep_Original<type_item>::backup(item);
}
};
template <int dummy>
struct insertHelper<true, dummy>
{
static void insertNewItem(T &t, type_dao_helper &dao)
{
type_item item = type_generic_container::createItem();
type_value_qx &item_val = item.value_qx();
qx::IxDataMember *pId = dao.getDataId();
qAssert(pId);
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
if (pId)
{
for (int i = 0; i < pId->getNameCount(); i++)
{
QVariant v = dao.getIdFromQuery(i);
qx::cvt::from_variant(v, item.key(), "", i, qx::cvt::context::e_database);
}
}
qx::dao::on_before_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
type_query_helper::resolveOutput(dao.getSqlRelationLinked(), item_val, dao.query(), dao.builder());
if (!dao.isValid())
{
return;
}
qx::dao::on_after_fetch<type_value_qx>((&item_val), (&dao));
if (!dao.isValid())
{
return;
}
type_generic_container::insertItem(t, item);
qx::dao::detail::QxDao_Keep_Original<type_item>::backup(item);
}
};
};
template <class T>
struct QxDao_FetchAll_WithRelation_Ptr
{
static inline QSqlError fetchAll(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
return (t ? qx::dao::fetch_by_query_with_relation(relation, query, (*t), pDatabase) : QSqlError());
}
};
template <class T>
struct QxDao_FetchAll_WithRelation
{
static inline QSqlError fetchAll(const QString &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
QStringList lst;
if (!relation.isEmpty())
{
lst = relation.split("|");
}
return QxDao_FetchAll_WithRelation<T>::fetchAll(lst, query, t, pDatabase);
}
static inline QSqlError fetchAll(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_FetchAll_WithRelation_Ptr<T>, qx::dao::detail::QxDao_FetchAll_WithRelation_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_FetchAll_WithRelation_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_FetchAll_WithRelation_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::fetchAll(relation, query, t, pDatabase);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,363 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_FetchById_Generic
{
static QSqlError fetchById(T &t, QSqlDatabase *pDatabase, const QStringList &columns)
{
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "fetch by id", new qx::QxSqlQueryBuilder_FetchById<T>());
if (!dao.isValid())
{
return dao.error();
}
if (!dao.isValidPrimaryKey(t))
{
return dao.errInvalidId();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
dao.setSqlColumns(columns);
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
QString json = qx::serialization::json::to_string(t, 1, "mongodb:only_id");
qx::dao::mongodb::QxMongoDB_Helper::findOne((&dao), dao.getDataMemberX()->getClass(), json, NULL);
if (!dao.isValid())
{
return dao.error();
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
QString ctx = QString("mongodb") + ((columns.count() > 0) ? (QString(":columns{,") + columns.join(",") + QString(",}")) : QString());
qx::serialization::json::from_string(t, json, 1, ctx);
qx::dao::on_after_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql(columns).getSqlQuery();
if (!dao.getDataId() || sql.isEmpty())
{
return dao.errEmpty();
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
{
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_FetchById<T>::resolveInput(t, dao.query(), dao.builder(), columns);
}
if (!dao.exec(true))
{
return dao.errFailed();
}
if (!dao.nextRecord())
{
return dao.errNoData();
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
qx::dao::detail::QxSqlQueryHelper_FetchById<T>::resolveOutput(t, dao.query(), dao.builder(), columns);
qx::dao::on_after_fetch<T>((&t), (&dao));
}
return dao.error();
}
};
template <class T>
struct QxDao_FetchById_Container
{
static QSqlError fetchById(T &t, QSqlDatabase *pDatabase, const QStringList &columns)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "fetch by id", new qx::QxSqlQueryBuilder_FetchById<type_item>());
if (!dao.isValid())
{
return dao.error();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
dao.setSqlColumns(columns);
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!fetchItem((*it), dao))
{
return dao.error();
}
}
QStringList &itemsAsJson = dao.itemsAsJson();
qx::dao::mongodb::QxMongoDB_Helper::findMany((&dao), dao.getDataMemberX()->getClass(), itemsAsJson, NULL, NULL);
if (!dao.isValid())
{
return dao.error();
}
dao.qxQuery().queryAt(2, "<done>");
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!fetchItem((*it), dao))
{
return dao.error();
}
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql(columns).getSqlQuery();
if (!dao.getDataId() || sql.isEmpty())
{
return dao.errEmpty();
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
dao.setSqlColumns(columns);
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!fetchItem((*it), dao))
{
return dao.error();
}
}
return dao.error();
}
private:
template <typename U>
static inline bool fetchItem(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bFetchOk = fetchItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::fetch(item, dao);
if (bFetchOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bFetchOk;
}
template <typename U, bool bIsPointer /* = true */>
struct fetchItem_Helper
{
static inline bool fetch(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_FetchById_Container<T>::fetchItem((*item), dao) : true);
}
};
template <typename U1, typename U2>
struct fetchItem_Helper<std::pair<U1, U2>, false>
{
static inline bool fetch(std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_FetchById_Container<T>::fetchItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct fetchItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool fetch(const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_FetchById_Container<T>::fetchItem(item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct fetchItem_Helper<QPair<U1, U2>, false>
{
static inline bool fetch(QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_FetchById_Container<T>::fetchItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct fetchItem_Helper<const QPair<U1, U2>, false>
{
static inline bool fetch(const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_FetchById_Container<T>::fetchItem(item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct fetchItem_Helper<U, false>
{
static bool fetch(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
QStringList columns = dao.getSqlColumns();
if (!dao.isValidPrimaryKey(item))
{
dao.errInvalidId();
return false;
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
if (dao.qxQuery().queryAt(2) == "<done>")
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
QString ctx = QString("mongodb") + ((columns.count() > 0) ? (QString(":columns{,") + columns.join(",") + QString(",}")) : QString());
if (!dao.itemsAsJson().isEmpty())
{
QString json = dao.itemsAsJson().takeFirst();
if (!json.isEmpty())
{
qx::serialization::json::from_string(item, json, 1, ctx);
}
}
qx::dao::on_after_fetch<U>((&item), (&dao));
return dao.isValid();
}
{
qx::dao::on_before_fetch<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
QVariant id = (dao.getDataId() ? dao.getDataId()->toVariant(&item) : QVariant());
if (!id.isNull() && !id.toString().isEmpty())
{
dao.itemsAsJson().append(id.toString());
}
}
return dao.isValid();
}
#endif // _QX_ENABLE_MONGODB
{
qx::dao::on_before_fetch<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_FetchById<U>::resolveInput(item, dao.query(), dao.builder(), columns);
}
if (!dao.exec(true))
{
dao.errFailed();
return false;
}
if (!dao.nextRecord())
{
dao.errNoData();
return false;
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
qx::dao::detail::QxSqlQueryHelper_FetchById<U>::resolveOutput(item, dao.query(), dao.builder(), columns);
qx::dao::on_after_fetch<U>((&item), (&dao));
}
return dao.isValid();
}
};
};
template <class T>
struct QxDao_FetchById_Ptr
{
static inline QSqlError fetchById(T &t, QSqlDatabase *pDatabase, const QStringList &columns)
{
if (!t)
{
qx::trait::construct_ptr<T>::get(t);
};
return qx::dao::fetch_by_id((*t), pDatabase, columns);
}
};
template <class T>
struct QxDao_FetchById
{
static inline QSqlError fetchById(T &t, QSqlDatabase *pDatabase, const QStringList &columns)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_FetchById_Ptr<T>, qx::dao::detail::QxDao_FetchById_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_FetchById_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_FetchById_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::fetchById(t, pDatabase, columns);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,459 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_FetchById_WithRelation_Generic
{
typedef qx::dao::detail::QxDao_Helper<T> type_dao_helper;
typedef qx::dao::detail::QxSqlQueryHelper_FetchById_WithRelation<T> type_query_helper;
static QSqlError fetchById(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
type_dao_helper dao(t, pDatabase, "fetch by id with relation", new qx::QxSqlQueryBuilder_FetchById_WithRelation<T>());
if (!dao.isValid())
{
return dao.error();
}
if (!dao.isValidPrimaryKey(t))
{
return dao.errInvalidId();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
QString json = qx::serialization::json::to_string(t, 1, "mongodb:only_id");
qx::dao::mongodb::QxMongoDB_Helper::findOne((&dao), dao.getDataMemberX()->getClass(), json, NULL);
if (!dao.isValid())
{
return dao.error();
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
qx::serialization::json::from_string(t, json, 1, "mongodb");
qx::dao::on_after_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QStringList columns;
QString sql = dao.builder().buildSql(columns, dao.getSqlRelationLinked()).getSqlQuery();
if (!dao.getDataId() || sql.isEmpty())
{
return dao.errEmpty();
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
type_query_helper::resolveInput(dao.getSqlRelationLinked(), t, dao.query(), dao.builder());
}
if (!dao.exec(true))
{
return dao.errFailed();
}
{
qx::dao::on_before_fetch<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
if (dao.getCartesianProduct())
{
fetchById_Complex(t, dao);
}
else
{
fetchById_Simple(t, dao);
}
if (!dao.isValid())
{
return dao.error();
}
qx::dao::on_after_fetch<T>((&t), (&dao));
}
return dao.error();
}
private:
static inline void fetchById_Simple(T &t, type_dao_helper &dao)
{
if (!dao.nextRecord())
{
dao.errNoData();
return;
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
type_query_helper::resolveOutput(dao.getSqlRelationLinked(), t, dao.query(), dao.builder());
}
static inline void fetchById_Complex(T &t, type_dao_helper &dao)
{
if (!dao.nextRecord())
{
dao.errNoData();
return;
}
do
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
type_query_helper::resolveOutput(dao.getSqlRelationLinked(), t, dao.query(), dao.builder());
if (!dao.isValid())
{
return;
}
} while (dao.nextRecord());
}
};
template <class T>
struct QxDao_FetchById_WithRelation_Container
{
typedef qx::dao::detail::QxDao_Helper_Container<T> type_dao_helper;
typedef qx::dao::detail::QxDao_FetchById_WithRelation_Container<T> type_this;
typedef qx::trait::generic_container<T> type_generic_container;
typedef typename type_generic_container::type_item type_item;
typedef typename type_item::type_value_qx type_value_qx;
typedef typename type_item::type_value type_value;
static QSqlError fetchById(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
type_dao_helper dao(t, pDatabase, "fetch by id with relation", new qx::QxSqlQueryBuilder_FetchById_WithRelation<type_value_qx>());
if (!dao.isValid())
{
return dao.error();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!fetchItem((*it), dao))
{
return dao.error();
}
}
QStringList &itemsAsJson = dao.itemsAsJson();
qx::dao::mongodb::QxMongoDB_Helper::findMany((&dao), dao.getDataMemberX()->getClass(), itemsAsJson, NULL, NULL);
if (!dao.isValid())
{
return dao.error();
}
dao.qxQuery().queryAt(2, "<done>");
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!fetchItem((*it), dao))
{
return dao.error();
}
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QStringList columns;
QString sql = dao.builder().buildSql(columns, dao.getSqlRelationLinked()).getSqlQuery();
if (!dao.getDataId() || sql.isEmpty())
{
return dao.errEmpty();
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!fetchItem((*it), dao))
{
return dao.error();
}
}
return dao.error();
}
private:
template <typename U>
static inline bool fetchItem(U &item, type_dao_helper &dao)
{
bool bFetchOk = fetchItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::fetch(item, dao);
if (bFetchOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bFetchOk;
}
template <typename U, bool bIsPointer /* = true */>
struct fetchItem_Helper
{
static inline bool fetch(U &item, type_dao_helper &dao)
{
return (item ? type_this::fetchItem((*item), dao) : true);
}
};
template <typename U1, typename U2>
struct fetchItem_Helper<std::pair<U1, U2>, false>
{
static inline bool fetch(std::pair<U1, U2> &item, type_dao_helper &dao)
{
return type_this::fetchItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct fetchItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool fetch(const std::pair<U1, U2> &item, type_dao_helper &dao)
{
return type_this::fetchItem(item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct fetchItem_Helper<QPair<U1, U2>, false>
{
static inline bool fetch(QPair<U1, U2> &item, type_dao_helper &dao)
{
return type_this::fetchItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct fetchItem_Helper<const QPair<U1, U2>, false>
{
static inline bool fetch(const QPair<U1, U2> &item, type_dao_helper &dao)
{
return type_this::fetchItem(item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct fetchItem_Helper<U, false>
{
typedef qx::dao::detail::QxSqlQueryHelper_FetchById_WithRelation<U> type_query_helper;
static bool fetch(U &item, type_dao_helper &dao)
{
if (!dao.isValidPrimaryKey(item))
{
dao.errInvalidId();
return false;
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
if (dao.qxQuery().queryAt(2) == "<done>")
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
if (!dao.itemsAsJson().isEmpty())
{
QString json = dao.itemsAsJson().takeFirst();
if (!json.isEmpty())
{
qx::serialization::json::from_string(item, json, 1, "mongodb");
}
}
qx::dao::on_after_fetch<U>((&item), (&dao));
return dao.isValid();
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
qx::dao::on_before_fetch<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
QVariant id = (dao.getDataId() ? dao.getDataId()->toVariant(&item) : QVariant());
if (!id.isNull() && !id.toString().isEmpty())
{
dao.itemsAsJson().append(id.toString());
}
}
return dao.isValid();
}
#endif // _QX_ENABLE_MONGODB
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
type_query_helper::resolveInput(dao.getSqlRelationLinked(), item, dao.query(), dao.builder());
}
if (!dao.exec(true))
{
dao.errFailed();
return false;
}
{
qx::dao::on_before_fetch<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
if (dao.getCartesianProduct())
{
fetch_Complex(item, dao);
}
else
{
fetch_Simple(item, dao);
}
if (!dao.isValid())
{
return false;
}
qx::dao::on_after_fetch<U>((&item), (&dao));
}
return dao.isValid();
}
static inline void fetch_Simple(U &item, type_dao_helper &dao)
{
if (!dao.nextRecord())
{
dao.errNoData();
return;
}
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
type_query_helper::resolveOutput(dao.getSqlRelationLinked(), item, dao.query(), dao.builder());
}
static inline void fetch_Complex(U &item, type_dao_helper &dao)
{
if (!dao.nextRecord())
{
dao.errNoData();
return;
}
do
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_build_instance);
type_query_helper::resolveOutput(dao.getSqlRelationLinked(), item, dao.query(), dao.builder());
if (!dao.isValid())
{
return;
}
} while (dao.nextRecord());
}
};
};
template <class T>
struct QxDao_FetchById_WithRelation_Ptr
{
static inline QSqlError fetchById(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
if (!t)
{
qx::trait::construct_ptr<T>::get(t);
};
return qx::dao::fetch_by_id_with_relation(relation, (*t), pDatabase);
}
};
template <class T>
struct QxDao_FetchById_WithRelation
{
static inline QSqlError fetchById(const QString &relation, T &t, QSqlDatabase *pDatabase)
{
QStringList lst;
if (!relation.isEmpty())
{
lst = relation.split("|");
}
return QxDao_FetchById_WithRelation<T>::fetchById(lst, t, pDatabase);
}
static inline QSqlError fetchById(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_FetchById_WithRelation_Ptr<T>, qx::dao::detail::QxDao_FetchById_WithRelation_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_FetchById_WithRelation_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_FetchById_WithRelation_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::fetchById(relation, t, pDatabase);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

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
**
****************************************************************************/
#include <QxDao/IxDao_Helper.h>
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
class QxDao_Helper : public IxDao_Helper
{
public:
QxDao_Helper(T &t, QSqlDatabase *pDatabase, const QString &sContext, qx::IxSqlQueryBuilder *pBuilder, const qx::QxSqlQuery *pQuery = NULL) : IxDao_Helper(pBuilder, pQuery)
{
Q_UNUSED(t);
init(pDatabase, sContext);
}
virtual ~QxDao_Helper() { static_assert(qx::trait::is_qx_registered<typename qx::QxSqlQueryBuilder<T>::type_sql>::value, "qx::trait::is_qx_registered<typename qx::QxSqlQueryBuilder<T>::type_sql>::value"); }
};
template <class T>
struct QxDao_Keep_Original
{
static inline void backup(T &t) { Q_UNUSED(t); }
};
template <typename T>
struct QxDao_Keep_Original<qx::dao::ptr<T>>
{
static inline void backup(qx::dao::ptr<T> &t)
{
if (t)
{
t.resetOriginal(qx::clone_to_qt_shared_ptr(*t));
}
}
};
} // namespace detail
} // namespace dao
} // namespace qx
#include "../../inl/QxDao/QxDao_Helper_Container.inl"

View File

@@ -0,0 +1,127 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
#define QX_DAO_HELPER_CONTAINER(className) \
namespace qx \
{ \
namespace dao \
{ \
namespace detail \
{ \
template <class T> \
class QxDao_Helper_Container<className<T>> : public IxDao_Helper \
{ \
public: \
QxDao_Helper_Container(className<T> &t, QSqlDatabase *pDatabase, const QString &sContext, qx::IxSqlQueryBuilder *pBuilder, const qx::QxSqlQuery *pQuery = NULL) : IxDao_Helper(pBuilder, pQuery) \
{ \
Q_UNUSED(t); \
init(pDatabase, sContext); \
} \
virtual ~QxDao_Helper_Container() { static_assert(qx::trait::is_qx_registered<typename qx::QxSqlQueryBuilder<T>::type_sql>::value, "qx::trait::is_qx_registered<typename qx::QxSqlQueryBuilder<T>::type_sql>::value"); } \
}; \
} \
} \
} // namespace qx::dao::detail
#define QX_DAO_HELPER_CONTAINER_KEY_VALUE(className) \
namespace qx \
{ \
namespace dao \
{ \
namespace detail \
{ \
template <class Key, class Value> \
class QxDao_Helper_Container<className<Key, Value>> : public IxDao_Helper \
{ \
public: \
QxDao_Helper_Container(className<Key, Value> &t, QSqlDatabase *pDatabase, const QString &sContext, qx::IxSqlQueryBuilder *pBuilder, const qx::QxSqlQuery *pQuery = NULL) : IxDao_Helper(pBuilder, pQuery) \
{ \
Q_UNUSED(t); \
init(pDatabase, sContext); \
} \
virtual ~QxDao_Helper_Container() { static_assert(qx::trait::is_qx_registered<typename qx::QxSqlQueryBuilder<Value>::type_sql>::value, "qx::trait::is_qx_registered<typename qx::QxSqlQueryBuilder<Value>::type_sql>::value"); } \
}; \
} \
} \
} // namespace qx::dao::detail
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Helper_Container
{
;
};
} // namespace detail
} // namespace dao
} // namespace qx
QX_DAO_HELPER_CONTAINER(std::vector)
QX_DAO_HELPER_CONTAINER(std::list)
QX_DAO_HELPER_CONTAINER(std::set)
QX_DAO_HELPER_CONTAINER_KEY_VALUE(std::map)
#ifdef _QX_ENABLE_BOOST
QX_DAO_HELPER_CONTAINER(boost::unordered_set)
QX_DAO_HELPER_CONTAINER(boost::unordered_multiset)
QX_DAO_HELPER_CONTAINER_KEY_VALUE(boost::unordered_map)
QX_DAO_HELPER_CONTAINER_KEY_VALUE(boost::unordered_multimap)
#endif // _QX_ENABLE_BOOST
QX_DAO_HELPER_CONTAINER(std::unordered_set)
QX_DAO_HELPER_CONTAINER(std::unordered_multiset)
QX_DAO_HELPER_CONTAINER_KEY_VALUE(std::unordered_map)
QX_DAO_HELPER_CONTAINER_KEY_VALUE(std::unordered_multimap)
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_DAO_HELPER_CONTAINER(QVector)
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
QX_DAO_HELPER_CONTAINER(QList)
QX_DAO_HELPER_CONTAINER(QSet)
QX_DAO_HELPER_CONTAINER_KEY_VALUE(QMap)
QX_DAO_HELPER_CONTAINER_KEY_VALUE(QMultiMap)
QX_DAO_HELPER_CONTAINER_KEY_VALUE(QHash)
QX_DAO_HELPER_CONTAINER_KEY_VALUE(QMultiHash)
#if (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
QX_DAO_HELPER_CONTAINER(QLinkedList)
#endif // (QT_VERSION < QT_VERSION_CHECK(5, 15, 0))
QX_DAO_HELPER_CONTAINER_KEY_VALUE(qx::QxCollection)

394
inl/QxDao/QxDao_Insert.inl Normal file
View File

@@ -0,0 +1,394 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Insert_Generic
{
static QSqlError insert(T &t, QSqlDatabase *pDatabase, bool bUseExecBatch)
{
Q_UNUSED(bUseExecBatch); // Useful only with containers
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "insert", new qx::QxSqlQueryBuilder_Insert<T>());
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.validateInstance(t))
{
return dao.error();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::on_before_insert<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
QString insertedId;
qx::dao::mongodb::QxMongoDB_Helper::insertOne((&dao), dao.getDataMemberX()->getClass(), qx::serialization::json::to_string(t, 1, "mongodb"), insertedId);
if (!dao.isValid())
{
return dao.error();
}
if (!insertedId.isEmpty() && dao.getDataId())
{
dao.getDataId()->fromVariant((&t), insertedId, -1, qx::cvt::context::e_database);
}
qx::dao::on_after_insert<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
IxSqlGenerator *pSqlGenerator = dao.getSqlGenerator();
QString sql = dao.builder().buildSql().getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!pDatabase)
{
dao.transaction();
}
if (pSqlGenerator)
{
pSqlGenerator->checkSqlInsert((&dao), sql);
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
if (pSqlGenerator)
{
pSqlGenerator->onBeforeInsert((&dao), (&t));
}
qx::dao::on_before_insert<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_Insert<T>::resolveInput(t, dao.query(), dao.builder());
}
if (!dao.exec(true))
{
return dao.errFailed();
}
dao.updateLastInsertId(t);
if (pSqlGenerator)
{
pSqlGenerator->onAfterInsert((&dao), (&t));
}
qx::dao::on_after_insert<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
};
template <class T>
struct QxDao_Insert_Container
{
static QSqlError insert(T &t, QSqlDatabase *pDatabase, bool bUseExecBatch)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "insert", new qx::QxSqlQueryBuilder_Insert<type_item>());
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.validateInstance(t))
{
return dao.error();
}
dao.setUseExecBatch(bUseExecBatch);
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!insertItem((*it), dao))
{
return dao.error();
}
}
QStringList &itemsAsJson = dao.itemsAsJson();
QStringList insertedId;
qx::dao::mongodb::QxMongoDB_Helper::insertMany((&dao), dao.getDataMemberX()->getClass(), itemsAsJson, insertedId);
if (!dao.isValid())
{
return dao.error();
}
dao.qxQuery().queryAt(2, "<done>");
dao.itemsAsJson().clear();
dao.itemsAsJson().append(insertedId);
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!insertItem((*it), dao))
{
return dao.error();
}
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
IxSqlGenerator *pSqlGenerator = dao.getSqlGenerator();
QString sql = dao.builder().buildSql().getSqlQuery();
if (sql.isEmpty())
{
return dao.errEmpty();
}
if (!pDatabase)
{
dao.transaction();
}
if (pSqlGenerator)
{
pSqlGenerator->checkSqlInsert((&dao), sql);
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!insertItem((*it), dao))
{
return dao.error();
}
}
if (bUseExecBatch && (!dao.exec()))
{
return dao.errFailed();
}
return dao.error();
}
private:
template <typename U>
static inline bool insertItem(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bInsertOk = insertItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::insert(item, dao);
if (bInsertOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bInsertOk;
}
template <typename U, bool bIsPointer /* = true */>
struct insertItem_Helper
{
static inline bool insert(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Insert_Container<T>::insertItem((*item), dao) : true);
}
};
template <typename U1, typename U2>
struct insertItem_Helper<std::pair<U1, U2>, false>
{
static inline bool insert(std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Insert_Container<T>::insertItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct insertItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool insert(const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Insert_Container<T>::insertItem(item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct insertItem_Helper<QPair<U1, U2>, false>
{
static inline bool insert(QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Insert_Container<T>::insertItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct insertItem_Helper<const QPair<U1, U2>, false>
{
static inline bool insert(const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Insert_Container<T>::insertItem(item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct insertItem_Helper<U, false>
{
static bool insert(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
if (dao.qxQuery().queryAt(2) == "<done>")
{
if (!dao.itemsAsJson().isEmpty())
{
QString oid = dao.itemsAsJson().takeFirst();
if (!oid.isEmpty() && dao.getDataId())
{
dao.getDataId()->fromVariant((&item), oid, -1, qx::cvt::context::e_database);
}
}
qx::dao::on_after_insert<U>((&item), (&dao));
return dao.isValid();
}
qx::dao::on_before_insert<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
dao.itemsAsJson().append(qx::serialization::json::to_string(item, 1, "mongodb"));
return dao.isValid();
}
#endif // _QX_ENABLE_MONGODB
IxSqlGenerator *pSqlGenerator = dao.getSqlGenerator();
if (pSqlGenerator)
{
pSqlGenerator->onBeforeInsert((&dao), (&item));
}
qx::dao::on_before_insert<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_Insert<U>::resolveInput(item, dao.query(), dao.builder());
}
if (dao.getUseExecBatch())
{
return dao.isValid();
}
if (!dao.exec(true))
{
dao.errFailed();
return false;
}
dao.updateLastInsertId(item);
if (pSqlGenerator)
{
pSqlGenerator->onAfterInsert((&dao), (&item));
}
qx::dao::on_after_insert<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
return dao.isValid();
}
};
};
template <class T>
struct QxDao_Insert_Ptr
{
static inline QSqlError insert(T &t, QSqlDatabase *pDatabase, bool bUseExecBatch)
{
return (t ? qx::dao::insert((*t), pDatabase, bUseExecBatch) : QSqlError());
}
};
template <class T>
struct QxDao_Insert
{
static inline QSqlError insert(T &t, QSqlDatabase *pDatabase, bool bUseExecBatch = false)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_Insert_Ptr<T>, qx::dao::detail::QxDao_Insert_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_Insert_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_Insert_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::insert(t, pDatabase, bUseExecBatch);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,276 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Insert_WithRelation_Generic
{
static QSqlError insert(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "insert with relation", new qx::QxSqlQueryBuilder_Insert<T>());
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
qx::QxSqlRelationParams params(0, 0, NULL, (&dao.builder()), (&dao.query()), (&t));
params.setDatabase((&dao.database()));
qx::QxSqlRelationLinked *pRelationLinked = dao.getSqlRelationLinked();
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnBeforeSave(params));
}
if (!dao.isValid())
{
return dao.error();
}
dao.updateError(qx::dao::insert(t, (&dao.database())));
if (!dao.isValid())
{
return dao.error();
}
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnAfterSave(params));
}
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
};
template <class T>
struct QxDao_Insert_WithRelation_Container
{
static QSqlError insert(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "insert with relation", new qx::QxSqlQueryBuilder_Insert<type_item>());
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!insertItem((*it), dao))
{
return dao.error();
}
}
return dao.error();
}
private:
template <typename U>
static inline bool insertItem(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bInsertOk = insertItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::insert(item, dao);
if (bInsertOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bInsertOk;
}
template <typename U, bool bIsPointer /* = true */>
struct insertItem_Helper
{
static inline bool insert(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Insert_WithRelation_Container<T>::insertItem((*item), dao) : true);
}
};
template <typename U1, typename U2>
struct insertItem_Helper<std::pair<U1, U2>, false>
{
static inline bool insert(std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Insert_WithRelation_Container<T>::insertItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct insertItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool insert(const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Insert_WithRelation_Container<T>::insertItem(item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct insertItem_Helper<QPair<U1, U2>, false>
{
static inline bool insert(QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Insert_WithRelation_Container<T>::insertItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct insertItem_Helper<const QPair<U1, U2>, false>
{
static inline bool insert(const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Insert_WithRelation_Container<T>::insertItem(item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct insertItem_Helper<U, false>
{
static bool insert(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
qx::QxSqlRelationParams params(0, 0, NULL, (&dao.builder()), (&dao.query()), (&item));
params.setDatabase((&dao.database()));
qx::QxSqlRelationLinked *pRelationLinked = dao.getSqlRelationLinked();
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnBeforeSave(params));
}
if (!dao.isValid())
{
return false;
}
dao.updateError(qx::dao::insert(item, (&dao.database())));
if (!dao.isValid())
{
return false;
}
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnAfterSave(params));
}
if (!dao.isValid())
{
return false;
}
return dao.isValid();
}
};
};
template <class T>
struct QxDao_Insert_WithRelation_Ptr
{
static inline QSqlError insert(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
return (t ? qx::dao::insert_with_relation(relation, (*t), pDatabase) : QSqlError());
}
};
template <class T>
struct QxDao_Insert_WithRelation
{
static inline QSqlError insert(const QString &relation, T &t, QSqlDatabase *pDatabase)
{
QStringList lst;
if (!relation.isEmpty())
{
lst = relation.split("|");
}
return QxDao_Insert_WithRelation<T>::insert(lst, t, pDatabase);
}
static inline QSqlError insert(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_Insert_WithRelation_Ptr<T>, qx::dao::detail::QxDao_Insert_WithRelation_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_Insert_WithRelation_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_Insert_WithRelation_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::insert(relation, t, pDatabase);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

222
inl/QxDao/QxDao_Save.inl Normal file
View File

@@ -0,0 +1,222 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Save_Generic
{
static QSqlError save(T &t, QSqlDatabase *pDatabase)
{
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "save", new qx::QxSqlQueryBuilder_Update<T>());
if (!dao.isValid())
{
return dao.error();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
qx_bool bExist = dao.isValidPrimaryKey(t);
if (bExist)
{
bExist = qx::dao::exist(t, (&dao.database()));
}
if (bExist)
{
dao.updateError(qx::dao::update(t, (&dao.database())));
}
else
{
dao.updateError(qx::dao::insert(t, (&dao.database())));
}
return dao.error();
}
};
template <class T>
struct QxDao_Save_Container
{
static QSqlError save(T &t, QSqlDatabase *pDatabase)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "save", new qx::QxSqlQueryBuilder_Update<type_item>());
if (!dao.isValid())
{
return dao.error();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!saveItem((*it), dao))
{
return dao.error();
}
}
return dao.error();
}
private:
template <typename U>
static inline bool saveItem(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bSaveOk = saveItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::save(item, dao);
if (bSaveOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bSaveOk;
}
template <typename U, bool bIsPointer /* = true */>
struct saveItem_Helper
{
static inline bool save(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Save_Container<T>::saveItem((*item), dao) : false);
}
};
template <typename U1, typename U2>
struct saveItem_Helper<std::pair<U1, U2>, false>
{
static inline bool save(std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_Container<T>::saveItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct saveItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool save(const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_Container<T>::saveItem(item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct saveItem_Helper<QPair<U1, U2>, false>
{
static inline bool save(QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_Container<T>::saveItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct saveItem_Helper<const QPair<U1, U2>, false>
{
static inline bool save(const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_Container<T>::saveItem(item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct saveItem_Helper<U, false>
{
static bool save(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
qx_bool bExist = dao.isValidPrimaryKey(item);
if (bExist)
{
bExist = qx::dao::exist(item, (&dao.database()));
}
if (bExist)
{
dao.updateError(qx::dao::update(item, (&dao.database())));
}
else
{
dao.updateError(qx::dao::insert(item, (&dao.database())));
}
return dao.isValid();
}
};
};
template <class T>
struct QxDao_Save_Ptr
{
static inline QSqlError save(T &t, QSqlDatabase *pDatabase)
{
return (t ? qx::dao::save((*t), pDatabase) : QSqlError());
}
};
template <class T>
struct QxDao_Save
{
static inline QSqlError save(T &t, QSqlDatabase *pDatabase)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_Save_Ptr<T>, qx::dao::detail::QxDao_Save_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_Save_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_Save_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::save(t, pDatabase);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,240 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Save_WithRelation_Generic
{
static QSqlError save(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "save with relation", new qx::QxSqlQueryBuilder_Update<T>());
if (!dao.isValid())
{
return dao.error();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
qx_bool bExist = dao.isValidPrimaryKey(t);
if (bExist)
{
bExist = qx::dao::exist(t, (&dao.database()));
}
if (bExist)
{
dao.updateError(qx::dao::update_with_relation(relation, t, (&dao.database())));
}
else
{
dao.updateError(qx::dao::insert_with_relation(relation, t, (&dao.database())));
}
return dao.error();
}
};
template <class T>
struct QxDao_Save_WithRelation_Container
{
static QSqlError save(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "save with relation", new qx::QxSqlQueryBuilder_Update<type_item>());
if (!dao.isValid())
{
return dao.error();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!saveItem(relation, (*it), dao))
{
return dao.error();
}
}
return dao.error();
}
private:
template <typename U>
static inline bool saveItem(const QStringList &relation, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bSaveOk = saveItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::save(relation, item, dao);
if (bSaveOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bSaveOk;
}
template <typename U, bool bIsPointer /* = true */>
struct saveItem_Helper
{
static inline bool save(const QStringList &relation, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Save_WithRelation_Container<T>::saveItem(relation, (*item), dao) : false);
}
};
template <typename U1, typename U2>
struct saveItem_Helper<std::pair<U1, U2>, false>
{
static inline bool save(const QStringList &relation, std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Container<T>::saveItem(relation, item.second, dao);
}
};
template <typename U1, typename U2>
struct saveItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool save(const QStringList &relation, const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Container<T>::saveItem(relation, item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct saveItem_Helper<QPair<U1, U2>, false>
{
static inline bool save(const QStringList &relation, QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Container<T>::saveItem(relation, item.second, dao);
}
};
template <typename U1, typename U2>
struct saveItem_Helper<const QPair<U1, U2>, false>
{
static inline bool save(const QStringList &relation, const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Container<T>::saveItem(relation, item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct saveItem_Helper<U, false>
{
static bool save(const QStringList &relation, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
qx_bool bExist = dao.isValidPrimaryKey(item);
if (bExist)
{
bExist = qx::dao::exist(item, (&dao.database()));
}
if (bExist)
{
dao.updateError(qx::dao::update_with_relation(relation, item, (&dao.database())));
}
else
{
dao.updateError(qx::dao::insert_with_relation(relation, item, (&dao.database())));
}
return dao.isValid();
}
};
};
template <class T>
struct QxDao_Save_WithRelation_Ptr
{
static inline QSqlError save(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
return (t ? qx::dao::save_with_relation(relation, (*t), pDatabase) : QSqlError());
}
};
template <class T>
struct QxDao_Save_WithRelation
{
static inline QSqlError save(const QString &relation, T &t, QSqlDatabase *pDatabase)
{
QStringList lst;
if (!relation.isEmpty())
{
lst = relation.split("|");
}
return QxDao_Save_WithRelation<T>::save(lst, t, pDatabase);
}
static inline QSqlError save(const QStringList &relation, T &t, QSqlDatabase *pDatabase)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_Save_WithRelation_Ptr<T>, qx::dao::detail::QxDao_Save_WithRelation_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_Save_WithRelation_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_Save_WithRelation_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::save(relation, t, pDatabase);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,516 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Save_WithRelation_Recursive_Generic
{
static QSqlError save(T &t, qx::dao::save_mode::e_save_mode eSaveMode, QSqlDatabase *pDatabase, qx::QxSqlRelationParams *pRelationParams)
{
QStringList relation("*");
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "save with relation recursive", new qx::QxSqlQueryBuilder_Update<T>());
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
qx::QxSqlRelationParams params(0, 0, NULL, (&dao.builder()), (&dao.query()), (&t));
if (!pRelationParams)
{
params.setDatabase((&dao.database()));
params.setSaveMode(eSaveMode);
params.setRecursiveMode(true);
}
else
{
params = (*pRelationParams);
params.setOwner(&t);
}
if (params.existRecursiveItem(&t))
{
return dao.error();
}
params.insertRecursiveItem(&t);
qx::QxSqlRelationLinked *pRelationLinked = dao.getSqlRelationLinked();
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnBeforeSave(params));
}
if (!dao.isValid())
{
return dao.error();
}
if (eSaveMode == qx::dao::save_mode::e_check_insert_or_update)
{
qx_bool bExist = dao.isValidPrimaryKey(t);
if (bExist)
{
bExist = qx::dao::exist(t, (&dao.database()));
}
if (bExist)
{
dao.updateError(qx::dao::update(t, (&dao.database())));
}
else
{
dao.updateError(qx::dao::insert(t, (&dao.database())));
}
}
else if (eSaveMode == qx::dao::save_mode::e_insert_only)
{
dao.updateError(qx::dao::insert(t, (&dao.database())));
}
else if (eSaveMode == qx::dao::save_mode::e_update_only)
{
dao.updateError(qx::dao::update(t, (&dao.database())));
}
else
{
qAssert(false);
}
if (!dao.isValid())
{
return dao.error();
}
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnAfterSave(params));
}
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
};
template <class T>
struct QxDao_Save_WithRelation_Recursive_Container
{
static QSqlError save(T &t, qx::dao::save_mode::e_save_mode eSaveMode, QSqlDatabase *pDatabase, qx::QxSqlRelationParams *pRelationParams)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
QStringList relation("*");
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "save with relation recursive", new qx::QxSqlQueryBuilder_Update<type_item>());
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
if (eSaveMode == qx::dao::save_mode::e_check_insert_or_update)
{
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!saveItem(eSaveMode, pRelationParams, (*it), dao))
{
return dao.error();
}
}
}
else if (eSaveMode == qx::dao::save_mode::e_insert_only)
{
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!hierarchyOnBeforeSave(eSaveMode, pRelationParams, (*it), dao))
{
return dao.error();
}
}
dao.updateError(qx::dao::insert(t, (&dao.database())));
if (!dao.isValid())
{
return dao.error();
}
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!hierarchyOnAfterSave(eSaveMode, pRelationParams, (*it), dao))
{
return dao.error();
}
}
}
else if (eSaveMode == qx::dao::save_mode::e_update_only)
{
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!hierarchyOnBeforeSave(eSaveMode, pRelationParams, (*it), dao))
{
return dao.error();
}
}
dao.updateError(qx::dao::update(t, (&dao.database())));
if (!dao.isValid())
{
return dao.error();
}
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!hierarchyOnAfterSave(eSaveMode, pRelationParams, (*it), dao))
{
return dao.error();
}
}
}
else
{
qAssert(false);
}
return dao.error();
}
private:
template <typename U>
static inline bool saveItem(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bSaveOk = saveItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::save(eSaveMode, pRelationParams, item, dao);
if (bSaveOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bSaveOk;
}
template <typename U>
static inline bool hierarchyOnBeforeSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bBeforeSaveOk = saveItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::hierarchyOnBeforeSave(eSaveMode, pRelationParams, item, dao);
if (bBeforeSaveOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bBeforeSaveOk;
}
template <typename U>
static inline bool hierarchyOnAfterSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bAfterSaveOk = saveItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::hierarchyOnAfterSave(eSaveMode, pRelationParams, item, dao);
if (bAfterSaveOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bAfterSaveOk;
}
template <typename U, bool bIsPointer /* = true */>
struct saveItem_Helper
{
static inline bool save(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::saveItem(eSaveMode, pRelationParams, (*item), dao) : false);
}
static inline bool hierarchyOnBeforeSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnBeforeSave(eSaveMode, pRelationParams, (*item), dao) : false);
}
static inline bool hierarchyOnAfterSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnAfterSave(eSaveMode, pRelationParams, (*item), dao) : false);
}
};
template <typename U1, typename U2>
struct saveItem_Helper<std::pair<U1, U2>, false>
{
static inline bool save(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::saveItem(eSaveMode, pRelationParams, item.second, dao);
}
static inline bool hierarchyOnBeforeSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnBeforeSave(eSaveMode, pRelationParams, item.second, dao);
}
static inline bool hierarchyOnAfterSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnAfterSave(eSaveMode, pRelationParams, item.second, dao);
}
};
template <typename U1, typename U2>
struct saveItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool save(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::saveItem(eSaveMode, pRelationParams, item.second, dao);
}
static inline bool hierarchyOnBeforeSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnBeforeSave(eSaveMode, pRelationParams, item.second, dao);
}
static inline bool hierarchyOnAfterSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnAfterSave(eSaveMode, pRelationParams, item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct saveItem_Helper<QPair<U1, U2>, false>
{
static inline bool save(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::saveItem(eSaveMode, pRelationParams, item.second, dao);
}
static inline bool hierarchyOnBeforeSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnBeforeSave(eSaveMode, pRelationParams, item.second, dao);
}
static inline bool hierarchyOnAfterSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnAfterSave(eSaveMode, pRelationParams, item.second, dao);
}
};
template <typename U1, typename U2>
struct saveItem_Helper<const QPair<U1, U2>, false>
{
static inline bool save(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::saveItem(eSaveMode, pRelationParams, item.second, dao);
}
static inline bool hierarchyOnBeforeSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnBeforeSave(eSaveMode, pRelationParams, item.second, dao);
}
static inline bool hierarchyOnAfterSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>::hierarchyOnAfterSave(eSaveMode, pRelationParams, item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct saveItem_Helper<U, false>
{
static bool save(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
qx::QxSqlRelationParams params(0, 0, NULL, (&dao.builder()), (&dao.query()), (&item));
if (!pRelationParams)
{
params.setDatabase((&dao.database()));
params.setSaveMode(eSaveMode);
params.setRecursiveMode(true);
}
else
{
params = (*pRelationParams);
params.setOwner(&item);
}
if (params.existRecursiveItem(&item))
{
return true;
}
params.insertRecursiveItem(&item);
qx::QxSqlRelationLinked *pRelationLinked = dao.getSqlRelationLinked();
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnBeforeSave(params));
}
if (!dao.isValid())
{
return false;
}
if (eSaveMode == qx::dao::save_mode::e_check_insert_or_update)
{
qx_bool bExist = dao.isValidPrimaryKey(item);
if (bExist)
{
bExist = qx::dao::exist(item, (&dao.database()));
}
if (bExist)
{
dao.updateError(qx::dao::update(item, (&dao.database())));
}
else
{
dao.updateError(qx::dao::insert(item, (&dao.database())));
}
}
else if (eSaveMode == qx::dao::save_mode::e_insert_only)
{
dao.updateError(qx::dao::insert(item, (&dao.database())));
}
else if (eSaveMode == qx::dao::save_mode::e_update_only)
{
dao.updateError(qx::dao::update(item, (&dao.database())));
}
else
{
qAssert(false);
}
if (!dao.isValid())
{
return false;
}
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnAfterSave(params));
}
if (!dao.isValid())
{
return false;
}
return dao.isValid();
}
static bool hierarchyOnBeforeSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
qx::QxSqlRelationParams params(0, 0, NULL, (&dao.builder()), (&dao.query()), (&item));
if (!pRelationParams)
{
params.setDatabase((&dao.database()));
params.setSaveMode(eSaveMode);
params.setRecursiveMode(true);
}
else
{
params = (*pRelationParams);
params.setOwner(&item);
}
qx::QxSqlRelationLinked *pRelationLinked = dao.getSqlRelationLinked();
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnBeforeSave(params));
}
return dao.isValid();
}
static bool hierarchyOnAfterSave(qx::dao::save_mode::e_save_mode eSaveMode, qx::QxSqlRelationParams *pRelationParams, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
qx::QxSqlRelationParams params(0, 0, NULL, (&dao.builder()), (&dao.query()), (&item));
if (!pRelationParams)
{
params.setDatabase((&dao.database()));
params.setSaveMode(eSaveMode);
params.setRecursiveMode(true);
}
else
{
params = (*pRelationParams);
params.setOwner(&item);
}
if (params.existRecursiveItem(&item))
{
return true;
}
params.insertRecursiveItem(&item);
qx::QxSqlRelationLinked *pRelationLinked = dao.getSqlRelationLinked();
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnAfterSave(params));
}
return dao.isValid();
}
};
};
template <class T>
struct QxDao_Save_WithRelation_Recursive_Ptr
{
static inline QSqlError save(T &t, qx::dao::save_mode::e_save_mode eSaveMode, QSqlDatabase *pDatabase, qx::QxSqlRelationParams *pRelationParams)
{
return (t ? qx::dao::save_with_relation_recursive((*t), eSaveMode, pDatabase, pRelationParams) : QSqlError());
}
};
template <class T>
struct QxDao_Save_WithRelation_Recursive
{
static inline QSqlError save(T &t, qx::dao::save_mode::e_save_mode eSaveMode, QSqlDatabase *pDatabase, qx::QxSqlRelationParams *pRelationParams)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_Save_WithRelation_Recursive_Ptr<T>, qx::dao::detail::QxDao_Save_WithRelation_Recursive_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_Save_WithRelation_Recursive_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_Save_WithRelation_Recursive_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::save(t, eSaveMode, pDatabase, pRelationParams);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

122
inl/QxDao/QxDao_Trigger.inl Normal file
View File

@@ -0,0 +1,122 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Trigger
{
private:
typedef typename qx::trait::get_base_class<T>::type type_base;
enum
{
is_valid_base_class = (!std::is_same<type_base, qx::trait::no_base_class_defined>::value)
};
public:
static inline void onBeforeInsert(T *t, qx::dao::detail::IxDao_Helper *dao) { TriggerHelper<is_valid_base_class, 0>::onBeforeInsert(t, dao); }
static inline void onBeforeUpdate(T *t, qx::dao::detail::IxDao_Helper *dao) { TriggerHelper<is_valid_base_class, 0>::onBeforeUpdate(t, dao); }
static inline void onBeforeDelete(T *t, qx::dao::detail::IxDao_Helper *dao) { TriggerHelper<is_valid_base_class, 0>::onBeforeDelete(t, dao); }
static inline void onBeforeFetch(T *t, qx::dao::detail::IxDao_Helper *dao) { TriggerHelper<is_valid_base_class, 0>::onBeforeFetch(t, dao); }
static inline void onAfterInsert(T *t, qx::dao::detail::IxDao_Helper *dao) { TriggerHelper<is_valid_base_class, 0>::onAfterInsert(t, dao); }
static inline void onAfterUpdate(T *t, qx::dao::detail::IxDao_Helper *dao) { TriggerHelper<is_valid_base_class, 0>::onAfterUpdate(t, dao); }
static inline void onAfterDelete(T *t, qx::dao::detail::IxDao_Helper *dao) { TriggerHelper<is_valid_base_class, 0>::onAfterDelete(t, dao); }
static inline void onAfterFetch(T *t, qx::dao::detail::IxDao_Helper *dao) { TriggerHelper<is_valid_base_class, 0>::onAfterFetch(t, dao); }
private:
template <bool isValidBaseClass /* = false */, int dummy>
struct TriggerHelper
{
static inline void onBeforeInsert(T *t, qx::dao::detail::IxDao_Helper *dao)
{
Q_UNUSED(t);
Q_UNUSED(dao);
}
static inline void onBeforeUpdate(T *t, qx::dao::detail::IxDao_Helper *dao)
{
Q_UNUSED(t);
Q_UNUSED(dao);
}
static inline void onBeforeDelete(T *t, qx::dao::detail::IxDao_Helper *dao)
{
Q_UNUSED(t);
Q_UNUSED(dao);
}
static inline void onBeforeFetch(T *t, qx::dao::detail::IxDao_Helper *dao)
{
Q_UNUSED(t);
Q_UNUSED(dao);
}
static inline void onAfterInsert(T *t, qx::dao::detail::IxDao_Helper *dao)
{
Q_UNUSED(t);
Q_UNUSED(dao);
}
static inline void onAfterUpdate(T *t, qx::dao::detail::IxDao_Helper *dao)
{
Q_UNUSED(t);
Q_UNUSED(dao);
}
static inline void onAfterDelete(T *t, qx::dao::detail::IxDao_Helper *dao)
{
Q_UNUSED(t);
Q_UNUSED(dao);
}
static inline void onAfterFetch(T *t, qx::dao::detail::IxDao_Helper *dao)
{
Q_UNUSED(t);
Q_UNUSED(dao);
}
};
template <int dummy>
struct TriggerHelper<true, dummy>
{
static inline void onBeforeInsert(T *t, qx::dao::detail::IxDao_Helper *dao) { qx::dao::detail::QxDao_Trigger<type_base>::onBeforeInsert(static_cast<type_base *>(t), dao); }
static inline void onBeforeUpdate(T *t, qx::dao::detail::IxDao_Helper *dao) { qx::dao::detail::QxDao_Trigger<type_base>::onBeforeUpdate(static_cast<type_base *>(t), dao); }
static inline void onBeforeDelete(T *t, qx::dao::detail::IxDao_Helper *dao) { qx::dao::detail::QxDao_Trigger<type_base>::onBeforeDelete(static_cast<type_base *>(t), dao); }
static inline void onBeforeFetch(T *t, qx::dao::detail::IxDao_Helper *dao) { qx::dao::detail::QxDao_Trigger<type_base>::onBeforeFetch(static_cast<type_base *>(t), dao); }
static inline void onAfterInsert(T *t, qx::dao::detail::IxDao_Helper *dao) { qx::dao::detail::QxDao_Trigger<type_base>::onAfterInsert(static_cast<type_base *>(t), dao); }
static inline void onAfterUpdate(T *t, qx::dao::detail::IxDao_Helper *dao) { qx::dao::detail::QxDao_Trigger<type_base>::onAfterUpdate(static_cast<type_base *>(t), dao); }
static inline void onAfterDelete(T *t, qx::dao::detail::IxDao_Helper *dao) { qx::dao::detail::QxDao_Trigger<type_base>::onAfterDelete(static_cast<type_base *>(t), dao); }
static inline void onAfterFetch(T *t, qx::dao::detail::IxDao_Helper *dao) { qx::dao::detail::QxDao_Trigger<type_base>::onAfterFetch(static_cast<type_base *>(t), dao); }
};
};
} // namespace detail
} // namespace dao
} // namespace qx

398
inl/QxDao/QxDao_Update.inl Normal file
View File

@@ -0,0 +1,398 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Update_Generic
{
static QSqlError update(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase, const QStringList &columns, bool bUseExecBatch)
{
Q_UNUSED(bUseExecBatch); // Useful only with containers
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "update", new qx::QxSqlQueryBuilder_Update<T>(), (&query));
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.isValidPrimaryKey(t))
{
return dao.errInvalidId();
}
if (!dao.validateInstance(t))
{
return dao.error();
}
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
qx::dao::on_before_update<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
QString ctx = QString("mongodb") + ((columns.count() > 0) ? (QString(":columns{,") + columns.join(",") + QString(",}")) : QString());
qx::dao::mongodb::QxMongoDB_Helper::updateOne((&dao), dao.getDataMemberX()->getClass(), qx::serialization::json::to_string(t, 1, ctx), (&query));
if (!dao.isValid())
{
return dao.error();
}
qx::dao::on_after_update<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql(columns).getSqlQuery();
if (!dao.getDataId() || sql.isEmpty())
{
return dao.errEmpty();
}
if (!query.isEmpty())
{
dao.addQuery(false);
sql = dao.builder().getSqlQuery();
}
if (!pDatabase)
{
dao.transaction();
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
IxSqlGenerator *pSqlGenerator = dao.getSqlGenerator();
if (pSqlGenerator)
{
pSqlGenerator->onBeforeUpdate((&dao), (&t));
}
qx::dao::on_before_update<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_Update<T>::resolveInput(t, dao.query(), dao.builder(), columns);
}
if (!query.isEmpty())
{
query.resolve(dao.query());
}
if (!dao.exec(true))
{
return dao.errFailed();
}
if (pSqlGenerator)
{
pSqlGenerator->onAfterUpdate((&dao), (&t));
}
qx::dao::on_after_update<T>((&t), (&dao));
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
};
template <class T>
struct QxDao_Update_Container
{
static QSqlError update(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase, const QStringList &columns, bool bUseExecBatch)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "update", new qx::QxSqlQueryBuilder_Update<type_item>(), (&query));
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.validateInstance(t))
{
return dao.error();
}
dao.setUseExecBatch(bUseExecBatch);
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
dao.setSqlColumns(columns);
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!updateItem((*it), dao))
{
return dao.error();
}
}
QStringList &itemsAsJson = dao.itemsAsJson();
qx::dao::mongodb::QxMongoDB_Helper::updateMany((&dao), dao.getDataMemberX()->getClass(), itemsAsJson, (&query));
if (!dao.isValid())
{
return dao.error();
}
dao.qxQuery().queryAt(2, "<done>");
dao.itemsAsJson().clear();
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!updateItem((*it), dao))
{
return dao.error();
}
}
return dao.error();
}
#endif // _QX_ENABLE_MONGODB
QString sql = dao.builder().buildSql(columns).getSqlQuery();
if (!dao.getDataId() || sql.isEmpty())
{
return dao.errEmpty();
}
if (!query.isEmpty())
{
dao.addQuery(false);
sql = dao.builder().getSqlQuery();
}
if (!pDatabase)
{
dao.transaction();
}
if (!dao.prepare(sql))
{
return dao.errFailed(true);
}
dao.setSqlColumns(columns);
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!updateItem((*it), dao))
{
return dao.error();
}
}
if (bUseExecBatch && (!dao.exec()))
{
return dao.errFailed();
}
return dao.error();
}
private:
template <typename U>
static inline bool updateItem(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bUpdateOk = updateItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::update(item, dao);
if (bUpdateOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bUpdateOk;
}
template <typename U, bool bIsPointer /* = true */>
struct updateItem_Helper
{
static inline bool update(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Update_Container<T>::updateItem((*item), dao) : true);
}
};
template <typename U1, typename U2>
struct updateItem_Helper<std::pair<U1, U2>, false>
{
static inline bool update(std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Update_Container<T>::updateItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct updateItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool update(const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Update_Container<T>::updateItem(item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct updateItem_Helper<QPair<U1, U2>, false>
{
static inline bool update(QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Update_Container<T>::updateItem(item.second, dao);
}
};
template <typename U1, typename U2>
struct updateItem_Helper<const QPair<U1, U2>, false>
{
static inline bool update(const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Update_Container<T>::updateItem(item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct updateItem_Helper<U, false>
{
static bool update(U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
QStringList columns = dao.getSqlColumns();
#ifdef _QX_ENABLE_MONGODB
if (dao.isMongoDB())
{
if (dao.qxQuery().queryAt(2) == "<done>")
{
qx::dao::on_after_update<U>((&item), (&dao));
return dao.isValid();
}
QString ctx = QString("mongodb") + ((columns.count() > 0) ? (QString(":columns{,") + columns.join(",") + QString(",}")) : QString());
qx::dao::on_before_update<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
dao.itemsAsJson().append(qx::serialization::json::to_string(item, 1, ctx));
return dao.isValid();
}
#endif // _QX_ENABLE_MONGODB
if (!dao.isValidPrimaryKey(item))
{
dao.errInvalidId();
return false;
}
IxSqlGenerator *pSqlGenerator = dao.getSqlGenerator();
if (pSqlGenerator)
{
pSqlGenerator->onBeforeUpdate((&dao), (&item));
}
qx::dao::on_before_update<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
{
qx::dao::detail::IxDao_Timer timer((&dao), qx::dao::detail::IxDao_Helper::timer_cpp_read_instance);
qx::dao::detail::QxSqlQueryHelper_Update<U>::resolveInput(item, dao.query(), dao.builder(), columns);
}
dao.resolveQuery();
if (dao.getUseExecBatch())
{
return dao.isValid();
}
if (!dao.exec(true))
{
dao.errFailed();
return false;
}
if (pSqlGenerator)
{
pSqlGenerator->onAfterUpdate((&dao), (&item));
}
qx::dao::on_after_update<U>((&item), (&dao));
if (!dao.isValid())
{
return false;
}
return dao.isValid();
}
};
};
template <class T>
struct QxDao_Update_Ptr
{
static inline QSqlError update(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase, const QStringList &columns, bool bUseExecBatch)
{
return (t ? qx::dao::update_by_query(query, (*t), pDatabase, columns, bUseExecBatch) : QSqlError());
}
};
template <class T>
struct QxDao_Update
{
static inline QSqlError update(const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase, const QStringList &columns, bool bUseExecBatch = false)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_Update_Ptr<T>, qx::dao::detail::QxDao_Update_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_Update_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_Update_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::update(query, t, pDatabase, columns, bUseExecBatch);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Update_Optimized_Generic
{
static inline QSqlError update_optimized(const qx::QxSqlQuery &query, qx::dao::ptr<T> &ptr, QSqlDatabase *pDatabase, bool bUseExecBatch)
{
Q_UNUSED(bUseExecBatch); // Useful only with containers
QStringList lstDiff;
if (ptr.isNull() || !ptr.isDirty(lstDiff))
{
return QSqlError();
}
return qx::dao::update_by_query(query, (*ptr), pDatabase, lstDiff);
}
};
template <class T>
struct QxDao_Update_Optimized_Container
{
static inline QSqlError update_optimized(const qx::QxSqlQuery &query, qx::dao::ptr<T> &ptr, QSqlDatabase *pDatabase, bool bUseExecBatch)
{
if (ptr.isNull() || (qx::trait::generic_container<T>::size(*ptr) <= 0))
{
return QSqlError();
}
if (!ptr.getOriginal() || (qx::trait::generic_container<T>::size(*ptr) != qx::trait::generic_container<T>::size(*ptr.getOriginal())))
{
return qx::dao::update_by_query(query, (*ptr), pDatabase);
}
QStringList lstDiffItem;
QSqlError errorItem;
QSqlDatabase db;
bool bCheckDatabaseTransaction = true;
#ifdef _QX_ENABLE_MONGODB
if (qx::QxSqlDatabase::getSingleton()->getDriverName() == "QXMONGODB")
{
bCheckDatabaseTransaction = false;
}
#endif // _QX_ENABLE_MONGODB
if (bCheckDatabaseTransaction)
{
db = (pDatabase ? (*pDatabase) : qx::QxSqlDatabase::getDatabase(errorItem));
if (errorItem.isValid())
{
return errorItem;
}
if (!pDatabase)
{
db.transaction();
}
}
typename T::const_iterator it2 = ptr.getOriginal()->begin();
for (typename T::const_iterator it1 = ptr->begin(); it1 != ptr->end(); ++it1)
{
lstDiffItem.clear();
qx::dao::detail::is_dirty((*it1), (*it2), lstDiffItem);
if (lstDiffItem.count() > 0)
{
errorItem = qx::dao::update_by_query(query, (*it1), (&db), lstDiffItem, bUseExecBatch);
}
if (errorItem.isValid())
{
break;
}
else
{
++it2;
}
}
if (bCheckDatabaseTransaction)
{
if (!pDatabase && !errorItem.isValid())
{
db.commit();
}
else if (!pDatabase)
{
db.rollback();
}
}
return errorItem;
}
};
template <class T>
struct QxDao_Update_Optimized
{
static inline QSqlError update_optimized(const qx::QxSqlQuery &query, qx::dao::ptr<T> &ptr, QSqlDatabase *pDatabase, bool bUseExecBatch = false)
{
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_Update_Optimized_Container<T>, qx::dao::detail::QxDao_Update_Optimized_Generic<T>>::type type_dao_1;
QSqlError error = type_dao_1::update_optimized(query, ptr, pDatabase, bUseExecBatch);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<qx::dao::ptr<T>>::backup(ptr);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,280 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxDao_Update_WithRelation_Generic
{
static QSqlError update(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
qx::dao::detail::QxDao_Helper<T> dao(t, pDatabase, "update with relation", new qx::QxSqlQueryBuilder_Update<T>());
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.isValidPrimaryKey(t))
{
return dao.errInvalidId();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
qx::QxSqlRelationParams params(0, 0, NULL, (&dao.builder()), (&dao.query()), (&t));
params.setDatabase((&dao.database()));
qx::QxSqlRelationLinked *pRelationLinked = dao.getSqlRelationLinked();
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnBeforeSave(params));
}
if (!dao.isValid())
{
return dao.error();
}
dao.updateError(qx::dao::update_by_query(query, t, (&dao.database())));
if (!dao.isValid())
{
return dao.error();
}
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnAfterSave(params));
}
if (!dao.isValid())
{
return dao.error();
}
return dao.error();
}
};
template <class T>
struct QxDao_Update_WithRelation_Container
{
static QSqlError update(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
typedef typename qx::trait::generic_container<T>::type_value_qx type_item;
if (qx::trait::generic_container<T>::size(t) <= 0)
{
return QSqlError();
}
qx::dao::detail::QxDao_Helper_Container<T> dao(t, pDatabase, "update with relation", new qx::QxSqlQueryBuilder_Update<type_item>());
if (!dao.isValid())
{
return dao.error();
}
if (dao.isReadOnly())
{
return dao.errReadOnly();
}
if (!dao.updateSqlRelationX(relation))
{
return dao.errInvalidRelation();
}
if (!pDatabase)
{
dao.transaction();
}
dao.quiet();
for (typename T::iterator it = t.begin(); it != t.end(); ++it)
{
if (!updateItem(query, (*it), dao))
{
return dao.error();
}
}
return dao.error();
}
private:
template <typename U>
static inline bool updateItem(const qx::QxSqlQuery &query, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
bool bUpdateOk = updateItem_Helper < U, std::is_pointer<U>::value || qx::trait::is_smart_ptr<U>::value > ::update(query, item, dao);
if (bUpdateOk)
{
qx::dao::detail::QxDao_Keep_Original<U>::backup(item);
}
return bUpdateOk;
}
template <typename U, bool bIsPointer /* = true */>
struct updateItem_Helper
{
static inline bool update(const qx::QxSqlQuery &query, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return (item ? qx::dao::detail::QxDao_Update_WithRelation_Container<T>::updateItem(query, (*item), dao) : true);
}
};
template <typename U1, typename U2>
struct updateItem_Helper<std::pair<U1, U2>, false>
{
static inline bool update(const qx::QxSqlQuery &query, std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Update_WithRelation_Container<T>::updateItem(query, item.second, dao);
}
};
template <typename U1, typename U2>
struct updateItem_Helper<const std::pair<U1, U2>, false>
{
static inline bool update(const qx::QxSqlQuery &query, const std::pair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Update_WithRelation_Container<T>::updateItem(query, item.second, dao);
}
};
#if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U1, typename U2>
struct updateItem_Helper<QPair<U1, U2>, false>
{
static inline bool update(const qx::QxSqlQuery &query, QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Update_WithRelation_Container<T>::updateItem(query, item.second, dao);
}
};
template <typename U1, typename U2>
struct updateItem_Helper<const QPair<U1, U2>, false>
{
static inline bool update(const qx::QxSqlQuery &query, const QPair<U1, U2> &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
return qx::dao::detail::QxDao_Update_WithRelation_Container<T>::updateItem(query, item.second, dao);
}
};
#endif // (QT_VERSION < QT_VERSION_CHECK(6, 0, 0))
template <typename U>
struct updateItem_Helper<U, false>
{
static bool update(const qx::QxSqlQuery &query, U &item, qx::dao::detail::QxDao_Helper_Container<T> &dao)
{
qx::QxSqlRelationParams params(0, 0, NULL, (&dao.builder()), (&dao.query()), (&item));
params.setDatabase((&dao.database()));
qx::QxSqlRelationLinked *pRelationLinked = dao.getSqlRelationLinked();
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnBeforeSave(params));
}
if (!dao.isValid())
{
return false;
}
dao.updateError(qx::dao::update_by_query(query, item, (&dao.database())));
if (!dao.isValid())
{
return false;
}
if (pRelationLinked)
{
dao.updateError(pRelationLinked->hierarchyOnAfterSave(params));
}
if (!dao.isValid())
{
return false;
}
return dao.isValid();
}
};
};
template <class T>
struct QxDao_Update_WithRelation_Ptr
{
static inline QSqlError update(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
return (t ? qx::dao::update_by_query_with_relation(relation, query, (*t), pDatabase) : QSqlError());
}
};
template <class T>
struct QxDao_Update_WithRelation
{
static inline QSqlError update(const QString &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
QStringList lst;
if (!relation.isEmpty())
{
lst = relation.split("|");
}
return QxDao_Update_WithRelation<T>::update(lst, query, t, pDatabase);
}
static inline QSqlError update(const QStringList &relation, const qx::QxSqlQuery &query, T &t, QSqlDatabase *pDatabase)
{
typedef typename std::conditional<std::is_pointer<T>::value, qx::dao::detail::QxDao_Update_WithRelation_Ptr<T>, qx::dao::detail::QxDao_Update_WithRelation_Generic<T>>::type type_dao_1;
typedef typename std::conditional<qx::trait::is_smart_ptr<T>::value, qx::dao::detail::QxDao_Update_WithRelation_Ptr<T>, type_dao_1>::type type_dao_2;
typedef typename std::conditional<qx::trait::is_container<T>::value, qx::dao::detail::QxDao_Update_WithRelation_Container<T>, type_dao_2>::type type_dao_3;
QSqlError error = type_dao_3::update(relation, query, t, pDatabase);
if (!error.isValid())
{
qx::dao::detail::QxDao_Keep_Original<T>::backup(t);
}
return error;
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,66 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_CreateTable
{
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_CreateTable(sql, builder);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
Q_UNUSED(t);
Q_UNUSED(query);
Q_UNUSED(builder);
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
Q_UNUSED(t);
Q_UNUSED(query);
Q_UNUSED(builder);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,65 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_DeleteById
{
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder, bool bSoftDelete)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_DeleteById(sql, builder, bSoftDelete);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::resolveInput_DeleteById((&t), query, builder);
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
Q_UNUSED(t);
Q_UNUSED(query);
Q_UNUSED(builder);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,67 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_Exist
{
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_Exist(sql, builder);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxDataMember *pId = builder.getDataId();
qAssert(pId);
pId->setSqlPlaceHolder(query, (&t));
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
Q_UNUSED(t);
Q_UNUSED(query);
Q_UNUSED(builder);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_FetchAll
{
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_FetchAll(sql, builder);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
Q_UNUSED(t);
Q_UNUSED(query);
Q_UNUSED(builder);
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::resolveOutput_FetchAll((&t), query, builder);
}
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder, const QStringList &columns)
{
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QxSqlQueryHelper_FetchAll<T>::sql(sql, builder);
return;
}
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_FetchAll(sql, builder, columns);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder, const QStringList &columns)
{
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QxSqlQueryHelper_FetchAll<T>::resolveInput(t, query, builder);
return;
}
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder, const QStringList &columns)
{
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QxSqlQueryHelper_FetchAll<T>::resolveOutput(t, query, builder);
return;
}
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::resolveOutput_FetchAll((&t), query, builder, columns);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_FetchAll_WithRelation
{
static void sql(qx::QxSqlRelationLinked *pRelationX, QString &sql, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
if (!pRelationX)
{
qAssert(false);
QxSqlQueryHelper_FetchAll<T>::sql(sql, builder);
return;
}
qx::IxSqlQueryBuilder::sql_FetchAll_WithRelation(pRelationX, sql, builder);
}
static void resolveInput(qx::QxSqlRelationLinked *pRelationX, T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
Q_UNUSED(pRelationX);
Q_UNUSED(t);
Q_UNUSED(query);
Q_UNUSED(builder);
}
static void resolveOutput(qx::QxSqlRelationLinked *pRelationX, T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
if (!pRelationX)
{
qAssert(false);
QxSqlQueryHelper_FetchAll<T>::resolveOutput(t, query, builder);
return;
}
qx::IxSqlQueryBuilder::resolveOutput_FetchAll_WithRelation(pRelationX, (&t), query, builder);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_FetchById
{
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_FetchById(sql, builder);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxDataMember *pId = builder.getDataId();
qAssert(pId);
pId->setSqlPlaceHolder(query, (&t));
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
QxSqlQueryHelper_FetchAll<T>::resolveOutput(t, query, builder);
}
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder, const QStringList &columns)
{
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QxSqlQueryHelper_FetchById<T>::sql(sql, builder);
return;
}
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_FetchById(sql, builder, columns);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder, const QStringList &columns)
{
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QxSqlQueryHelper_FetchById<T>::resolveInput(t, query, builder);
return;
}
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxDataMember *pId = builder.getDataId();
qAssert(pId);
pId->setSqlPlaceHolder(query, (&t));
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder, const QStringList &columns)
{
QxSqlQueryHelper_FetchAll<T>::resolveOutput(t, query, builder, columns);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,77 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_FetchById_WithRelation
{
static void sql(qx::QxSqlRelationLinked *pRelationX, QString &sql, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
if (!pRelationX)
{
qAssert(false);
QxSqlQueryHelper_FetchById<T>::sql(sql, builder);
return;
}
qx::IxSqlQueryBuilder::sql_FetchById_WithRelation(pRelationX, sql, builder);
}
static void resolveInput(qx::QxSqlRelationLinked *pRelationX, T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
if (!pRelationX)
{
qAssert(false);
QxSqlQueryHelper_FetchById<T>::resolveInput(t, query, builder);
return;
}
qx::IxDataMember *pId = builder.getDataId();
qAssert(pId);
pId->setSqlPlaceHolder(query, (&t));
}
static void resolveOutput(qx::QxSqlRelationLinked *pRelationX, T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
QxSqlQueryHelper_FetchAll_WithRelation<T>::resolveOutput(pRelationX, t, query, builder);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,65 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_Insert
{
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_Insert(sql, builder);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::resolveInput_Insert((&t), query, builder);
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
Q_UNUSED(t);
Q_UNUSED(query);
Q_UNUSED(builder);
}
};
} // namespace detail
} // namespace dao
} // namespace qx

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
**
****************************************************************************/
namespace qx
{
namespace dao
{
namespace detail
{
template <class T>
struct QxSqlQueryHelper_Update
{
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_Update(sql, builder);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::resolveInput_Update((&t), query, builder);
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder)
{
Q_UNUSED(t);
Q_UNUSED(query);
Q_UNUSED(builder);
}
static void sql(QString &sql, qx::IxSqlQueryBuilder &builder, const QStringList &columns)
{
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QxSqlQueryHelper_Update<T>::sql(sql, builder);
return;
}
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::sql_Update(sql, builder, columns);
}
static void resolveInput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder, const QStringList &columns)
{
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QxSqlQueryHelper_Update<T>::resolveInput(t, query, builder);
return;
}
static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
qx::IxSqlQueryBuilder::resolveInput_Update((&t), query, builder, columns);
}
static void resolveOutput(T &t, QSqlQuery &query, qx::IxSqlQueryBuilder &builder, const QStringList &columns)
{
if ((columns.count() <= 0) || (columns.at(0) == "*"))
{
QxSqlQueryHelper_Update<T>::resolveOutput(t, query, builder);
return;
}
}
};
} // namespace detail
} // namespace dao
} // namespace qx

View File

@@ -0,0 +1,35 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
} // namespace qx

View File

@@ -0,0 +1,463 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
template <class T>
IxDataMember *QxDataMemberX<T>::initId(IxDataMember *pId, long lVersion)
{
if (!pId)
{
qAssert(false);
return NULL;
}
qAssert(lVersion <= getVersion());
QString sKey = pId->getKey();
pId->setSqlType(qx::trait::get_sql_type<typename QxDataMemberX<T>::type_primary_key>::get());
pId->setAutoIncrement(std::is_integral<typename QxDataMemberX<T>::type_primary_key>::value);
pId->setNameParent(getName());
pId->setIsPrimaryKey(true);
pId->setNotNull(true);
pId->setVersion(lVersion);
pId->setParent(this);
this->setId(pId);
this->getListDataMemberRef().insert(sKey, pId);
return pId;
}
template <class T>
IxDataMember *QxDataMemberX<T>::initData(IxDataMember *pData, long lVersion)
{
if (!pData)
{
qAssert(false);
return NULL;
}
qAssert(lVersion <= getVersion());
QString sKey = pData->getKey();
pData->setVersion(lVersion);
pData->setNameParent(getName());
pData->setParent(this);
this->getListDataMemberRef().insert(sKey, pData);
return pData;
}
template <class T>
IxDataMember *QxDataMemberX<T>::initPImpl(IxDataMember *pImpl)
{
if (!pImpl)
{
qAssert(false);
return NULL;
}
QString sKey = pImpl->getKey();
if (this->getListPImplRef().exist(sKey))
{
qAssert(false);
return NULL;
}
pImpl->setNameParent(getName());
pImpl->setParent(this);
this->getListPImplRef().insert(sKey, pImpl);
return pImpl;
}
template <class T>
template <typename V, typename U>
IxDataMember *QxDataMemberX<T>::add(V U::*pData, const QString &sKey, long lVersion /* = 0 */, bool bSerialize /* = true */, bool bDao /* = true */)
{
typedef std::is_base_of<U, T> is_valid_class_tmp;
static_assert(is_valid_class_tmp::value, "is_valid_class_tmp::value");
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pNewDataMember = new QxDataMember<V, T>(pData, sKey, lVersion, bSerialize, bDao);
pNewDataMember->setSqlType(qx::trait::get_sql_type<V>::get());
return this->initData(pNewDataMember, lVersion);
}
template <class T>
IxDataMember *QxDataMemberX<T>::add(const QString &sKey, long lVersion)
{
if (!qx::trait::qt_meta_object<T>::is_valid)
{
qDebug("[QxOrm] qx::QxDataMemberX<T>::add() : '%s'", "Qt introspection engine works only with QObject class");
qAssert(false);
return NULL;
}
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
return this->initData(new QxDataMember_QObject(qx::trait::qt_meta_object<T>::get(), sKey), lVersion);
}
template <class T>
IxDataMember *QxDataMemberX<T>::id(typename QxDataMemberX<T>::type_primary_key T::*pDataMemberId, const QString &sKey, long lVersion /* = 0 */)
{
if (getId_WithDaoStrategy())
{
qDebug("[QxOrm] qx::QxDataMemberX<T> id (primary key) already defined '%s'", qPrintable(getId_WithDaoStrategy()->getName()));
}
if (exist_WithDaoStrategy(sKey) || getId_WithDaoStrategy())
{
qAssert(false);
return getId_WithDaoStrategy();
}
return this->initId(new QxDataMember<typename QxDataMemberX<T>::type_primary_key, T>(pDataMemberId, sKey, lVersion, true, true), lVersion);
}
template <class T>
IxDataMember *QxDataMemberX<T>::id(const QString &sKey, long lVersion)
{
if (!qx::trait::qt_meta_object<T>::is_valid)
{
qDebug("[QxOrm] qx::QxDataMemberX<T>::id() : '%s'", "Qt introspection engine works only with QObject class");
qAssert(false);
return NULL;
}
if (getId_WithDaoStrategy())
{
qDebug("[QxOrm] qx::QxDataMemberX<T> id (primary key) already defined '%s'", qPrintable(getId_WithDaoStrategy()->getName()));
}
if (exist_WithDaoStrategy(sKey) || getId_WithDaoStrategy())
{
qAssert(false);
return getId_WithDaoStrategy();
}
return this->initId(new QxDataMember_QObject(qx::trait::qt_meta_object<T>::get(), sKey), lVersion);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxDataMemberX<T>::relationOneToOne(V U::*pData, const QString &sKey, long lVersion /* = 0 */)
{
typedef std::is_base_of<U, T> is_valid_class_tmp;
static_assert(is_valid_class_tmp::value, "is_valid_class_tmp::value");
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pDataMember = this->add(pData, sKey, lVersion);
IxSqlRelation *pSqlRelation = new QxSqlRelation_OneToOne<V, T>(pDataMember);
pDataMember->setSqlRelation(pSqlRelation);
return pSqlRelation;
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxDataMemberX<T>::relationManyToOne(V U::*pData, const QString &sKey, long lVersion /* = 0 */)
{
typedef std::is_base_of<U, T> is_valid_class_tmp;
static_assert(is_valid_class_tmp::value, "is_valid_class_tmp::value");
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pDataMember = this->add(pData, sKey, lVersion);
IxSqlRelation *pSqlRelation = new QxSqlRelation_ManyToOne<V, T>(pDataMember);
pDataMember->setSqlRelation(pSqlRelation);
return pSqlRelation;
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxDataMemberX<T>::relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion /* = 0 */)
{
typedef std::is_base_of<U, T> is_valid_class_tmp;
static_assert(is_valid_class_tmp::value, "is_valid_class_tmp::value");
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pDataMember = this->add(pData, sKey, lVersion);
IxSqlRelation *pSqlRelation = new QxSqlRelation_OneToMany<V, T>(pDataMember, sForeignKey);
pDataMember->setSqlRelation(pSqlRelation);
return pSqlRelation;
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxDataMemberX<T>::relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion /* = 0 */)
{
typedef std::is_base_of<U, T> is_valid_class_tmp;
static_assert(is_valid_class_tmp::value, "is_valid_class_tmp::value");
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pDataMember = this->add(pData, sKey, lVersion);
IxSqlRelation *pSqlRelation = new QxSqlRelation_ManyToMany<V, T>(pDataMember, sExtraTable, sForeignKeyOwner, sForeignKeyDataType);
pDataMember->setSqlRelation(pSqlRelation);
return pSqlRelation;
}
template <class T>
template <typename V, typename U>
IxDataMember *QxDataMemberX<T>::pimpl(V U::*pData, const QString &sKey)
{
IxDataMember *pNewDataMember = new QxDataMember_PImpl<V, U>(pData, sKey);
return this->initPImpl(pNewDataMember);
}
template <class T>
template <typename U>
IxDataMember *QxDataMemberX<T>::id(typename QxDataMemberX<T>::type_primary_key U::*pDataMemberId, const QString &sKey, long lVersion, IxDataMember *pImpl)
{
if (pImpl)
{
qAssert((pImpl->getParent()) && (pImpl->getParent()->getClass() == this->getClass()));
}
if (getId_WithDaoStrategy())
{
qDebug("[QxOrm] qx::QxDataMemberX<T> id (primary key) already defined '%s'", qPrintable(getId_WithDaoStrategy()->getName()));
}
if (exist_WithDaoStrategy(sKey) || getId_WithDaoStrategy())
{
qAssert(false);
return getId_WithDaoStrategy();
}
return this->initId(new QxDataMember<typename QxDataMemberX<T>::type_primary_key, U>(pDataMemberId, sKey, lVersion, true, true, pImpl), lVersion);
}
template <class T>
template <typename V, typename U>
IxDataMember *QxDataMemberX<T>::add(V U::*pData, const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl)
{
if (pImpl)
{
qAssert((pImpl->getParent()) && (pImpl->getParent()->getClass() == this->getClass()));
}
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pNewDataMember = new QxDataMember<V, U>(pData, sKey, lVersion, bSerialize, bDao, pImpl);
pNewDataMember->setSqlType(qx::trait::get_sql_type<V>::get());
return this->initData(pNewDataMember, lVersion);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxDataMemberX<T>::relationOneToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl)
{
if (pImpl)
{
qAssert((pImpl->getParent()) && (pImpl->getParent()->getClass() == this->getClass()));
}
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pDataMember = this->add(pData, sKey, lVersion, true, true, pImpl);
IxSqlRelation *pSqlRelation = new QxSqlRelation_OneToOne<V, T>(pDataMember);
pDataMember->setSqlRelation(pSqlRelation);
return pSqlRelation;
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxDataMemberX<T>::relationManyToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl)
{
if (pImpl)
{
qAssert((pImpl->getParent()) && (pImpl->getParent()->getClass() == this->getClass()));
}
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pDataMember = this->add(pData, sKey, lVersion, true, true, pImpl);
IxSqlRelation *pSqlRelation = new QxSqlRelation_ManyToOne<V, T>(pDataMember);
pDataMember->setSqlRelation(pSqlRelation);
return pSqlRelation;
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxDataMemberX<T>::relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion, IxDataMember *pImpl)
{
if (pImpl)
{
qAssert((pImpl->getParent()) && (pImpl->getParent()->getClass() == this->getClass()));
}
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pDataMember = this->add(pData, sKey, lVersion, true, true, pImpl);
IxSqlRelation *pSqlRelation = new QxSqlRelation_OneToMany<V, T>(pDataMember, sForeignKey);
pDataMember->setSqlRelation(pSqlRelation);
return pSqlRelation;
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxDataMemberX<T>::relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion, IxDataMember *pImpl)
{
if (pImpl)
{
qAssert((pImpl->getParent()) && (pImpl->getParent()->getClass() == this->getClass()));
}
if (exist_WithDaoStrategy(sKey))
{
qAssert(false);
return NULL;
}
IxDataMember *pDataMember = this->add(pData, sKey, lVersion, true, true, pImpl);
IxSqlRelation *pSqlRelation = new QxSqlRelation_ManyToMany<V, T>(pDataMember, sExtraTable, sForeignKeyOwner, sForeignKeyDataType);
pDataMember->setSqlRelation(pSqlRelation);
return pSqlRelation;
}
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
template <class T>
template <class Archive>
inline void QxDataMemberX<T>::toArchive(const T *pOwner, Archive &ar, const unsigned int file_version) const
{
Q_UNUSED(file_version);
const QxCollection<QString, IxDataMember *> &lstDataMember = this->getListDataMemberRef();
_foreach_if(IxDataMember * pDataMember, lstDataMember, (pDataMember->getSerialize()))
pDataMember->toArchive(pOwner, ar);
}
template <class T>
template <class Archive>
inline void QxDataMemberX<T>::fromArchive(T *pOwner, Archive &ar, const unsigned int file_version)
{
Q_UNUSED(file_version);
QxCollection<QString, IxDataMember *> &lstDataMember = this->getListDataMemberRef();
_foreach_if(IxDataMember * pDataMember, lstDataMember, (pDataMember->getSerialize() && (pDataMember->getVersion() <= static_cast<long>(file_version))))
pDataMember->fromArchive(pOwner, ar);
}
#endif // _QX_ENABLE_BOOST_SERIALIZATION
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE
QxDataMemberX<qx::trait::no_base_class_defined>::QxDataMemberX() : IxDataMemberX(), QxSingleton<QxDataMemberX<qx::trait::no_base_class_defined>>("qx::QxDataMemberX_no_base_class_defined") { ; }
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE
QxDataMemberX<QObject>::QxDataMemberX() : IxDataMemberX(), QxSingleton<QxDataMemberX<QObject>>("qx::QxDataMemberX_QObject") { ; }
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE long QxDataMemberX<qx::trait::no_base_class_defined>::count_WithDaoStrategy_Helper() const { return 0; }
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE bool QxDataMemberX<qx::trait::no_base_class_defined>::exist_WithDaoStrategy_Helper(const QString &sKey) const
{
Q_UNUSED(sKey);
return false;
}
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember *QxDataMemberX<qx::trait::no_base_class_defined>::get_WithDaoStrategy_Helper(long lIndex) const
{
Q_UNUSED(lIndex);
return NULL;
}
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember *QxDataMemberX<qx::trait::no_base_class_defined>::get_WithDaoStrategy_Helper(const QString &sKey) const
{
Q_UNUSED(sKey);
return NULL;
}
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember *QxDataMemberX<qx::trait::no_base_class_defined>::getId_WithDaoStrategy_Helper() const { return NULL; }
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE long QxDataMemberX<QObject>::count_WithDaoStrategy_Helper() const { return 0; }
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE bool QxDataMemberX<QObject>::exist_WithDaoStrategy_Helper(const QString &sKey) const
{
Q_UNUSED(sKey);
return false;
}
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember *QxDataMemberX<QObject>::get_WithDaoStrategy_Helper(long lIndex) const
{
Q_UNUSED(lIndex);
return NULL;
}
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember *QxDataMemberX<QObject>::get_WithDaoStrategy_Helper(const QString &sKey) const
{
Q_UNUSED(sKey);
return NULL;
}
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember *QxDataMemberX<QObject>::getId_WithDaoStrategy_Helper() const { return NULL; }
} // namespace qx

View File

@@ -0,0 +1,56 @@
/****************************************************************************
**
** 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 _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4996)
#pragma warning(disable : 4094)
#endif // _MSC_VER
#include <QxSerialize/QxSerialize.h>
#ifndef QX_REGISTER_FACTORY_HPP
#define QX_REGISTER_FACTORY_COMPLEX_CLASS_NAME_HPP(className, classNameFormatted) \
extern qx::QxFactory<className> G_QX_REGISTER_FACTORY_##classNameFormatted;
#define QX_REGISTER_FACTORY_HPP(className) \
QX_REGISTER_FACTORY_COMPLEX_CLASS_NAME_HPP(className, className)
#endif // QX_REGISTER_FACTORY_HPP
#ifndef QX_REGISTER_FACTORY_CPP
#define QX_REGISTER_FACTORY_COMPLEX_CLASS_NAME_CPP(className, classNameFormatted) \
qx::QxFactory<className> G_QX_REGISTER_FACTORY_##classNameFormatted(QString(#className));
#define QX_REGISTER_FACTORY_CPP(className) \
QX_REGISTER_FACTORY_COMPLEX_CLASS_NAME_CPP(className, className)
#endif // QX_REGISTER_FACTORY_CPP
#ifdef _MSC_VER
#pragma warning(pop)
#endif // _MSC_VER

361
inl/QxRegister/QxClass.inl Normal file
View File

@@ -0,0 +1,361 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
#include <QxRegister/QxVersion.h>
namespace qx
{
template <class T>
void QxClass<T>::init()
{
this->setDataMemberX(QxDataMemberX<T>::getSingleton());
this->getDataMemberX()->setClass(this);
this->setFctMemberX(new IxFunctionX());
this->setFctStaticX(new IxFunctionX());
#ifdef _QX_ENABLE_BOOST_SERIALIZATION
this->setVersion(boost::serialization::version<T>::value);
#else // _QX_ENABLE_BOOST_SERIALIZATION
this->setVersion(qx::version<T>::value);
#endif // _QX_ENABLE_BOOST_SERIALIZATION
this->setKey(qx::trait::get_class_name<T>::get());
this->setDaoStrategy(QxClass<typename QxClass<T>::type_base_class>::getSingleton()->getDaoStrategy());
this->setName(qx::trait::get_class_name<T>::get_xml_tag());
this->updateClassX();
beforeRegisterClass();
}
template <class T>
IxDataMember *QxClass<T>::data(const QString &sKey, long lVersion)
{
return this->dataMemberX()->add(sKey, lVersion);
}
template <class T>
template <typename V, typename U>
IxDataMember *QxClass<T>::data(V U::*pData, const QString &sKey, long lVersion /* = 0 */, bool bSerialize /* = true */, bool bDao /* = true */)
{
return this->dataMemberX()->add(pData, sKey, lVersion, bSerialize, bDao);
}
template <class T>
IxDataMember *QxClass<T>::id(const QString &sKey, long lVersion)
{
return this->dataMemberX()->id(sKey, lVersion);
}
template <class T>
IxDataMember *QxClass<T>::id(typename QxClass<T>::type_primary_key T::*pDataMemberId, const QString &sKey, long lVersion /* = 0 */)
{
return this->dataMemberX()->id(pDataMemberId, sKey, lVersion);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxClass<T>::relationOneToOne(V U::*pData, const QString &sKey, long lVersion /* = 0 */)
{
return this->dataMemberX()->relationOneToOne(pData, sKey, lVersion);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxClass<T>::relationManyToOne(V U::*pData, const QString &sKey, long lVersion /* = 0 */)
{
return this->dataMemberX()->relationManyToOne(pData, sKey, lVersion);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxClass<T>::relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion /* = 0 */)
{
return this->dataMemberX()->relationOneToMany(pData, sKey, sForeignKey, lVersion);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxClass<T>::relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion /* = 0 */)
{
return this->dataMemberX()->relationManyToMany(pData, sKey, sExtraTable, sForeignKeyOwner, sForeignKeyDataType, lVersion);
}
template <class T>
template <typename V, typename U>
IxDataMember *QxClass<T>::pimpl(V U::*pData, const QString &sKey /* = QString("_PIMPL_") */)
{
return this->dataMemberX()->pimpl(pData, sKey);
}
template <class T>
template <typename U>
IxDataMember *QxClass<T>::id(typename QxClass<T>::type_primary_key U::*pDataMemberId, const QString &sKey, long lVersion, IxDataMember *pImpl)
{
return this->dataMemberX()->id(pDataMemberId, sKey, lVersion, pImpl);
}
template <class T>
template <typename V, typename U>
IxDataMember *QxClass<T>::data(V U::*pData, const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl)
{
return this->dataMemberX()->add(pData, sKey, lVersion, bSerialize, bDao, pImpl);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxClass<T>::relationOneToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl)
{
return this->dataMemberX()->relationOneToOne(pData, sKey, lVersion, pImpl);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxClass<T>::relationManyToOne(V U::*pData, const QString &sKey, long lVersion, IxDataMember *pImpl)
{
return this->dataMemberX()->relationManyToOne(pData, sKey, lVersion, pImpl);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxClass<T>::relationOneToMany(V U::*pData, const QString &sKey, const QString &sForeignKey, long lVersion, IxDataMember *pImpl)
{
return this->dataMemberX()->relationOneToMany(pData, sKey, sForeignKey, lVersion, pImpl);
}
template <class T>
template <typename V, typename U>
IxSqlRelation *QxClass<T>::relationManyToMany(V U::*pData, const QString &sKey, const QString &sExtraTable, const QString &sForeignKeyOwner, const QString &sForeignKeyDataType, long lVersion, IxDataMember *pImpl)
{
return this->dataMemberX()->relationManyToMany(pData, sKey, sExtraTable, sForeignKeyOwner, sForeignKeyDataType, lVersion, pImpl);
}
template <class T>
IxFunction *QxClass<T>::insertFct(IxFunction_ptr pFct, const QString &sKey)
{
if (!this->getFctMemberX() || sKey.isEmpty() || this->getFctMemberX()->exist(sKey))
{
qAssert(false);
return NULL;
}
bool bInsertOk = this->getFctMemberX()->insert(sKey, pFct);
if (bInsertOk)
{
pFct->setKey(sKey);
}
return (bInsertOk ? pFct.get() : NULL);
}
template <class T>
IxFunction *QxClass<T>::insertFctStatic(IxFunction_ptr pFct, const QString &sKey)
{
if (!this->getFctStaticX() || sKey.isEmpty() || this->getFctStaticX()->exist(sKey))
{
qAssert(false);
return NULL;
}
bool bInsertOk = this->getFctStaticX()->insert(sKey, pFct);
if (bInsertOk)
{
pFct->setKey(sKey);
}
return (bInsertOk ? pFct.get() : NULL);
}
template <class T>
template <typename R>
IxFunction *QxClass<T>::fct_0(const typename QxFunction_0<T, R>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_0<T, R>(fct), sKey);
}
template <class T>
template <typename R, typename P1>
IxFunction *QxClass<T>::fct_1(const typename QxFunction_1<T, R, P1>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_1<T, R, P1>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2>
IxFunction *QxClass<T>::fct_2(const typename QxFunction_2<T, R, P1, P2>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_2<T, R, P1, P2>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3>
IxFunction *QxClass<T>::fct_3(const typename QxFunction_3<T, R, P1, P2, P3>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_3<T, R, P1, P2, P3>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4>
IxFunction *QxClass<T>::fct_4(const typename QxFunction_4<T, R, P1, P2, P3, P4>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_4<T, R, P1, P2, P3, P4>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
IxFunction *QxClass<T>::fct_5(const typename QxFunction_5<T, R, P1, P2, P3, P4, P5>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_5<T, R, P1, P2, P3, P4, P5>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
IxFunction *QxClass<T>::fct_6(const typename QxFunction_6<T, R, P1, P2, P3, P4, P5, P6>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_6<T, R, P1, P2, P3, P4, P5, P6>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
IxFunction *QxClass<T>::fct_7(const typename QxFunction_7<T, R, P1, P2, P3, P4, P5, P6, P7>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_7<T, R, P1, P2, P3, P4, P5, P6, P7>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
IxFunction *QxClass<T>::fct_8(const typename QxFunction_8<T, R, P1, P2, P3, P4, P5, P6, P7, P8>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_8<T, R, P1, P2, P3, P4, P5, P6, P7, P8>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
IxFunction *QxClass<T>::fct_9(const typename QxFunction_9<T, R, P1, P2, P3, P4, P5, P6, P7, P8, P9>::type_fct &fct, const QString &sKey)
{
return this->insertFct(qx::function::bind_member_fct_9<T, R, P1, P2, P3, P4, P5, P6, P7, P8, P9>(fct), sKey);
}
template <class T>
template <typename R>
IxFunction *QxClass<T>::fctStatic_0(const typename QxFunction_0<void, R>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_0<void, R>(fct), sKey);
}
template <class T>
template <typename R, typename P1>
IxFunction *QxClass<T>::fctStatic_1(const typename QxFunction_1<void, R, P1>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_1<void, R, P1>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2>
IxFunction *QxClass<T>::fctStatic_2(const typename QxFunction_2<void, R, P1, P2>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_2<void, R, P1, P2>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3>
IxFunction *QxClass<T>::fctStatic_3(const typename QxFunction_3<void, R, P1, P2, P3>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_3<void, R, P1, P2, P3>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4>
IxFunction *QxClass<T>::fctStatic_4(const typename QxFunction_4<void, R, P1, P2, P3, P4>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_4<void, R, P1, P2, P3, P4>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5>
IxFunction *QxClass<T>::fctStatic_5(const typename QxFunction_5<void, R, P1, P2, P3, P4, P5>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_5<void, R, P1, P2, P3, P4, P5>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6>
IxFunction *QxClass<T>::fctStatic_6(const typename QxFunction_6<void, R, P1, P2, P3, P4, P5, P6>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_6<void, R, P1, P2, P3, P4, P5, P6>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7>
IxFunction *QxClass<T>::fctStatic_7(const typename QxFunction_7<void, R, P1, P2, P3, P4, P5, P6, P7>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_7<void, R, P1, P2, P3, P4, P5, P6, P7>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8>
IxFunction *QxClass<T>::fctStatic_8(const typename QxFunction_8<void, R, P1, P2, P3, P4, P5, P6, P7, P8>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_8<void, R, P1, P2, P3, P4, P5, P6, P7, P8>(fct), sKey);
}
template <class T>
template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9>
IxFunction *QxClass<T>::fctStatic_9(const typename QxFunction_9<void, R, P1, P2, P3, P4, P5, P6, P7, P8, P9>::type_fct &fct, const QString &sKey)
{
return this->insertFctStatic(qx::function::bind_fct_9<void, R, P1, P2, P3, P4, P5, P6, P7, P8, P9>(fct), sKey);
}
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE
QxClass<qx::trait::no_base_class_defined>::QxClass() : IxClass(), QxSingleton<QxClass<qx::trait::no_base_class_defined>>("qx::QxClass_no_base_class_defined")
{
setName("qx::trait::no_base_class_defined");
setFinalClass(true);
}
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE
QxClass<QObject>::QxClass() : IxClass(), QxSingleton<QxClass<QObject>>("qx::QxClass_QObject")
{
setKey("QObject");
setName("QObject");
setFinalClass(true);
}
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE void QxClass<qx::trait::no_base_class_defined>::registerClass() { ; }
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE void QxClass<QObject>::registerClass() { ; }
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE void QxClass<qx::trait::no_base_class_defined>::beforeRegisterClass() { ; }
template <>
QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE void QxClass<QObject>::beforeRegisterClass() { ; }
} // namespace qx

View File

@@ -0,0 +1,416 @@
/****************************************************************************
**
** 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_SERIALIZATION
namespace qx
{
template <class T, class ArchiveInput /* = QX_DEFAULT_ARCHIVE_INPUT */, class ArchiveOutput /* = QX_DEFAULT_ARCHIVE_OUTPUT */>
qx_bool QxArchive_ToFile<T, ArchiveInput, ArchiveOutput>::toFile(const T &obj, const QString &sFileName, unsigned int flags /* = boost::archive::no_header */)
{
typedef typename qx::trait::archive_wide_traits<ArchiveOutput>::type_ofstream qx_type_ofstream;
qx_type_ofstream ofile(qPrintable(sFileName), (std::ios_base::binary | std::ios_base::out | std::ios_base::trunc));
if (!ofile.is_open())
{
return qx_bool(false, 0, QString("Cannot create or open file '") + sFileName + QString("'"));
}
ArchiveOutput oar(ofile, flags);
qx_bool bSerializeOk = false;
const char *sTag = QxClassName<T>::get_xml_tag();
QxBoostSerializeRegisterHelperX::helper(oar);
try
{
oar << boost::serialization::make_nvp(sTag, obj);
bSerializeOk = ofile.good();
}
catch (const boost::archive::archive_exception &e)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (const std::exception &e)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (...)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", "unknown error"));
}
ofile.close();
if (!bSerializeOk.getDesc().isEmpty())
{
QString sMsg = QString("qx::QxArchive_ToFile<T>::toFile() -> ") + bSerializeOk.getDesc();
qDebug("[QxOrm] %s", qPrintable(sMsg));
}
qAssert(bSerializeOk);
return bSerializeOk;
}
template <class T, class ArchiveInput /* = QX_DEFAULT_ARCHIVE_INPUT */, class ArchiveOutput /* = QX_DEFAULT_ARCHIVE_OUTPUT */>
qx_bool QxArchive_FromFile<T, ArchiveInput, ArchiveOutput>::fromFile(T &obj, const QString &sFileName, unsigned int flags /* = boost::archive::no_header */)
{
typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_ifstream qx_type_ifstream;
qx_type_ifstream ifile(qPrintable(sFileName), (std::ios_base::binary | std::ios_base::in));
if (!ifile.is_open())
{
return qx_bool(false, 0, QString("Cannot open file '") + sFileName + QString("'"));
}
ArchiveInput iar(ifile, flags);
qx_bool bDeserializeOk = false;
const char *sTag = QxClassName<T>::get_xml_tag();
QxBoostSerializeRegisterHelperX::helper(iar);
try
{
iar >> boost::serialization::make_nvp(sTag, obj);
bDeserializeOk = true;
}
catch (const boost::archive::archive_exception &e)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (const std::exception &e)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (...)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", "unknown error"));
}
ifile.close();
if (!bDeserializeOk.getDesc().isEmpty())
{
QString sMsg = QString("qx::QxArchive_FromFile<T>::fromFile() -> ") + bDeserializeOk.getDesc();
qDebug("[QxOrm] %s", qPrintable(sMsg));
}
qAssert(bDeserializeOk);
return bDeserializeOk;
}
template <class T, class ArchiveInput /* = QX_DEFAULT_ARCHIVE_INPUT */, class ArchiveOutput /* = QX_DEFAULT_ARCHIVE_OUTPUT */>
qx_bool QxArchive_ToFileCompressed<T, ArchiveInput, ArchiveOutput>::toFileCompressed(const T &obj, const QString &sFileName, unsigned int flags /* = boost::archive::no_header */, int iCompressionLevel /* = -1 */)
{
typedef typename qx::trait::archive_wide_traits<ArchiveOutput>::type_ostringstream qx_type_ostringstream;
qx_type_ostringstream oss(std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
ArchiveOutput oar(oss, flags);
qx_bool bSerializeOk = false;
const char *sTag = QxClassName<T>::get_xml_tag();
QxBoostSerializeRegisterHelperX::helper(oar);
try
{
oar << boost::serialization::make_nvp(sTag, obj);
bSerializeOk = oss.good();
}
catch (const boost::archive::archive_exception &e)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (const std::exception &e)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (...)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", "unknown error"));
}
qAssert(bSerializeOk);
if (!bSerializeOk.getDesc().isEmpty())
{
QString sMsg = QString("qx::QxArchive_ToFileCompressed<T>::toFileCompressed() -> ") + bSerializeOk.getDesc();
qDebug("[QxOrm] %s", qPrintable(sMsg));
}
if (!bSerializeOk)
{
return false;
}
oss.seekp(0, std::ios::end);
QByteArray compressed = qCompress((unsigned char *)(oss.str().c_str()), static_cast<int>(oss.tellp()), iCompressionLevel);
if (compressed.isEmpty())
{
qAssert(false);
return qx_bool(false, 0, QString("Cannot compress archive"));
}
typedef typename qx::trait::archive_wide_traits<ArchiveOutput>::type_ofstream qx_type_ofstream;
qx_type_ofstream ofile(qPrintable(sFileName), (std::ios_base::binary | std::ios_base::out | std::ios_base::trunc));
if (!ofile.is_open())
{
return qx_bool(false, 0, QString("Cannot create or open compressed file '") + sFileName + QString("'"));
}
ofile.write(compressed.constData(), compressed.size());
ofile.close();
return true;
}
template <class T, class ArchiveInput /* = QX_DEFAULT_ARCHIVE_INPUT */, class ArchiveOutput /* = QX_DEFAULT_ARCHIVE_OUTPUT */>
qx_bool QxArchive_FromFileCompressed<T, ArchiveInput, ArchiveOutput>::fromFileCompressed(T &obj, const QString &sFileName, unsigned int flags /* = boost::archive::no_header */)
{
typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_ifstream qx_type_ifstream;
typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_char qx_type_char;
typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_string qx_type_string;
typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_istringstream qx_type_istringstream;
qx_type_ifstream ifile(qPrintable(sFileName), (std::ios_base::binary | std::ios_base::in));
if (!ifile.is_open())
{
return qx_bool(false, 0, QString("Cannot open compressed file '") + sFileName + QString("'"));
}
ifile.seekg(0, std::ios::end);
int iSize = ifile.tellg();
ifile.seekg(0, std::ios::beg);
qx_type_char *buffer = new qx_type_char[iSize];
ifile.read(buffer, iSize);
ifile.close();
QByteArray uncompressed = qUncompress((unsigned char *)(buffer), iSize);
if (uncompressed.isEmpty())
{
delete[] buffer;
qAssert(false);
return qx_bool(false, 0, QString("Cannot uncompress archive"));
}
delete[] buffer;
qx_type_string str(uncompressed.constData(), uncompressed.count());
qx_type_istringstream iss(str, (std::ios_base::binary | std::ios_base::in));
ArchiveInput iar(iss, flags);
qx_bool bDeserializeOk = false;
const char *sTag = QxClassName<T>::get_xml_tag();
QxBoostSerializeRegisterHelperX::helper(iar);
try
{
iar >> boost::serialization::make_nvp(sTag, obj);
bDeserializeOk = true;
}
catch (const boost::archive::archive_exception &e)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (const std::exception &e)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (...)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", "unknown error"));
}
if (!bDeserializeOk.getDesc().isEmpty())
{
QString sMsg = QString("qx::QxArchive_FromFileCompressed<T>::fromFileCompressed() -> ") + bDeserializeOk.getDesc();
qDebug("[QxOrm] %s", qPrintable(sMsg));
}
qAssert(bDeserializeOk);
return bDeserializeOk;
}
template <class T, class ArchiveInput /* = QX_DEFAULT_ARCHIVE_INPUT */, class ArchiveOutput /* = QX_DEFAULT_ARCHIVE_OUTPUT */>
QString QxArchive_ToString<T, ArchiveInput, ArchiveOutput>::toString(const T &obj, unsigned int flags /* = boost::archive::no_header */)
{
typedef typename qx::trait::archive_wide_traits<ArchiveOutput>::type_ostringstream qx_type_ostringstream;
qx_type_ostringstream oss(std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
ArchiveOutput oar(oss, flags);
qx_bool bSerializeOk = false;
const char *sTag = QxClassName<T>::get_xml_tag();
QxBoostSerializeRegisterHelperX::helper(oar);
try
{
oar << boost::serialization::make_nvp(sTag, obj);
bSerializeOk = oss.good();
}
catch (const boost::archive::archive_exception &e)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (const std::exception &e)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (...)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", "unknown error"));
}
if (!bSerializeOk.getDesc().isEmpty())
{
QString sMsg = QString("qx::QxArchive_ToString<T>::toString() -> ") + bSerializeOk.getDesc();
qDebug("[QxOrm] %s", qPrintable(sMsg));
}
qAssert(bSerializeOk);
return (bSerializeOk ? qx::trait::archive_wide_traits<ArchiveOutput>::toQString(oss.str()) : QString());
}
template <class T, class ArchiveInput /* = QX_DEFAULT_ARCHIVE_INPUT */, class ArchiveOutput /* = QX_DEFAULT_ARCHIVE_OUTPUT */>
qx_bool QxArchive_FromString<T, ArchiveInput, ArchiveOutput>::fromString(T &obj, const QString &sString, unsigned int flags /* = boost::archive::no_header */)
{
typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_string qx_type_string;
typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_istringstream qx_type_istringstream;
qx_type_string str;
if (sString.isEmpty())
{
return false;
}
qx::trait::archive_wide_traits<ArchiveInput>::fromQString(sString, str);
qx_type_istringstream iss(str, (std::ios_base::binary | std::ios_base::in));
ArchiveInput iar(iss, flags);
qx_bool bDeserializeOk = false;
const char *sTag = QxClassName<T>::get_xml_tag();
QxBoostSerializeRegisterHelperX::helper(iar);
try
{
iar >> boost::serialization::make_nvp(sTag, obj);
bDeserializeOk = true;
}
catch (const boost::archive::archive_exception &e)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (const std::exception &e)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (...)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", "unknown error"));
}
if (!bDeserializeOk.getDesc().isEmpty())
{
QString sMsg = QString("qx::QxArchive_FromString<T>::fromString() -> ") + bDeserializeOk.getDesc();
qDebug("[QxOrm] %s", qPrintable(sMsg));
}
qAssert(bDeserializeOk);
return bDeserializeOk;
}
template <class T, class ArchiveInput /* = QX_DEFAULT_ARCHIVE_INPUT */, class ArchiveOutput /* = QX_DEFAULT_ARCHIVE_OUTPUT */>
QByteArray QxArchive_ToByteArray<T, ArchiveInput, ArchiveOutput>::toByteArray(const T &obj, type_string *owner /* = NULL */, unsigned int flags /* = boost::archive::no_header */)
{
typedef typename qx::trait::archive_wide_traits<ArchiveOutput>::type_ostringstream qx_type_ostringstream;
qx_type_ostringstream oss(std::ios_base::binary | std::ios_base::out | std::ios_base::trunc);
ArchiveOutput oar(oss, flags);
qx_bool bSerializeOk = false;
const char *sTag = QxClassName<T>::get_xml_tag();
QxBoostSerializeRegisterHelperX::helper(oar);
try
{
oar << boost::serialization::make_nvp(sTag, obj);
bSerializeOk = oss.good();
}
catch (const boost::archive::archive_exception &e)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (const std::exception &e)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (...)
{
bSerializeOk.setDesc(QString(QX_STR_SERIALIZATION_ERROR).replace("%ERR%", "unknown error"));
}
if (!bSerializeOk.getDesc().isEmpty())
{
QString sMsg = QString("qx::QxArchive_ToByteArray<T>::toByteArray() -> ") + bSerializeOk.getDesc();
qDebug("[QxOrm] %s", qPrintable(sMsg));
}
qAssert(bSerializeOk);
return (bSerializeOk ? qx::trait::archive_wide_traits<ArchiveOutput>::toQByteArray(oss.str(), owner) : QByteArray());
}
template <class T, class ArchiveInput /* = QX_DEFAULT_ARCHIVE_INPUT */, class ArchiveOutput /* = QX_DEFAULT_ARCHIVE_OUTPUT */>
qx_bool QxArchive_FromByteArray<T, ArchiveInput, ArchiveOutput>::fromByteArray(T &obj, const QByteArray &data, unsigned int flags /* = boost::archive::no_header */)
{
typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_string qx_type_string;
typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_istringstream qx_type_istringstream;
qx_type_string str;
if (data.size() <= 0)
{
return false;
}
qx::trait::archive_wide_traits<ArchiveInput>::fromQByteArray(data, str);
qx_type_istringstream iss(str, (std::ios_base::binary | std::ios_base::in));
ArchiveInput iar(iss, flags);
qx_bool bDeserializeOk = false;
const char *sTag = QxClassName<T>::get_xml_tag();
QxBoostSerializeRegisterHelperX::helper(iar);
try
{
iar >> boost::serialization::make_nvp(sTag, obj);
bDeserializeOk = true;
}
catch (const boost::archive::archive_exception &e)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (const std::exception &e)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", e.what()));
}
catch (...)
{
bDeserializeOk.setDesc(QString(QX_STR_DESERIALIZATION_ERROR).replace("%ERR%", "unknown error"));
}
if (!bDeserializeOk.getDesc().isEmpty())
{
QString sMsg = QString("qx::QxArchive_FromByteArray<T>::fromByteArray() -> ") + bDeserializeOk.getDesc();
qDebug("[QxOrm] %s", qPrintable(sMsg));
}
qAssert(bDeserializeOk);
return bDeserializeOk;
}
} // namespace qx
#endif // _QX_ENABLE_BOOST_SERIALIZATION

View File

@@ -0,0 +1,50 @@
/****************************************************************************
**
** 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_SERIALIZATION
namespace boost
{
namespace serialization
{
template <class Archive>
inline void serialize(Archive &ar, qx::trait::no_base_class_defined &t, const unsigned int file_version)
{
Q_UNUSED(ar);
Q_UNUSED(t);
Q_UNUSED(file_version);
}
} // namespace serialization
} // namespace boost
#endif // _QX_ENABLE_BOOST_SERIALIZATION

View File

@@ -0,0 +1,69 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
namespace qx
{
template <class T>
T *QxSingleton<T>::m_pSingleton = NULL;
template <class T>
QMutex QxSingleton<T>::m_oMutexSingleton;
template <class T>
T *QxSingleton<T>::getSingleton()
{
if (m_pSingleton)
return m_pSingleton;
IxSingleton::initQxSingletonX();
QMutexLocker locker(QCoreApplication::instance() ? (&m_oMutexSingleton) : NULL);
if (!m_pSingleton)
{
m_pSingleton = new T();
}
return m_pSingleton;
}
template <class T>
void QxSingleton<T>::deleteSingleton()
{
QMutexLocker locker(QCoreApplication::instance() ? (&m_oMutexSingleton) : NULL);
if (!m_pSingleton)
{
return;
}
delete m_pSingleton;
m_pSingleton = NULL;
}
} // namespace qx

85
inl/QxXml/QxXml.inl Normal file
View File

@@ -0,0 +1,85 @@
/****************************************************************************
**
** 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
**
****************************************************************************/
template <class T>
QString QxXml<T>::toXml(T *pOwner)
{
if (!pOwner)
{
return "";
}
QxXmlWriter xmlWriter;
QxDataMemberX<T>::toXml(pOwner, &xmlWriter);
return xmlWriter.getXml();
}
template <class T>
bool QxXml<T>::fromXml(T *pOwner, const QString &sXml)
{
if (!pOwner || sXml.isEmpty())
{
return false;
}
QxXmlReader xmlReader(sXml);
QxDataMemberX<T>::fromXml(pOwner, &xmlReader);
return true;
}
template <class T>
std::shared_ptr<QxXmlWriter> QxXml<T>::toXmlWriter(T *pOwner)
{
if (!pOwner)
{
return std::shared_ptr<QxXmlWriter>();
}
std::shared_ptr<QxXmlWriter> pXmlWriter;
pXmlWriter.reset(new QxXmlWriter());
QxDataMemberX<T>::toXml(pOwner, pXmlWriter.get());
return pXmlWriter;
}
template <class T>
bool QxXml<T>::fromXmlReader(T *pOwner, QxXmlReader *pXmlReader)
{
if (!pOwner || !pXmlReader)
{
return false;
}
QxDataMemberX<T>::fromXml(pOwner, pXmlReader);
return true;
}