libpqxx  7.7.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-2022, 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 
22 namespace pqxx::internal
23 {
25 class PQXX_LIBEXPORT PQXX_NOVTABLE basic_robusttransaction
26  : public dbtransaction
27 {
28 public:
29  virtual ~basic_robusttransaction() override = 0;
30 
31 protected:
33  connection &c, zview begin_command, std::string_view tname);
34  basic_robusttransaction(connection &c, zview begin_command);
35 
36 private:
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 
51 namespace pqxx
52 {
59 
81 template<isolation_level ISOLATION = read_committed>
83 {
84 public:
89  robusttransaction(connection &c, std::string_view tname) :
90  internal::basic_robusttransaction{
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 
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
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:53
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:26
Connection to a database.
Definition: connection.hxx:185
Helper base class for the robusttransaction class template.
Definition: robusttransaction.hxx:25
virtual ~robusttransaction() noexcept override
Definition: robusttransaction.hxx:113
robusttransaction(connection &c)
Definition: robusttransaction.hxx:108
robusttransaction(connection &c, std::string_view tname)
Definition: robusttransaction.hxx:89
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
Internal items for libpqxx&#39; own use. Do not use these yourself.
Definition: composite.hxx:82
Slightly slower, better-fortified version of transaction.
Definition: robusttransaction.hxx:82
robusttransaction(connection &c, std::string &&tname)
Definition: robusttransaction.hxx:99