11 #ifndef PQXX_H_TRANSACTOR 12 #define PQXX_H_TRANSACTOR 14 #include "pqxx/compiler-public.hxx" 15 #include "pqxx/compiler-internal-pre.hxx" 17 #include "pqxx/connection_base.hxx" 18 #include "pqxx/transaction.hxx" 98 template<
typename TRANSACTION_CALLBACK>
99 inline auto perform(
const TRANSACTION_CALLBACK &callback,
int attempts=3)
100 -> decltype(callback())
103 throw std::invalid_argument{
104 "Zero or negative number of attempts passed to pqxx::perform()."};
106 for (; attempts > 0; --attempts)
127 if (attempts <= 1)
throw;
134 if (attempts <= 1)
throw;
156 template<
typename TRANSACTION=transaction<read_committed>>
class transactor 161 const std::string &TName=
"transactor") :
217 std::string
name()
const {
return m_name; }
224 template<
typename TRANSACTOR>
229 if (Attempts <= 0)
return;
242 typename TRANSACTOR::argument_type X{*
this, T2.name()};
254 catch (
const std::exception &e)
257 T2.on_abort(e.what());
258 if (Attempts <= 0)
throw;
264 T2.on_abort(
"Unknown exception");
273 #include "pqxx/compiler-internal-post.hxx" void operator()(TRANSACTION &T)
Overridable transaction definition; insert your database code here.
The backend saw itself forced to roll back the ongoing transaction.
Definition: except.hxx:167
Exception class for lost or failed backend connection.
Definition: except.hxx:118
We can't tell whether our last statement succeeded.
Definition: except.hxx:191
"Help, I don't know whether transaction was committed successfully!"
Definition: except.hxx:159
void on_abort(const char[]) noexcept
Optional overridable function to be called if transaction is aborted.
Definition: transactor.hxx:193
std::string name() const
The transactor's name.
Definition: transactor.hxx:217
void on_commit()
Optional overridable function to be called after successful commit.
Definition: transactor.hxx:200
Internal error in libpqxx library.
Definition: except.hxx:207
Definition: transactor.hxx:156
auto perform(const TRANSACTION_CALLBACK &callback, int attempts=3) -> decltype(callback())
Simple way to execute a transaction with automatic retry.
Definition: transactor.hxx:99
TRANSACTION argument_type
Definition: transactor.hxx:159
void on_doubt() noexcept
Overridable function to be called when "in doubt" about outcome.
Definition: transactor.hxx:214
transactor(const std::string &TName="transactor")
Definition: transactor.hxx:160
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
void perform(const TRANSACTOR &T, int Attempts)
Definition: transactor.hxx:225