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/connectionitf.h"
00030 #include "pqxx/result.h"
00031
00032
00033
00034
00035
00036 namespace pqxx
00037 {
00038 class ConnectionItf;
00039 class Result;
00040 class TableStream;
00041
00042
00043 template<> inline PGSTD::string Classname(const TableStream *)
00044 {
00045 return "TableStream";
00046 }
00047
00048
00050
00058 class PQXX_LIBEXPORT TransactionItf
00059 {
00060 public:
00061 virtual ~TransactionItf() =0;
00062
00064
00076 void Commit();
00077
00079
00082 void Abort();
00083
00085
00089 Result Exec(const char Query[],
00090 const PGSTD::string &Desc=PGSTD::string());
00091
00093
00100 Result Exec(const PGSTD::string &Query,
00101 const PGSTD::string &Desc=PGSTD::string())
00102 { return Exec(Query.c_str(), Desc); }
00103
00105 void ProcessNotice(const char Msg[]) { m_Conn.ProcessNotice(Msg); }
00107
00108 { m_Conn.ProcessNotice(Msg); }
00109
00110 PGSTD::string Name() const { return m_Name; }
00111
00113 ConnectionItf &Conn() const { return m_Conn; }
00114
00115 protected:
00118 explicit TransactionItf(ConnectionItf &,
00119 const PGSTD::string &TName=PGSTD::string());
00120
00123 void Begin();
00124
00126 void End() throw ();
00127
00129 virtual void DoBegin() =0;
00130 virtual Result DoExec(const char Query[]) =0;
00131 virtual void DoCommit() =0;
00132 virtual void DoAbort() =0;
00133
00134
00135
00137 Result DirectExec(const char C[], int Retries, const char OnReconnect[]);
00138
00139 private:
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157 enum Status
00158 {
00159 st_nascent,
00160 st_active,
00161 st_aborted,
00162 st_committed,
00163 st_in_doubt
00164 };
00165
00166
00167 friend class Cursor;
00168 int GetUniqueCursorNum() { return m_UniqueCursorNum++; }
00169 void MakeEmpty(Result &R) const { m_Conn.MakeEmpty(R); }
00170
00171 friend class TableStream;
00172 void RegisterStream(const TableStream *);
00173 void UnregisterStream(const TableStream *) throw ();
00174 void EndCopy() { m_Conn.EndCopy(); }
00175 friend class TableReader;
00176 void BeginCopyRead(const PGSTD::string &Table)
00177 { m_Conn.BeginCopyRead(Table); }
00178 bool ReadCopyLine(PGSTD::string &L) { return m_Conn.ReadCopyLine(L); }
00179 friend class TableWriter;
00180 void BeginCopyWrite(const PGSTD::string &Table)
00181 { m_Conn.BeginCopyWrite(Table); }
00182 void WriteCopyLine(const PGSTD::string &L) { m_Conn.WriteCopyLine(L); }
00183
00184 ConnectionItf &m_Conn;
00185
00186 PGSTD::string m_Name;
00187 int m_UniqueCursorNum;
00188 Unique<TableStream> m_Stream;
00189 Status m_Status;
00190 bool m_Registered;
00191
00192
00193 TransactionItf();
00194 TransactionItf(const TransactionItf &);
00195 TransactionItf &operator=(const TransactionItf &);
00196 };
00197
00198
00199 }
00200
00201 #endif
00202