UNIVERS  15.3
UNIVERS base processing software API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Public Member Functions | Protected Member Functions | List of all members
hds::db::LockerQSql Class Reference

#include <locker_qsql.hpp>

Inheritance diagram for hds::db::LockerQSql:
hds::db::Locker hds::db::QSqlImpl

Public Member Functions

 LockerQSql (const QSqlDatabase &db, const std::string &name="hds_db_locker", const size_t timeout=1)
 
 LockerQSql (const ContextQSql &dbc, const std::string &name="hds_db_locker", const size_t timeout=1)
 
virtual ~LockerQSql ()
 
virtual DbIndex lock (const LockDescription &ld)
 
virtual void release (const DbIndex &id)
 
virtual size_t releaseAll ()
 
virtual void list (LockDescriptionVec &locks)
 
virtual ErrCode lastError () const
 
- Public Member Functions inherited from hds::db::Locker
 Locker ()
 
virtual ~Locker ()
 
- Public Member Functions inherited from hds::db::QSqlImpl
 QSqlImpl ()
 
 QSqlImpl (const ContextQSql &dbc)
 
virtual ~QSqlImpl ()
 
const ContextQSqlgetDbContext () const
 
QSqlDatabase & getDb ()
 
bool supportTransactionsFlag () const
 
ErrCode dbConnect () const
 
QMutex & getDefaultMutex () const
 

Protected Member Functions

ErrCode init (const std::string &mutex_name, const size_t timeout)
 
ErrCode db_create_locks_table () const
 
ErrCode db_get_locks_num (const std::string &name, const LockType &lt, unsigned int &locks_num) const
 
ErrCode db_clear_invalid_locks ()
 
- Protected Member Functions inherited from hds::db::QSqlImpl
ErrCode db_init (const hds::db::ContextQSql &context)
 
ErrCode db_close (const hds::db::ContextQSql &context)
 
ErrCode db_lock_tables (const TLDVec &tld_vec)
 
ErrCode db_release_tables_locks ()
 
ErrCode db_get_lock (const std::string &lock_name, const size_t timeout=3) const
 
ErrCode db_release_lock (const std::string &lock_name) const
 
ErrCode db_set_item_value (const std::string &table_name, const std::string &field_name, const std::string &key_name, const DbIndex &key_id, const std::string &value)
 
ErrCode db_get_item_value (const std::string &table_name, const std::string &field_name, const std::string &key_name, const DbIndex &key_id, std::string &value) const
 
time_t db_table_creation_time (const std::string &table_name, ErrCode *prc=NULL) const
 
time_t db_table_modification_time (const std::string &table_name, ErrCode *prc=NULL) const
 
quint64 db_table_size (const std::string &table_name, ErrCode *prc=NULL) const
 
size_t db_table_rows_num (const std::string &table_name, ErrCode *prc=NULL) const
 
ErrCode db_transaction_begin () const
 
ErrCode db_transaction_commit ()
 
ErrCode db_transaction_rollback ()
 
QString get_db_name_hash (const hds::db::ContextQSql &context) const
 

Additional Inherited Members

- Public Types inherited from hds::db::QSqlImpl
enum  TableLockType { TLT_READ = 0, TLT_WRITE }
 
typedef std::vector
< TableLockDescr
TLDVec
 
- Protected Attributes inherited from hds::db::QSqlImpl
QSqlDatabase m_db
 
ContextQSql m_dbc
 
bool m_is_transaction_started
 

Detailed Description

Qt SQL database locker.

Constructor & Destructor Documentation

hds::db::LockerQSql::LockerQSql ( const QSqlDatabase &  db,
const std::string &  name = "hds_db_locker",
const size_t  timeout = 1 
)
Construct locker with provided database mutex name.

If name is not empty then access to locks is blocked for any SQL connection until the object is destroyed. After initialization lastError() may return: EC_LOCKED_WRITE if access to locks timed out, EC_UNDEFINED on internal SQL error, EC_NO_ERROR on success.

Parameters
dbQt SQL database interface. Has to be initialized, just copied inside.
nameName of the locker (database mutex name).
timeout(s) waiting timeout.
hds::db::LockerQSql::LockerQSql ( const ContextQSql dbc,
const std::string &  name = "hds_db_locker",
const size_t  timeout = 1 
)
Construct locker with provided database mutex name.

If name is not empty then access to locks is blocked for any SQL connection until the object is destroyed. New database connection is created. After initialization lastError() may return: EC_LOCKED_WRITE if access to locks timed out, EC_UNDEFINED on internal SQL error, EC_NO_ERROR on success.

Parameters
dbcDatabase context.
mutex_nameName of the locker (database mutex name).
timeout(s) waiting timeout.
virtual hds::db::LockerQSql::~LockerQSql ( )
virtual

Unlock access to locks and destroy object.

Member Function Documentation

ErrCode hds::db::LockerQSql::db_clear_invalid_locks ( )
protected
Clear locks with ids of not connected clients. 
Returns
EC_NO_ERROR if ok, corresponednt error code otherwise.
ErrCode hds::db::LockerQSql::db_create_locks_table ( ) const
protected
Creates table of locks. 
Returns
EC_NO_ERROR if ok, corresponednt error code otherwise.
ErrCode hds::db::LockerQSql::db_get_locks_num ( const std::string &  name,
const LockType lt,
unsigned int &  locks_num 
) const
protected
Get number of locks with provided name and type.
Parameters
nameName of lock.
ltType of locks to be counted.
locks_numResulted number of locks in database.
Returns
EC_NO_ERROR if ok, correspondent error code otherwise.
ErrCode hds::db::LockerQSql::init ( const std::string &  mutex_name,
const size_t  timeout 
)
protected
Initialize locker. 
Parameters
mutex_nameName of the tatabase mutex.
timeout(s) waiting timeout.
Returns
EC_LOCKED_WRITE if access to locks timed out, EC_UNDEFINED on internal SQL error, EC_NO_ERROR on success.
virtual ErrCode hds::db::LockerQSql::lastError ( ) const
virtual

Get the last error occurred.

Implements hds::db::Locker.

virtual void hds::db::LockerQSql::list ( LockDescriptionVec locks)
virtual
Get list of database locks. lastError() will return: 

EC_UNDEFINED on internal error, EC_NO_ERROR on success.

Parameters
locksResulted list of locks.

Implements hds::db::Locker.

virtual DbIndex hds::db::LockerQSql::lock ( const LockDescription ld)
virtual
Try to obtain a lock with provided name. lastError() may return: 

EC_LOCKED_READ if can't obtain lock because provided name locked for reading, EC_LOCKED_WRITE if can't obtain lock because provided name locked for writing, EC_UNDEFINED on internal SQL error, EC_NO_ERROR if lock is obtained successfully.

Parameters
lock_descrDescription of the lock.
Returns
Uniq index of lock obtained on success. Has no means on error.

Implements hds::db::Locker.

virtual void hds::db::LockerQSql::release ( const DbIndex id)
virtual
Tries to release lock with provided id. lastError() may return: 

EC_UNDEFINED on internal SQL error, EC_NO_ERROR on success.

Parameters
idUniq index of lock to be released.

Implements hds::db::Locker.

virtual size_t hds::db::LockerQSql::releaseAll ( )
virtual
Tries to release all locks. lastError() may return: 

EC_UNDEFINED on internal SQL error, EC_NO_ERROR on success.

Returns
number of locks released.

Implements hds::db::Locker.


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