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 #include "pqxx/util.h"
00031
00032
00033
00034
00035
00036 namespace pqxx
00037 {
00038 class Connection;
00039 class Result;
00040 class TableStream;
00041
00042
00043 template<> inline PGSTD::string Classname(const TableStream *)
00044 {
00045 return "TableStream";
00046 }
00047
00048
00050
00054 class PQXX_LIBEXPORT TransactionItf
00055 {
00056 public:
00057 virtual ~TransactionItf() =0;
00058
00059 void Commit();
00060 void Abort();
00061
00063 Result Exec(const char[]);
00064
00065 void ProcessNotice(const char Msg[]) { m_Conn.ProcessNotice(Msg); }
00066 void ProcessNotice(const PGSTD::string &Msg)
00067 { m_Conn.ProcessNotice(Msg); }
00068
00069 PGSTD::string Name() const { return m_Name; }
00070
00071 protected:
00074 explicit TransactionItf(Connection &,
00075 const PGSTD::string &TName=PGSTD::string());
00076
00079 void Begin();
00080
00082 void End() throw ();
00083
00085 virtual void DoBegin() =0;
00086 virtual Result DoExec(const char C[]) =0;
00087 virtual void DoCommit() =0;
00088 virtual void DoAbort() =0;
00089
00090
00091
00093 Result DirectExec(const char C[], int Retries, const char OnReconnect[]);
00094 Connection &Conn() const { return m_Conn; }
00095
00096
00097 private:
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 enum Status
00116 {
00117 st_nascent,
00118 st_active,
00119 st_aborted,
00120 st_committed,
00121 st_in_doubt
00122 };
00123
00124
00125 friend class Cursor;
00126 int GetUniqueCursorNum() { return m_UniqueCursorNum++; }
00127 void MakeEmpty(Result &R) const { m_Conn.MakeEmpty(R); }
00128
00129 friend class TableStream;
00130 void RegisterStream(const TableStream *);
00131 void UnregisterStream(const TableStream *) throw ();
00132 void EndCopy() { m_Conn.EndCopy(); }
00133 friend class TableReader;
00134 void BeginCopyRead(const PGSTD::string &Table)
00135 { m_Conn.BeginCopyRead(Table); }
00136 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00137 friend class TableWriter;
00138 void BeginCopyWrite(const PGSTD::string &Table)
00139 { m_Conn.BeginCopyWrite(Table); }
00140 void WriteCopyLine(const PGSTD::string &L) { m_Conn.WriteCopyLine(L); }
00141
00142 Connection &m_Conn;
00143
00144 PGSTD::string m_Name;
00145 int m_UniqueCursorNum;
00146 Unique<TableStream> m_Stream;
00147 Status m_Status;
00148 bool m_Registered;
00149
00150
00151 TransactionItf();
00152 TransactionItf(const TransactionItf &);
00153 TransactionItf &operator=(const TransactionItf &);
00154 };
00155
00156
00158
00164 class PQXX_LIBEXPORT in_doubt_error : public PGSTD::runtime_error
00165 {
00166 public:
00167 explicit in_doubt_error(const PGSTD::string &whatarg) :
00168 PGSTD::runtime_error(whatarg) {}
00169 };
00170
00171 }
00172
00173 #endif
00174