libpqxx 7.8.1
robusttransaction.hxx
1/* Definition of the pqxx::robusttransaction class.
2 *
3 * pqxx::robusttransaction is a slower but safer transaction class.
4 *
5 * DO NOT INCLUDE THIS FILE DIRECTLY; include pqxx/robusttransaction instead.
6 *
7 * Copyright (c) 2000-2023, Jeroen T. Vermeulen.
8 *
9 * See COPYING for copyright license. If you did not receive a file called
10 * COPYING with this source code, please notify the distributor of this
11 * mistake, or contact the author.
12 */
13#ifndef PQXX_H_ROBUSTTRANSACTION
14#define PQXX_H_ROBUSTTRANSACTION
15
16#if !defined(PQXX_HEADER_PRE)
17# error "Include libpqxx headers as <pqxx/header>, not <pqxx/header.hxx>."
18#endif
19
20#include "pqxx/dbtransaction.hxx"
21
22namespace pqxx::internal
23{
25class PQXX_LIBEXPORT PQXX_NOVTABLE basic_robusttransaction
26 : public dbtransaction
27{
28public:
29 virtual ~basic_robusttransaction() override = 0;
30
31protected:
33 connection &c, zview begin_command, std::string_view tname);
34 basic_robusttransaction(connection &c, zview begin_command);
35
36private:
37 using IDType = unsigned long;
38
39 std::string m_conn_string;
40 std::string m_xid;
41 int m_backendpid = -1;
42
43 void init(zview begin_command);
44
45 // @warning This function will become `final`.
46 virtual void do_commit() override;
47};
48} // namespace pqxx::internal
49
50
51namespace pqxx
52{
60
81template<isolation_level ISOLATION = read_committed>
82class robusttransaction final : public internal::basic_robusttransaction
83{
84public:
89 robusttransaction(connection &c, std::string_view tname) :
91 c, pqxx::internal::begin_cmd<ISOLATION, write_policy::read_write>,
92 tname}
93 {}
94
99 robusttransaction(connection &c, std::string &&tname) :
100 internal::basic_robusttransaction{
101 c, pqxx::internal::begin_cmd<ISOLATION, write_policy::read_write>,
102 std::move(tname)}
103 {}
104
108 explicit robusttransaction(connection &c) :
109 internal::basic_robusttransaction{
110 c, pqxx::internal::begin_cmd<ISOLATION, write_policy::read_write>}
111 {}
112
113 virtual ~robusttransaction() noexcept override { close(); }
114};
115
119} // namespace pqxx
120#endif
The home of all libpqxx classes, functions, templates, etc.
Definition array.hxx:33
write_policy
Should a transaction be read-only, or read-write?
Definition isolation.hxx:27
Internal items for libpqxx' own use. Do not use these yourself.
Definition composite.hxx:84
Connection to a database.
Definition connection.hxx:253
Abstract transaction base class: bracket transactions on the database.
Definition dbtransaction.hxx:54
Helper base class for the robusttransaction class template.
Definition robusttransaction.hxx:27
virtual ~basic_robusttransaction() override=0
basic_robusttransaction(connection &c, zview begin_command, std::string_view tname)
Definition robusttransaction.cxx:104
void close() noexcept
End transaction. To be called by implementing class' destructor.
Definition transaction_base.cxx:343
Marker-type wrapper: zero-terminated std::string_view.
Definition zview.hxx:38