comparison Framework/Common/DatabaseManager.h @ 237:35598014f140

refactoring to remove GlobalProperties.cpp
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 08 Apr 2021 19:09:04 +0200
parents 0a9b48d19643
children a063bbf10a3e
comparison
equal deleted inserted replaced
236:d1d2edbbe6fb 237:35598014f140
34 { 34 {
35 /** 35 /**
36 * WARNING: In PostgreSQL releases <= 3.3 and in MySQL releases <= 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 37 * 3.0, this class was protected by a mutex. It is now assumed that
38 * locking must be implemented at a higher level. 38 * locking must be implemented at a higher level.
39 *
40 * This class maintains a list of precompiled statements. At any
41 * time, this class handles 0 or 1 active transaction.
39 **/ 42 **/
40 class DatabaseManager : public boost::noncopyable 43 class DatabaseManager : public boost::noncopyable
41 { 44 {
42 private: 45 private:
43 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements; 46 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements;
45 std::unique_ptr<IDatabase> database_; 48 std::unique_ptr<IDatabase> database_;
46 std::unique_ptr<ITransaction> transaction_; 49 std::unique_ptr<ITransaction> transaction_;
47 CachedStatements cachedStatements_; 50 CachedStatements cachedStatements_;
48 Dialect dialect_; 51 Dialect dialect_;
49 52
50 IDatabase& GetDatabase()
51 {
52 return *database_;
53 }
54
55 void CloseIfUnavailable(Orthanc::ErrorCode e); 53 void CloseIfUnavailable(Orthanc::ErrorCode e);
56 54
57 IPrecompiledStatement* LookupCachedStatement(const StatementLocation& location) const; 55 IPrecompiledStatement* LookupCachedStatement(const StatementLocation& location) const;
58 56
59 IPrecompiledStatement& CacheStatement(const StatementLocation& location, 57 IPrecompiledStatement& CacheStatement(const StatementLocation& location,
69 ~DatabaseManager() 67 ~DatabaseManager()
70 { 68 {
71 Close(); 69 Close();
72 } 70 }
73 71
72 IDatabase& GetDatabase()
73 {
74 return *database_;
75 }
76
74 Dialect GetDialect() const 77 Dialect GetDialect() const
75 { 78 {
76 return dialect_; 79 return dialect_;
77 } 80 }
78 81
107 } 110 }
108 111
109 IDatabase& GetDatabase() 112 IDatabase& GetDatabase()
110 { 113 {
111 return database_; 114 return database_;
115 }
116
117 bool DoesTableExist(const std::string& name)
118 {
119 return manager_.GetTransaction().DoesTableExist(name);
120 }
121
122 bool DoesTriggerExist(const std::string& name)
123 {
124 return manager_.GetTransaction().DoesTriggerExist(name);
125 }
126
127 void ExecuteMultiLines(const std::string& sql)
128 {
129 manager_.GetTransaction().ExecuteMultiLines(sql);
112 } 130 }
113 }; 131 };
114 132
115 133
116 class StatementBase : public boost::noncopyable 134 class StatementBase : public boost::noncopyable