libpqxx  7.4.0
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-2021, 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 #include "pqxx/compiler-public.hxx"
17 #include "pqxx/internal/compiler-internal-pre.hxx"
18 
19 #include "pqxx/dbtransaction.hxx"
20 
21 namespace pqxx::internal
22 {
24 class PQXX_LIBEXPORT PQXX_NOVTABLE basic_robusttransaction
25  : public dbtransaction
26 {
27 public:
28  virtual ~basic_robusttransaction() override = 0;
29 
30 protected:
32  connection &c, zview begin_command, std::string_view tname);
33  basic_robusttransaction(connection &c, zview begin_command);
34 
35 private:
36  using IDType = unsigned long;
37 
38  std::string m_conn_string;
39  std::string m_xid;
40  int m_backendpid = -1;
41 
42  void init(zview begin_command);
43 
44  // @warning This function will become @c final.
45  virtual void do_commit() override;
46 };
47 } // namespace pqxx::internal
48 
49 
50 namespace pqxx
51 {
58 
80 template<isolation_level ISOLATION = read_committed>
82 {
83 public:
88  robusttransaction(connection &c, std::string_view tname) :
89  internal::basic_robusttransaction{
90  c, pqxx::internal::begin_cmd<ISOLATION, write_policy::read_write>,
91  tname}
92  {}
93 
98  robusttransaction(connection &c, std::string &&tname) :
99  internal::basic_robusttransaction{
100  c, pqxx::internal::begin_cmd<ISOLATION, write_policy::read_write>,
101  std::move(tname)}
102  {}
103 
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 
121 #include "pqxx/internal/compiler-internal-post.hxx"
122 #endif
The home of all libpqxx classes, functions, templates, etc.
Definition: array.hxx:25
robusttransaction(connection &c, std::string &&tname)
Definition: robusttransaction.hxx:98
virtual ~robusttransaction() noexcept override
Definition: robusttransaction.hxx:113
Helper base class for the robusttransaction class template.
Definition: robusttransaction.hxx:24
Connection to a database.
Definition: connection.hxx:181
robusttransaction(connection &c)
Definition: robusttransaction.hxx:108
Abstract transaction base class: bracket transactions on the database.
Definition: dbtransaction.hxx:52
Marker-type wrapper: zero-terminated std::string_view.
Definition: zview.hxx:37
robusttransaction(connection &c, std::string_view tname)
Definition: robusttransaction.hxx:88
Slightly slower, better-fortified version of transaction.
Definition: robusttransaction.hxx:81
Internal items for libpqxx&#39; own use. Do not use these yourself.
Definition: composite.hxx:73