00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pqxx/connection_base"
00020 #include "pqxx/transaction"
00021
00022
00023
00024
00025
00027 #define PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00028
00029 namespace pqxx
00030 {
00031
00033
00059 template<typename TRANSACTION=transaction<read_committed> >
00060 class transactor :
00061 public PGSTD::unary_function<TRANSACTION, void>
00062 {
00063 public:
00064 explicit transactor(const PGSTD::string &TName="transactor") :
00065 m_Name(TName) { }
00066
00068
00077 void operator()(TRANSACTION &T);
00078
00079
00080
00081
00082
00083
00084
00086
00094 void on_abort(const char[]) throw () {}
00095
00097
00101 void on_commit() {}
00102
00104
00115 void on_doubt() throw () {}
00116
00117 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00118
00119
00120 void OnCommit() {}
00122
00123 void OnAbort(const char[]) throw () {}
00125
00126 void OnDoubt() throw () {}
00127 #endif
00128
00129
00131 PGSTD::string Name() const { return m_Name; }
00132
00133 private:
00134 PGSTD::string m_Name;
00135 };
00136
00137
00138 }
00139
00140
00151 template<typename TRANSACTOR>
00152 inline void pqxx::connection_base::perform(const TRANSACTOR &T,
00153 int Attempts)
00154 {
00155 if (Attempts <= 0) return;
00156
00157 bool Done = false;
00158
00159
00160
00161 do
00162 {
00163 --Attempts;
00164
00165
00166 TRANSACTOR T2(T);
00167 try
00168 {
00169 typename TRANSACTOR::argument_type X(*this, T2.Name());
00170 T2(X);
00171 X.commit();
00172 Done = true;
00173 }
00174 catch (const in_doubt_error &)
00175 {
00176
00177
00178 T2.OnDoubt();
00179 throw;
00180 }
00181 catch (const PGSTD::exception &e)
00182 {
00183
00184 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00185 T2.OnAbort(e.what());
00186 #endif
00187 T2.on_abort(e.what());
00188 if (Attempts <= 0) throw;
00189 continue;
00190 }
00191 catch (...)
00192 {
00193
00194 T2.OnAbort("Unknown exception");
00195 throw;
00196 }
00197
00198 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00199 T2.OnCommit();
00200 #endif
00201 T2.on_commit();
00202 } while (!Done);
00203 }
00204
00205