LeechCraft  %{LEECHCRAFT_VERSION}
Modular cross-platform feature rich live environment.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
LeechCraft::Util::DBLock Class Reference

Provides database transaction lock. More...

#include "dblock.h"

Public Member Functions

 DBLock (const DBLock &)=delete
 
DBLockoperator= (const DBLock &)=delete
 
UTIL_API DBLock (QSqlDatabase &database)
 Constructor. More...
 
UTIL_API ~DBLock ()
 Destructor. More...
 
UTIL_API void Init ()
 Initializes the transaction. More...
 
UTIL_API void Good ()
 Notifies the lock about successful higher-level operations. More...
 

Static Public Member Functions

static UTIL_API void DumpError (const QSqlError &error)
 Dumps the error to the qWarning() stream. More...
 
static UTIL_API void DumpError (const QSqlQuery &query)
 Dumps the error to the qWarning() stream. More...
 

Detailed Description

Provides database transaction lock.

To use the lock, create an instance of it passing a non-const reference to the QSqlDatabase to be guarded. To initialize and start the locking mechanism, call Init(). To notify DBLock that everything is good and the database shouldn't be rolled back, call Good(). Transaction would be either commited or rolled back in class' destructor.

The state could be unusable, usable or correct. Unusable means that the class itself isn't usable, usable means that the class is usable, but the transaction state isn't necesseraly in a correct state, and correct means that the lock class is usable and the transaction state is correct.

Definition at line 60 of file dblock.h.

Constructor & Destructor Documentation

LeechCraft::Util::DBLock::DBLock ( const DBLock )
delete
LeechCraft::Util::DBLock::DBLock ( QSqlDatabase &  database)

Constructor.

Constructs the lock and prepares it to work with the database. Creating the lock doesn't begin the transaction. Lock is in usable state after that.

Parameters
[in]databaseNon-const reference to the database to be guarded.

Definition at line 41 of file dblock.cpp.

LeechCraft::Util::DBLock::~DBLock ( )

Destructor.

Ends the transaction if the lock is in a correct state. If Good() was called, it commits the transaction, otherwise rolls back.

Definition at line 48 of file dblock.cpp.

Member Function Documentation

void LeechCraft::Util::DBLock::DumpError ( const QSqlError &  error)
static

Dumps the error to the qWarning() stream.

Parameters
[in]errorThe error class.

Definition at line 85 of file dblock.cpp.

void LeechCraft::Util::DBLock::DumpError ( const QSqlQuery &  query)
static

Dumps the error to the qWarning() stream.

Parameters
[in]queryThe query that should be dumped.

Definition at line 92 of file dblock.cpp.

void LeechCraft::Util::DBLock::Good ( )

Notifies the lock about successful higher-level operations.

Calling this function makes the lock to commit the transaction upon destruction instead of rolling back.

Definition at line 80 of file dblock.cpp.

void LeechCraft::Util::DBLock::Init ( )

Initializes the transaction.

Tries to start the transaction. If this wasn't successful, the lock remains in a usable but not correct state.

Exceptions
std::runtime_error

Definition at line 62 of file dblock.cpp.

DBLock& LeechCraft::Util::DBLock::operator= ( const DBLock )
delete

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