comparison Framework/Common/DatabaseManager.h @ 255:d663d9e44f8d

reintroduction of IDatabaseFactory into DatabaseManager
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Apr 2021 17:57:08 +0200
parents 8a4ce70f456a
children 29d2b76516f6
comparison
equal deleted inserted replaced
254:8a4ce70f456a 255:d663d9e44f8d
19 **/ 19 **/
20 20
21 21
22 #pragma once 22 #pragma once
23 23
24 #include "IDatabase.h" 24 #include "IDatabaseFactory.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
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 * 39 *
40 * This class maintains a list of precompiled statements. At any 40 * This class maintains a list of precompiled statements. At any
41 * time, this class handles 0 or 1 active transaction. 41 * time, this class handles 0 or 1 active transaction.
42 *
43 * "DatabaseManager" takes a "IDatabaseFactory" as input, in order
44 * to be able to automatically re-open the database connection if
45 * the latter gets lost.
42 **/ 46 **/
43 class DatabaseManager : public boost::noncopyable 47 class DatabaseManager : public boost::noncopyable
44 { 48 {
45 private: 49 private:
46 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements; 50 typedef std::map<StatementLocation, IPrecompiledStatement*> CachedStatements;
47 51
52 std::unique_ptr<IDatabaseFactory> factory_;
48 std::unique_ptr<IDatabase> database_; 53 std::unique_ptr<IDatabase> database_;
49 std::unique_ptr<ITransaction> transaction_; 54 std::unique_ptr<ITransaction> transaction_;
50 CachedStatements cachedStatements_; 55 CachedStatements cachedStatements_;
51 Dialect dialect_; 56 Dialect dialect_;
52 57
60 ITransaction& GetTransaction(); 65 ITransaction& GetTransaction();
61 66
62 void ReleaseImplicitTransaction(); 67 void ReleaseImplicitTransaction();
63 68
64 public: 69 public:
65 explicit DatabaseManager(IDatabase* database); // Takes ownership 70 explicit DatabaseManager(IDatabaseFactory* factory); // Takes ownership
66 71
67 ~DatabaseManager() 72 ~DatabaseManager()
68 { 73 {
69 Close(); 74 Close();
70 } 75 }
71 76
72 IDatabase& GetDatabase(); 77 IDatabase& GetDatabase();
73 78
74 Dialect GetDialect() const 79 Dialect GetDialect() const;
75 {
76 return dialect_;
77 }
78 80
79 void Close(); 81 void Close();
80 82
81 void StartTransaction(TransactionType type); 83 void StartTransaction(TransactionType type);
82 84