comparison Framework/Common/DatabaseManager.cpp @ 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
157 } 157 }
158 } 158 }
159 } 159 }
160 160
161 161
162 DatabaseManager::DatabaseManager(IDatabase* database) : 162 DatabaseManager::DatabaseManager(IDatabaseFactory* factory) :
163 database_(database) 163 factory_(factory),
164 { 164 dialect_(Dialect_Unknown)
165 if (database == NULL) 165 {
166 if (factory == NULL)
166 { 167 {
167 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); 168 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
168 } 169 }
169
170 dialect_ = database->GetDialect();
171 } 170 }
172 171
173 172
174 IDatabase& DatabaseManager::GetDatabase() 173 IDatabase& DatabaseManager::GetDatabase()
175 { 174 {
175 assert(factory_.get() != NULL);
176
176 if (database_.get() == NULL) 177 if (database_.get() == NULL)
177 { 178 {
178 throw Orthanc::OrthancException(Orthanc::ErrorCode_DatabaseUnavailable); 179 database_.reset(factory_->Open());
179 } 180
180 else 181 if (database_.get() == NULL)
181 { 182 {
182 return *database_; 183 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
183 } 184 }
184 } 185
185 186 dialect_ = database_->GetDialect();
187 if (dialect_ == Dialect_Unknown)
188 {
189 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
190 }
191 }
192
193 return *database_;
194 }
195
196
197 Dialect DatabaseManager::GetDialect() const
198 {
199 if (database_.get() == NULL)
200 {
201 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
202 }
203 else
204 {
205 assert(dialect_ != Dialect_Unknown);
206 return dialect_;
207 }
208 }
209
186 210
187 void DatabaseManager::StartTransaction(TransactionType type) 211 void DatabaseManager::StartTransaction(TransactionType type)
188 { 212 {
189 try 213 try
190 { 214 {