Transaction Class ReferenceTransaction can be created from archive to enclose set of database operations in single reversable unit.
More...
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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. | |
| Transaction & | operator= (const Transaction &pTransaction) |
| Assigment operator. | |
| void | rollback () |
| Rollback transaction. | |
| Transaction (const Transaction &pTransaction) | |
| Copy constructor. | |
| ~Transaction () throw () | |
| Destructor. | |
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.
|
|
Type of transaction to create.
|
|
|
Copy constructor.
|
|
|
Commit transaction. Commits all current changes to streams and starts new transaction just after it. |
|
|
Get SQLOStream related to Transaction.
|
|
|
Get SQLOStream related to Transaction.
|
|
|
Assigment operator.
|
|
|
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. |
| Documentation |
|---|
| Quick start |
| Examples |
| Search |
| API Documentation |
|---|
| Class hierarchy |
| Member index |
| API Reference |
| Store filters |
| Store table macros |