/**************************************************************************** ** ** https://www.qxorm.com/ ** Copyright (C) 2013 Lionel Marty (contact@qxorm.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 Lionel Marty ** ** 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 : ** contact@qxorm.com ** ****************************************************************************/ namespace qx { template IxDataMember * QxDataMemberX::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::type_primary_key>::get()); pId->setAutoIncrement(std::is_integral::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 IxDataMember * QxDataMemberX::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 template IxDataMember * QxDataMemberX::add(V U::* pData, const QString & sKey, long lVersion /* = 0 */, bool bSerialize /* = true */, bool bDao /* = true */) { typedef std::is_base_of 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(pData, sKey, lVersion, bSerialize, bDao); pNewDataMember->setSqlType(qx::trait::get_sql_type::get()); return this->initData(pNewDataMember, lVersion); } template IxDataMember * QxDataMemberX::add(const QString & sKey, long lVersion) { if (! qx::trait::qt_meta_object::is_valid) { qDebug("[QxOrm] qx::QxDataMemberX::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::get(), sKey), lVersion); } template IxDataMember * QxDataMemberX::id(typename QxDataMemberX::type_primary_key T::* pDataMemberId, const QString & sKey, long lVersion /* = 0 */) { if (getId_WithDaoStrategy()) { qDebug("[QxOrm] qx::QxDataMemberX 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::type_primary_key, T>(pDataMemberId, sKey), lVersion); } template IxDataMember * QxDataMemberX::id(const QString & sKey, long lVersion) { if (! qx::trait::qt_meta_object::is_valid) { qDebug("[QxOrm] qx::QxDataMemberX::id() : '%s'", "Qt introspection engine works only with QObject class"); qAssert(false); return NULL; } if (getId_WithDaoStrategy()) { qDebug("[QxOrm] qx::QxDataMemberX 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::get(), sKey), lVersion); } template template IxSqlRelation * QxDataMemberX::relationOneToOne(V U::* pData, const QString & sKey, long lVersion /* = 0 */) { typedef std::is_base_of 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(pDataMember); pDataMember->setSqlRelation(pSqlRelation); return pSqlRelation; } template template IxSqlRelation * QxDataMemberX::relationManyToOne(V U::* pData, const QString & sKey, long lVersion /* = 0 */) { typedef std::is_base_of 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(pDataMember); pDataMember->setSqlRelation(pSqlRelation); return pSqlRelation; } template template IxSqlRelation * QxDataMemberX::relationOneToMany(V U::* pData, const QString & sKey, const QString & sForeignKey, long lVersion /* = 0 */) { typedef std::is_base_of 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(pDataMember, sForeignKey); pDataMember->setSqlRelation(pSqlRelation); return pSqlRelation; } template template IxSqlRelation * QxDataMemberX::relationManyToMany(V U::* pData, const QString & sKey, const QString & sExtraTable, const QString & sForeignKeyOwner, const QString & sForeignKeyDataType, long lVersion /* = 0 */) { typedef std::is_base_of 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(pDataMember, sExtraTable, sForeignKeyOwner, sForeignKeyDataType); pDataMember->setSqlRelation(pSqlRelation); return pSqlRelation; } #ifdef _QX_ENABLE_BOOST_SERIALIZATION template template inline void QxDataMemberX::toArchive(const T * pOwner, Archive & ar, const unsigned int file_version) const { Q_UNUSED(file_version); const QxCollection & lstDataMember = this->getListDataMemberRef(); _foreach_if(IxDataMember * pDataMember, lstDataMember, (pDataMember->getSerialize())) pDataMember->toArchive(pOwner, ar); } template template inline void QxDataMemberX::fromArchive(T * pOwner, Archive & ar, const unsigned int file_version) { Q_UNUSED(file_version); QxCollection & lstDataMember = this->getListDataMemberRef(); _foreach_if(IxDataMember * pDataMember, lstDataMember, (pDataMember->getSerialize() && (pDataMember->getVersion() <= static_cast(file_version)))) pDataMember->fromArchive(pOwner, ar); } #endif // _QX_ENABLE_BOOST_SERIALIZATION template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE QxDataMemberX::QxDataMemberX() : IxDataMemberX(), QxSingleton< QxDataMemberX >("qx::QxDataMemberX_no_base_class_defined") { ; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE QxDataMemberX::QxDataMemberX() : IxDataMemberX(), QxSingleton< QxDataMemberX >("qx::QxDataMemberX_QObject") { ; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE long QxDataMemberX::count_WithDaoStrategy_Helper() const { return 0; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE bool QxDataMemberX::exist_WithDaoStrategy_Helper(const QString & sKey) const { Q_UNUSED(sKey); return false; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember * QxDataMemberX::get_WithDaoStrategy_Helper(long lIndex) const { Q_UNUSED(lIndex); return NULL; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember * QxDataMemberX::get_WithDaoStrategy_Helper(const QString & sKey) const { Q_UNUSED(sKey); return NULL; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember * QxDataMemberX::getId_WithDaoStrategy_Helper() const { return NULL; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE long QxDataMemberX::count_WithDaoStrategy_Helper() const { return 0; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE bool QxDataMemberX::exist_WithDaoStrategy_Helper(const QString & sKey) const { Q_UNUSED(sKey); return false; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember * QxDataMemberX::get_WithDaoStrategy_Helper(long lIndex) const { Q_UNUSED(lIndex); return NULL; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember * QxDataMemberX::get_WithDaoStrategy_Helper(const QString & sKey) const { Q_UNUSED(sKey); return NULL; } template <> QX_GCC_WORKAROUND_TEMPLATE_SPEC_INLINE IxDataMember * QxDataMemberX::getId_WithDaoStrategy_Helper() const { return NULL; } } // namespace qx