Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

transaction.h

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/transaction.h
00005  *
00006  *   DESCRIPTION
00007  *      definition of the pqxx::transaction class.
00008  *   pqxx::transaction represents a database transaction
00009  *
00010  * Copyright (c) 2001-2003, Jeroen T. Vermeulen <jtv@xs4all.nl>
00011  *
00012  * See COPYING for copyright license.  If you did not receive a file called
00013  * COPYING with this source code, please notify the distributor of this mistake,
00014  * or contact the author.
00015  *
00016  *-------------------------------------------------------------------------
00017  */
00018 #ifndef PQXX_TRANSACTION_H
00019 #define PQXX_TRANSACTION_H
00020 
00021 /* While you may choose to create your own transaction object to interface to 
00022  * the database backend, it is recommended that you wrap your transaction code 
00023  * into a transactor code instead and let the transaction be created for you.
00024  * See pqxx/transactor.h for more about transactor.
00025  *
00026  * If you should find that using a transactor makes your code less portable or 
00027  * too complex, go ahead, create your own transaction anyway.
00028  */
00029 
00030 // Usage example: double all wages
00031 //
00032 // extern connection C;
00033 // transaction<> T(C);
00034 // try
00035 // {
00036 //   T.Exec("UPDATE employees SET wage=wage*2");
00037 //   T.Commit();        // NOTE: do this inside try block
00038 // } 
00039 // catch (const exception &e)
00040 // {
00041 //   cerr << e.what() << endl;
00042 //   T.Abort();         // Usually not needed; same happens when T's life ends.
00043 // }
00044 
00045 #include "pqxx/dbtransaction.h"
00046 
00047 /* Methods tested in eg. self-test program test1 are marked with "//[t1]"
00048  */
00049 
00050 
00051 // TODO: Any user-friendliness we can add to invoking stored procedures?
00052 
00053 namespace pqxx
00054 {
00055 
00056 class PQXX_LIBEXPORT basic_transaction : public dbtransaction
00057 {
00058 protected:
00059   explicit basic_transaction(connection_base &C, 
00060                              const PGSTD::string &IsolationLevel,
00061                              const PGSTD::string &TName) :              //[t1]
00062     dbtransaction(C, IsolationLevel, TName) {}
00063 
00064 private:
00065   virtual void DoBegin();                                               //[t1]
00066   virtual result DoExec(const char[]);                                  //[t1]
00067   virtual void DoCommit();                                              //[t1]
00068   virtual void DoAbort();                                               //[t13]
00069 
00070 };
00071 
00072 
00074 template<> inline PGSTD::string Classname(const basic_transaction *) 
00075 { 
00076   return "basic_transaction"; 
00077 }
00078 
00079 
00081 
00105 template<isolation_level ISOLATIONLEVEL=read_committed>
00106 class PQXX_LIBEXPORT transaction : public basic_transaction
00107 {
00108 public:
00109   typedef isolation_traits<ISOLATIONLEVEL> isolation_tag;
00110 
00113   explicit transaction(connection_base &C,
00114                        const PGSTD::string &TName=PGSTD::string()) :    //[]
00115     basic_transaction(C, isolation_tag::name(), TName) 
00116         { Begin(); }
00117 
00118   virtual ~transaction() { End(); }
00119 };
00120 
00121 
00123 template<isolation_level ISOLATIONLEVEL> 
00124 inline PGSTD::string Classname(const transaction<ISOLATIONLEVEL> *) 
00125 { 
00126   return "transaction<" + isolation_traits<ISOLATIONLEVEL>::name() + ">";
00127 }
00128 
00129 
00131 typedef transaction<read_committed> Transaction;
00132 
00133 }
00134 
00135 #endif
00136 

Generated on Sat Jun 7 00:49:34 2003 for libpqxx by doxygen1.3-rc3