00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PQXX_TRANSACTIONITF_H
00016 #define PQXX_TRANSACTIONITF_H
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #include "pqxx/connection.h"
00030
00031
00032
00033
00034
00035 namespace pqxx
00036 {
00037 class Connection;
00038 class Result;
00039 class TableStream;
00040
00041
00042 template<> inline PGSTD::string Classname(const TableStream *)
00043 {
00044 return "TableStream";
00045 }
00046
00047
00049
00053 class PQXX_LIBEXPORT TransactionItf
00054 {
00055 public:
00056 virtual ~TransactionItf() =0;
00057
00058 void Commit();
00059 void Abort();
00060
00062 Result Exec(const char[]);
00063
00064 void ProcessNotice(const char Msg[]) { m_Conn.ProcessNotice(Msg); }
00065 void ProcessNotice(const PGSTD::string &Msg)
00066 { m_Conn.ProcessNotice(Msg); }
00067
00068 PGSTD::string Name() const { return m_Name; }
00069
00070 protected:
00073 explicit TransactionItf(Connection &,
00074 const PGSTD::string &TName=PGSTD::string());
00075
00078 void Begin();
00079
00081 void End() throw ();
00082
00084 virtual void DoBegin() =0;
00085 virtual Result DoExec(const char C[]) =0;
00086 virtual void DoCommit() =0;
00087 virtual void DoAbort() =0;
00088
00089
00090
00092 Result DirectExec(const char C[], int Retries, const char OnReconnect[]);
00093 Connection &Conn() const { return m_Conn; }
00094
00095
00096 private:
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 enum Status
00115 {
00116 st_nascent,
00117 st_active,
00118 st_aborted,
00119 st_committed,
00120 st_in_doubt
00121 };
00122
00123
00124 friend class Cursor;
00125 int GetUniqueCursorNum() { return m_UniqueCursorNum++; }
00126 void MakeEmpty(Result &R) const { m_Conn.MakeEmpty(R); }
00127
00128 friend class TableStream;
00129 void RegisterStream(const TableStream *);
00130 void UnregisterStream(const TableStream *) throw ();
00131 void EndCopy() { m_Conn.EndCopy(); }
00132 friend class TableReader;
00133 void BeginCopyRead(const PGSTD::string &Table)
00134 { m_Conn.BeginCopyRead(Table); }
00135 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00136 friend class TableWriter;
00137 void BeginCopyWrite(const PGSTD::string &Table)
00138 { m_Conn.BeginCopyWrite(Table); }
00139 void WriteCopyLine(const PGSTD::string &L) { m_Conn.WriteCopyLine(L); }
00140
00141 Connection &m_Conn;
00142
00143 PGSTD::string m_Name;
00144 int m_UniqueCursorNum;
00145 Unique<TableStream> m_Stream;
00146 Status m_Status;
00147 bool m_Registered;
00148
00149
00150 TransactionItf();
00151 TransactionItf(const TransactionItf &);
00152 TransactionItf &operator=(const TransactionItf &);
00153 };
00154
00155
00157
00163 class PQXX_LIBEXPORT in_doubt_error : public PGSTD::runtime_error
00164 {
00165 public:
00166 explicit in_doubt_error(const PGSTD::string &whatarg) :
00167 PGSTD::runtime_error(whatarg) {}
00168 };
00169
00170 }
00171
00172 #endif
00173