kexi
KexiDB::TransactionGuard Class Reference
#include <transaction.h>
Detailed Description
Helper class for using inside methods for given connection.It can be used in two ways:
- start new transaction in constructor and rollback on destruction (1st constructor),
- use already started transaction and rollback on destruction (2nd constructor). In any case, if transaction is committed or rolled back outside this TransactionGuard object in the meantime, nothing happens on TransactionGuard destruction.
Example usage: void myclas::my_method() { Transaction *transaction = connection->beginTransaction(); TransactionGuard tg(transaction); ...some code that operates inside started transaction... if (something) return //after return from this code block: tg will call connection->rollbackTransaction() automatically if (something_else) transaction->commit(); for now tg won't do anything because transaction does not exist }
Definition at line 119 of file transaction.h.
Public Member Functions | |
TransactionGuard (Connection &conn) | |
TransactionGuard (const Transaction &trans) | |
TransactionGuard () | |
~TransactionGuard () | |
void | setTransaction (const Transaction &trans) |
bool | commit () |
void | doNothing () |
const Transaction | transaction () const |
Protected Attributes | |
Transaction | m_trans |
bool | m_doNothing: 1 |
Constructor & Destructor Documentation
|
Constructor #1: Starts new transaction constructor for connection. Started transaction handle is available via transaction(). Definition at line 130 of file transaction.cpp. |
|
Constructor #2: Uses already started transaction. Definition at line 136 of file transaction.cpp. |
|
Constructor #3: Creates TransactionGuard without transaction assinged. setTransaction() can be used later to do so. Definition at line 142 of file transaction.cpp. |
|
Rollbacks not commited transaction. Definition at line 147 of file transaction.cpp. |
Member Function Documentation
|
Comits the guarded transaction. It is convenient shortcut to connection->commitTransaction(this->transaction()) Definition at line 153 of file transaction.cpp. |
|
Makes guarded transaction not guarded, so nothing will be performed on guard's desctruction. Definition at line 161 of file transaction.cpp. |
|
Assigns transaction trans to this guard. Previously assigned transaction will be unassigned from this guard. Definition at line 138 of file transaction.h. |
|
Transaction that are controlled by this guard. Definition at line 148 of file transaction.h. |
The documentation for this class was generated from the following files: