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
00061 template<typename TRANSACTION=transaction<read_committed> >
00062 class transactor :
00063 public PGSTD::unary_function<TRANSACTION, void>
00064 {
00065 public:
00066 explicit transactor(const PGSTD::string &TName="transactor") :
00067 m_Name(TName) { }
00068
00070
00081 void operator()(TRANSACTION &T);
00082
00083
00084
00085
00086
00087
00088
00090
00098 void on_abort(const char[]) throw () {}
00099
00101
00105 void on_commit() {}
00106
00108
00119 void on_doubt() throw () {}
00120
00121 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00122
00123
00124 void OnCommit() {}
00126
00127 void OnAbort(const char[]) throw () {}
00129
00130 void OnDoubt() throw () {}
00131 #endif
00132
00133
00135 PGSTD::string Name() const { return m_Name; }
00136
00137 private:
00138 PGSTD::string m_Name;
00139 };
00140
00141
00142 }
00143
00144
00155 template<typename TRANSACTOR>
00156 inline void pqxx::connection_base::perform(const TRANSACTOR &T,
00157 int Attempts)
00158 {
00159 if (Attempts <= 0) return;
00160
00161 bool Done = false;
00162
00163
00164
00165 do
00166 {
00167 --Attempts;
00168
00169
00170 TRANSACTOR T2(T);
00171 try
00172 {
00173 typename TRANSACTOR::argument_type X(*this, T2.Name());
00174 T2(X);
00175 X.commit();
00176 Done = true;
00177 }
00178 catch (const in_doubt_error &)
00179 {
00180
00181
00182 T2.OnDoubt();
00183 throw;
00184 }
00185 catch (const PGSTD::exception &e)
00186 {
00187
00188 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00189 T2.OnAbort(e.what());
00190 #endif
00191 T2.on_abort(e.what());
00192 if (Attempts <= 0) throw;
00193 continue;
00194 }
00195 catch (...)
00196 {
00197
00198 T2.OnAbort("Unknown exception");
00199 throw;
00200 }
00201
00202 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00203 T2.OnCommit();
00204 #endif
00205 T2.on_commit();
00206 } while (!Done);
00207 }
00208
00209