LeechCraft 0.6.70-16373-g319c272718
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
LC::Util::DBLock Class Reference

Provides database transaction lock. More...

#include "dblock.h"

Public Member Functions

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

Static Public Member Functions

static UTIL_DB_API void DumpError (const QSqlError &error)
 Dumps the error to the qWarning() stream.
 
static UTIL_DB_API void DumpError (const QSqlQuery &query)
 Dumps the error to the qWarning() stream.
 
static UTIL_DB_API void Execute (QSqlQuery &query)
 Tries to execute the given query.
 

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 41 of file dblock.h.

Constructor & Destructor Documentation

◆ DBLock() [1/3]

LC::Util::DBLock::DBLock ( const DBLock & )
delete

◆ DBLock() [2/3]

LC::Util::DBLock::DBLock ( DBLock && )
default

◆ DBLock() [3/3]

LC::Util::DBLock::DBLock ( QSqlDatabase & database)
explicit

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 24 of file dblock.cpp.

◆ ~DBLock()

LC::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 29 of file dblock.cpp.

References DumpError(), and LC::Util::Filter().

+ Here is the call graph for this function:

Member Function Documentation

◆ DumpError() [1/2]

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

Dumps the error to the qWarning() stream.

Parameters
[in]errorThe error class.

Definition at line 68 of file dblock.cpp.

References LC::Util::Filter().

Referenced by ~DBLock(), LC::Util::oral::detail::DoInsert(), DumpError(), Execute(), Init(), LC::Util::oral::detail::SelectWrapperCommon::RunQuery(), and LC::Util::RunTextQuery().

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

◆ DumpError() [2/2]

void LC::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 75 of file dblock.cpp.

References DumpError(), and LC::Util::Filter().

+ Here is the call graph for this function:

◆ Execute()

void LC::Util::DBLock::Execute ( QSqlQuery & query)
static

Tries to execute the given query.

If query execution is successful, this function just returns. Otherwise it calls DumpError() to write the error to the logs and throws an exception.

Parameters
[in]queryThe query that should be dumped.

Definition at line 85 of file dblock.cpp.

References DumpError(), and LC::Util::Filter().

Referenced by LC::Util::RunQuery().

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

◆ Good()

void LC::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 63 of file dblock.cpp.

◆ Init()

void LC::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 45 of file dblock.cpp.

References DumpError(), and LC::Util::Filter().

Referenced by LC::Util::oral::Migrate().

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

◆ operator=()

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

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