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

transaction.hxx

Go to the documentation of this file.
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/transaction.hxx
00005  *
00006  *   DESCRIPTION
00007  *      definition of the pqxx::transaction class.
00008  *   pqxx::transaction represents a standard database transaction
00009  *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/transaction instead.
00010  *
00011  * Copyright (c) 2001-2003, Jeroen T. Vermeulen <jtv@xs4all.nl>
00012  *
00013  * See COPYING for copyright license.  If you did not receive a file called
00014  * COPYING with this source code, please notify the distributor of this mistake,
00015  * or contact the author.
00016  *
00017  *-------------------------------------------------------------------------
00018  */
00019 #include "pqxx/dbtransaction"
00020 
00021 
00022 /* While you may choose to create your own transaction object to interface to 
00023  * the database backend, it is recommended that you wrap your transaction code 
00024  * into a transactor code instead and let the transaction be created for you.
00025  * See pqxx/transactor.h for more about transactor.
00026  *
00027  * If you should find that using a transactor makes your code less portable or 
00028  * too complex, go ahead, create your own transaction anyway.
00029  */
00030 
00031 // Usage example: double all wages
00032 //
00033 // extern connection C;
00034 // work T(C);
00035 // try
00036 // {
00037 //   T.exec("UPDATE employees SET wage=wage*2");
00038 //   T.commit();        // NOTE: do this inside try block
00039 // } 
00040 // catch (const exception &e)
00041 // {
00042 //   cerr << e.what() << endl;
00043 //   T.abort();         // Usually not needed; same happens when T's life ends.
00044 // }
00045 
00046 /* Methods tested in eg. self-test program test1 are marked with "//[t1]"
00047  */
00048 
00049 
00050 namespace pqxx
00051 {
00052 
00053 class PQXX_LIBEXPORT basic_transaction : public dbtransaction
00054 {
00055 protected:
00056   explicit basic_transaction(connection_base &C, 
00057                              const PGSTD::string &IsolationLevel,
00058                              const PGSTD::string &TName) :              //[t1]
00059     dbtransaction(C, IsolationLevel, TName) {}
00060 
00061 private:
00062   virtual void do_begin();                                              //[t1]
00063   virtual result do_exec(const char[]);                                 //[t1]
00064   virtual void do_commit();                                             //[t1]
00065   virtual void do_abort();                                              //[t13]
00066 
00067 };
00068 
00069 
00071 template<> inline PGSTD::string Classname(const basic_transaction *) 
00072 { 
00073   return "basic_transaction"; 
00074 }
00075 
00076 
00078 
00081 template<isolation_level ISOLATIONLEVEL=read_committed>
00082 class transaction : public basic_transaction
00083 {
00084 public:
00085   typedef isolation_traits<ISOLATIONLEVEL> isolation_tag;
00086 
00089   explicit transaction(connection_base &C,
00090                        const PGSTD::string &TName=PGSTD::string()) :    //[t1]
00091     basic_transaction(C, isolation_tag::name(), TName) 
00092         { Begin(); }
00093 
00094   virtual ~transaction() { End(); }
00095 };
00096 
00097 
00099 typedef transaction<> work;
00100 
00101 
00103 template<isolation_level ISOLATIONLEVEL> 
00104 inline PGSTD::string Classname(const transaction<ISOLATIONLEVEL> *) 
00105 { 
00106   return "transaction<" + isolation_traits<ISOLATIONLEVEL>::name() + ">";
00107 }
00108 
00109 }
00110 
00111 

Generated on Fri Oct 24 20:21:37 2003 for libpqxx by doxygen 1.3.4