comparison Framework/Common/DatabaseManager.h @ 231:0a9b48d19643

removed mutex out of DatabaseManager
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 06 Apr 2021 11:59:31 +0200
parents a4918d57435c
children 35598014f140
comparison
equal deleted inserted replaced
230:675f8322eb7c 231:0a9b48d19643
25 #include "StatementLocation.h" 25 #include "StatementLocation.h"
26 26
27 #include <Compatibility.h> // For std::unique_ptr<> 27 #include <Compatibility.h> // For std::unique_ptr<>
28 #include <Enumerations.h> 28 #include <Enumerations.h>
29 29
30 #include <boost/thread/recursive_mutex.hpp>
31 #include <memory> 30 #include <memory>
32 31
33 32
34 namespace OrthancDatabases 33 namespace OrthancDatabases
35 { 34 {
35 /**
36 * WARNING: In PostgreSQL releases <= 3.3 and in MySQL releases <=
37 * 3.0, this class was protected by a mutex. It is now assumed that
38 * locking must be implemented at a higher level.
39 **/
36 class DatabaseManager : public boost::noncopyable 40 class DatabaseManager : public boost::noncopyable
37 { 41 {
38 private: 42 private:
39 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements; 43 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements;
40 44
41 boost::recursive_mutex mutex_;
42 std::unique_ptr<IDatabase> database_; 45 std::unique_ptr<IDatabase> database_;
43 std::unique_ptr<ITransaction> transaction_; 46 std::unique_ptr<ITransaction> transaction_;
44 CachedStatements cachedStatements_; 47 CachedStatements cachedStatements_;
45 Dialect dialect_; 48 Dialect dialect_;
46 49
84 87
85 // This class is only used in the "StorageBackend" 88 // This class is only used in the "StorageBackend"
86 class Transaction : public boost::noncopyable 89 class Transaction : public boost::noncopyable
87 { 90 {
88 private: 91 private:
89 boost::recursive_mutex::scoped_lock lock_; 92 DatabaseManager& manager_;
90 DatabaseManager& manager_; 93 IDatabase& database_;
91 IDatabase& database_; 94 bool committed_;
92 bool committed_;
93 95
94 public: 96 public:
95 explicit Transaction(DatabaseManager& manager, 97 explicit Transaction(DatabaseManager& manager,
96 TransactionType type); 98 TransactionType type);
97 99
112 114
113 115
114 class StatementBase : public boost::noncopyable 116 class StatementBase : public boost::noncopyable
115 { 117 {
116 private: 118 private:
117 DatabaseManager& manager_; 119 DatabaseManager& manager_;
118 boost::recursive_mutex::scoped_lock lock_; 120 ITransaction& transaction_;
119 ITransaction& transaction_; 121 std::unique_ptr<Query> query_;
120 std::unique_ptr<Query> query_; 122 std::unique_ptr<IResult> result_;
121 std::unique_ptr<IResult> result_;
122 123
123 IResult& GetResult() const; 124 IResult& GetResult() const;
124 125
125 protected: 126 protected:
126 DatabaseManager& GetManager() const 127 DatabaseManager& GetManager() const