DotNetDupe
4.0.6
C++17/20 Implementation of the .NET Base Class Library (BCL)
Toggle main menu visibility
Loading...
Searching...
No Matches
DatabaseEngine.cpp
Go to the documentation of this file.
1
#include "
pch.h
"
2
#include "
System/Data/Internal/DatabaseEngine.h
"
3
#include "
System/InvalidOperationException.h
"
4
#include "
System/ArgumentException.h
"
5
#include <mutex>
6
#include <unordered_map>
7
#include <memory>
8
9
namespace
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
30
void
DatabaseEngine::RegisterBackend
(
const
DotNetDupe::System::String
& dbName,
DotNetDupe::System::SmartPointer<IDatabaseBackend>
backend) {
32
std::lock_guard<std::mutex> lock(m_pImpl->m_mutex);
33
35
m_pImpl->m_pBackends[dbName.
GetRawString
()] = backend;
36
}
37
38
DotNetDupe::System::SmartPointer<IDatabaseBackend>
DatabaseEngine::GetBackend
(
const
DotNetDupe::System::String
& dbName) {
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
49
return
DotNetDupe::System::SmartPointer<IDatabaseBackend>
(
nullptr
);
50
}
51
52
void
DatabaseEngine::ClearDatabase
(
const
DotNetDupe::System::String
& dbName) {
54
auto
spBackend =
GetBackend
(dbName);
55
57
if
(spBackend) {
58
spBackend->ClearDatabase();
59
}
60
}
61
62
Collections::Generic::List<Row>
DatabaseEngine::Execute
(
63
const
DotNetDupe::System::String
& dbName,
64
const
String
& sql,
65
const
Collections::Generic::Dictionary<String, String>
& parameters,
66
Collections::Generic::List<String>
& columnNames,
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
();
78
return
Collections::Generic::List<Row>
();
79
}
80
81
}
82
}
83
}
84
}
ArgumentException.h
Defines the exception thrown when an invalid argument is provided to a method.
DatabaseEngine.h
InvalidOperationException.h
Defines the exception thrown when a method call is invalid for the object's current state.
DotNetDupe::System::Collections::Generic::Dictionary
Represents a collection of keys and values.
Definition
Dictionary.h:66
DotNetDupe::System::Collections::Generic::List
Represents a strongly typed list of objects accessible by index.
Definition
List.h:29
DotNetDupe::System::Collections::Generic::List::Clear
void Clear()
Removes all elements from the List.
Definition
List.h:160
DotNetDupe::System::Data::Internal::DatabaseEngine::GetBackend
DotNetDupe::System::SmartPointer< IDatabaseBackend > GetBackend(const DotNetDupe::System::String &dbName)
Retrieves the backend associated with a database name.
Definition
DatabaseEngine.cpp:38
DotNetDupe::System::Data::Internal::DatabaseEngine::ClearDatabase
void ClearDatabase(const DotNetDupe::System::String &dbName)
Clears all contents of the specified database.
Definition
DatabaseEngine.cpp:52
DotNetDupe::System::Data::Internal::DatabaseEngine::RegisterBackend
void RegisterBackend(const DotNetDupe::System::String &dbName, DotNetDupe::System::SmartPointer< IDatabaseBackend > backend)
Registers a backend instance for a specific database name.
Definition
DatabaseEngine.cpp:30
DotNetDupe::System::Data::Internal::DatabaseEngine::Execute
Collections::Generic::List< Row > Execute(const DotNetDupe::System::String &dbName, const String &sql, const Collections::Generic::Dictionary< String, String > ¶meters, Collections::Generic::List< String > &columnNames, int &rowsAffected)
Executes a SQL command against the named database backend.
Definition
DatabaseEngine.cpp:62
DotNetDupe::System::Data::Internal::DatabaseEngine::Instance
static DatabaseEngine & Instance()
Retrieves the singleton instance of the DatabaseEngine.
Definition
DatabaseEngine.cpp:24
DotNetDupe::System::SmartPointer
A unified smart pointer that supports both unique and shared ownership semantics.
Definition
SmartPointer.h:72
DotNetDupe::System::String
Represents text as a sequence of UTF-8 code units with culture-invariant operations.
Definition
String.h:74
DotNetDupe::System::String::GetRawString
const char * GetRawString() const
Definition
String.cpp:230
DotNetDupe::System::Data::Internal
Definition
DatabaseEngine.h:12
DotNetDupe::System::Data
Definition
DbCommand.h:11
DotNetDupe::System::IO::FileAttributes::System
@ System
Definition
File.h:20
DotNetDupe::System
Definition
Action.h:11
DotNetDupe
Definition
IServiceCollection.h:7
pch.h
DotNetDupe
DatabaseEngine.cpp
Generated by
1.18.0