-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSessionFactoryConfiguration.cpp
More file actions
187 lines (142 loc) · 3.39 KB
/
SessionFactoryConfiguration.cpp
File metadata and controls
187 lines (142 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "stdafx.h"
#include "SessionFactoryConfiguration.h"
#include "MappingRegistrar.h"
SessionFactoryConfiguration::SessionFactoryConfiguration() :
_trusted(true)
{
}
SessionFactoryConfiguration::SessionFactoryConfiguration(const SessionFactoryConfiguration &other) :
_driver(other._driver)
, _server(other._server)
, _database(other._database)
, _username(other._username)
, _password(other._password)
, _trusted(other._trusted)
, _registry(other._registry)
{
}
SessionFactoryConfiguration::~SessionFactoryConfiguration()
{
}
SessionFactoryConfiguration &SessionFactoryConfiguration::operator =(const SessionFactoryConfiguration &other)
{
if (this != &other)
{
_driver = other._driver;
_server = other._server;
_database = other._database;
_username = other._username;
_password = other._password;
_trusted = other._trusted;
_registry = other._registry;
}
return *this;
}
void SessionFactoryConfiguration::SetDriver(const std::string &driver)
{
_driver = driver;
}
std::string SessionFactoryConfiguration::GetDriver() const
{
return _driver;
}
void SessionFactoryConfiguration::SetServer(const std::string &server)
{
_server = server;
}
std::string SessionFactoryConfiguration::GetServer() const
{
return _server;
}
void SessionFactoryConfiguration::SetDatabase(const std::string &database)
{
_database = database;
}
std::string SessionFactoryConfiguration::GetDatabase() const
{
return _database;
}
void SessionFactoryConfiguration::SetUserName(const std::string &username)
{
_username = username;
}
std::string SessionFactoryConfiguration::GetUserName() const
{
return _username;
}
void SessionFactoryConfiguration::SetPassword(const std::string &password)
{
_password = password;
}
std::string SessionFactoryConfiguration::GetPassword() const
{
return _password;
}
void SessionFactoryConfiguration::SetTrusted(const bool trusted)
{
_trusted = trusted;
}
bool SessionFactoryConfiguration::IsTrusted() const
{
return _trusted;
}
std::string SessionFactoryConfiguration::BuildConnectionString() const
{
std::string result;
//Driver={SQL Server Native Client 11.0}; Server=(local); Database=OdbcCppTestDatabase; Trusted_Connection=Yes;
if (_driver.empty())
{
std::exception e("Driver cannot be empty.");
throw e;
}
result.append("Driver={");
result.append(_driver);
result.append("}; ");
if (_server.empty())
{
std::exception e("Server cannot be empty.");
throw e;
}
result.append("Server=");
result.append(_server);
result.append("; ");
if (_database.empty())
{
std::exception e("Database cannot be empty.");
throw e;
}
result.append("Database=");
result.append(_database);
result.append("; ");
if (_trusted)
{
result.append("Trusted_Connection=Yes;");
}
else
{
if (_username.empty() || _password.empty())
{
std::exception e("Either trusted connection must be true or you must set the username and password.");
throw e;
}
result.append("UserName=");
result.append(_username);
result.append("; ");
result.append("Password=");
result.append(_password);
result.append("; ");
}
return result;
}
void SessionFactoryConfiguration::ConfigureMappingRegistry(const MappingRegistrar ®istrar)
{
registrar.Register(_registry);
}
MappingRegistry &SessionFactoryConfiguration::GetMappingRegistry()
{
return _registry;
}
const MappingRegistry &SessionFactoryConfiguration::GetMappingRegistry() const
{
return _registry;
}