00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pqxx/libcompiler.h"
00020
00021 #include "pqxx/connection_base"
00022 #include "pqxx/transaction"
00023
00024
00025
00026
00027
00029 #define PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00030
00031 namespace pqxx
00032 {
00033
00035
00064 template<typename TRANSACTION=transaction<read_committed> >
00065 class transactor :
00066 public PGSTD::unary_function<TRANSACTION, void>
00067 {
00068 public:
00069 explicit transactor(const PGSTD::string &TName="transactor") :
00070 m_Name(TName) { }
00071
00073
00084 void operator()(TRANSACTION &T);
00085
00086
00087
00088
00089
00090
00091
00093
00101 void on_abort(const char[]) throw () {}
00102
00104
00108 void on_commit() {}
00109
00111
00122 void on_doubt() throw () {}
00123
00124 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00125
00129
00130
00131 void OnCommit() {}
00133
00134 void OnAbort(const char[]) throw () {}
00136
00137 void OnDoubt() throw () {}
00139 #endif
00140
00141
00143 PGSTD::string Name() const { return m_Name; }
00144
00145 private:
00146 PGSTD::string m_Name;
00147 };
00148
00149
00150 }
00151
00152
00163 template<typename TRANSACTOR>
00164 inline void pqxx::connection_base::perform(const TRANSACTOR &T,
00165 int Attempts)
00166 {
00167 if (Attempts <= 0) return;
00168
00169 bool Done = false;
00170
00171
00172
00173 do
00174 {
00175 --Attempts;
00176
00177
00178 TRANSACTOR T2(T);
00179 try
00180 {
00181 typename TRANSACTOR::argument_type X(*this, T2.Name());
00182 T2(X);
00183 X.commit();
00184 Done = true;
00185 }
00186 catch (const in_doubt_error &)
00187 {
00188
00189
00190 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00191 T2.OnDoubt();
00192 #endif
00193 T2.on_doubt();
00194 throw;
00195 }
00196 catch (const PGSTD::exception &e)
00197 {
00198
00199 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00200 T2.OnAbort(e.what());
00201 #endif
00202 T2.on_abort(e.what());
00203 if (Attempts <= 0) throw;
00204 continue;
00205 }
00206 catch (...)
00207 {
00208
00209 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00210 T2.OnAbort("Unknown exception");
00211 #endif
00212 T2.on_abort("Unknown exception");
00213 throw;
00214 }
00215
00216 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00217 T2.OnCommit();
00218 #endif
00219 T2.on_commit();
00220 } while (!Done);
00221 }
00222
00223