libpqxx 4.0
robusttransaction.hxx
00001 /*-------------------------------------------------------------------------
00002  *
00003  *   FILE
00004  *      pqxx/robusttransaction.hxx
00005  *
00006  *   DESCRIPTION
00007  *      definition of the pqxx::robusttransaction class.
00008  *   pqxx::robusttransaction is a slower but safer transaction class
00009  *   DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/robusttransaction instead.
00010  *
00011  * Copyright (c) 2002-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_ROBUSTTRANSACTION
00020 #define PQXX_H_ROBUSTTRANSACTION
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 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
00033  */
00034 
00035 
00036 namespace pqxx
00037 {
00038 
00045 class PQXX_LIBEXPORT PQXX_NOVTABLE basic_robusttransaction :
00046   public dbtransaction
00047 {
00048 public:
00050   typedef isolation_traits<read_committed> isolation_tag;
00051 
00052   virtual ~basic_robusttransaction() =0;                                //[t16]
00053 
00054 protected:
00055   basic_robusttransaction(
00056         connection_base &C,
00057         const PGSTD::string &IsolationLevel,
00058         const PGSTD::string &table_name=PGSTD::string());               //[t16]
00059 
00060 private:
00061   typedef unsigned long IDType;
00062   IDType m_record_id;
00063   PGSTD::string m_xid;
00064   PGSTD::string m_LogTable;
00065   PGSTD::string m_sequence;
00066   int m_backendpid;
00067 
00068   virtual void do_begin();                                              //[t18]
00069   virtual void do_commit();                                             //[t16]
00070   virtual void do_abort();                                              //[t18]
00071 
00072   void PQXX_PRIVATE CreateLogTable();
00073   void PQXX_PRIVATE CreateTransactionRecord();
00074   PGSTD::string PQXX_PRIVATE sql_delete() const;
00075   void PQXX_PRIVATE DeleteTransactionRecord() throw ();
00076   bool PQXX_PRIVATE CheckTransactionRecord();
00077 };
00078 
00079 
00080 
00082 
00148 template<isolation_level ISOLATIONLEVEL=read_committed>
00149 class robusttransaction : public basic_robusttransaction
00150 {
00151 public:
00152   typedef isolation_traits<ISOLATIONLEVEL> isolation_tag;
00153 
00155 
00159   explicit robusttransaction(connection_base &C,
00160       const PGSTD::string &Name=PGSTD::string()) :
00161     namedclass(fullname("robusttransaction",isolation_tag::name()), Name),
00162     basic_robusttransaction(C, isolation_tag::name())
00163         { Begin(); }
00164 
00165   virtual ~robusttransaction() throw ()
00166   {
00167 #ifdef PQXX_QUIET_DESTRUCTORS
00168     quiet_errorhandler quiet(conn());
00169 #endif
00170     End();
00171   }
00172 };
00173 
00178 } // namespace pqxx
00179 
00180 
00181 #include "pqxx/compiler-internal-post.hxx"
00182 
00183 #endif
00184