comparison Framework/Common/DatabaseManager.cpp @ 231:0a9b48d19643

removed mutex out of DatabaseManager
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 06 Apr 2021 11:59:31 +0200
parents a4918d57435c
children d1b124d116c1
comparison
equal deleted inserted replaced
230:675f8322eb7c 231:0a9b48d19643
162 } 162 }
163 163
164 164
165 void DatabaseManager::StartTransaction(TransactionType type) 165 void DatabaseManager::StartTransaction(TransactionType type)
166 { 166 {
167 boost::recursive_mutex::scoped_lock lock(mutex_);
168
169 try 167 try
170 { 168 {
171 if (transaction_.get() != NULL) 169 if (transaction_.get() != NULL)
172 { 170 {
173 LOG(ERROR) << "Cannot start another transaction while there is an uncommitted transaction"; 171 LOG(ERROR) << "Cannot start another transaction while there is an uncommitted transaction";
184 } 182 }
185 183
186 184
187 void DatabaseManager::CommitTransaction() 185 void DatabaseManager::CommitTransaction()
188 { 186 {
189 boost::recursive_mutex::scoped_lock lock(mutex_);
190
191 if (transaction_.get() == NULL) 187 if (transaction_.get() == NULL)
192 { 188 {
193 LOG(ERROR) << "Cannot commit a non-existing transaction"; 189 LOG(ERROR) << "Cannot commit a non-existing transaction";
194 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 190 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
195 } 191 }
209 } 205 }
210 206
211 207
212 void DatabaseManager::RollbackTransaction() 208 void DatabaseManager::RollbackTransaction()
213 { 209 {
214 boost::recursive_mutex::scoped_lock lock(mutex_);
215
216 if (transaction_.get() == NULL) 210 if (transaction_.get() == NULL)
217 { 211 {
218 LOG(ERROR) << "Cannot rollback a non-existing transaction"; 212 LOG(ERROR) << "Cannot rollback a non-existing transaction";
219 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls); 213 throw Orthanc::OrthancException(Orthanc::ErrorCode_BadSequenceOfCalls);
220 } 214 }
234 } 228 }
235 229
236 230
237 DatabaseManager::Transaction::Transaction(DatabaseManager& manager, 231 DatabaseManager::Transaction::Transaction(DatabaseManager& manager,
238 TransactionType type) : 232 TransactionType type) :
239 lock_(manager.mutex_),
240 manager_(manager), 233 manager_(manager),
241 database_(manager.GetDatabase()), 234 database_(manager.GetDatabase()),
242 committed_(false) 235 committed_(false)
243 { 236 {
244 manager_.StartTransaction(type); 237 manager_.StartTransaction(type);
326 } 319 }
327 320
328 321
329 DatabaseManager::StatementBase::StatementBase(DatabaseManager& manager) : 322 DatabaseManager::StatementBase::StatementBase(DatabaseManager& manager) :
330 manager_(manager), 323 manager_(manager),
331 lock_(manager_.mutex_),
332 transaction_(manager_.GetTransaction()) 324 transaction_(manager_.GetTransaction())
333 { 325 {
334 } 326 }
335 327
336 328