Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

pqxx::transactor< TRANSACTION > Class Template Reference

Wrapper for transactions that automatically restarts them on failure. More...

#include <transactor.hxx>

List of all members.

Public Member Functions

 transactor (const PGSTD::string &TName="transactor")
void operator() (TRANSACTION &T)
 Overridable transaction definition; insert your database code here.
void on_abort (const char[]) throw ()
 Optional overridable function to be called if transaction is aborted.
void on_commit ()
 Optional overridable function to be called after successful commit.
void on_doubt () throw ()
 Overridable function to be called when "in doubt" about outcome.
void OnCommit ()
void OnAbort (const char[]) throw ()
void OnDoubt () throw ()
PGSTD::string Name () const
 The transactor's name.


Detailed Description

template<typename TRANSACTION = transaction<read_committed>>
class pqxx::transactor< TRANSACTION >

Wrapper for transactions that automatically restarts them on failure.

Some transactions may be replayed if their connection fails, until they do succeed. These can be encapsulated in a transactor-derived classes. The transactor framework will take care of setting up a backend transaction context for the operation, and of aborting and retrying if its connection goes bad.

The transactor framework also makes it easier for you to do this safely, avoiding typical pitfalls and encouraging programmers to separate their transaction definitions (essentially, business rules implementations) from their higher-level code (application using those business rules). The former go into the transactor-based class.

Pass an object of your transactor-based class to connection_base::perform() to execute the transaction code embedded in it (see the definitions in pqxx/connection_base.hxx).

connection_base::Perform() is actually a template, specializing itself to any transactor type you pass to it. This means you will have to pass it a reference of your object's ultimate static type; runtime polymorphism is not allowed. Hence the absence of virtual methods in transactor. The exact methods to be called at runtime *must* be resolved at compile time.

Your transactor-derived class must define a copy constructor. This will be used to create a "clean" copy of your transactor for every attempt that Perform() makes to run it.


Constructor & Destructor Documentation

template<typename TRANSACTION = transaction<read_committed>>
pqxx::transactor< TRANSACTION >::transactor const PGSTD::string &  TName = "transactor< TRANSACTION >"  )  [explicit]
 


Member Function Documentation

template<typename TRANSACTION = transaction<read_committed>>
PGSTD::string pqxx::transactor< TRANSACTION >::Name  )  const
 

The transactor's name.

template<typename TRANSACTION = transaction<read_committed>>
void pqxx::transactor< TRANSACTION >::on_abort const   char[]  )  throw ()
 

Optional overridable function to be called if transaction is aborted.

This need not imply complete failure; the transactor will automatically retry the operation a number of times before giving up. on_abort() will be called for each of the failed attempts.

One parameter is passed in by the framework: an error string describing why the transaction failed. This will also be logged to the connection's notice processor.

template<typename TRANSACTION = transaction<read_committed>>
void pqxx::transactor< TRANSACTION >::on_commit  ) 
 

Optional overridable function to be called after successful commit.

If your on_commit() throws an exception, the actual back-end transaction will remain committed, so any changes in the database remain regardless of how this function terminates.

template<typename TRANSACTION = transaction<read_committed>>
void pqxx::transactor< TRANSACTION >::on_doubt  )  throw ()
 

Overridable function to be called when "in doubt" about outcome.

This may happen if the connection to the backend is lost while attempting to commit. In that case, the backend may have committed the transaction but is unable to confirm this to the frontend; or the transaction may have failed, causing it to be rolled back, but again without acknowledgement to the client program. The best way to deal with this situation is typically to wave red flags in the user's face and ask him to investigate.

The robusttransaction class is intended to reduce the chances of this error occurring, at a certain cost in performance.

See also:
robusttransaction

template<typename TRANSACTION = transaction<read_committed>>
void pqxx::transactor< TRANSACTION >::OnAbort const   char[]  )  throw ()
 

See also:
on_abort

template<typename TRANSACTION = transaction<read_committed>>
void pqxx::transactor< TRANSACTION >::OnCommit  ) 
 

See also:
on_commit

template<typename TRANSACTION = transaction<read_committed>>
void pqxx::transactor< TRANSACTION >::OnDoubt  )  throw ()
 

See also:
on_doubt

template<typename TRANSACTION = transaction<read_committed>>
void pqxx::transactor< TRANSACTION >::operator() TRANSACTION &  T  ) 
 

Overridable transaction definition; insert your database code here.

The operation will be retried if connection is lost, but not if an exception is thrown while the connection remains open.

Recommended practice is to allow this operator to modify only the transactor itself, and the dedicated transaction object it is passed as an argument. This is what makes side effects, retrying etc. controllable in the transactor framework.

Parameters:
T Dedicated transaction context created to perform this operation.


The documentation for this class was generated from the following file:
Generated on Mon Nov 15 11:28:05 2004 for libpqxx by  doxygen 1.3.9.1