Transaction Class Reference
[Public API]

Transaction can be created from archive to enclose set of database operations in single reversable unit. More...

#include <sharedsqlarchive.h>

Collaboration diagram for Transaction:

Collaboration graph
[legend]
List of all members.

Public Types

enum  creationType { TRANS_USE_LAST, TRANS_NEW }
 Type of transaction to create. More...

Public Member Functions

void commit ()
 Commit transaction.
SQLIStream getIStream ()
 Get SQLOStream related to Transaction.
SQLOStream getOStream ()
 Get SQLOStream related to Transaction.
bool isRolledback () const
 Check if transaction is rolled back.
Transactionoperator= (const Transaction &pTransaction)
 Assigment operator.
void rollback ()
 Rollback transaction.
 Transaction (const Transaction &pTransaction)
 Copy constructor.
 ~Transaction () throw ()
 Destructor.

Detailed Description

Transaction can be created from archive to enclose set of database operations in single reversable unit.

To reverse all operations call rollback() on transaction.

Transactions can be created in two modes. If TRANS_USE_LAST (default) mode is used, then first call to SharedSQLArchive::createTransaction will get DbConnection from connection pool and create transaction on it. All subsequent calls to SharedSQLArchive::createTransaction will create child Transactions using already selected connection. This way you can enclose parts of code to be in single transaction context like this:

void 
myStoreFunction() {
  Trasaction local(mArchive.createTransaction());
  //do some queries here
}

void myDataProcessing() {
  Trasaction tp(mArchive.createTransaction());
  myStoreFunction();
  myStoreFunction();
  //some other queries
}

When myDataProcessing is called then database transaction is started when tp is created and commited when tp is destructed. Creation of "local" Transaction instance do nothing, because it is called in already created transaction context.

If myStoreFunction sould be called where there was no active transaction object created, then SharedSQLArchive will assign DbConnection to it and start new transaction.

Second mode, TRANS_NEW will break exisiting transaction context and create new one. That is, if in above example "local" would be created using TRANS_NEW mode then new DbConnection would be assigned to it and new transaction would be started on that connection.

All streams returned by Transaction object shares one internal DbConnection and all operations on that streams are done in transaction context. You should not close or destroy returned streams Transaction destructor will take care of it.

The default action when Transaction is destroyed is to commit transaction to database. If you want to rollback all operations instead, then you should call rollback() before top-most Transaction instance is destructed. Calling rollback will mark Transaction to be rolled back - SQL ROLLBACK TRANSACTION query is sent when last Transaction instance in current transaction context goes out of scope.

See also:
SharedSQLArchive::createTransaction


Member Enumeration Documentation

enum creationType
 

Type of transaction to create.

Enumerator:
TRANS_USE_LAST  create child of last existing transaction
TRANS_NEW  create new transaction

Constructor & Destructor Documentation

Transaction const Transaction pTransaction  ) 
 

Copy constructor.

Parameters:
pTransaction object to copy from

Member Function Documentation

void commit  ) 
 

Commit transaction.

Commits all current changes to streams and starts new transaction just after it.

SQLIStream getIStream  ) 
 

Get SQLOStream related to Transaction.

Returns:
SQLOStream instance

SQLOStream getOStream  ) 
 

Get SQLOStream related to Transaction.

Warning:
this stream should not be closed - To close streams delete Transaction instance
Returns:
SQLOStream instance

Transaction& operator= const Transaction pTransaction  ) 
 

Assigment operator.

Parameters:
pTransaction object to copy from

void rollback  ) 
 

Rollback transaction.

All changes done from time when first topmost parent Transaction instance was created will be rolled back when last instance of child Transaction will be destructed.


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

Documentation
Quick start
Examples
Search

API Documentation
Class hierarchy
Member index
API Reference
Store filters
Store table macros
Back

Generated by doxygen at Sun Nov 9 02:08:33 2008