Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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-2004, 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.hxx 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 
00060 private:
00061   virtual void do_begin();                                              //[t1]
00062   virtual void do_commit();                                             //[t1]
00063   virtual void do_abort();                                              //[t13]
00064 };
00065 
00066 
00068 
00071 template<isolation_level ISOLATIONLEVEL=read_committed>
00072 class transaction : public basic_transaction
00073 {
00074 public:
00075   typedef isolation_traits<ISOLATIONLEVEL> isolation_tag;
00076 
00079   explicit transaction(connection_base &C, const PGSTD::string &TName): //[t1]
00080     basic_transaction(C, isolation_tag::name(), TName) 
00081         { Begin(); }
00082 
00083   explicit transaction(connection_base &C) :                            //[t1]
00084     basic_transaction(C, isolation_tag::name(), PGSTD::string()) 
00085         { Begin(); }
00086 
00087   virtual ~transaction() throw () { End(); }
00088 
00089 protected:
00090   virtual const char *classname() const throw () { return "transaction"; }
00091 };
00092 
00093 
00095 typedef transaction<> work;
00096 
00097 }
00098 
00099 

Generated on Thu Oct 14 20:43:29 2004 for libpqxx by  doxygen 1.3.9