Mercurial > hg > orthanc
comparison OrthancServer/ServerIndex.cpp @ 1311:d1a430176401
integration db-changes->default
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 11 Feb 2015 10:51:45 +0100 |
parents | 61ce8147f30d |
children | 77e129ba64e4 |
comparison
equal
deleted
inserted
replaced
1307:f796207e3df1 | 1311:d1a430176401 |
---|---|
230 } | 230 } |
231 | 231 |
232 ~Transaction() | 232 ~Transaction() |
233 { | 233 { |
234 index_.listener_->EndTransaction(); | 234 index_.listener_->EndTransaction(); |
235 | |
236 if (!isCommitted_) | |
237 { | |
238 transaction_->Rollback(); | |
239 } | |
235 } | 240 } |
236 | 241 |
237 void Commit(uint64_t sizeOfAddedFiles) | 242 void Commit(uint64_t sizeOfAddedFiles) |
238 { | 243 { |
239 if (!isCommitted_) | 244 if (!isCommitted_) |
808 uint64_t cs = currentStorageSize_; | 813 uint64_t cs = currentStorageSize_; |
809 assert(cs == db_.GetTotalCompressedSize()); | 814 assert(cs == db_.GetTotalCompressedSize()); |
810 uint64_t us = db_.GetTotalUncompressedSize(); | 815 uint64_t us = db_.GetTotalUncompressedSize(); |
811 target["TotalDiskSize"] = boost::lexical_cast<std::string>(cs); | 816 target["TotalDiskSize"] = boost::lexical_cast<std::string>(cs); |
812 target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us); | 817 target["TotalUncompressedSize"] = boost::lexical_cast<std::string>(us); |
813 target["TotalDiskSizeMB"] = boost::lexical_cast<unsigned int>(cs / MEGA_BYTES); | 818 target["TotalDiskSizeMB"] = static_cast<unsigned int>(cs / MEGA_BYTES); |
814 target["TotalUncompressedSizeMB"] = boost::lexical_cast<unsigned int>(us / MEGA_BYTES); | 819 target["TotalUncompressedSizeMB"] = static_cast<unsigned int>(us / MEGA_BYTES); |
815 | 820 |
816 target["CountPatients"] = static_cast<unsigned int>(db_.GetResourceCount(ResourceType_Patient)); | 821 target["CountPatients"] = static_cast<unsigned int>(db_.GetResourceCount(ResourceType_Patient)); |
817 target["CountStudies"] = static_cast<unsigned int>(db_.GetResourceCount(ResourceType_Study)); | 822 target["CountStudies"] = static_cast<unsigned int>(db_.GetResourceCount(ResourceType_Study)); |
818 target["CountSeries"] = static_cast<unsigned int>(db_.GetResourceCount(ResourceType_Series)); | 823 target["CountSeries"] = static_cast<unsigned int>(db_.GetResourceCount(ResourceType_Series)); |
819 target["CountInstances"] = static_cast<unsigned int>(db_.GetResourceCount(ResourceType_Instance)); | 824 target["CountInstances"] = static_cast<unsigned int>(db_.GetResourceCount(ResourceType_Instance)); |
1145 | 1150 |
1146 void ServerIndex::LogExportedResource(const std::string& publicId, | 1151 void ServerIndex::LogExportedResource(const std::string& publicId, |
1147 const std::string& remoteModality) | 1152 const std::string& remoteModality) |
1148 { | 1153 { |
1149 boost::mutex::scoped_lock lock(mutex_); | 1154 boost::mutex::scoped_lock lock(mutex_); |
1155 Transaction transaction(*this); | |
1150 | 1156 |
1151 int64_t id; | 1157 int64_t id; |
1152 ResourceType type; | 1158 ResourceType type; |
1153 if (!db_.LookupResource(id, type, publicId)) | 1159 if (!db_.LookupResource(id, type, publicId)) |
1154 { | 1160 { |
1203 bool ok = db_.LookupParent(currentId, currentId); | 1209 bool ok = db_.LookupParent(currentId, currentId); |
1204 assert(ok); | 1210 assert(ok); |
1205 } | 1211 } |
1206 } | 1212 } |
1207 | 1213 |
1208 // No need for a SQLite::ITransaction here, as we only insert 1 record | |
1209 ExportedResource resource(-1, | 1214 ExportedResource resource(-1, |
1210 type, | 1215 type, |
1211 publicId, | 1216 publicId, |
1212 remoteModality, | 1217 remoteModality, |
1213 Toolbox::GetNowIsoString(), | 1218 Toolbox::GetNowIsoString(), |
1214 patientId, | 1219 patientId, |
1215 studyInstanceUid, | 1220 studyInstanceUid, |
1216 seriesInstanceUid, | 1221 seriesInstanceUid, |
1217 sopInstanceUid); | 1222 sopInstanceUid); |
1223 | |
1218 db_.LogExportedResource(resource); | 1224 db_.LogExportedResource(resource); |
1225 transaction.Commit(0); | |
1219 } | 1226 } |
1220 | 1227 |
1221 | 1228 |
1222 void ServerIndex::GetExportedResources(Json::Value& target, | 1229 void ServerIndex::GetExportedResources(Json::Value& target, |
1223 int64_t since, | 1230 int64_t since, |
1382 | 1389 |
1383 void ServerIndex::SetProtectedPatient(const std::string& publicId, | 1390 void ServerIndex::SetProtectedPatient(const std::string& publicId, |
1384 bool isProtected) | 1391 bool isProtected) |
1385 { | 1392 { |
1386 boost::mutex::scoped_lock lock(mutex_); | 1393 boost::mutex::scoped_lock lock(mutex_); |
1394 Transaction transaction(*this); | |
1387 | 1395 |
1388 // Lookup for the requested resource | 1396 // Lookup for the requested resource |
1389 int64_t id; | 1397 int64_t id; |
1390 ResourceType type; | 1398 ResourceType type; |
1391 if (!db_.LookupResource(id, type, publicId) || | 1399 if (!db_.LookupResource(id, type, publicId) || |
1392 type != ResourceType_Patient) | 1400 type != ResourceType_Patient) |
1393 { | 1401 { |
1394 throw OrthancException(ErrorCode_ParameterOutOfRange); | 1402 throw OrthancException(ErrorCode_ParameterOutOfRange); |
1395 } | 1403 } |
1396 | 1404 |
1397 // No need for a SQLite::ITransaction here, as we only make 1 write to the DB | |
1398 db_.SetProtectedPatient(id, isProtected); | 1405 db_.SetProtectedPatient(id, isProtected); |
1406 transaction.Commit(0); | |
1399 | 1407 |
1400 if (isProtected) | 1408 if (isProtected) |
1401 LOG(INFO) << "Patient " << publicId << " has been protected"; | 1409 LOG(INFO) << "Patient " << publicId << " has been protected"; |
1402 else | 1410 else |
1403 LOG(INFO) << "Patient " << publicId << " has been unprotected"; | 1411 LOG(INFO) << "Patient " << publicId << " has been unprotected"; |
1595 | 1603 |
1596 | 1604 |
1597 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence) | 1605 uint64_t ServerIndex::IncrementGlobalSequence(GlobalProperty sequence) |
1598 { | 1606 { |
1599 boost::mutex::scoped_lock lock(mutex_); | 1607 boost::mutex::scoped_lock lock(mutex_); |
1600 | 1608 Transaction transaction(*this); |
1601 std::auto_ptr<SQLite::ITransaction> transaction(db_.StartTransaction()); | 1609 |
1602 | |
1603 transaction->Begin(); | |
1604 uint64_t seq = IncrementGlobalSequenceInternal(sequence); | 1610 uint64_t seq = IncrementGlobalSequenceInternal(sequence); |
1605 transaction->Commit(); | 1611 transaction.Commit(0); |
1606 | 1612 |
1607 return seq; | 1613 return seq; |
1608 } | 1614 } |
1609 | 1615 |
1610 | 1616 |
1611 | 1617 |
1612 void ServerIndex::LogChange(ChangeType changeType, | 1618 void ServerIndex::LogChange(ChangeType changeType, |
1613 const std::string& publicId) | 1619 const std::string& publicId) |
1614 { | 1620 { |
1615 boost::mutex::scoped_lock lock(mutex_); | 1621 boost::mutex::scoped_lock lock(mutex_); |
1616 std::auto_ptr<SQLite::ITransaction> transaction(db_.StartTransaction()); | 1622 Transaction transaction(*this); |
1617 transaction->Begin(); | |
1618 | 1623 |
1619 int64_t id; | 1624 int64_t id; |
1620 ResourceType type; | 1625 ResourceType type; |
1621 if (!db_.LookupResource(id, type, publicId)) | 1626 if (!db_.LookupResource(id, type, publicId)) |
1622 { | 1627 { |
1623 throw OrthancException(ErrorCode_UnknownResource); | 1628 throw OrthancException(ErrorCode_UnknownResource); |
1624 } | 1629 } |
1625 | 1630 |
1626 LogChange(id, changeType, type, publicId); | 1631 LogChange(id, changeType, type, publicId); |
1627 | 1632 transaction.Commit(0); |
1628 transaction->Commit(); | |
1629 } | 1633 } |
1630 | 1634 |
1631 | 1635 |
1632 void ServerIndex::DeleteChanges() | 1636 void ServerIndex::DeleteChanges() |
1633 { | 1637 { |
1745 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies, | 1749 GetStatisticsInternal(compressedSize, uncompressedSize, countStudies, |
1746 countSeries, countInstances, top, type); | 1750 countSeries, countInstances, top, type); |
1747 | 1751 |
1748 target = Json::objectValue; | 1752 target = Json::objectValue; |
1749 target["DiskSize"] = boost::lexical_cast<std::string>(compressedSize); | 1753 target["DiskSize"] = boost::lexical_cast<std::string>(compressedSize); |
1750 target["DiskSizeMB"] = boost::lexical_cast<unsigned int>(compressedSize / MEGA_BYTES); | 1754 target["DiskSizeMB"] = static_cast<unsigned int>(compressedSize / MEGA_BYTES); |
1751 target["UncompressedSize"] = boost::lexical_cast<std::string>(uncompressedSize); | 1755 target["UncompressedSize"] = boost::lexical_cast<std::string>(uncompressedSize); |
1752 target["UncompressedSizeMB"] = boost::lexical_cast<unsigned int>(uncompressedSize / MEGA_BYTES); | 1756 target["UncompressedSizeMB"] = static_cast<unsigned int>(uncompressedSize / MEGA_BYTES); |
1753 | 1757 |
1754 switch (type) | 1758 switch (type) |
1755 { | 1759 { |
1756 // Do NOT add "break" below this point! | 1760 // Do NOT add "break" below this point! |
1757 case ResourceType_Patient: | 1761 case ResourceType_Patient: |
1975 | 1979 |
1976 void ServerIndex::DeleteAttachment(const std::string& publicId, | 1980 void ServerIndex::DeleteAttachment(const std::string& publicId, |
1977 FileContentType type) | 1981 FileContentType type) |
1978 { | 1982 { |
1979 boost::mutex::scoped_lock lock(mutex_); | 1983 boost::mutex::scoped_lock lock(mutex_); |
1980 | |
1981 Transaction t(*this); | 1984 Transaction t(*this); |
1982 | 1985 |
1983 ResourceType rtype; | 1986 ResourceType rtype; |
1984 int64_t id; | 1987 int64_t id; |
1985 if (!db_.LookupResource(id, rtype, publicId)) | 1988 if (!db_.LookupResource(id, rtype, publicId)) |