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 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00183       T2.OnDoubt();
00184 #endif
00185       T2.on_doubt();
00186       throw;
00187     }
00188     catch (const PGSTD::exception &e)
00189     {
00190       
00191 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00192       T2.OnAbort(e.what());
00193 #endif
00194       T2.on_abort(e.what());
00195       if (Attempts <= 0) throw;
00196       continue;
00197     }
00198     catch (...)
00199     {
00200       
00201 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00202       T2.OnAbort("Unknown exception");
00203 #endif
00204       T2.on_abort("Unknown exception");
00205       throw;
00206     }
00207 
00208 #ifdef PQXX_DEPRECATED_TRANSACTION_CALLBACKS
00209     T2.OnCommit();
00210 #endif
00211     T2.on_commit();
00212   } while (!Done);
00213 }
00214 
00215