kexi

KexiDB::TransactionGuard Class Reference

#include <transaction.h>

List of all members.


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

TransactionGuard::TransactionGuard ( Connection conn  ) 

Constructor #1: Starts new transaction constructor for connection. Started transaction handle is available via transaction().

Definition at line 130 of file transaction.cpp.

TransactionGuard::TransactionGuard ( const Transaction trans  ) 

Constructor #2: Uses already started transaction.

Definition at line 136 of file transaction.cpp.

TransactionGuard::TransactionGuard (  ) 

Constructor #3: Creates TransactionGuard without transaction assinged. setTransaction() can be used later to do so.

Definition at line 142 of file transaction.cpp.

TransactionGuard::~TransactionGuard (  ) 

Rollbacks not commited transaction.

Definition at line 147 of file transaction.cpp.


Member Function Documentation

bool TransactionGuard::commit (  ) 

Comits the guarded transaction. It is convenient shortcut to connection->commitTransaction(this->transaction())

Definition at line 153 of file transaction.cpp.

void TransactionGuard::doNothing (  ) 

Makes guarded transaction not guarded, so nothing will be performed on guard's desctruction.

Definition at line 161 of file transaction.cpp.

void KexiDB::TransactionGuard::setTransaction ( const Transaction trans  )  [inline]

Assigns transaction trans to this guard. Previously assigned transaction will be unassigned from this guard.

Definition at line 138 of file transaction.h.

const Transaction KexiDB::TransactionGuard::transaction (  )  const [inline]

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:
KDE Home | KDE Accessibility Home | Description of Access Keys