DotNetDupe 4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Loading...
Searching...
No Matches
DatabaseEngine.cpp
Go to the documentation of this file.
1#include "pch.h"
5#include <mutex>
6#include <unordered_map>
7#include <memory>
8
9namespace DotNetDupe {
10 namespace System {
11 namespace Data {
12 namespace Internal {
13
14 struct DatabaseEngine::Impl {
15 std::unordered_map<std::string, DotNetDupe::System::SmartPointer<IDatabaseBackend>> m_pBackends;
16 std::mutex m_mutex;
17 };
18
19 DatabaseEngine::DatabaseEngine() : m_pImpl(DotNetDupe::System::SmartPointer<Impl>::NewShared()) {
20 }
21
22 DatabaseEngine::~DatabaseEngine() = default;
23
24 DatabaseEngine& DatabaseEngine::Instance() {
26 static DatabaseEngine instance;
27 return instance;
28 }
29
32 std::lock_guard<std::mutex> lock(m_pImpl->m_mutex);
33
35 m_pImpl->m_pBackends[dbName.GetRawString()] = backend;
36 }
37
40 std::lock_guard<std::mutex> lock(m_pImpl->m_mutex);
41
43 auto it = m_pImpl->m_pBackends.find(dbName.GetRawString());
44 if (it != m_pImpl->m_pBackends.end()) {
45 return it->second;
46 }
47
50 }
51
54 auto spBackend = GetBackend(dbName);
55
57 if (spBackend) {
58 spBackend->ClearDatabase();
59 }
60 }
61
63 const DotNetDupe::System::String& dbName,
64 const String& sql,
67 int& rowsAffected
68 ) {
70 auto spBackend = GetBackend(dbName);
71 if (spBackend) {
72 return spBackend->Execute(sql, parameters, columnNames, rowsAffected);
73 }
74
76 rowsAffected = 0;
77 columnNames.Clear();
79 }
80
81 }
82 }
83 }
84}
Defines the exception thrown when an invalid argument is provided to a method.
Defines the exception thrown when a method call is invalid for the object's current state.
Represents a collection of keys and values.
Definition Dictionary.h:66
Represents a strongly typed list of objects accessible by index.
Definition List.h:29
void Clear()
Removes all elements from the List.
Definition List.h:160
DotNetDupe::System::SmartPointer< IDatabaseBackend > GetBackend(const DotNetDupe::System::String &dbName)
Retrieves the backend associated with a database name.
void ClearDatabase(const DotNetDupe::System::String &dbName)
Clears all contents of the specified database.
void RegisterBackend(const DotNetDupe::System::String &dbName, DotNetDupe::System::SmartPointer< IDatabaseBackend > backend)
Registers a backend instance for a specific database name.
Collections::Generic::List< Row > Execute(const DotNetDupe::System::String &dbName, const String &sql, const Collections::Generic::Dictionary< String, String > &parameters, Collections::Generic::List< String > &columnNames, int &rowsAffected)
Executes a SQL command against the named database backend.
static DatabaseEngine & Instance()
Retrieves the singleton instance of the DatabaseEngine.
A unified smart pointer that supports both unique and shared ownership semantics.
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition String.h:74
const char * GetRawString() const
Definition String.cpp:230