Heart 1.3.842.34c2ab5
Heart is base back end library for your c++ Qt projects.
QH::ISqlDB Class Referenceabstract

The ISqlDB class it is db cache and bridge for DbWriters. Work Scheme of the database cache: More...

#include <isqldb.h>

Inheritance diagram for QH::ISqlDB:
Inheritance graph
Collaboration diagram for QH::ISqlDB:
Collaboration graph

Signals

void sigItemChanged (const QSharedPointer< QH::PKG::DBObject > &obj)
 sigItemChanged This signal emitted when database object is changed.
 
void sigItemDeleted (const QH::DbAddress &obj)
 sigItemDeleted This signal emitted when database object is deleted.
 

Public Member Functions

 ISqlDB (qint64 updateInterval=DEFAULT_UPDATE_INTERVAL, SqlDBCasheWriteMode mode=SqlDBCasheWriteMode::Default)
 ISqlDB This is default constructor of dbcache.
 
 ~ISqlDB () override
 
SqlDBWriterwriter () const
 writer This method return is database writer object. For more inforamation about writer see the SqlDBWriter class.
 
void setWriter (SqlDBWriter *writer)
 setWriter This method set new writer for this cache.
 
bool getAllObjects (const PKG::DBObject &templateObject, QList< QSharedPointer< QH::PKG::DBObject > > &result) override
 
bool updateObject (const QSharedPointer< QH::PKG::DBObject > &saveObject, bool wait=false) override
 
bool deleteObject (const QSharedPointer< QH::PKG::DBObject > &delObj, bool wait=false) override
 
bool insertObject (const QSharedPointer< QH::PKG::DBObject > &saveObject, bool wait=false, const QWeakPointer< unsigned int > &autoincrementIdResult={}) override
 
bool replaceObject (const QSharedPointer< QH::PKG::DBObject > &saveObject, bool wait=false) override
 
bool doQuery (const QString &query, const QVariantMap &bindValues, bool wait=false, QSqlQuery *result=nullptr) const override
 doQuery This method execute a query in this database.
 
bool doSql (const QString &sqlFile, bool wait) const override
 doSql This method execute a query in this database.
 
bool changeObjects (const PKG::DBObject &templateObject, const std::function< bool(const QSharedPointer< PKG::DBObject > &)> &changeAction)
 changeObjects This method change object of the database.
 
qint64 getUpdateInterval () const
 getUpdateInterval This method return update interval for save changes into database. This is work for default and On_New_Thread mdes. For more information see the QH::SqlDBCasheWriteMode enum.
 
void setUpdateInterval (const qint64 &value)
 getUpdateInterval This method set new value of an update interval for save changes into database. This is work for default and On_New_Thread mdes. For more information see the QH::SqlDBCasheWriteMode enum.
 
virtual bool init (const QString &initDbParams="")
 init This method init the cache object and invoke the SqlDBWriter::initDb method.
 
virtual bool init (const QVariantMap &params)
 init This method init the cache object and invoke the SqlDBWriter::initDb method.
 
void setSQLSources (const QStringList &list) override
 setSQLSources This method set sql sources for deployed database.
 
- Public Member Functions inherited from QH::iObjectProvider
template<class TYPE >
QSharedPointer< TYPE > getObject (const TYPE &templateVal)
 getObject this method return a strong pointer to DBObject created by select method of the template object (templateVal).
 
QSharedPointer< PKG::DBObjectgetObjectRaw (const PKG::DBObject &templateVal)
 getObjectRaw This method return object without test object type.
 
virtual bool getAllObjects (const PKG::DBObject &templateObject, QList< QSharedPointer< PKG::DBObject > > &result)=0
 getAllObjects This method execute a select method of the templateObject and return list of all selected from databaes or cache objects
 
virtual bool replaceObject (const QSharedPointer< PKG::DBObject > &saveObject, bool wait)=0
 replaceObject This method execute a replace method of the saveObject and insert or save if not exists, all changes into database.
 
virtual bool updateObject (const QSharedPointer< PKG::DBObject > &saveObject, bool wait)=0
 updateObject This method execute a update method of the saveObject and save all changes into database.
 
virtual bool insertObject (const QSharedPointer< PKG::DBObject > &saveObject, bool wait, const QWeakPointer< unsigned int > &autoincrementIdResult)=0
 insertObject This method execute a insert method of the saveObject and insert it into database.
 
virtual bool deleteObject (const QSharedPointer< PKG::DBObject > &obj, bool wait)=0
 deleteObject This method execute a delete method of obj and remove current object from database.
 
- Public Member Functions inherited from QH::SoftDelete
 SoftDelete ()
 
virtual ~SoftDelete ()
 ~SoftDelete This destructor has bin crashed if the softDelete method not will be invoked before delete this object. IF you try delete this object on release distribution then you get error message only without invoked std::abort method.
 
void softDelete ()
 softDelete This method remove this object and save all changes into database.
 

Protected Member Functions

void prepareForDelete () override
 prepareForDelete This method must be prepare object for delete. Override this for working main functions of this class. For more information see the SoftDelete class and SoftDelete::~SoftDelete distructor.
 
qint64 getLastUpdateTime () const
 getLastUpdateTime This method return time of last update.
 
void setLastUpdateTime (const qint64 &value)
 setLastUpdateTime This method set new value of the update time.
 
virtual void deleteFromCache (const QSharedPointer< QH::PKG::DBObject > &delObj)=0
 deleteFromCache This method delete object from db cache, bat not from database.
 
virtual bool insertToCache (const QSharedPointer< QH::PKG::DBObject > &obj)=0
 insertToCache This method insert object into cache, but not database. If Object exists in the cache this method return false.
 
virtual bool updateCache (const QSharedPointer< QH::PKG::DBObject > &obj)=0
 updateCache This method update already exits object on the cache, but not database.
 
virtual QList< QSharedPointer< QH::PKG::DBObject > > getFromCache (const PKG::DBObject *obj)=0
 getFromCache This method return strong pointer to the database object from cache (pool).
 
virtual void pushToQueue (const QSharedPointer< QH::PKG::DBObject > &obj, CacheAction type)
 pushToQueue this method should be add the object to the update queue in the physical data dash.
 
SqlDBCasheWriteMode getMode () const
 getMode This method return mode of work database cache. For more information see the QH::SqlDBCasheWriteMode enum.
 
void setMode (const SqlDBCasheWriteMode &mode)
 setMode This method set a new value of the mode database cache.
 
virtual void globalUpdateDataBasePrivate (qint64 currentTime)
 globalUpdateDataBasePrivate This method update(write) all data from cache into database. Override this method if you want change method of writing a data from cache.
 
virtual void globalUpdateDataBase (SqlDBCasheWriteMode mode=SqlDBCasheWriteMode::Default)
 globalUpdateDataBase This is base method for syncing data from the cache with database.
 

Detailed Description

The ISqlDB class it is db cache and bridge for DbWriters. Work Scheme of the database cache:

This class implements only base functions of the cache. You need to override this class and create implementation for all methods of work with the cache.

  • updateCache
  • insertToCache
  • deleteFromCache
  • getFromCache
Note
Objects of all implementation of this class must be deleted using the softDelete. The softDelete method create save all cached data into database. If you try delete this object without using softDelete method then destructor of this object emit runtime error exception (on the debug mode only).

Definition at line 72 of file isqldb.h.

Constructor & Destructor Documentation

◆ ISqlDB()

QH::ISqlDB::ISqlDB ( qint64  updateInterval = DEFAULT_UPDATE_INTERVAL,
SqlDBCasheWriteMode  mode = SqlDBCasheWriteMode::Default 
)

ISqlDB This is default constructor of dbcache.

Parameters
updateIntervalSee the SqlDBCache::setUpdateInterval for more information.
modeSee the SqlDBCache::setMode method for more information.

Definition at line 139 of file isqldb.cpp.

Here is the call graph for this function:

◆ ~ISqlDB()

QH::ISqlDB::~ISqlDB ( )
override

Definition at line 146 of file isqldb.cpp.

Member Function Documentation

◆ changeObjects()

bool QH::ISqlDB::changeObjects ( const PKG::DBObject templateObject,
const std::function< bool(const QSharedPointer< PKG::DBObject > &)> &  changeAction 
)

changeObjects This method change object of the database.

Parameters
templateObjectThis is template for get objects from database.
changeActionThis is lambda function for work with non const pointer of the object for change.
Note
If templateObject selecte more than 1 objects then the lambda function call for each all selected objects.
Returns
true if function finished successful.

Definition at line 295 of file isqldb.cpp.

Here is the call graph for this function:

◆ deleteFromCache()

virtual void QH::ISqlDB::deleteFromCache ( const QSharedPointer< QH::PKG::DBObject > &  delObj)
protectedpure virtual

deleteFromCache This method delete object from db cache, bat not from database.

Parameters
delObj[pointer to object for delete.
Returns
true if object has been delete successful.
Here is the caller graph for this function:

◆ deleteObject()

bool QH::ISqlDB::deleteObject ( const QSharedPointer< QH::PKG::DBObject > &  delObj,
bool  wait = false 
)
override

Definition at line 185 of file isqldb.cpp.

Here is the call graph for this function:

◆ doQuery()

bool QH::ISqlDB::doQuery ( const QString &  query,
const QVariantMap &  bindValues,
bool  wait = false,
QSqlQuery *  result = nullptr 
) const
overridevirtual

doQuery This method execute a query in this database.

Parameters
queryThis is query that will be executed.
bindValuesThis is values that need to bind before excute query.
resultThis is query result value.
Warning
The result works onlt on await mode. Set the wait param to true.
Returns
true if the query finished successful

Implements QH::iObjectProvider.

Definition at line 249 of file isqldb.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ doSql()

bool QH::ISqlDB::doSql ( const QString &  sqlFile,
bool  wait 
) const
overridevirtual

doSql This method execute a query in this database.

Parameters
sqlFileThis is sql file that will be executed.
Returns
true if the query finished successful

Implements QH::iObjectProvider.

Definition at line 259 of file isqldb.cpp.

Here is the call graph for this function:

◆ getAllObjects()

bool QH::ISqlDB::getAllObjects ( const PKG::DBObject templateObject,
QList< QSharedPointer< QH::PKG::DBObject > > &  result 
)
override

Definition at line 158 of file isqldb.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFromCache()

virtual QList< QSharedPointer< QH::PKG::DBObject > > QH::ISqlDB::getFromCache ( const PKG::DBObject obj)
protectedpure virtual

getFromCache This method return strong pointer to the database object from cache (pool).

Parameters
objThis is database cache id.
Returns
database Object from cache. if object with objKey not exits return nullptr.

Implemented in QH::SqlDB.

Here is the caller graph for this function:

◆ getLastUpdateTime()

qint64 QH::ISqlDB::getLastUpdateTime ( ) const
protected

getLastUpdateTime This method return time of last update.

Returns
msec of the last update.

Definition at line 124 of file isqldb.cpp.

◆ getMode()

SqlDBCasheWriteMode QH::ISqlDB::getMode ( ) const
protected

getMode This method return mode of work database cache. For more information see the QH::SqlDBCasheWriteMode enum.

Returns
QH::SqlDBCasheWriteMode value.

Definition at line 320 of file isqldb.cpp.

◆ getUpdateInterval()

qint64 QH::ISqlDB::getUpdateInterval ( ) const

getUpdateInterval This method return update interval for save changes into database. This is work for default and On_New_Thread mdes. For more information see the QH::SqlDBCasheWriteMode enum.

Returns
time in milliseconds.

Definition at line 390 of file isqldb.cpp.

◆ globalUpdateDataBase()

void QH::ISqlDB::globalUpdateDataBase ( SqlDBCasheWriteMode  mode = SqlDBCasheWriteMode::Default)
protectedvirtual

globalUpdateDataBase This is base method for syncing data from the cache with database.

Parameters
modeThis is mode writing into database.

Reimplemented in QH::SqlDB.

Definition at line 22 of file isqldb.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ globalUpdateDataBasePrivate()

void QH::ISqlDB::globalUpdateDataBasePrivate ( qint64  currentTime)
protectedvirtual

globalUpdateDataBasePrivate This method update(write) all data from cache into database. Override this method if you want change method of writing a data from cache.

Parameters
currentTimeThis is current time for saving time of the invoke of this method.

Reimplemented in QH::SqlDB.

Definition at line 328 of file isqldb.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init() [1/2]

bool QH::ISqlDB::init ( const QString &  initDbParams = "")
virtual

init This method init the cache object and invoke the SqlDBWriter::initDb method.

Parameters
initDbParamsThis is path to json file with database params.
Returns
true if initialize of database finished successful.

Definition at line 267 of file isqldb.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ init() [2/2]

bool QH::ISqlDB::init ( const QVariantMap &  params)
virtual

init This method init the cache object and invoke the SqlDBWriter::initDb method.

Parameters
paramsThis is database params map.
Returns
true if initialize of database finished successful.

Definition at line 276 of file isqldb.cpp.

Here is the call graph for this function:

◆ insertObject()

bool QH::ISqlDB::insertObject ( const QSharedPointer< QH::PKG::DBObject > &  saveObject,
bool  wait = false,
const QWeakPointer< unsigned int > &  autoincrementIdResult = {} 
)
override

Definition at line 220 of file isqldb.cpp.

Here is the call graph for this function:

◆ insertToCache()

virtual bool QH::ISqlDB::insertToCache ( const QSharedPointer< QH::PKG::DBObject > &  obj)
protectedpure virtual

insertToCache This method insert object into cache, but not database. If Object exists in the cache this method return false.

Parameters
objThis is object for save into cache.
Returns
true if insert finished successful. If Object exists then return false.
Here is the caller graph for this function:

◆ prepareForDelete()

void QH::ISqlDB::prepareForDelete ( )
overrideprotectedvirtual

prepareForDelete This method must be prepare object for delete. Override this for working main functions of this class. For more information see the SoftDelete class and SoftDelete::~SoftDelete distructor.

Implements QH::SoftDelete.

Definition at line 291 of file isqldb.cpp.

Here is the call graph for this function:

◆ pushToQueue()

void QH::ISqlDB::pushToQueue ( const QSharedPointer< QH::PKG::DBObject > &  obj,
CacheAction  type 
)
protectedvirtual

pushToQueue this method should be add the object to the update queue in the physical data dash.

Parameters
objThis is obje for update.
typeThis is type of action. For more information see the CacheAction enum.

Definition at line 132 of file isqldb.cpp.

◆ replaceObject()

bool QH::ISqlDB::replaceObject ( const QSharedPointer< QH::PKG::DBObject > &  saveObject,
bool  wait = false 
)
override

Definition at line 235 of file isqldb.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLastUpdateTime()

void QH::ISqlDB::setLastUpdateTime ( const qint64 &  value)
protected

setLastUpdateTime This method set new value of the update time.

Parameters
valuenew time of update.

Definition at line 128 of file isqldb.cpp.

Here is the caller graph for this function:

◆ setMode()

void QH::ISqlDB::setMode ( const SqlDBCasheWriteMode mode)
protected

setMode This method set a new value of the mode database cache.

Parameters
modeThis is new value of mode working the database cache

Definition at line 324 of file isqldb.cpp.

Here is the caller graph for this function:

◆ setSQLSources()

void QH::ISqlDB::setSQLSources ( const QStringList &  list)
overridevirtual

setSQLSources This method set sql sources for deployed database.

Parameters
listThis is list of sql files with database sources.

For more information about sql sources see the DataBaseNode::SQLSources method.

Implements QH::iObjectProvider.

Definition at line 285 of file isqldb.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setUpdateInterval()

void QH::ISqlDB::setUpdateInterval ( const qint64 &  value)

getUpdateInterval This method set new value of an update interval for save changes into database. This is work for default and On_New_Thread mdes. For more information see the QH::SqlDBCasheWriteMode enum.

Parameters
valuethis is new update interval.

Definition at line 394 of file isqldb.cpp.

◆ setWriter()

void QH::ISqlDB::setWriter ( SqlDBWriter writer)

setWriter This method set new writer for this cache.

Parameters
writernew writer.

Definition at line 154 of file isqldb.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sigItemChanged

void QH::ISqlDB::sigItemChanged ( const QSharedPointer< QH::PKG::DBObject > &  obj)
signal

sigItemChanged This signal emitted when database object is changed.

Note
emit implemented in updateObject and insertObject methods. So If you override then methods do not forget add emit of the sigItemChanged signal.
Parameters
objThis is changed object.
Here is the caller graph for this function:

◆ sigItemDeleted

void QH::ISqlDB::sigItemDeleted ( const QH::DbAddress obj)
signal

sigItemDeleted This signal emitted when database object is deleted.

Note
emit implemented in the deleteObject method. So if you override the deleteObject method do not forget add emit of the sigItemChanged signal.
Parameters
objThis is address of the removed object.
Here is the caller graph for this function:

◆ updateCache()

virtual bool QH::ISqlDB::updateCache ( const QSharedPointer< QH::PKG::DBObject > &  obj)
protectedpure virtual

updateCache This method update already exits object on the cache, but not database.

Parameters
objThis is object with changes for update the object rtom cache.
Returns
true if save finished successful. If the obj mot exits in the cache then return false.

◆ updateObject()

bool QH::ISqlDB::updateObject ( const QSharedPointer< QH::PKG::DBObject > &  saveObject,
bool  wait = false 
)
override

Definition at line 204 of file isqldb.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ writer()

SqlDBWriter * QH::ISqlDB::writer ( ) const

writer This method return is database writer object. For more inforamation about writer see the SqlDBWriter class.

Returns
the pointer to writer.

Definition at line 150 of file isqldb.cpp.

Here is the caller graph for this function:

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