comparison OrthancServer/ServerIndex.cpp @ 1235:9b4977e3c19d

abstraction
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 05 Dec 2014 14:31:46 +0100
parents efece308018e
children 21d84e3acc0d
comparison
equal deleted inserted replaced
1234:a65ad39596cb 1235:9b4977e3c19d
41 #include "EmbeddedResources.h" 41 #include "EmbeddedResources.h"
42 #include "OrthancInitialization.h" 42 #include "OrthancInitialization.h"
43 #include "../Core/Toolbox.h" 43 #include "../Core/Toolbox.h"
44 #include "../Core/Uuid.h" 44 #include "../Core/Uuid.h"
45 #include "../Core/DicomFormat/DicomArray.h" 45 #include "../Core/DicomFormat/DicomArray.h"
46 #include "../Core/SQLite/Transaction.h"
47 #include "FromDcmtkBridge.h" 46 #include "FromDcmtkBridge.h"
48 #include "ServerContext.h" 47 #include "ServerContext.h"
49 48
50 #include <boost/lexical_cast.hpp> 49 #include <boost/lexical_cast.hpp>
51 #include <stdio.h> 50 #include <stdio.h>
212 211
213 class ServerIndex::Transaction 212 class ServerIndex::Transaction
214 { 213 {
215 private: 214 private:
216 ServerIndex& index_; 215 ServerIndex& index_;
217 std::auto_ptr<SQLite::Transaction> transaction_; 216 std::auto_ptr<SQLite::ITransaction> transaction_;
218 bool isCommitted_; 217 bool isCommitted_;
219 218
220 public: 219 public:
221 Transaction(ServerIndex& index) : 220 Transaction(ServerIndex& index) :
222 index_(index), 221 index_(index),
1057 bool ok = db_->LookupParent(currentId, currentId); 1056 bool ok = db_->LookupParent(currentId, currentId);
1058 assert(ok); 1057 assert(ok);
1059 } 1058 }
1060 } 1059 }
1061 1060
1062 // No need for a SQLite::Transaction here, as we only insert 1 record 1061 // No need for a SQLite::ITransaction here, as we only insert 1 record
1063 db_->LogExportedResource(type, 1062 db_->LogExportedResource(type,
1064 publicId, 1063 publicId,
1065 remoteModality, 1064 remoteModality,
1066 patientId, 1065 patientId,
1067 studyInstanceUid, 1066 studyInstanceUid,
1231 type != ResourceType_Patient) 1230 type != ResourceType_Patient)
1232 { 1231 {
1233 throw OrthancException(ErrorCode_ParameterOutOfRange); 1232 throw OrthancException(ErrorCode_ParameterOutOfRange);
1234 } 1233 }
1235 1234
1236 // No need for a SQLite::Transaction here, as we only make 1 write to the DB 1235 // No need for a SQLite::ITransaction here, as we only make 1 write to the DB
1237 db_->SetProtectedPatient(id, isProtected); 1236 db_->SetProtectedPatient(id, isProtected);
1238 1237
1239 if (isProtected) 1238 if (isProtected)
1240 LOG(INFO) << "Patient " << publicId << " has been protected"; 1239 LOG(INFO) << "Patient " << publicId << " has been protected";
1241 else 1240 else
1435 1434
1436 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence) 1435 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence)
1437 { 1436 {
1438 boost::mutex::scoped_lock lock(mutex_); 1437 boost::mutex::scoped_lock lock(mutex_);
1439 1438
1440 std::auto_ptr<SQLite::Transaction> transaction(db_->StartTransaction()); 1439 std::auto_ptr<SQLite::ITransaction> transaction(db_->StartTransaction());
1441 1440
1442 transaction->Begin(); 1441 transaction->Begin();
1443 uint64_t seq = db_->IncrementGlobalSequence(sequence); 1442 uint64_t seq = db_->IncrementGlobalSequence(sequence);
1444 transaction->Commit(); 1443 transaction->Commit();
1445 1444
1450 1449
1451 void ServerIndex::LogChange(ChangeType changeType, 1450 void ServerIndex::LogChange(ChangeType changeType,
1452 const std::string& publicId) 1451 const std::string& publicId)
1453 { 1452 {
1454 boost::mutex::scoped_lock lock(mutex_); 1453 boost::mutex::scoped_lock lock(mutex_);
1455 std::auto_ptr<SQLite::Transaction> transaction(db_->StartTransaction()); 1454 std::auto_ptr<SQLite::ITransaction> transaction(db_->StartTransaction());
1456 transaction->Begin(); 1455 transaction->Begin();
1457 1456
1458 int64_t id; 1457 int64_t id;
1459 ResourceType type; 1458 ResourceType type;
1460 if (!db_->LookupResource(publicId, id, type)) 1459 if (!db_->LookupResource(publicId, id, type))