Mercurial > hg > orthanc-databases
comparison Framework/Common/DatabaseManager.h @ 226:a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 02 Apr 2021 19:23:36 +0200 |
parents | 73cc85f3d9c1 |
children | 0a9b48d19643 |
comparison
equal
deleted
inserted
replaced
225:94c9908e6aca | 226:a4918d57435c |
---|---|
19 **/ | 19 **/ |
20 | 20 |
21 | 21 |
22 #pragma once | 22 #pragma once |
23 | 23 |
24 #include "IDatabaseFactory.h" | 24 #include "IDatabase.h" |
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 |
36 class DatabaseManager : public boost::noncopyable | 36 class DatabaseManager : public boost::noncopyable |
37 { | 37 { |
38 private: | 38 private: |
39 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements; | 39 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements; |
40 | 40 |
41 boost::recursive_mutex mutex_; | 41 boost::recursive_mutex mutex_; |
42 std::unique_ptr<IDatabaseFactory> factory_; | 42 std::unique_ptr<IDatabase> database_; |
43 std::unique_ptr<IDatabase> database_; | 43 std::unique_ptr<ITransaction> transaction_; |
44 std::unique_ptr<ITransaction> transaction_; | 44 CachedStatements cachedStatements_; |
45 CachedStatements cachedStatements_; | 45 Dialect dialect_; |
46 Dialect dialect_; | 46 |
47 | 47 IDatabase& GetDatabase() |
48 IDatabase& GetDatabase(); | 48 { |
49 return *database_; | |
50 } | |
49 | 51 |
50 void CloseIfUnavailable(Orthanc::ErrorCode e); | 52 void CloseIfUnavailable(Orthanc::ErrorCode e); |
51 | 53 |
52 IPrecompiledStatement* LookupCachedStatement(const StatementLocation& location) const; | 54 IPrecompiledStatement* LookupCachedStatement(const StatementLocation& location) const; |
53 | 55 |
57 ITransaction& GetTransaction(); | 59 ITransaction& GetTransaction(); |
58 | 60 |
59 void ReleaseImplicitTransaction(); | 61 void ReleaseImplicitTransaction(); |
60 | 62 |
61 public: | 63 public: |
62 explicit DatabaseManager(IDatabaseFactory* factory); // Takes ownership | 64 explicit DatabaseManager(IDatabase* database); // Takes ownership |
63 | 65 |
64 ~DatabaseManager() | 66 ~DatabaseManager() |
65 { | 67 { |
66 Close(); | 68 Close(); |
67 } | 69 } |
68 | 70 |
69 Dialect GetDialect() const | 71 Dialect GetDialect() const |
70 { | 72 { |
71 return dialect_; | 73 return dialect_; |
72 } | |
73 | |
74 void Open() | |
75 { | |
76 GetDatabase(); | |
77 } | 74 } |
78 | 75 |
79 void Close(); | 76 void Close(); |
80 | 77 |
81 void StartTransaction(TransactionType type); | 78 void StartTransaction(TransactionType type); |