libpqxx 4.0
transaction.hxx
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-2011, 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 #ifndef PQXX_H_TRANSACTION
00020 #define PQXX_H_TRANSACTION
00021 
00022 #include "pqxx/compiler-public.hxx"
00023 #include "pqxx/compiler-internal-pre.hxx"
00024 
00025 #include "pqxx/dbtransaction"
00026 
00027 #ifdef PQXX_QUIET_DESTRUCTORS
00028 #include "pqxx/errorhandler"
00029 #endif
00030 
00031 
00032 
00033 /* Methods tested in eg. self-test program test1 are marked with "//[t1]"
00034  */
00035 
00036 
00037 namespace pqxx
00038 {
00039 
00044 
00045 class PQXX_LIBEXPORT basic_transaction : public dbtransaction
00046 {
00047 protected:
00048   basic_transaction(                                                    //[t1]
00049         connection_base &C,
00050         const PGSTD::string &IsolationLevel,
00051         readwrite_policy);
00052 
00053 private:
00054   virtual void do_commit();                                             //[t1]
00055 };
00056 
00057 
00059 
00087 template<
00088         isolation_level ISOLATIONLEVEL=read_committed,
00089         readwrite_policy READWRITE=read_write>
00090 class transaction : public basic_transaction
00091 {
00092 public:
00093   typedef isolation_traits<ISOLATIONLEVEL> isolation_tag;
00094 
00096 
00101   explicit transaction(connection_base &C, const PGSTD::string &TName): //[t1]
00102     namedclass(fullname("transaction", isolation_tag::name()), TName),
00103     basic_transaction(C, isolation_tag::name(), READWRITE)
00104         { Begin(); }
00105 
00106   explicit transaction(connection_base &C) :                            //[t1]
00107     namedclass(fullname("transaction", isolation_tag::name())),
00108     basic_transaction(C, isolation_tag::name(), READWRITE)
00109         { Begin(); }
00110 
00111   virtual ~transaction() throw ()
00112   {
00113 #ifdef PQXX_QUIET_DESTRUCTORS
00114     quiet_errorhandler quiet(conn());
00115 #endif
00116     End();
00117   }
00118 };
00119 
00120 
00122 typedef transaction<> work;
00123 
00125 typedef transaction<read_committed, read_only> read_transaction;
00126 
00128 
00129 }
00130 
00131 
00132 #include "pqxx/compiler-internal-post.hxx"
00133 
00134 #endif
00135