libpqxx  4.0.1
robusttransaction.hxx
1 /*-------------------------------------------------------------------------
2  *
3  * FILE
4  * pqxx/robusttransaction.hxx
5  *
6  * DESCRIPTION
7  * definition of the pqxx::robusttransaction class.
8  * pqxx::robusttransaction is a slower but safer transaction class
9  * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/robusttransaction instead.
10  *
11  * Copyright (c) 2002-2011, Jeroen T. Vermeulen <jtv@xs4all.nl>
12  *
13  * See COPYING for copyright license. If you did not receive a file called
14  * COPYING with this source code, please notify the distributor of this mistake,
15  * or contact the author.
16  *
17  *-------------------------------------------------------------------------
18  */
19 #ifndef PQXX_H_ROBUSTTRANSACTION
20 #define PQXX_H_ROBUSTTRANSACTION
21 
22 #include "pqxx/compiler-public.hxx"
23 #include "pqxx/compiler-internal-pre.hxx"
24 
25 #include "pqxx/dbtransaction"
26 
27 #ifdef PQXX_QUIET_DESTRUCTORS
28 #include "pqxx/errorhandler"
29 #endif
30 
31 
32 /* Methods tested in eg. self-test program test001 are marked with "//[t1]"
33  */
34 
35 
36 namespace pqxx
37 {
38 
45 class PQXX_LIBEXPORT PQXX_NOVTABLE basic_robusttransaction :
46  public dbtransaction
47 {
48 public:
51 
52  virtual ~basic_robusttransaction() =0; //[t16]
53 
54 protected:
56  connection_base &C,
57  const PGSTD::string &IsolationLevel,
58  const PGSTD::string &table_name=PGSTD::string()); //[t16]
59 
60 private:
61  typedef unsigned long IDType;
62  IDType m_record_id;
63  PGSTD::string m_xid;
64  PGSTD::string m_LogTable;
65  PGSTD::string m_sequence;
66  int m_backendpid;
67 
68  virtual void do_begin(); //[t18]
69  virtual void do_commit(); //[t16]
70  virtual void do_abort(); //[t18]
71 
72  void PQXX_PRIVATE CreateLogTable();
73  void PQXX_PRIVATE CreateTransactionRecord();
74  PGSTD::string PQXX_PRIVATE sql_delete() const;
75  void PQXX_PRIVATE DeleteTransactionRecord() throw ();
76  bool PQXX_PRIVATE CheckTransactionRecord();
77 };
78 
79 
80 
82 
148 template<isolation_level ISOLATIONLEVEL=read_committed>
150 {
151 public:
153 
155 
160  const PGSTD::string &Name=PGSTD::string()) :
161  namedclass(fullname("robusttransaction",isolation_tag::name()), Name),
162  basic_robusttransaction(C, isolation_tag::name())
163  { Begin(); }
164 
165  virtual ~robusttransaction() throw ()
166  {
167 #ifdef PQXX_QUIET_DESTRUCTORS
168  quiet_errorhandler quiet(conn());
169 #endif
170  End();
171  }
172 };
173 
178 } // namespace pqxx
179 
180 
181 #include "pqxx/compiler-internal-post.hxx"
182 
183 #endif
184