QxOrm is a C++ library designed to provide Object Relational Mapping (ORM) feature to C++ users.
QxOrm is developed by Lionel Marty, a software development engineer since 2003.QxOrm provides many functionalities starting from a simple C++ setting function by class :

QxOrm uses qmake process from Qt library to create makefile and build the project.qmake is portable and multi-platform, so it works perfectly on Windows, Linux (Unix) and Mac.
To build QxOrm library, just execute following commands :qmakemake debugmake release

On Windows, *.vcproj and *.sln files are available for Visual C++ 2008, Visual C++ 2010 and Visual C++ 2012.*.pro files are readable by Qt Creator, and some plugins are available to interface to other C++ IDE.mingw_build_all_debug.bat and mingw_build_all_release.bat scripts in the directory ./tools/ can quickly built QxOrm library and all tests with MinGW compiler on Windows.gcc_build_all_debug.sh and gcc_build_all_release.sh scripts in the directory ./tools/ can quickly built QxOrm library and all tests with GCC compiler on Linux.osx_build_all_debug.sh and osx_build_all_release.sh scripts in the directory ./tools/ can quickly built QxOrm library and all tests on Mac (thanks very much to Dominique Billet).

QxOrm uses the engine QtSql of Qt based on a system of plug-in.
A detailed list of supported databases is available on the website of Qt here. The plug-in ODBC (QODBC) ensures compatibility with many databases. For optimal performances, it is possible to use a plug-in specific to a database :

QxOrm uses many functionalities available in excellent libraries : boost and Qt.
In addition, these two libraries are used in many projects both professional and open source.
A large number of forums, tutorials, and a whole community are available to answer any issue that could arise.
The QxOrm objective is not to redevelop features that already exist but to provide a powerful tool for access to databases such as it exists in other languages (Java with Hibernate, .Net with NHibernate, Ruby, Python, etc...).

Qt : cross-platform application development framework : GUI (QtGui), network (QtNetwork), XML (QtXml), database (QtSql)...
Qt provides excellent support and documentation. Using Qt, you can write simple and powerful C++ code.
Qt is produced by Digia's Qt Development Frameworks division and is available under LGPL license.
QxOrm is compatible with many Qt's objects : QObject, QString, QDate, QTime, QDateTime, QList, QHash, QSharedPointer, QScopedPointer...
It is recommended to install the latest version of Qt available at the following address : http://www.qt.io/

boost : many of boost's founders are on the C++ standard committee and several boost libraries have been accepted for incorporation into C++1x (new standard for the C++ programming language).
The boost's libraries are aimed at a wide range of C++ users and application domains.
QxOrm uses the following boost's features (header files *.hpp only, boost serialization dependency is optional) : smart_pointer, type_traits, multi_index_container, unordered_container, any, tuple, foreach, function.
It is recommended to get the latest version of boost available at the following address : http://www.boost.org/

QxOrm uses the techniques of C++ meta-programming to provide most of its functionalities.
You do not need to know how to use meta-programming to work with QxOrm library.
Indeed, QxOrm is simple to use and the C++ code written with Qt and QxOrm is easy to read, therefore easy to develop and to maintain.

However, meta-programming is costly in compilation times.
By using a precompiled.h file, your project will be compiled much more quickly.
Last but not least, another advantage is that the file QxOrm.h includes the basic functionalities of libraries boost and Qt.
It is thus not necessary anymore to write #include <QtCore/QString.h> to use the class QString of Qt for example.
In the same way, there is no need anymore to write #include <boost/shared_ptr.hpp> to use smart pointers of boost library.

Yes, if the serialization of your data in XML format is not used in your project, you can disable this functionality.
The compilation times will be then reduced but you will not have anymore access to the namespace qx::serialization:xml.
To disable XML serialization, it is necessary to open the QxOrm.pri config file and to remove (or comment) the compilation option _QX_ENABLE_BOOST_SERIALIZATION_XML.
A recompilation of QxOrm library is necessary to take into account this modification.

Another possibility is to use the polymorphic classes of the library boost::serialization (instead of template).
This feature reduces compilation times and the size of the executable that is generated.
However, the speed of execution of your program will be reduced since part of the work carried out during compilation will be done during the execution of your application.
To use this feature with QxOrm, you must enable the compilation option _QX_ENABLE_BOOST_SERIALIZATION_POLYMORPHIC in the QxOrm.pri config file.Warning : the serialization functions will be then accessible from the following namespace : qx::serialization::polymorphic_binary, qx::serialization::polymorphic_text and qx::serialization::polymorphic_xml.
A recompilation of QxOrm library is necessary to take into account this modification.

It is also possible to use Q_PROPERTY macro to define properties for a class inherited from QObject type.
In this case, there is two different ways to register properties in QxOrm context and you can reduce noticeably compilation times of your project.
For more details about this feature, click here.

Note : it is important to check if all optimizations provided by the compiler are enabled, for example to compile using several processors :

MSVC++ : use environment variable SET CL=/MP

GCC and Clang : put processors count as parameter to the make process, for example to use 8 processors : SET MAKE_COMMAND=make -j8

QxOrm is based on boost serialization library.
There are several types of serialization available : binary, XML, text, etc...QxOrm.pri config file can enable and/or disable some types of serialization.

Note :binary type is not portable, so you can't transfer data between Windows and Unix for example.
If you need to transfer data over network between different platforms, you have to use text or XML serialization.QxOrm provides another solution : portable_binary serialization.portable_binary has the same characteristics as binary type and can serialize data in a portable way.
However, portable_binary is not provided officially by boost library, so it's necessary to test before using in a production software.

There are many containers in stl, boost and Qt libraries.
It is therefore legitimate to ask this question : what is qx::QxCollection<Key, Value> ?qx::QxCollection<Key, Value> is a new container (based on the excellent library boost::multi_index_container) which has the following functionalities :

preserves the insertion order of elements in the list

quick access to an element by its index : is equivalent to std::vector<T> or QList<T> for example

quick access to an element by a key (hash-map) : is equivalent to QHash<Key, Value> or boost::unordered_map<Key, Value> for example

sort by Key type and by Value type

Note :qx::QxCollection<Key, Value> is compatible with the foreach macro provided by Qt library and the BOOST_FOREACH macro provided by boost library.
However, each element returned by these 2 macros corresponds to an object of type std::pair<Key, Value>.
To obtain a more natural and more readable result, it is advised to use the _foreach macro : this macro uses BOOST_FOREACH for all the containers except for qx::QxCollection<Key, Value>.
In this case, the returned element corresponds to the Value type (cf. sample).
The macro _foreach is compatible with all containers (stl, Qt, boost...) since it uses the macro BOOST_FOREACH.

Additional note :qx::QxCollection<Key, Value> is particularly suited to receive data resulting from a database. Indeed, these data can be sorted (by using ORDER BY in a sql request for example), it is thus important to preserve the insertion order of the elements in the list.
Furthermore, each data resulting from a database has a unique id. It is thus important to be able to access quickly to an element based on this single identifier (hash-map).

QxOrm can be used with smart-pointers of boost and Qt libraries.QxOrm smart-pointer is based on QSharedPointer and provides new features with 'qx::dao::...' functions.qx::dao::ptr<T> keeps automatically values from database.
So it's possible to detect if an instance has been modified using the method 'isDirty()' : this method can return list of properties changed.qx::dao::ptr<T> can also be used with the function 'qx::dao::update_optimized()' to update in database only properties changed.qx::dao::ptr<T> can be used with a simple object and with many containers : stl, boost, Qt and qx::QxCollection<Key, Value>.

QxOrm advises to use the QString class for the management of the character strings.
Even if boost provides many functionalities with its module boost::string_algo, the QString class is easier to use and supports many formats : ASCII, Utf8, Utf16...
However, QxOrm is compatible with std::string and std::wstring if you prefer to use this kind of character strings.

QxOrm strongly advises to use boost or Qtsmart-pointers.
The C++ language does not have Garbage Collector like Java or C# for example.
The use of smart-pointers simplifies the memory management in C++.
The ideal in a C++ program is not to have any call to delete or delete[].
Furthermore, smart-pointer is a new functionality of the new C++ standard : C++1x.
It is thus essential to know the following classes today :

It is possible to define a unique id of QString type or other with QxOrm library.
By default, the unique id is long type.
To indicate that a class has a single identifier of QString type or other, it is necessary to specialize the template qx::trait::get_primary_key.
To simplify, you can use the macro : QX_REGISTER_PRIMARY_KEY(myClass, QString).

Warning : the macro QX_REGISTER_PRIMARY_KEY must be used before the macro QX_REGISTER_HPP_... in the definition of your class, otherwise a compilation error occurs.

Here is an example with author class of qxBlog tutorial and a QString primary key :

QxOrm supports 'multi-columns primary key'.
The class id must be defined with following type :
* QPair or std::pair to define 2 columns
* boost::tuple to define from 2 columns to 9 columns

It is necessary to use the macro QX_REGISTER_PRIMARY_KEY() to specialize the template and to map class id with multi-columns in database.
The list of multi-columns names must be defined with '|' character : 'column1|column2|column3|etc...'.

Sample with class 'author' from project 'qxBlogCompositeKey', this class has an id mapped to 3 columns in database :

To register private or protected members into QxOrm context (qx::register_class<T> function), it's necessary to declare some friend class.
To simplify writing C++ template, QxOrm library provides this macro : QX_REGISTER_FRIEND_CLASS(myClass).
An example using this macro can be found in ./test/qxDllSample/dll1/ directory of QxOrm package with CPerson class :

QxMemLeak module provides a fast detection of memory leaks in Debug mode once the execution of the program is finished (with indication of the file and the line => style MFC from Microsoft).
This module is developed by Wu Yongwei and has undergone some modifications to be integrated in QxOrm.
If another tool is already used in your projects (Valgrind for example), this functionality should not be activated.
To enable/disable QxMemLeak module, all is needed is to modify the constant _QX_USE_MEM_LEAK_DETECTION defined in the QxConfig.h. file.
A recompilation of QxOrm library is necessary to take into account this modification.

QxOrm works by default with Concrete Table Inheritance strategy (others are not supported yet).
Many tutorials and forums are available on internet to more details about ORM inheritance and database.
You can find a sample in the directory ./test/qxDllSample/dll2/ with the class BaseClassTrigger.

With QxOrmTrigger, it is possible to execute process before and/or after an insert, update or delete query in the database.
You can find a sample in the directory ./test/qxDllSample/dll2/ with the class BaseClassTrigger.
The class BaseClassTrigger contains 5 properties : m_id, m_dateCreation, m_dateModification, m_userCreation and m_userModification.
Each property will be automatically auto-updated for all derived classes from BaseClassTrigger (see Foo class and Bar class in the same project).
It is necessary to specialize 'QxDao_Trigger' template to work with this feature.

A C++ abstract class (with at least one pure virtual method) cannot be mapped to a table of a database (because it cannot be instantiated).
However, in some case, it can be interesting to define properties into abstract class used by a persistent object (by inheritance).
A sample of abstract class registered in QxOrm context is available in the directory ./test/qxDllSample/dll2/ of QxOrm package with the class BaseClassTrigger.
To register an abstract class into QxOrm context, you have to :

register the class with 'void register_class' like any other class ;

use macro QX_REGISTER_ABSTRACT_CLASS(className) just after the class definition.

If a class is defined into a namespace, a compilation error occurs using macros : QX_REGISTER_HPP and QX_REGISTER_CPP.
To avoid this compilation error, it is necessary to use followings macros : QX_REGISTER_COMPLEX_CLASS_NAME_HPP and QX_REGISTER_COMPLEX_CLASS_NAME_CPP.
You can find a sample in the directory ./test/qxDllSample/dll1/ of QxOrm package with the class CPerson defined into namespace qx::test :

A soft delete doesn't remove rows from database (this is not a physical delete) : a new column is added to the table definition to flag a row as deleted or not.
This column can contain a boolean (1 means row deleted, 0 or NULL means row not deleted), or can contain deletion date-time (if empty or NULL, row is not deleted).
So you can reactivate a deleted row by setting NULL or empty value into database.

To define a soft delete behavior with QxOrm library, you have to use the class qx::QxSoftDelete in function mapping by class qx::register_class<T>.
Here is an example with the class Bar containing 2 properties m_id and m_desc :

SQL queries builded by QxOrm library will take into account this soft delete parameter to add conditions (don't fetch deleted item, don't delete physically a row, etc.).
For example, if you execute this code with the class Bar :

A database transaction is a sequence of operations performed as a single logical unit of work.
If no errors occurred during the execution of the transaction then the system commits the transaction.
If an error occurs during the transaction, or if the user specifies a rollback operation, the data manipulations within the transaction are not persisted to the database.

{ // Start a scope where a new session is instantiated
// Create a session : a valid database connexion by thread is automatically assigned to the session and a transaction is opened
qx::QxSession session;
// Execute some operations with database (using += operator of qx::QxSession class and session database connexion)
session += qx::dao::insert(my_object, session.database());
session += qx::dao::update(my_object, session.database());
session += qx::dao::fetch_by_id(my_object, session.database());
session += qx::dao::delete_by_id(my_object, session.database());
// If the session is not valid (so an error occured) => display first error
if (! session.isValid()) { qDebug("[QxOrm] session error : '%s'", qPrintable(session.firstError().text())); }
} // End of scope : session is destroyed (transaction => automatically commit or rollback if there is an error)

Note : a session can throw a qx::dao::sql_error exception when a SQL error occured (by default, there is no exception). You can setup this feature using :
* qx::QxSession constructor (for a specific session) ;
* qx::QxSqlDatabase::getSingleton()->setSessionThrowable(bool b) parameter (for all sessions).

Other note : don't forget to pass the session database connexion to each qx::dao::xxx functions (using session.database() method).
Moreover, you can manage your own database connexion (from a connexion pool for example) using constructor of qx::QxSession class.

qx::QxSession class provides also persistent methods (CRUD) to make easier to write C++ code.
Here is the same example using methods of qx::QxSession class instead of functions into namespaceqx::dao :

{ // Start a scope where a new session is instantiated
// Create a session : a valid database connexion by thread is automatically assigned to the session and a transaction is opened
qx::QxSession session;
// Execute some operations with database
session.insert(my_object);
session.update(my_object);
session.fetchById(my_object);
session.deleteById(my_object);
// If the session is not valid (so an error occured) => display first error
if (! session.isValid()) { qDebug("[QxOrm] session error : '%s'", qPrintable(session.firstError().text())); }
} // End of scope : session is destroyed (transaction => automatically commit or rollback if there is an error)

QxOrm library can persist every types, not only classes registered in QxOrm context using qx::register_class<T>().

It's necessary to write serialization functions from boost framework, using the non intrusive method (because source code is not available or is read-only).
For more details on boost serialization module, goto official website.

For example, imagine that you have the class 'ExtObject3D' from an external library and the source code is not available or is read-only.
Here is the code to can persist an instance of 'ExtObject3D' type into database :

Now you can persist an instance of 'ExtObject3D' type into database : so you can have a 'ExtObject3D' property in a persistent class registered in QxOrm context.
This property can be mapped with a column of type TEXT or VARCHAR into database.

The default behaviour of QxOrm library is : the instance is serialized to XML format before to be inserted or updated into database.
This default behaviour can be useful, for example if you want to save a collection of items without to make relation (so you don't have to manage another table into database).
For example, with a property of type std::vector<mon_objet> in a persistent class without relation, the list of items will be saved into database under XML format.

Note : the default behaviour can be easily modified for a specific type.
QtSql engine uses QVariant type to link C++ code and database.
QVariant type can contain text, numeric, binary, etc.
So it can be interesting to specialize the default behaviour (XML serialization) if you want to save datas under binary format or to optimize your application (XML serialization is not very fast).
You just have to write (with boost serialization functions) a conversion into/from QVariant type, for example with 'ExtObject3D' class :

All classes registered in QxOrm context using qx::register_class<T>() function can be used by introspection engine (or reflection engine) of QxOrm library.
Introspection engine can provide dynamically (so during program execution) some informations about types.
Those informations are called meta-datas and can list all classes characteristics (properties, methods, etc.).
Many programming languages (for example Java or C#) have natively this mechanism, but not C++, that's why QxOrm library emulates an introspection engine.

Here is a list of QxOrm library classes to access to meta-datas :

qx::QxClassX : singleton class to iterate over all classes registered in QxOrm context using qx::register_class<T>() ;

Note : you can add some informations to introspection engine using property bag mechanism.
Indeed, qx::IxClass, qx::IxDataMember and qx::IxFunction classes contain a list of QVariant items associated to a QString key (see qx::QxPropertyBag class for more details).

All classes inherited from QObject type can use Q_PROPERTY macro : those properties become meta-properties.
This is how Qt framework provides an introspection engine using the moc process.
Meta-properties can be used for example by QML engine, QtScript, etc.

QxOrm library needs to register each properties per class in the mapping function void qx::register_class<T>() to provide all features (persistence, XML and binary serialization, etc.).
It's possible to register automatically all Qt meta-properties into QxOrm context without to manage any mapping function per class void qx::register_class<T>() : QX_REGISTER_ALL_QT_PROPERTIES() macro works with Qt introspection engine to iterate over all meta-properties.

Here is an example with TestQtProperty class into ./test/qxDllSample/dll1/include/ directory of QxOrm package :

Note : the second parameter of QX_REGISTER_ALL_QT_PROPERTIES macro is the name of the property mapped to the primary key into database.
If this parameter is empty, then the class doesn't have any primary key or the primary key has been registered in a base class.

All properties defined with Q_PROPERTY macro can be registered in QxOrm context in two different ways :1- with the classic method : t.data(& MyQObject::my_property, "my_property", 0);2- or without writing the data-member pointer : t.data("my_property", 0);

You can use the first or the second method to register your properties into QxOrm context and access to the same functionalities using the common interface qx::IxDataMember.
You can also mix Qt meta-properties and classic registration data-member into the same mapping function void qx::register_class<T>().
Each registration method has some advantages and disadvantages.

Here is the list of advantages using the second registration method into QxOrm context :

much more faster to compile ;

reduce exec size ;

strong integration with Qt introspection/moc engine ;

no need to manage any mapping function per class using QX_REGISTER_ALL_QT_PROPERTIES macro.

Here is the list of disadvantages compared to the classic registration method :

need to inherit from QObject class to use Q_PROPERTY macro ;

program execution more slower (QVariant type versus C++ template) ;

doesn't support relation between tables into database (one-to-one, one-to-many, many-to-one and many-to-many) ;

cannot access to the data-member pointer of a class (need to convert to QVariant type before to access or to modify a value).

The class qx::QxSqlQuery (or its typedef qx_query) is used to communicate with database (to filter, to sort, etc.) in two different ways :

writing manually SQL query ;

using C++ methods with a syntax similar to SQL (same concept than the great library SubSonic for .Net).

With the first method (writing manually SQL query), you can use some optimizations specific for each database.
The second method (using C++ code to build SQL query) binds automatically SQL parameters without using qx::QxSqlQuery::bind() function.

Here is an example with qx::QxSqlQuery class writing manually a SQL query :

With C++ methods of qx::QxSqlQuery class, you don't have to bind any SQL parameter, and the syntax is similar to real SQL.
All SQL parameters will be provided to database automatically with the following style : qx::QxSqlDatabase::getSingleton()->getSqlPlaceHolderStyle().

Here is an example with many methods of qx::QxSqlQuery class (or its typedef qx_query) :

This code will produce following SQL for MySQL, PostgreSQL and SQLite databases (for Oracle and SQLServer, there is a specific process for limit() method) :

WHERE sex = :sex_1_0
AND age > :age_3_0
OR last_name <> :last_name_5_0
OR first_name LIKE :first_name_7_0
AND ( id <= :id_10_0 AND birth_date BETWEEN :birth_date_12_0_1 AND :birth_date_12_0_2 )
OR id IN (:id_15_0_0, :id_15_0_1, :id_15_0_2, :id_15_0_3, :id_15_0_4)
AND is_deleted IS NOT NULL
ORDER BY last_name ASC, first_name ASC, sex ASC
LIMIT :limit_rows_count_19_0 OFFSET :offset_start_row_19_0

Here is the list of all functions available to use qx::QxSqlQuery class (or its typedef qx_query) :

Cache engine provided by QxOrm library (QxCache module) is thread-safe and can store easily any kind of objects.
Functions to access to the cache engine are inside namespaceqx::cache.qx::cache engine can provide a program optimization : you can for example store items fetched by a query to database.

Each item into the cache is associated with a key of type QString : this key provides a quick access to an item stored into the cache.
If a new item is inserted with a key already in the cache, then the old item associated with this key is removed automatically from the cache.

Cache engine of QxOrm library doesn't manage memory : there is no delete called by the cache engine.
This is why it's strongly recommended (but not an obligation) to store smart-pointers into the cache : for example, boost::shared_ptr<T> of boost library or QSharedPointer<T> of Qt library.

Cache engine can have a max cost to avoid too much memory usage : each item inserted to the cache can be associated with a cost (for example, element's count of a collection).
When the limit (max cost) of the cache engine is reached, first items inserted to the cache are automatically removed (insertion order) until limit of the cache is ok.

It's also possible to associate a date-time insertion when an item is added to the cache.
If there is no date-time, then the current date-time is taken into account.
This feature provides a way to verify that an item stored into the cache must be updated or not.

Here is an example using cache engine of QxOrm library (functions into namespaceqx::cache) :

QxOrm library doesn't provide a generator to create and to update automatically tables into database.
Indeed, qx::dao::create_table<T> function must be used only to create prototypes or samples.
It's strongly recommended to work with a tool provided by each SGBD to design and to manage tables into database (for example Navicat with MySql, pgAdmin with PostgreSQL, SQLite Manager with SQLite, etc.).
Moreover, each tool provided by each SGBD can add some optimizations to the database (add some indexes for example).

But sometimes, it can be useful to not have to manage manually tables into database.
In this case, it's possible to create a C++ function to iterate over all persistents classes registered in QxOrm context (using introspection engine of QxOrm library) : so you can build a SQL script to create and to update tables into database.

QxOrm library provides an example of a C++ function : based on this function, you can create your own function to build SQL schema.
This QxOrm function is written in the file ./src/QxRegister/QxClassX.cpp and is called QString qx::QxClassX::dumpSqlSchema().
This QxOrm function builds a SQL script and returns a QString value : it's also possible to modify the function to generate a file with SQL script or to execute each SQL process directly to the SGBD.

Here is a sample implementation provided by dodobibi to manage a PostgreSQL database : this sample works with a version number to add columns to existing tables, to add some indexes to existing columns, etc.
When you start your application, a version number is provided and incremented when a new version of your application is released :

QApplication app(argc, argv);
app.setProperty("DomainVersion", 1);

A table into the database must be created to store this version number.
A C++ persistent class is mapped to this table :

Note : this code (like qx::QxClassX::dumpSqlSchema() function) can be modified to provide more features.
For example, it could be interesting to create by default another table (like DatabaseVersion table) to store the list of all persistents classes registered in QxOrm context : instead of using "db.tables()" Qt function, it could be possible to fetch all tables with more informations (version number for each table, columns count registered in QxOrm context, table description, etc.).

QxValidator module of QxOrm library provides a validation engine for classes registered in QxOrm context.
To use this validation engine, you have to define your constraints into the mapping function per class : void qx::register_class.
If for an instance of class, at least one constraint violation is detected, then the instance is invalid : the object cannot be saved into database (INSERT or UPDATE).

It's also possible to use QxValidator module to validate an instance on the presentation layer : if some datas from a user are invalids, an error message can be displayed, and it's not necessary to try to send the instance to the data access layer.
The validation mechanism can be executed in different layers in your application without having to duplicate any of these rules (presentation layer, data access layer).

Here is a description of some classes defined into QxValidator module :

qx::IxValidator : each constraint defined into void qx::register_class function is associated with an interface of type qx::IxValidator ;

// Example of global functions 'validateFirstName' and 'validateDateTime' used by 'QxValidator' module
// Those functions will be called automatically by validator engine of QxOrm library :
// - when you try to insert or update using 'qx::dao::xxx' functions
// - when you call 'qx::validate()' function
void validateFirstName(const QVariant & value, const qx::IxValidator * validator, qx::QxInvalidValueX & invalidValues)
{
// Here you can test the value (converted to QVariant type)
// If an invalid value is detected, just add a message into 'invalidValues' collection
// For example, if the value must be never equal to "admin" :
if (value.toString() == "admin")
{ invalidValues.insert("value must not be equal to 'admin'"); }
}
void validateDateTime(const QDateTime & value, const qx::IxValidator * validator, qx::QxInvalidValueX & invalidValues)
{
// Here you can test the value (with its real type, in this example, the data-member is a 'QDateTime' type)
// If an invalid value is detected, just add a message into 'invalidValues' collection
// For example, if the date-time must be valid :
if (! value.isValid())
{ invalidValues.insert("date-time value must not be empty and must be valid"); }
}

During program execution of this code, 'personValidate' instance is not valid : 'invalidValues' collection contains 4 items :
- "property 'firstName' must not be empty" ;
- "person sex must be defined : male or female" ;
- "value must not be equal to 'admin'" ;
- "date-time value must not be empty and must be valid".

QxValidator module provides some built-in constraints, which cover most of the basic data checks.
As we'll see later, you're not limited to them, you can literally in a minute write your own constraints :

add_NotNull() : checks if the value is not null ;

add_NotEmpty() : checks if the string is not empty ;

add_MinValue() : checks if the value is more than or equals to min ;

add_MaxValue() : checks if the value is less than or equals to max ;

add_Range() : checks if the value is between Min and Max (included) ;

add_MinDecimal() : checks if the decimal value is more than or equals to min ;

add_MaxDecimal() : checks if the decimal value is less than or equals to max ;

add_RangeDecimal() : checks if the decimal value is between Min and Max (included) ;

add_MinLength() : checks if the string length is more than or equals to min ;

add_MaxLength() : checks if the string length is less than or equals to max ;

add_Size() : checks if the string length is between the min-max range ;

add_DatePast() : checks if the date is in the past ;

add_DateFuture() : checks if the date is in the future ;

add_RegExp() : checks if the property matches the regular expression given a match flag ;

Like 'person' class example, it's possible to define a custom validator : it's a function or a class method called automatically by QxValidator module to validate a property or an instance of class.
There are 3 kinds of custom validator :

Note : each validator can be associated with a group (optional parameter for each function add_XXX() of qx::IxValidatorX class).
So it's possible to create a context validation during program execution : for example, a person from IHM A can have different validation rules than a person from IHM B.
To execute a validation process by group (for example "myGroup"), you have to call the following function : "qx::QxInvalidValueX invalidValues = qx::validate(personValidate, "myGroup");".

Other note :QxValidator module provides default messages when a constraint violation is detected.
It's possible to modify those default messages (for example, a traduction) using the following collection : "QHash * lstMessage = QxClassX::getAllValidatorMessage();".
For example : "lstMessage->insert("min_value", "la valeur '%NAME%' doit être inférieure ou égale à '%CONSTRAINT%'");".%NAME% and %CONSTRAINT% fields will be automatically replaced by the good value.
To modify a message for a specific validator (and not globally), you have to use the optional parameter provided by each function add_XXX() of qx::IxValidatorX class.

qx::IxPersistable interface (or abstract class) provides only pure virtual methods.
Using qx::IxPersistable, you will have a common base class to call all persistents functions without knowing the real type of current instance (polymorphism concept).
QxOrm library doesn't force developers to work with a base class to register a persistent type into QxOrm context, however it's sometimes useful to have an interface to write some generic algorithms.

Note : project test from ./test/qxDllSample/dll1/ directory provides a kind of 'super base class' : qx::QxPersistable class implements qx::IxPersistable interface and inherits from QObject.
So SIGNAL-SLOT concept from Qt library can be used with this class and could be an interesting way to use QxOrm triggers.qx::QxPersistable class provides also some virtual methods to override to manage for example data validation process from QxValidator module.
For information, qx::QxPersistable class is not a part of QxOrm library, but you can copy-past it into your own project to use all its features :

QxOrm library supports 4 kind of relationships to link C++ classes registered in QxOrm context : one-to-one, one-to-many, many-to-one and many-to-many.
For more details to define relationships, you can take a look at qxBlog tutorial.
We will explain here how to fetch datas from many tables (QxDao module, functions of qx::dao namespace) :

qx::dao::execute_query<T>() function is a template function : T type must be registered in QxOrm context (qx::register_class<T> function).
All datas returned by the stored procedure or the custom SQL query which could be associated with members of the C++ class (of T type) will be fetched automatically.
An automatic search is done on the name of each fields returned by the query.
Here is an example from qxBlog project of QxOrm package :

qx::dao::call_query() function is not a template function : you have to iterate over each result using qx::QxSqlQuery class (or qx_query).
To get an output value parameter (must be pass as QSql::Out or QSql::InOut) returned by a stored procedure, just call the following method : QVariant qx::QxSqlQuery::boundValue(const QString & sKey) const;.

Sometimes, it's necessary to execute some queries to database in asynchronous way (multi-thread), for example to avoid to freeze a GUI if a query is too long to execute.
To make easier to work with asynchronous queries, QxOrm library provides qx::QxDaoAsync class.
This class executes a query in another thread and returns the queryFinished()SIGNAL when query is terminated.
To use qx::QxDaoAsync class, you just have to :

qx::IxModel interface provides a generic way for all models linked to persistents classes registered in QxOrm context. All methods of this class prefixed by 'qx' call functions from 'qx::dao' namespace and then communicate with database.

The qxBlogModelView sample project in ./test/ directory of QxOrm package shows how to create quickly a model and associate it to the Qt model/view engine (first with a Qt widget, then with a QML view).

1- Here is an example to display/modify data from 'author' table (go to qxBlog tutorial for 'author' class definition) in a QTableView :

// Create a model and fetch all data from database
qx::IxModel * pModel = new qx::QxModel<author>();
pModel->qxFetchAll();
// Associate the model to a QTableView and display it
QTableView tableView;
tableView.setModel(pModel);
tableView.show();

As you can see in the 'main.qml' file, 'author_id' and 'name' properties of 'author' model (myModel variable) can be automatically read and write (because they are registered in QxOrm context).
Moreover, qx::IxModel interface provides a list of methods for QML side (Q_INVOKABLE) to communicate with database : for example, the 'Save' button will save the model in database without having to write a C++ function.

Note : a QxEntityEditor plugin generates automatically the code to manage models with relationships. Then it is possible to work with nested C++ models.