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

#include <qsql_impl.hpp>

Inheritance diagram for hds::db::QSqlImpl:
hds::db::LockerQSql hds::db::ProjectQSql hds::db::SeismicQSql

Classes

struct  TableLockDescr
 

Public Types

enum  TableLockType { TLT_READ = 0, TLT_WRITE }
 
typedef std::vector
< TableLockDescr
TLDVec
 

Public Member Functions

 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 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
 

Protected Attributes

QSqlDatabase m_db
 
ContextQSql m_dbc
 
bool m_is_transaction_started
 

Detailed Description

Implementation of common methods using Qt SQL features.

Member Typedef Documentation

Vector of table locks descriptions.

Member Enumeration Documentation

Type of SQL table lock.

Enumerator
TLT_READ 

Read lock.

TLT_WRITE 

Write lock.

Constructor & Destructor Documentation

hds::db::QSqlImpl::QSqlImpl ( )

Default constructor.

hds::db::QSqlImpl::QSqlImpl ( const ContextQSql dbc)

Constructor with database context provided.

virtual hds::db::QSqlImpl::~QSqlImpl ( )
virtual

Destructor.

Member Function Documentation

ErrCode hds::db::QSqlImpl::db_close ( const hds::db::ContextQSql context)
protected
Close database session associated with provided context. 

Return EC_NO_ERROR if all ok.

ErrCode hds::db::QSqlImpl::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
protected
Get value of the row item with provided key id for table with provided name. 

Return EC_NO_ERROR if all ok.

ErrCode hds::db::QSqlImpl::db_get_lock ( const std::string &  lock_name,
const size_t  timeout = 3 
) const
protected
Tries to make database lock (mutex) with provided name and waiting timeout. 
Parameters
lock_nameName of the lock.
timeoutLock try waiting timeout (s).
Returns
: EC_NO_ERROR if all ok, EC_LOCKED_WRITE if timed out, EC_UNDEFINED on internal error.
ErrCode hds::db::QSqlImpl::db_init ( const hds::db::ContextQSql context)
protected
Initialize database session associated with provided context. 

Return EC_NO_ERROR if all ok.

ErrCode hds::db::QSqlImpl::db_lock_tables ( const TLDVec tld_vec)
protected

Try to lock tables provided with table locks descriptions.

ErrCode hds::db::QSqlImpl::db_release_lock ( const std::string &  lock_name) const
protected
Releases database lock (mutex) with provided name. 
Parameters
lock_nameName of the lock.
Returns
: EC_NO_ERROR if all ok or EC_UNDEFINED on internal error.
ErrCode hds::db::QSqlImpl::db_release_tables_locks ( )
protected

Unlock all tables in the session.

ErrCode hds::db::QSqlImpl::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 
)
protected
Set value of the row item with provided key id for table with provided name. 

Return EC_NO_ERROR if all ok.

time_t hds::db::QSqlImpl::db_table_creation_time ( const std::string &  table_name,
ErrCode prc = NULL 
) const
protected
Get table creation time.
Parameters
table_nameName of the table.
prcResulted error code, EC_NO_ERROR if all ok.
Returns
time of table creation.
time_t hds::db::QSqlImpl::db_table_modification_time ( const std::string &  table_name,
ErrCode prc = NULL 
) const
protected
Get table creation time.
Parameters
table_nameName of the table.
prcResulted error code, EC_NO_ERROR if all ok.
Returns
time of table creation.
size_t hds::db::QSqlImpl::db_table_rows_num ( const std::string &  table_name,
ErrCode prc = NULL 
) const
protected
Get number of rows of table with provided name. 
Parameters
table_nameName of the table.
prcResulted error code, EC_NO_ERROR if all ok.
Returns
number of rows.
quint64 hds::db::QSqlImpl::db_table_size ( const std::string &  table_name,
ErrCode prc = NULL 
) const
protected
Get size of table with provided name.
Parameters
table_nameName of the table.
prcResulted error code, EC_NO_ERROR if all ok.
Returns
size of table in bytes.
ErrCode hds::db::QSqlImpl::db_transaction_begin ( ) const
protected
Start transaction. 

Do nothing if transaction not supported, this case not a error. Do nothing if transaction is started, this case not a error.

Returns
EC_NO_ERROR if all ok.
ErrCode hds::db::QSqlImpl::db_transaction_commit ( )
protected
Commit transaction. 

Do nothing if transaction not supported, this case not a error. Do nothing if transaction not started, this case not a error.

Returns
EC_NO_ERROR if all ok.
ErrCode hds::db::QSqlImpl::db_transaction_rollback ( )
protected
Rollback transaction. 

Do nothing if transaction not supported, this case not a error. Do nothing if transaction not started, this case not a error.

Returns
EC_NO_ERROR if all ok.
ErrCode hds::db::QSqlImpl::dbConnect ( ) const
Connect to db with provided context. Do nothing if already connected.

Return EC_NO_ERROR if all ok.

QString hds::db::QSqlImpl::get_db_name_hash ( const hds::db::ContextQSql context) const
protected

Get database name hash for provided database context.

QSqlDatabase& hds::db::QSqlImpl::getDb ( )
inline

Access to database.

const ContextQSql& hds::db::QSqlImpl::getDbContext ( ) const
inline

Access to current database condext.

QMutex& hds::db::QSqlImpl::getDefaultMutex ( ) const

Access to default mutex object.

bool hds::db::QSqlImpl::supportTransactionsFlag ( ) const

Returrn true or false if database provides or not provides transactions.

Member Data Documentation

QSqlDatabase hds::db::QSqlImpl::m_db
mutableprotected

< SQL database connector. Data base context.

ContextQSql hds::db::QSqlImpl::m_dbc
protected

Is transaction started flag.


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