00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "pqxx/compiler-public.hxx"
00020 #include "pqxx/compiler-internal-pre.hxx"
00021
00022 #include "pqxx/connection_base"
00023 #include "pqxx/transaction"
00024
00025
00026
00027
00028
00030 #define PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00031
00032 namespace pqxx
00033 {
00034
00036
00065 template<typename TRANSACTION=transaction<read_committed> >
00066 class transactor :
00067 public PGSTD::unary_function<TRANSACTION, void>
00068 {
00069 public:
00070 explicit transactor(const PGSTD::string &TName="transactor") :
00071 m_Name(TName) { }
00072
00074
00085 void operator()(TRANSACTION &T);
00086
00087
00088
00089
00090
00091
00092
00094
00102 void on_abort(const char[]) throw () {}
00103
00105
00109 void on_commit() {}
00110
00112
00123 void on_doubt() throw () {}
00124
00125 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00126
00130
00131
00132 void OnCommit() {}
00134
00135 void OnAbort(const char[]) throw () {}
00137
00138 void OnDoubt() throw () {}
00140 #endif
00141
00142
00144 PGSTD::string Name() const { return m_Name; }
00145
00146 private:
00147 PGSTD::string m_Name;
00148 };
00149
00150
00151 }
00152
00153
00154 template<typename TRANSACTOR>
00155 inline void pqxx::connection_base::perform(const TRANSACTOR &T,
00156 int Attempts)
00157 {
00158 if (Attempts <= 0) return;
00159
00160 bool Done = false;
00161
00162
00163
00164 do
00165 {
00166 --Attempts;
00167
00168
00169 TRANSACTOR T2(T);
00170 try
00171 {
00172 typename TRANSACTOR::argument_type X(*this, T2.Name());
00173 T2(X);
00174 X.commit();
00175 Done = true;
00176 }
00177 catch (const in_doubt_error &)
00178 {
00179
00180
00181 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00182 T2.OnDoubt();
00183 #endif
00184 T2.on_doubt();
00185 throw;
00186 }
00187 catch (const PGSTD::exception &e)
00188 {
00189
00190 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00191 T2.OnAbort(e.what());
00192 #endif
00193 T2.on_abort(e.what());
00194 if (Attempts <= 0) throw;
00195 continue;
00196 }
00197 catch (...)
00198 {
00199
00200 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00201 T2.OnAbort("Unknown exception");
00202 #endif
00203 T2.on_abort("Unknown exception");
00204 throw;
00205 }
00206
00207 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00208 T2.OnCommit();
00209 #endif
00210 T2.on_commit();
00211 } while (!Done);
00212 }
00213
00214
00215 #include "pqxx/compiler-internal-post.hxx"