The Battle for Wesnoth  1.15.3+dev
transaction.hpp
Go to the documentation of this file.
1 //
2 // M A R I A D B + +
3 //
4 // Copyright Sylvain Rochette Langlois 2013,
5 // The ViaDuck Project 2016 - 2018.
6 // Distributed under the Boost Software License, Version 1.0.
7 // (See accompanying file LICENSE or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9 
10 #ifndef _MARIADB_TRANSACTION_HPP_
11 #define _MARIADB_TRANSACTION_HPP_
12 
13 #include <vector>
14 #include <algorithm>
15 #include <mariadb++/save_point.hpp>
16 #include <mariadb++/types.hpp>
17 
18 namespace mariadb {
19 class connection;
20 class save_point;
21 
22 /**
23  * Class representing a SQL transaction having automatic rollback functionality
24  */
25 class transaction {
26  friend class connection;
27  friend class save_point;
28 
29  public:
30  /**
31  * Destructor initiates automatic rollback if changes were not committed
32  */
33  virtual ~transaction();
34 
35  /**
36  * Commits the changes, releases all savepoints
37  */
38  void commit();
39 
40  /**
41  * Create named savepoint
42  * Note: only valid until the transaction is destroyed or committed
43  *
44  * @return Reference to a unique new savepoint
45  */
47 
48  private:
49  /**
50  * Create a transaction with given isolation level and snapshot setting
51  *
52  * @param conn Connection to start transaction on
53  * @param level Level of database isolation to use
54  * @param consistent_snapshot Controls whether the transaction needs a consistent snapshot on
55  * creation
56  */
57  transaction(connection* conn, isolation::level level, bool consistent_snapshot);
58 
59  /**
60  * Removes a savepoint from the list of savepoints
61  *
62  * @param sv_point savepoint to remove
63  */
64  void remove_save_point(save_point* sv_point);
65 
66  /**
67  * Cleans up the transaction, releases all savepoints
68  */
69  void cleanup();
70 
71  private:
72  // parent connection pointer
74  // list of created savepoints for this transaction
75  std::vector<save_point*> m_save_points;
76 };
77 
78 typedef std::shared_ptr<transaction> transaction_ref;
79 }
80 
81 #endif
std::shared_ptr< transaction > transaction_ref
Definition: transaction.hpp:78
connection * m_connection
Definition: transaction.hpp:73
Class representing a SQL transaction having automatic rollback functionality.
Definition: transaction.hpp:25
std::vector< save_point * > m_save_points
Definition: transaction.hpp:75
save_point_ref create_save_point()
Create named savepoint Note: only valid until the transaction is destroyed or committed.
Definition: transaction.cpp:57
Class used to represent a MariaDB savepoint having automatic rollback functionality.
Definition: save_point.hpp:22
void remove_save_point(save_point *sv_point)
Removes a savepoint from the list of savepoints.
Definition: transaction.cpp:65
transaction(connection *conn, isolation::level level, bool consistent_snapshot)
Create a transaction with given isolation level and snapshot setting.
Definition: transaction.cpp:30
Wraps a Database connection.
Definition: connection.hpp:27
std::shared_ptr< save_point > save_point_ref
Definition: save_point.hpp:50
void cleanup()
Cleans up the transaction, releases all savepoints.
Definition: transaction.cpp:43
void commit()
Commits the changes, releases all savepoints.
Definition: transaction.cpp:49
virtual ~transaction()
Destructor initiates automatic rollback if changes were not committed.
Definition: transaction.cpp:36