32#ifndef _IX_DATA_MEMBER_H_
33#define _IX_DATA_MEMBER_H_
48#pragma warning(disable:4996)
51#include <QtSql/qsqlquery.h>
54#include <QtCore/qjsonvalue.h>
71#define QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(ArchiveInput, ArchiveOutput) \
72virtual void toArchive(const void * pOwner, ArchiveOutput & ar) const = 0; \
73virtual void fromArchive(void * pOwner, ArchiveInput & ar) = 0;
79class IxSqlQueryBuilder;
80struct IxDataMemberSqlCallbackParams;
97 template <
typename DataType,
class Owner>
106 struct IxDataMemberImpl;
166 void setMinValue(
long lMinValue,
const QString & sMessage = QString());
167 void setMinValue(
double dMinValue,
const QString & sMessage = QString());
168 void setMaxValue(
long lMaxValue,
const QString & sMessage = QString());
169 void setMaxValue(
double dMaxValue,
const QString & sMessage = QString());
170 void setMinLength(
int iMinLength,
const QString & sMessage = QString());
171 void setMaxLength(
int iMaxLength,
const QString & sMessage = QString());
172 void setNotNull(
bool bNotNull,
const QString & sMessage = QString());
179 QString
getName(
int iIndex,
const QString & sOtherName = QString())
const;
183 QString
getSqlPlaceHolder(
const QString & sAppend = QString(),
int iIndexName = 0,
const QString & sSep = QString(
", "),
const QString & sOtherName = QString(),
bool bCheckFKPartOfPK =
false)
const;
185 QString
getSqlAliasEqualToPlaceHolder(
const QString & sTable = QString(),
bool bClauseWhere =
false,
const QString & sAppend = QString(),
const QString & sSep = QString(
" AND "),
bool bCheckFKPartOfPK =
false,
qx::IxSqlQueryBuilder * pSqlQueryBuilder = NULL)
const;
187 QString
getSqlTablePointNameAsAlias(
const QString & sTable,
const QString & sSep = QString(
", "),
const QString & sSuffixAlias = QString(),
bool bCheckFKPartOfPK =
false,
const QString & sCustomAlias = QString(),
qx::IxSqlQueryBuilder * pSqlQueryBuilder = NULL)
const;
188 QString
getSqlName(
const QString & sSep = QString(
", "),
const QString & sOtherName = QString(),
bool bCheckFKPartOfPK =
false,
qx::IxSqlQueryBuilder * pSqlQueryBuilder = NULL)
const;
189 QString
getSqlNameAndTypeAndParams(
const QString & sSep = QString(
", "),
const QString & sOtherName = QString(),
bool bCheckFKPartOfPK =
false)
const;
197 static QString
getSqlFromTable(
const QString & sTable,
const QString & sCustomAlias = QString());
203 virtual bool isEqual(
const void * pOwner1,
const void * pOwner2)
const = 0;
211 virtual QJsonValue
toJson(
const void * pOwner,
const QString & sFormat)
const = 0;
212 virtual qx_bool fromJson(
void * pOwner,
const QJsonValue & j,
const QString & sFormat) = 0;
214 QJsonValue
toJson(
const void * pOwner)
const;
229 void *
getValueVoidPtr(
const void * pOwner)
const {
return this->getDataVoidPtr(pOwner); }
232 template <
typename T>
235 if (bOk) { (* bOk) =
false; }
236 if (! getAccessDataPointer()) { qDebug(
"[QxOrm] qx::IxDataMember::getValuePtr<T>() : '%s'",
"cannot access data-member pointer");
return NULL; }
237 qx::any a = this->getDataPtr(pOwner);
238 try { T * t =
qx::any_cast<T *>(a);
if (bOk) { (* bOk) = (t != NULL); };
return t; }
239 catch (
const qx::bad_any_cast & err) { Q_UNUSED(err); qDebug(
"[QxOrm] qx::IxDataMember::getValuePtr<T>() : '%s'",
"bad any cast exception");
return NULL; }
240 catch (...) { qDebug(
"[QxOrm] qx::IxDataMember::getValuePtr<T>() : '%s'",
"unknown cast exception");
return NULL; }
243 template <
typename T>
247 T * t = this->getValuePtr<T>(pOwner, bOk);
248 return (t ? (* t) : T());
251 template <
typename T>
255 T * t = this->getValuePtr<T>(pOwner);
256 if (t) { (* t) = val; }
262 template <
typename T,
int dummy>
266 { Q_UNUSED(pData); Q_UNUSED(pOwner); qDebug(
"[QxOrm] qx::IxDataMember::qxCannotAccessDataPointer<T>::getValue() : '%s'",
"type T not supported");
if (bOk) { (* bOk) =
false; };
return T(); }
268 { Q_UNUSED(pData); Q_UNUSED(pOwner); Q_UNUSED(val); qDebug(
"[QxOrm] qx::IxDataMember::qxCannotAccessDataPointer<T>::setValue() : '%s'",
"type T not supported");
return false; }
275 {
if (bOk) { (* bOk) = (pData != NULL); };
return (pData ? pData->
toVariant(pOwner,
"") : QVariant()); }
284 {
if (bOk) { (* bOk) = (pData != NULL); };
return (pData ? pData->
toVariant(pOwner,
"").toString() : QString()); }
286 { QVariant tmp(val);
return (pData ? pData->
fromVariant(pOwner, tmp,
"").
getValue() :
false); }
291#ifdef _QX_ENABLE_BOOST_SERIALIZATION
293#if _QX_SERIALIZE_POLYMORPHIC
297#if _QX_SERIALIZE_BINARY
301#if _QX_SERIALIZE_TEXT
309#if _QX_SERIALIZE_PORTABLE_BINARY
313#if _QX_SERIALIZE_WIDE_BINARY
317#if _QX_SERIALIZE_WIDE_TEXT
321#if _QX_SERIALIZE_WIDE_XML
329#ifdef _QX_ENABLE_BOOST_SERIALIZATION
330 template <
class Archive>
331 void serialize(Archive & ar,
const unsigned int version);
QX_DLL_EXPORT_INLINE_FCT bool operator<(const qx::IxDataMember &i1, const qx::IxDataMember &i2)
QX_DLL_EXPORT_INLINE_FCT bool operator>(const qx::IxDataMember &i1, const qx::IxDataMember &i2)
#define QX_IX_DATA_MEMBER_PURE_VIRTUAL_ARCHIVE(ArchiveInput, ArchiveOutput)
qx::any : basic implementation of boost::any (written by Kevlin Henney) when boost dependency is not ...
qx_bool : QxOrm library boolean type with code and description message when an error occured
QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
qx::cvt : namespace to provide global functions to convert any kind of objects to/from QString and QV...
#define QX_DLL_EXPORT_INLINE_FCT
Used by introspection engine (IxClass, IxDataMember, IxFunction, etc.) to add meta-data (property bag...
Portable binary input archive using little endian format.
Portable binary output archive using little endian format.
qx::IxDataMember : common interface for all class properties registered into QxOrm context
bool hasSqlRelation() const
qx::any getValueAnyPtr(void *pOwner)
QString getTypeParent() const
void customGetSqlName(type_fct_sql_callback fct)
virtual qx_bool fromJson(void *pOwner, const QJsonValue &j, const QString &sFormat)=0
QString getNameParent() const
QVariant toVariant(const void *pOwner, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context) const
QString getSqlTablePointNameAsAlias(const QString &sTable, const QString &sSep=QString(", "), const QString &sSuffixAlias=QString(), bool bCheckFKPartOfPK=false, const QString &sCustomAlias=QString(), qx::IxSqlQueryBuilder *pSqlQueryBuilder=NULL) const
void setSqlRelation(IxSqlRelation *p)
void setMaxValue(long lMaxValue, const QString &sMessage=QString())
void customGetSqlNameEqualToPlaceHolder(type_fct_sql_callback fct)
bool getIsPrimaryKey() const
virtual void * getDataVoidPtr(void *pOwner)=0
virtual void * getDataVoidPtr(const void *pOwner) const =0
T getValue(void *pOwner, bool *bOk=NULL)
static QString getSqlColumnNameAlias(const QString &sColumn)
virtual QString getType() const
void customGetSqlAlias(type_fct_sql_callback fct)
virtual ~IxDataMember()=0
std::function< void(IxDataMemberSqlCallbackParams &)> type_fct_sql_callback
void setAutoIncrement(bool b)
void setFormat(const QString &s)
QString getSqlTypeAndParams(int iIndexName=-1) const
IxDataMember(const QString &sKey, long lVersion, bool bSerialize, bool bDao, IxDataMember *pImpl)
void setRelationPartOfPrimaryKey(int iIndexNamePK, IxSqlRelation *pRelation, int iIndexNameFK)
void setMinLength(int iMinLength, const QString &sMessage=QString())
void serialize(Archive &ar, const unsigned int version)
QString getSqlPlaceHolder(const QString &sAppend=QString(), int iIndexName=0, const QString &sSep=QString(", "), const QString &sOtherName=QString(), bool bCheckFKPartOfPK=false) const
void setParent(IxDataMemberX *p)
bool isPartOfPrimaryKey(int iIndexNameFK, IxDataMember *&pPrimaryKey, int &iIndexNamePK) const
void setIsPrimaryKey(bool b)
static QString getSqlColumnName(const QString &sColumn)
const char * getNamePtr() const
bool getAutoIncrement() const
void setNotNull(bool bNotNull, const QString &sMessage=QString())
virtual QJsonValue toJson(const void *pOwner, const QString &sFormat) const =0
void setMaxLength(int iMaxLength, const QString &sMessage=QString())
QString getSqlNameAndTypeAndParams(const QString &sSep=QString(", "), const QString &sOtherName=QString(), bool bCheckFKPartOfPK=false) const
bool getSerialize() const
static QString getSqlTableNameAlias(const QString &sTable)
void setSqlType(const QString &s)
virtual bool isEqual(const void *pOwner1, const void *pOwner2) const =0
QString getFormat() const
QString getSqlNameEqualToPlaceHolder(const QString &sAppend=QString(), const QString &sSep=QString(" AND "), bool bCheckFKPartOfPK=false, qx::IxSqlQueryBuilder *pSqlQueryBuilder=NULL) const
QJsonValue toJson(const void *pOwner) const
virtual qx::any getDataPtr(void *pOwner)=0
qx_bool fromVariant(void *pOwner, const QVariant &v, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)
bool getAccessDataPointer() const
virtual qx::any getDataPtr(const void *pOwner) const =0
void * getValueVoidPtr(void *pOwner)
static QString getSqlTableName(const QString &sTable)
void setName(const QString &s)
QString getName(int iIndex, const QString &sOtherName=QString()) const
QString getDescription() const
bool setValue(void *pOwner, const T &val)
IxDataMember * getPImpl() const
qx_bool fromJson(void *pOwner, const QJsonValue &j)
IxDataMemberX * getParent() const
QVariant getMaxValue() const
std::unique_ptr< IxDataMemberImpl > m_pImpl
Private implementation idiom.
T * getValuePtr(void *pOwner, bool *bOk=NULL)
void customGetSqlAliasEqualToPlaceHolder(type_fct_sql_callback fct)
virtual qx_bool fromVariant(void *pOwner, const QVariant &v, const QString &sFormat, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context)=0
QString getSqlAliasEqualToPlaceHolder(const QString &sTable=QString(), bool bClauseWhere=false, const QString &sAppend=QString(), const QString &sSep=QString(" AND "), bool bCheckFKPartOfPK=false, qx::IxSqlQueryBuilder *pSqlQueryBuilder=NULL) const
QString getSqlAlias(const QString &sTable=QString(), bool bClauseWhere=false, int iIndexName=0, qx::IxSqlQueryBuilder *pSqlQueryBuilder=NULL) const
void setMaxValue(double dMaxValue, const QString &sMessage=QString())
void setPartOfPrimaryKey(int iIndexNameFK, IxDataMember *pPrimaryKey, int iIndexNamePK)
void setSqlPlaceHolder(QSqlQuery &query, void *pOwner, const QString &sAppend=QString(), const QString &sOtherName=QString(), bool bCheckFKPartOfPK=false, qx::QxCollection< QString, QVariantList > *pLstExecBatch=NULL) const
void * getValueVoidPtr(const void *pOwner) const
QString getSqlType(int iIndexName=-1) const
void setAccessDataPointer(bool b)
void setDefaultValue(const QVariant &v)
QString getSqlName(const QString &sSep=QString(", "), const QString &sOtherName=QString(), bool bCheckFKPartOfPK=false, qx::IxSqlQueryBuilder *pSqlQueryBuilder=NULL) const
void setSqlAlias(const QString &s)
void setDescription(const QString &s)
IxSqlRelation * getSqlRelation() const
void setMinValue(double dMinValue, const QString &sMessage=QString())
bool isThereRelationPartOfPrimaryKey(int iIndexNamePK, IxSqlRelation *&pRelation, int &iIndexNameFK) const
QVariant getMinValue() const
static QString getSqlFromTable(const QString &sTable, const QString &sCustomAlias=QString())
virtual QVariant toVariant(const void *pOwner, const QString &sFormat, int iIndexName=-1, qx::cvt::context::ctx_type ctx=qx::cvt::context::e_no_context) const =0
void setNameParent(const QString &s)
void customGetSqlTablePointNameAsAlias(type_fct_sql_callback fct)
qx::any getValueAnyPtr(const void *pOwner) const
void setSerialize(bool b)
QVariant getDefaultValue() const
void setMinValue(long lMinValue, const QString &sMessage=QString())
qx::IxDataMemberX : common interface for a list of IxDataMember class properties registered into QxOr...
qx::IxSqlQueryBuilder : common interface to build SQL queries to communicate with database
qx::IxSqlRelation : common interface for all relationships defined between 2 classes (or between 2 ta...
qx_bool : boolean type with code and description message when an error occured
qx::QxCollection<Key, Value> : QxOrm thread-safe container (keep insertion order + quick access by in...
qx::QxDataMember<DataType, Owner> : concrete property of type DataType registered into QxOrm context ...
qx::QxPropertyBag : used by introspection engine (IxClass, IxDataMember, IxFunction,...
qx::dao::detail::IxDao_Helper : helper class to communicate with database
Root namespace for all QxOrm library features.
ValueType * any_cast(any *)
std::shared_ptr< IxDataMember > IxDataMember_ptr
static bool setValue(IxDataMember *pData, void *pOwner, const QString &val)
static QString getValue(IxDataMember *pData, void *pOwner, bool *bOk)
static QVariant getValue(IxDataMember *pData, void *pOwner, bool *bOk)
static bool setValue(IxDataMember *pData, void *pOwner, const QVariant &val)
static bool setValue(IxDataMember *pData, void *pOwner, const T &val)
static T getValue(IxDataMember *pData, void *pOwner, bool *bOk)
qx::IxDataMemberSqlCallbackParams : list of parameters used by custom callback functions to override ...
QString sCustomAlias
SQL custom alias (not always provided)
IxDataMemberSqlCallbackParams(const IxDataMember *p, QString &sql)
bool bCheckFKPartOfPK
Check if foreign key is part of primary key (not always provided)
QString sAppend
String to append to SQL query (not always provided)
QString sSep
SQL separator (not always provided)
int iIndexName
Index name for composite primary key (not always provided)
qx::dao::detail::IxDao_Helper * pDaoHelper
DAO helper instance.
qx::IxSqlQueryBuilder * pSqlQueryBuilder
SQL query builder instance.
~IxDataMemberSqlCallbackParams()
QString sSuffixAlias
SQL suffix alias (not always provided)
bool bClauseWhere
Define if we are building SQL in the clause WHERE or not (not always provided)
QString & sSQL
Default value is the SQL generated by QxOrm library for this data member, can be changed by the custo...
QString sOtherName
SQL other name for this data member (not always provided)
const IxDataMember * pDataMember
The data member instance which calls custom callback function.
QString sTable
SQL table name (not always provided)