LeechCraft
0.6.70-15082-g543737046d
Modular cross-platform feature rich live environment.
|
Provides database transaction lock. More...
#include "dblock.h"
Public Member Functions | |
DBLock (const DBLock &)=delete | |
DBLock & | operator= (const DBLock &)=delete |
DBLock (DBLock &&)=default | |
UTIL_DB_API | DBLock (QSqlDatabase &database) |
Constructor. More... | |
UTIL_DB_API | ~DBLock () |
Destructor. More... | |
UTIL_DB_API void | Init () |
Initializes the transaction. More... | |
UTIL_DB_API void | Good () |
Notifies the lock about successful higher-level operations. More... | |
Static Public Member Functions | |
static UTIL_DB_API void | DumpError (const QSqlError &error) |
Dumps the error to the qWarning() stream. More... | |
static UTIL_DB_API void | DumpError (const QSqlQuery &query) |
Dumps the error to the qWarning() stream. More... | |
static UTIL_DB_API void | Execute (QSqlQuery &query) |
Tries to execute the given query. More... | |
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.
|
delete |
|
default |
|
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.
[in] | database | Non-const reference to the database to be guarded. |
Definition at line 30 of file dblock.cpp.
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 35 of file dblock.cpp.
|
static |
Dumps the error to the qWarning() stream.
[in] | error | The error class. |
Definition at line 74 of file dblock.cpp.
Referenced by LC::Util::MakeDatabase(), and LC::Util::oral::detail::ToVariantF().
|
static |
Dumps the error to the qWarning() stream.
[in] | query | The query that should be dumped. |
Definition at line 80 of file dblock.cpp.
|
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.
[in] | query | The query that should be dumped. |
Definition at line 87 of file dblock.cpp.
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 69 of file dblock.cpp.
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.
std::runtime_error |
Definition at line 51 of file dblock.cpp.