QxOrm  1.4.5
C++ Object Relational Mapping library

qx::QxDaoAsync : helper class to execute SQL queries in another thread (asynchronous way) using qx::IxPersistable interface More...

#include <QxDaoAsync.h>

List of all members.

Signals

void queryStarted (qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams)
void queryFinished (const QSqlError &daoError, qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams)

Public Member Functions

 QxDaoAsync ()
virtual ~QxDaoAsync ()
bool asyncCount (const QString &className, const qx::QxSqlQuery &query=qx::QxSqlQuery(), QSqlDatabase *pDatabase=NULL)
bool asyncFetchById (IxPersistable_ptr pToFetch, const QVariant &id=QVariant(), const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
bool asyncFetchAll (const QString &className, const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
bool asyncFetchByQuery (const QString &className, const qx::QxSqlQuery &query, const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
bool asyncInsert (IxPersistable_ptr pToInsert, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
bool asyncUpdate (IxPersistable_ptr pToUpdate, const qx::QxSqlQuery &query=qx::QxSqlQuery(), const QStringList &columns=QStringList(), const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
bool asyncSave (IxPersistable_ptr pToSave, const QStringList &relation=QStringList(), QSqlDatabase *pDatabase=NULL)
bool asyncDeleteById (IxPersistable_ptr pToDelete, const QVariant &id=QVariant(), QSqlDatabase *pDatabase=NULL)
bool asyncDeleteAll (const QString &className, QSqlDatabase *pDatabase=NULL)
bool asyncDeleteByQuery (const QString &className, const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
bool asyncDestroyById (IxPersistable_ptr pToDestroy, const QVariant &id=QVariant(), QSqlDatabase *pDatabase=NULL)
bool asyncDestroyAll (const QString &className, QSqlDatabase *pDatabase=NULL)
bool asyncDestroyByQuery (const QString &className, const qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
bool asyncExecuteQuery (const QString &className, qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
bool asyncCallQuery (qx::QxSqlQuery &query, QSqlDatabase *pDatabase=NULL)
bool isQueryRunning () const

Protected Member Functions

virtual void run ()
void startQuery ()

Protected Attributes

QMutex m_mutex
 Mutex => qx::QxDaoAsync is thread-safe.
qx::dao::detail::QxDaoAsyncParams_ptr m_pDaoParams
 Parameters to execute query.

Private Slots

void onQueryFinished (const QSqlError &daoError, qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams)

Detailed Description

qx::QxDaoAsync : helper class to execute SQL queries in another thread (asynchronous way) using qx::IxPersistable interface

To use qx::QxDaoAsync helper class : 1- be careful to work only with classes implementing qx::IxPersistable interface ; 2- create an instance of qx::QxDaoAsync type (for example, a property of a QWidget derived class) ; 3- connect a SLOT to the qx::QxDaoAsync::queryFinished() SIGNAL (for example, a SLOT of a QWidget derived class) ; 4- run a query using one of qx::QxDaoAsync::asyncXXXX() methods.

For example, with a MyWidget class :

class MyWidget : public QWidget
{
   Q_OBJECT
   //...
   qx::QxDaoAsync m_daoAsync;
   //...
Q_SLOTS:
   void onQueryFinished(const QSqlError & daoError, qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams);
   //...
};

And here is the implementation of MyWidget class :

MyWidget::MyWidget() : QObject()
{
   //...
   QObject::connect((& m_daoAsync), SIGNAL(queryFinished(const QSqlError &, qx::dao::detail::QxDaoAsyncParams_ptr)), this, SLOT(onQueryFinished(const QSqlError &, qx::dao::detail::QxDaoAsyncParams_ptr)));
   //...
}
void MyWidget::onQueryFinished(const QSqlError & daoError, qx::dao::detail::QxDaoAsyncParams_ptr pDaoParams)
{
   if (! pDaoParams) { return; }
   qx::QxSqlQuery query = pDaoParams->query;
   if (! daoError.isValid()) { ; }
   // If the async query is associated to a simple object, just use 'pDaoParams->pInstance' method
   qx::IxPersistable_ptr ptr = pDaoParams->pInstance;
   // If the async query is associated to a list of objects, just use 'pDaoParams->pListOfInstances' method
   qx::IxPersistableCollection_ptr lst = pDaoParams->pListOfInstances;
   //...
}

Definition at line 169 of file QxDaoAsync.h.


Constructor & Destructor Documentation

qx::QxDaoAsync::QxDaoAsync ( )
virtual qx::QxDaoAsync::~QxDaoAsync ( ) [virtual]

Member Function Documentation

bool qx::QxDaoAsync::asyncCallQuery ( qx::QxSqlQuery query,
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncCount ( const QString &  className,
const qx::QxSqlQuery query = qx::QxSqlQuery(),
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncDeleteAll ( const QString &  className,
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncDeleteById ( IxPersistable_ptr  pToDelete,
const QVariant &  id = QVariant(),
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncDeleteByQuery ( const QString &  className,
const qx::QxSqlQuery query,
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncDestroyAll ( const QString &  className,
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncDestroyById ( IxPersistable_ptr  pToDestroy,
const QVariant &  id = QVariant(),
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncDestroyByQuery ( const QString &  className,
const qx::QxSqlQuery query,
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncExecuteQuery ( const QString &  className,
qx::QxSqlQuery query,
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncFetchAll ( const QString &  className,
const QStringList &  columns = QStringList(),
const QStringList &  relation = QStringList(),
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncFetchById ( IxPersistable_ptr  pToFetch,
const QVariant &  id = QVariant(),
const QStringList &  columns = QStringList(),
const QStringList &  relation = QStringList(),
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncFetchByQuery ( const QString &  className,
const qx::QxSqlQuery query,
const QStringList &  columns = QStringList(),
const QStringList &  relation = QStringList(),
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncInsert ( IxPersistable_ptr  pToInsert,
const QStringList &  relation = QStringList(),
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncSave ( IxPersistable_ptr  pToSave,
const QStringList &  relation = QStringList(),
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::asyncUpdate ( IxPersistable_ptr  pToUpdate,
const qx::QxSqlQuery query = qx::QxSqlQuery(),
const QStringList &  columns = QStringList(),
const QStringList &  relation = QStringList(),
QSqlDatabase *  pDatabase = NULL 
)
bool qx::QxDaoAsync::isQueryRunning ( ) const [inline]

Definition at line 200 of file QxDaoAsync.h.

void qx::QxDaoAsync::onQueryFinished ( const QSqlError &  daoError,
qx::dao::detail::QxDaoAsyncParams_ptr  pDaoParams 
) [private, slot]
void qx::QxDaoAsync::queryFinished ( const QSqlError &  daoError,
qx::dao::detail::QxDaoAsyncParams_ptr  pDaoParams 
) [signal]
void qx::QxDaoAsync::queryStarted ( qx::dao::detail::QxDaoAsyncParams_ptr  pDaoParams) [signal]
virtual void qx::QxDaoAsync::run ( ) [protected, virtual]
void qx::QxDaoAsync::startQuery ( ) [protected]

Member Data Documentation

QMutex qx::QxDaoAsync::m_mutex [protected]

Mutex => qx::QxDaoAsync is thread-safe.

Definition at line 176 of file QxDaoAsync.h.

Parameters to execute query.

Definition at line 177 of file QxDaoAsync.h.


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