QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches

qx::QxPersistableCollection<Key, Value, T> : concrete class for collection persistent classes based on qx::IxPersistableCollection and qx::QxCollection<Key, Value> More...

#include <IxPersistableCollection.h>

Inheritance diagram for qx::QxPersistableCollection< Key, Value, T >:
qx::IxPersistableCollection qx::QxCollection< Key, Value > qx::IxPersistable qx::IxCollection

Public Member Functions

 QxPersistableCollection ()
 
virtual ~QxPersistableCollection ()
 
virtual long __count () const
 
virtual void __clear ()
 
virtual bool __remove (long idx)
 
virtual qx::IxPersistable_ptr __at (long idx) const
 
virtual long qxCount (const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL, const QStringList &relation=QStringList())
 Return the number of lines in the table (database) mapped to the current C++ class (registered into QxOrm context) and filtered by a user SQL query.
 
virtual QSqlError qxCount (long &lCount, const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL, const QStringList &relation=QStringList())
 Return the number of lines in the table (database) mapped to the current C++ class (registered into QxOrm context) and filtered by a user SQL query.
 
virtual QSqlError qxFetchById (const QVariant &id=QVariant(), const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
 Fetch current instance (retrieve all its properties) mapped to a table in the database (current instance must have a valid id before to be fetched without error, or pass the id to the first parameter of this method)
 
virtual QSqlError qxFetchAll (qx::IxPersistableCollection *list=NULL, const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
 Fetch a list of objects (retrieve all elements and properties associated) of current type (container registered into QxOrm context) mapped to a table in the database.
 
virtual QSqlError qxFetchByQuery (const qx::QxSqlQuery &query, qx::IxPersistableCollection *list=NULL, const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
 Fetch a list of objects (retrieve all elements and properties associated) of current type (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query.
 
virtual QSqlError qxInsert (const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
 Insert current instance into database.
 
virtual QSqlError qxUpdate (const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
 Update current instance into database (you can add a user SQL query to the default SQL query builded by QxOrm library)
 
virtual QSqlError qxSave (const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL, qx::dao::save_mode::e_save_mode eSaveRecursiveMode=qx::dao::save_mode::e_none)
 Insert (if no exist) or update (if already exist) current instance into database.
 
virtual QSqlError qxDeleteById (const QVariant &id=QVariant(), QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
 Delete current instance from database.
 
virtual QSqlError qxDeleteAll (QSqlDatabase *pDatabase=NULL)
 Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context)
 
virtual QSqlError qxDeleteByQuery (const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
 Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context) and filtered by a user SQL query.
 
virtual QSqlError qxDestroyById (const QVariant &id=QVariant(), QSqlDatabase *pDatabase=NULL, bool bUseExecBatch=false)
 Delete current instance from database.
 
virtual QSqlError qxDestroyAll (QSqlDatabase *pDatabase=NULL)
 Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context)
 
virtual QSqlError qxDestroyByQuery (const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
 Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context) and filtered by a user SQL query.
 
virtual QSqlError qxExecuteQuery (qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
 Execute a custom SQL query or a stored procedure, all columns that can be mapped to the instance of type T will be fetched automatically.
 
virtual QSqlError qxExecuteQuery (qx::QxSqlQuery &query, qx::IxPersistableCollection *list=NULL, QSqlDatabase *pDatabase=NULL)
 Execute a custom SQL query or a stored procedure, all columns that can be mapped to the instance of type T will be fetched automatically.
 
virtual qx_bool qxExist (const QVariant &id=QVariant(), QSqlDatabase *pDatabase=NULL)
 Search if current instance already exists into database.
 
virtual qx::QxInvalidValueX qxValidate (const QStringList &groups=QStringList())
 Check if current instance is valid or not.
 
virtual std::shared_ptr< qx::IxPersistableCollectionqxNewPersistableCollection (bool bAsList=false) const
 Create a new collection smart-pointer to fetch a list of items of current class type.
 
virtual qx::IxClassqxClass () const
 Access to introspection engine (or reflection engine) of QxOrm library.
 
virtual QString toJson (const QString &format=QString()) const
 
virtual QJsonValue toJson_ (const QString &format=QString()) const
 
virtual qx_bool fromJson (const QString &json, const QString &format=QString())
 
virtual qx_bool fromJson_ (const QJsonValue &json, const QString &format=QString())
 
- Public Member Functions inherited from qx::IxPersistableCollection
 IxPersistableCollection ()
 
virtual ~IxPersistableCollection ()
 
- Public Member Functions inherited from qx::IxPersistable
 IxPersistable ()
 
virtual ~IxPersistable ()
 
- Public Member Functions inherited from qx::QxCollection< Key, Value >
 QxCollection ()
 Construct an empty list.
 
 QxCollection (const QxCollection< Key, Value > &other)
 Construct a copy of 'other'.
 
virtual ~QxCollection ()
 Destroy the list.
 
QxCollection< Key, Value > & operator= (const QxCollection< Key, Value > &other)
 Assign 'other' to this list and return a reference to this list.
 
bool operator== (const QxCollection< Key, Value > &other) const
 Return 'true' if 'other' is equal to this list, otherwise return 'false' (same values in the same order)
 
bool operator!= (const QxCollection< Key, Value > &other) const
 Return 'true' if 'other' is not equal to this list, otherwise return 'false'.
 
iterator begin ()
 Return an STL-style iterator pointing to the first item in the list.
 
iterator end ()
 Return an STL-style iterator pointing to the imaginary item after the last item in the list.
 
const_iterator begin () const
 Return a const STL-style iterator pointing to the first item in the list.
 
const_iterator end () const
 Return a const STL-style iterator pointing to the imaginary item after the last item in the list.
 
reverse_iterator rbegin ()
 Return a reverse STL-style iterator pointing to the first item in the list.
 
reverse_iterator rend ()
 Return a reverse STL-style iterator pointing to the imaginary item after the last item in the list.
 
const_reverse_iterator rbegin () const
 Return a const reverse STL-style iterator pointing to the first item in the list.
 
const_reverse_iterator rend () const
 Return a const reverse STL-style iterator pointing to the imaginary item after the last item in the list.
 
void reserve (long size)
 Request that the capacity of the allocated storage space for the items of the container be at least enough to hold 'size' elements.
 
void reverse ()
 Reverse all items in the list.
 
void clear ()
 Remove all items from the list.
 
long count () const
 Return the number of items in the list (same as 'size()')
 
long size () const
 Return the number of items in the list (same as 'count()')
 
bool contains (const Key &key) const
 Return 'true' if the list contains an occurrence of 'key', otherwise return 'false' (same as 'exist()')
 
bool exist (const Key &key) const
 Return 'true' if the list contains an occurrence of 'key', otherwise return 'false' (same as 'contains()')
 
bool empty () const
 Return 'true' if the list contains no items; otherwise return 'false'.
 
bool push_back (const Key &key, const Value &value)
 Add element 'value' at the end of the list indexed by 'key'.
 
bool push_front (const Key &key, const Value &value)
 Insert 'value' at the beginning of the list indexed by 'key'.
 
bool insert (const Key &key, const Value &value)
 Add element 'value' at the end of the list indexed by 'key'.
 
bool insert (long index, const Key &key, const Value &value)
 Insert element 'value' at position 'index' in the list indexed by 'key'.
 
bool insert (const QxCollection< Key, Value > &other)
 Add all items of 'other' at the end of the list.
 
bool insert (long index, const QxCollection< Key, Value > &other)
 Insert all items of 'other' at the end of the list.
 
bool replace (long index, const Key &key, const Value &value)
 Replace the item at index position 'index' with element 'value' indexed by 'key'.
 
bool swap (long index1, long index2)
 Exchange the item at index position 'index1' with the item at index position 'index2'.
 
bool move (long indexFrom, long indexTo)
 Move the item at index position 'indexFrom' to index position 'indexTo'.
 
bool removeByKey (const Key &key)
 Remove the item indexed by 'key' in the list.
 
bool removeByIndex (long index)
 Remove the item at index position 'index'.
 
bool removeByIndex (long first, long last)
 Remove all items from index position 'first' to index position 'last'.
 
bool removeFirst ()
 Remove the first item in the list.
 
bool removeLast ()
 Remove the last item in the list.
 
const_reference_value getByKey (const Key &key) const
 Return the item associated with the 'key'.
 
const_reference_value getByIndex (long index) const
 Return the item at index position 'index'.
 
const_reference_value getFirst () const
 Return the first element in the list.
 
const_reference_value getLast () const
 Return the last element in the list.
 
const_reference_key getKeyByIndex (long index) const
 Return the key associated with the element at index position 'index'.
 
void sortByKey (bool bAscending=true)
 Sort all items in the list using associated keys to compare.
 
void sortByValue (bool bAscending=true)
 Sort all items in the list.
 
template<typename Compare >
void sort (Compare comp)
 
virtual long _count () const
 
virtual void _clear ()
 
virtual bool _remove (long index)
 
virtual qx::any _at (long index) const
 
- Public Member Functions inherited from qx::IxCollection
 IxCollection ()
 
virtual ~IxCollection ()=0
 
template<typename T >
_get (long index) const
 

Private Types

enum  { qx_is_valid = qx::trait::is_qx_registered<T>::value }
 

Additional Inherited Members

- Public Types inherited from qx::QxCollection< Key, Value >
typedef QPair< Key, Value > type_pair_key_value
 
typedef type_list_pair_key_value::iterator iterator
 
typedef type_list_pair_key_value::const_iterator const_iterator
 
typedef type_list_pair_key_value::reverse_iterator reverse_iterator
 
typedef type_list_pair_key_value::const_reverse_iterator const_reverse_iterator
 
typedef const Key & const_reference_key
 
typedef const Value & const_reference_value
 
- Static Public Member Functions inherited from qx::IxPersistable
static std::shared_ptr< qx::IxPersistableCollectionqxFetchAll (const QString &className, const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL, bool bAsList=false)
 
static std::shared_ptr< qx::IxPersistableCollectionqxFetchByQuery (const QString &className, const qx::QxSqlQuery &query, const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL, bool bAsList=false)
 
static std::shared_ptr< qx::IxPersistableCollectionqxExecuteQuery (const QString &className, qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL, bool bAsList=false)
 
- Protected Types inherited from qx::QxCollection< Key, Value >
typedef QList< type_pair_key_valuetype_list_pair_key_value
 
typedef QHash< Key, long > type_hash_position
 
- Protected Member Functions inherited from qx::QxCollection< Key, Value >
void cloneCollection (QxCollection< Key, Value > *pClone, const QxCollection< Key, Value > &pRef)
 
bool isSameCollection (const QxCollection< Key, Value > *p1, const QxCollection< Key, Value > &p2) const
 
void updateHashPosition (long from=0, long to=-1, bool check=false)
 
- Protected Attributes inherited from qx::QxCollection< Key, Value >
QMutex m_mutex
 Mutex => qx::QxCollection is thread-safe.
 
type_list_pair_key_value m_list
 Container to keep insertion order.
 
type_hash_position m_hash
 Container for fast search by key.
 
bool m_batch
 Batch mode to sync internal containers.
 

Detailed Description

template<typename Key, typename Value, typename T>
class qx::QxPersistableCollection< Key, Value, T >

qx::QxPersistableCollection<Key, Value, T> : concrete class for collection persistent classes based on qx::IxPersistableCollection and qx::QxCollection<Key, Value>

Definition at line 85 of file IxPersistableCollection.h.

Member Enumeration Documentation

◆ anonymous enum

template<typename Key , typename Value , typename T >
anonymous enum
private
Enumerator
qx_is_valid 

Definition at line 88 of file IxPersistableCollection.h.

Constructor & Destructor Documentation

◆ QxPersistableCollection()

template<typename Key , typename Value , typename T >
qx::QxPersistableCollection< Key, Value, T >::QxPersistableCollection ( )
inline

Definition at line 92 of file IxPersistableCollection.h.

◆ ~QxPersistableCollection()

template<typename Key , typename Value , typename T >
virtual qx::QxPersistableCollection< Key, Value, T >::~QxPersistableCollection ( )
inlinevirtual

Definition at line 93 of file IxPersistableCollection.h.

Member Function Documentation

◆ __at()

template<typename Key , typename Value , typename T >
virtual qx::IxPersistable_ptr qx::QxPersistableCollection< Key, Value, T >::__at ( long idx) const
inlinevirtual

Implements qx::IxPersistableCollection.

Definition at line 98 of file IxPersistableCollection.h.

◆ __clear()

template<typename Key , typename Value , typename T >
virtual void qx::QxPersistableCollection< Key, Value, T >::__clear ( )
inlinevirtual

Implements qx::IxPersistableCollection.

Definition at line 96 of file IxPersistableCollection.h.

◆ __count()

template<typename Key , typename Value , typename T >
virtual long qx::QxPersistableCollection< Key, Value, T >::__count ( ) const
inlinevirtual

Implements qx::IxPersistableCollection.

Definition at line 95 of file IxPersistableCollection.h.

◆ __remove()

template<typename Key , typename Value , typename T >
virtual bool qx::QxPersistableCollection< Key, Value, T >::__remove ( long idx)
inlinevirtual

Implements qx::IxPersistableCollection.

Definition at line 97 of file IxPersistableCollection.h.

◆ fromJson()

template<typename Key , typename Value , typename T >
virtual qx_bool qx::QxPersistableCollection< Key, Value, T >::fromJson ( const QString & json,
const QString & format = QString() )
inlinevirtual

Implements qx::IxPersistable.

Definition at line 205 of file IxPersistableCollection.h.

◆ fromJson_()

template<typename Key , typename Value , typename T >
virtual qx_bool qx::QxPersistableCollection< Key, Value, T >::fromJson_ ( const QJsonValue & json,
const QString & format = QString() )
inlinevirtual

Implements qx::IxPersistable.

Definition at line 208 of file IxPersistableCollection.h.

◆ qxClass()

template<typename Key , typename Value , typename T >
virtual qx::IxClass * qx::QxPersistableCollection< Key, Value, T >::qxClass ( ) const
inlinevirtual

Access to introspection engine (or reflection engine) of QxOrm library.

Returns
Return a qx::IxClass pointer to access to introspection engine (or reflection engine) of QxOrm library, and get some informations about current class (properties, methods, etc...)

Implements qx::IxPersistable.

Definition at line 194 of file IxPersistableCollection.h.

◆ qxCount() [1/2]

template<typename Key , typename Value , typename T >
virtual long qx::QxPersistableCollection< Key, Value, T >::qxCount ( const qx::QxSqlQuery & query = qx::QxSqlQuery(),
QSqlDatabase * pDatabase = NULL,
const QStringList & relation = QStringList() )
inlinevirtual

Return the number of lines in the table (database) mapped to the current C++ class (registered into QxOrm context) and filtered by a user SQL query.

Parameters
queryDefine a user SQL query added to default SQL query builded by QxOrm library
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
relationList of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)

qx::IxPersistable * p = ...;
p->qxCount(...) execute following SQL query :
SELECT COUNT(*) FROM my_table + XXX_JOINS_XXX + WHERE my_query...

Implements qx::IxPersistable.

Definition at line 100 of file IxPersistableCollection.h.

◆ qxCount() [2/2]

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxCount ( long & lCount,
const qx::QxSqlQuery & query = qx::QxSqlQuery(),
QSqlDatabase * pDatabase = NULL,
const QStringList & relation = QStringList() )
inlinevirtual

Return the number of lines in the table (database) mapped to the current C++ class (registered into QxOrm context) and filtered by a user SQL query.

Parameters
lCountOutput parameter with the number of lines in the table associated to the SQL query
queryDefine a user SQL query added to default SQL query builded by QxOrm library
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
relationList of relationships keys to be fetched (eager fetch instead of default lazy fetch for a relation)

qx::IxPersistable * p = ...;
p->qxCount(...) execute following SQL query :
SELECT COUNT(*) FROM my_table + XXX_JOINS_XXX + WHERE my_query...

Implements qx::IxPersistable.

Definition at line 106 of file IxPersistableCollection.h.

◆ qxDeleteAll()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxDeleteAll ( QSqlDatabase * pDatabase = NULL)
inlinevirtual

Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context)

Parameters
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxDeleteAll(...) execute following SQL query :
DELETE FROM my_table

If a soft delete behavior is defined for current class, p->qxDeleteAll(...) execute following SQL query :
UPDATE my_table SET is_deleted='1'

Implements qx::IxPersistable.

Definition at line 164 of file IxPersistableCollection.h.

◆ qxDeleteById()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxDeleteById ( const QVariant & id = QVariant(),
QSqlDatabase * pDatabase = NULL,
bool bUseExecBatch = false )
inlinevirtual

Delete current instance from database.

Parameters
idUnique id to delete from database (if empty, check id of current instance)
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
bUseExecBatchIf true then use the QSqlQuery::execBatch() method to improve performance deleting a list of instances in database
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxDeleteById(...) execute following SQL query :
DELETE FROM my_table WHERE my_id = ?

If a soft delete behavior is defined for current class, p->qxDeleteById(...) execute following SQL query :
UPDATE my_table SET is_deleted='1' WHERE my_id = ?

Implements qx::IxPersistable.

Definition at line 161 of file IxPersistableCollection.h.

◆ qxDeleteByQuery()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxDeleteByQuery ( const qx::QxSqlQuery & query,
QSqlDatabase * pDatabase = NULL )
inlinevirtual

Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context) and filtered by a user SQL query.

Parameters
queryDefine a user SQL query added to default SQL query builded by QxOrm library
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxDeleteByQuery(...) execute following SQL query :
DELETE FROM my_table + WHERE my_query...

If a soft delete behavior is defined for current class, p->qxDeleteByQuery(...) execute following SQL query :
UPDATE my_table SET is_deleted='1' + WHERE my_query...

Implements qx::IxPersistable.

Definition at line 167 of file IxPersistableCollection.h.

◆ qxDestroyAll()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxDestroyAll ( QSqlDatabase * pDatabase = NULL)
inlinevirtual

Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context)

Parameters
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxDestroyAll(...) execute following SQL query :
DELETE FROM my_table

Implements qx::IxPersistable.

Definition at line 173 of file IxPersistableCollection.h.

◆ qxDestroyById()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxDestroyById ( const QVariant & id = QVariant(),
QSqlDatabase * pDatabase = NULL,
bool bUseExecBatch = false )
inlinevirtual

Delete current instance from database.

Parameters
idUnique id to delete from database (if empty, check id of current instance)
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
bUseExecBatchIf true then use the QSqlQuery::execBatch() method to improve performance destroying a list of instances in database
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxDestroyById(...) execute following SQL query :
DELETE FROM my_table WHERE my_id = ?

Implements qx::IxPersistable.

Definition at line 170 of file IxPersistableCollection.h.

◆ qxDestroyByQuery()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxDestroyByQuery ( const qx::QxSqlQuery & query,
QSqlDatabase * pDatabase = NULL )
inlinevirtual

Delete all lines of a table (database) mapped to current C++ class (registered into QxOrm context) and filtered by a user SQL query.

Parameters
queryDefine a user SQL query added to default SQL query builded by QxOrm library
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxDestroyByQuery(...) execute following SQL query :
DELETE FROM my_table + WHERE my_query...

Implements qx::IxPersistable.

Definition at line 176 of file IxPersistableCollection.h.

◆ qxExecuteQuery() [1/2]

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxExecuteQuery ( qx::QxSqlQuery & query,
QSqlDatabase * pDatabase = NULL )
inlinevirtual

Execute a custom SQL query or a stored procedure, all columns that can be mapped to the instance of type T will be fetched automatically.

Parameters
queryDefine a user SQL query added to default SQL query builded by QxOrm library
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Implements qx::IxPersistable.

Definition at line 179 of file IxPersistableCollection.h.

◆ qxExecuteQuery() [2/2]

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxExecuteQuery ( qx::QxSqlQuery & query,
qx::IxPersistableCollection * list = NULL,
QSqlDatabase * pDatabase = NULL )
inlinevirtual

Execute a custom SQL query or a stored procedure, all columns that can be mapped to the instance of type T will be fetched automatically.

Parameters
queryDefine a user SQL query added to default SQL query builded by QxOrm library
listContainer to fetch all items (retrieve all elements and properties associated); list is cleared before executing SQL query
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

Implements qx::IxPersistable.

Definition at line 182 of file IxPersistableCollection.h.

◆ qxExist()

template<typename Key , typename Value , typename T >
virtual qx_bool qx::QxPersistableCollection< Key, Value, T >::qxExist ( const QVariant & id = QVariant(),
QSqlDatabase * pDatabase = NULL )
inlinevirtual

Search if current instance already exists into database.

Parameters
idUnique id to check into database (if empty, check id of current instance)
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Return true if element already exists into database; otherwise return false; if an error occurred, qx_bool object contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxExist(...) execute following SQL query :
SELECT * FROM my_table WHERE my_id = ?

Implements qx::IxPersistable.

Definition at line 185 of file IxPersistableCollection.h.

◆ qxFetchAll()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxFetchAll ( qx::IxPersistableCollection * list = NULL,
const QStringList & columns = QStringList(),
const QStringList & relation = QStringList(),
QSqlDatabase * pDatabase = NULL )
inlinevirtual

Fetch a list of objects (retrieve all elements and properties associated) of current type (container registered into QxOrm context) mapped to a table in the database.

Parameters
listContainer to fetch all items (retrieve all elements and properties associated); list is cleared before executing SQL query
columnsList of database table columns (mapped to properties of C++ class) to fetch (if empty, all columns are fetched)
relationList of relationships keys to fetch (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
std::shared_ptr<qx::IxPersistableCollection> lst = p->qxNewPersistableCollection();
p->qxFetchAll(& lst, ...) execute following SQL query :
SELECT * FROM my_table

Implements qx::IxPersistable.

Definition at line 120 of file IxPersistableCollection.h.

◆ qxFetchById()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxFetchById ( const QVariant & id = QVariant(),
const QStringList & columns = QStringList(),
const QStringList & relation = QStringList(),
QSqlDatabase * pDatabase = NULL )
inlinevirtual

Fetch current instance (retrieve all its properties) mapped to a table in the database (current instance must have a valid id before to be fetched without error, or pass the id to the first parameter of this method)

Parameters
idUnique id to fetch properties from database (if empty, check id of current instance)
columnsList of database table columns (mapped to properties of C++ class) to fetch (if empty, all columns are fetched)
relationList of relationships keys to fetch (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxFetchById(...) execute following SQL query :
SELECT * FROM my_table WHERE my_id = ?

Implements qx::IxPersistable.

Definition at line 112 of file IxPersistableCollection.h.

◆ qxFetchByQuery()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxFetchByQuery ( const qx::QxSqlQuery & query,
qx::IxPersistableCollection * list = NULL,
const QStringList & columns = QStringList(),
const QStringList & relation = QStringList(),
QSqlDatabase * pDatabase = NULL )
inlinevirtual

Fetch a list of objects (retrieve all elements and properties associated) of current type (container registered into QxOrm context) mapped to a table in the database and filtered by a user SQL query.

Parameters
queryDefine a user SQL query added to default SQL query builded by QxOrm library
listContainer to fetch all items (retrieve all elements and properties associated); list is cleared before executing SQL query
columnsList of database table columns (mapped to properties of C++ class) to fetch (if empty, all columns are fetched)
relationList of relationships keys to fetch (eager fetch instead of default lazy fetch for a relation) : use "|" separator to put many relationships keys into this parameter
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
std::shared_ptr<qx::IxPersistableCollection> lst = p->qxNewPersistableCollection();
p->qxFetchByQuery(my_query, & lst, ...) execute following SQL query :
SELECT * FROM my_table + WHERE my_query...

Implements qx::IxPersistable.

Definition at line 128 of file IxPersistableCollection.h.

◆ qxInsert()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxInsert ( const QStringList & relation = QStringList(),
QSqlDatabase * pDatabase = NULL,
bool bUseExecBatch = false )
inlinevirtual

Insert current instance into database.

Parameters
relationList of relationships keys to insert in others tables of database : use "|" separator to put many relationships keys into this parameter
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
bUseExecBatchIf true then use the QSqlQuery::execBatch() method to improve performance inserting a list of instances to database (but doesn't fill the last inserted identifier in the C++ instances)
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxInsert(...) execute following SQL query :
INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)

Implements qx::IxPersistable.

Definition at line 136 of file IxPersistableCollection.h.

◆ qxNewPersistableCollection()

template<typename Key , typename Value , typename T >
virtual std::shared_ptr< qx::IxPersistableCollection > qx::QxPersistableCollection< Key, Value, T >::qxNewPersistableCollection ( bool bAsList = false) const
inlinevirtual

Create a new collection smart-pointer to fetch a list of items of current class type.

Parameters
bAsListIf true, returns a list (array) of persistent instances instead of key/value hash-map
Returns
Return a new collection smart-pointer to fetch a list of items of current class type

Implements qx::IxPersistable.

Definition at line 191 of file IxPersistableCollection.h.

◆ qxSave()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxSave ( const QStringList & relation = QStringList(),
QSqlDatabase * pDatabase = NULL,
qx::dao::save_mode::e_save_mode eSaveRecursiveMode = qx::dao::save_mode::e_none )
inlinevirtual

Insert (if no exist) or update (if already exist) current instance into database.

Parameters
relationList of relationships keys to insert or update in others tables of database : use "|" separator to put many relationships keys into this parameter
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
eSaveRecursiveModeParameter to call qx::dao::save_with_relation_recursive function
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxSave(...) execute following SQL query :
INSERT INTO my_table (my_column_1, my_column_2, etc.) VALUES (?, ?, etc.)
or (if already exist into database) :
UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc.

Implements qx::IxPersistable.

Definition at line 152 of file IxPersistableCollection.h.

◆ qxUpdate()

template<typename Key , typename Value , typename T >
virtual QSqlError qx::QxPersistableCollection< Key, Value, T >::qxUpdate ( const qx::QxSqlQuery & query = qx::QxSqlQuery(),
const QStringList & columns = QStringList(),
const QStringList & relation = QStringList(),
QSqlDatabase * pDatabase = NULL,
bool bUseExecBatch = false )
inlinevirtual

Update current instance into database (you can add a user SQL query to the default SQL query builded by QxOrm library)

Parameters
queryDefine a user SQL query added to default SQL query builded by QxOrm library
columnsList of database table columns (mapped to properties of C++ class) to update (if empty, all columns are updated)
relationList of relationships keys to update in others tables of database : use "|" separator to put many relationships keys into this parameter
pDatabaseConnection to database (you can manage your own connection pool for example, you can also define a transaction, etc.); if NULL, a valid connection for the current thread is provided by qx::QxSqlDatabase singleton class
bUseExecBatchIf true then use the QSqlQuery::execBatch() method to improve performance updating a list of instances in database
Returns
Empty QSqlError object (from Qt library) if no error occurred; otherwise QSqlError contains a description of database error executing SQL query

qx::IxPersistable * p = ...;
p->qxUpdate(...) execute following SQL query :
UPDATE my_table SET my_column_1 = ?, my_column_2 = ?, etc. + WHERE my_query...

Implements qx::IxPersistable.

Definition at line 144 of file IxPersistableCollection.h.

◆ qxValidate()

template<typename Key , typename Value , typename T >
virtual qx::QxInvalidValueX qx::QxPersistableCollection< Key, Value, T >::qxValidate ( const QStringList & groups = QStringList())
inlinevirtual

Check if current instance is valid or not.

Parameters
groupsList of groups to check (defined into QxValidator module for current class)
Returns
Return list of invalid values (if empty, current instance is valid)

For more details about QxValidator module : https://www.qxorm.com/qxorm_en/faq.html#faq_250

Implements qx::IxPersistable.

Definition at line 188 of file IxPersistableCollection.h.

◆ toJson()

template<typename Key , typename Value , typename T >
virtual QString qx::QxPersistableCollection< Key, Value, T >::toJson ( const QString & format = QString()) const
inlinevirtual

Implements qx::IxPersistable.

Definition at line 199 of file IxPersistableCollection.h.

◆ toJson_()

template<typename Key , typename Value , typename T >
virtual QJsonValue qx::QxPersistableCollection< Key, Value, T >::toJson_ ( const QString & format = QString()) const
inlinevirtual

Implements qx::IxPersistable.

Definition at line 202 of file IxPersistableCollection.h.


The documentation for this class was generated from the following file: