Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp @ 5455:176bc05f85f4 pg-transactions
DB: new Capabilities class to manage future new methods from DB plugins + Added IncrementGlobalProperty
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 07 Dec 2023 12:04:11 +0100 |
parents | fafdb6179829 |
children | dceed5e3d6a9 |
comparison
equal
deleted
inserted
replaced
5454:099d45f49fe1 | 5455:176bc05f85f4 |
---|---|
227 | 227 |
228 void ListLabelsInternal(std::set<std::string>& target, | 228 void ListLabelsInternal(std::set<std::string>& target, |
229 bool isSingleResource, | 229 bool isSingleResource, |
230 int64_t resource) | 230 int64_t resource) |
231 { | 231 { |
232 if (database_.HasLabelsSupport()) | 232 if (database_.GetDatabaseCapabilities().HasLabelsSupport()) |
233 { | 233 { |
234 DatabasePluginMessages::TransactionRequest request; | 234 DatabasePluginMessages::TransactionRequest request; |
235 request.mutable_list_labels()->set_single_resource(isSingleResource); | 235 request.mutable_list_labels()->set_single_resource(isSingleResource); |
236 request.mutable_list_labels()->set_id(resource); | 236 request.mutable_list_labels()->set_id(resource); |
237 | 237 |
303 // Destructors must not throw exceptions | 303 // Destructors must not throw exceptions |
304 LOG(ERROR) << "Cannot finalize the database engine: " << e.What(); | 304 LOG(ERROR) << "Cannot finalize the database engine: " << e.What(); |
305 } | 305 } |
306 } | 306 } |
307 | 307 |
308 virtual const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const ORTHANC_OVERRIDE | |
309 { | |
310 return database_.GetDatabaseCapabilities(); | |
311 } | |
308 | 312 |
309 void* GetTransactionObject() | 313 void* GetTransactionObject() |
310 { | 314 { |
311 return transaction_; | 315 return transaction_; |
312 } | 316 } |
770 { | 774 { |
771 return false; | 775 return false; |
772 } | 776 } |
773 } | 777 } |
774 | 778 |
779 | |
780 virtual int64_t IncrementGlobalProperty(GlobalProperty property, | |
781 int64_t increment, | |
782 bool shared) ORTHANC_OVERRIDE | |
783 { | |
784 DatabasePluginMessages::TransactionRequest request; | |
785 request.mutable_increment_global_property()->set_server_id(shared ? "" : database_.GetServerIdentifier()); | |
786 request.mutable_increment_global_property()->set_property(property); | |
787 request.mutable_increment_global_property()->set_increment(increment); | |
788 | |
789 DatabasePluginMessages::TransactionResponse response; | |
790 ExecuteTransaction(response, DatabasePluginMessages::OPERATION_INCREMENT_GLOBAL_PROPERTY, request); | |
791 | |
792 return response.increment_global_property().new_value(); | |
793 } | |
775 | 794 |
776 virtual bool LookupMetadata(std::string& target, | 795 virtual bool LookupMetadata(std::string& target, |
777 int64_t& revision, | 796 int64_t& revision, |
778 int64_t id, | 797 int64_t id, |
779 MetadataType type) ORTHANC_OVERRIDE | 798 MetadataType type) ORTHANC_OVERRIDE |
946 ResourceType queryLevel, | 965 ResourceType queryLevel, |
947 const std::set<std::string>& labels, | 966 const std::set<std::string>& labels, |
948 LabelsConstraint labelsConstraint, | 967 LabelsConstraint labelsConstraint, |
949 uint32_t limit) ORTHANC_OVERRIDE | 968 uint32_t limit) ORTHANC_OVERRIDE |
950 { | 969 { |
951 if (!database_.HasLabelsSupport() && | 970 if (!database_.GetDatabaseCapabilities().HasLabelsSupport() && |
952 !labels.empty()) | 971 !labels.empty()) |
953 { | 972 { |
954 throw OrthancException(ErrorCode_InternalError); | 973 throw OrthancException(ErrorCode_InternalError); |
955 } | 974 } |
956 | 975 |
1195 | 1214 |
1196 | 1215 |
1197 virtual void AddLabel(int64_t resource, | 1216 virtual void AddLabel(int64_t resource, |
1198 const std::string& label) ORTHANC_OVERRIDE | 1217 const std::string& label) ORTHANC_OVERRIDE |
1199 { | 1218 { |
1200 if (database_.HasLabelsSupport()) | 1219 if (database_.GetDatabaseCapabilities().HasLabelsSupport()) |
1201 { | 1220 { |
1202 DatabasePluginMessages::TransactionRequest request; | 1221 DatabasePluginMessages::TransactionRequest request; |
1203 request.mutable_add_label()->set_id(resource); | 1222 request.mutable_add_label()->set_id(resource); |
1204 request.mutable_add_label()->set_label(label); | 1223 request.mutable_add_label()->set_label(label); |
1205 | 1224 |
1214 | 1233 |
1215 | 1234 |
1216 virtual void RemoveLabel(int64_t resource, | 1235 virtual void RemoveLabel(int64_t resource, |
1217 const std::string& label) ORTHANC_OVERRIDE | 1236 const std::string& label) ORTHANC_OVERRIDE |
1218 { | 1237 { |
1219 if (database_.HasLabelsSupport()) | 1238 if (database_.GetDatabaseCapabilities().HasLabelsSupport()) |
1220 { | 1239 { |
1221 DatabasePluginMessages::TransactionRequest request; | 1240 DatabasePluginMessages::TransactionRequest request; |
1222 request.mutable_remove_label()->set_id(resource); | 1241 request.mutable_remove_label()->set_id(resource); |
1223 request.mutable_remove_label()->set_label(label); | 1242 request.mutable_remove_label()->set_label(label); |
1224 | 1243 |
1254 errorDictionary_(errorDictionary), | 1273 errorDictionary_(errorDictionary), |
1255 definition_(database), | 1274 definition_(database), |
1256 serverIdentifier_(serverIdentifier), | 1275 serverIdentifier_(serverIdentifier), |
1257 open_(false), | 1276 open_(false), |
1258 databaseVersion_(0), | 1277 databaseVersion_(0), |
1259 hasFlushToDisk_(false), | 1278 dbCapabilities_(false, false, false, false) // updated in Open() |
1260 hasRevisionsSupport_(false), | |
1261 hasLabelsSupport_(false) | |
1262 { | 1279 { |
1263 CLOG(INFO, PLUGINS) << "Identifier of this Orthanc server for the global properties " | 1280 CLOG(INFO, PLUGINS) << "Identifier of this Orthanc server for the global properties " |
1264 << "of the custom database: \"" << serverIdentifier << "\""; | 1281 << "of the custom database: \"" << serverIdentifier << "\""; |
1265 | 1282 |
1266 if (definition_.backend == NULL || | 1283 if (definition_.backend == NULL || |
1323 | 1340 |
1324 { | 1341 { |
1325 DatabasePluginMessages::DatabaseRequest request; | 1342 DatabasePluginMessages::DatabaseRequest request; |
1326 DatabasePluginMessages::DatabaseResponse response; | 1343 DatabasePluginMessages::DatabaseResponse response; |
1327 ExecuteDatabase(response, *this, DatabasePluginMessages::OPERATION_GET_SYSTEM_INFORMATION, request); | 1344 ExecuteDatabase(response, *this, DatabasePluginMessages::OPERATION_GET_SYSTEM_INFORMATION, request); |
1328 databaseVersion_ = response.get_system_information().database_version(); | 1345 |
1329 hasFlushToDisk_ = response.get_system_information().supports_flush_to_disk(); | 1346 const ::Orthanc::DatabasePluginMessages::GetSystemInformation_Response& systemInfo = response.get_system_information(); |
1330 hasRevisionsSupport_ = response.get_system_information().supports_revisions(); | 1347 databaseVersion_ = systemInfo.database_version(); |
1331 hasLabelsSupport_ = response.get_system_information().supports_labels(); | 1348 dbCapabilities_.hasFlushToDisk_ = systemInfo.supports_flush_to_disk(); |
1349 dbCapabilities_.hasRevisionsSupport_ = systemInfo.supports_revisions(); | |
1350 dbCapabilities_.hasLabelsSupport_ = systemInfo.supports_labels(); | |
1351 dbCapabilities_.hasAtomicIncrementGlobalProperty_ = systemInfo.supports_increment_global_property(); | |
1332 } | 1352 } |
1333 | 1353 |
1334 open_ = true; | 1354 open_ = true; |
1335 } | 1355 } |
1336 | 1356 |
1348 ExecuteDatabase(response, *this, DatabasePluginMessages::OPERATION_CLOSE, request); | 1368 ExecuteDatabase(response, *this, DatabasePluginMessages::OPERATION_CLOSE, request); |
1349 } | 1369 } |
1350 } | 1370 } |
1351 | 1371 |
1352 | 1372 |
1353 bool OrthancPluginDatabaseV4::HasFlushToDisk() const | |
1354 { | |
1355 if (!open_) | |
1356 { | |
1357 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1358 } | |
1359 else | |
1360 { | |
1361 return hasFlushToDisk_; | |
1362 } | |
1363 } | |
1364 | |
1365 | 1373 |
1366 void OrthancPluginDatabaseV4::FlushToDisk() | 1374 void OrthancPluginDatabaseV4::FlushToDisk() |
1367 { | 1375 { |
1368 if (!open_ || | 1376 if (!open_ || |
1369 !hasFlushToDisk_) | 1377 !GetDatabaseCapabilities().HasFlushToDisk()) |
1370 { | 1378 { |
1371 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 1379 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
1372 } | 1380 } |
1373 else | 1381 else |
1374 { | 1382 { |
1436 throw; | 1444 throw; |
1437 } | 1445 } |
1438 } | 1446 } |
1439 } | 1447 } |
1440 | 1448 |
1441 | 1449 |
1442 bool OrthancPluginDatabaseV4::HasRevisionsSupport() const | 1450 const IDatabaseWrapper::Capabilities& OrthancPluginDatabaseV4::GetDatabaseCapabilities() const |
1443 { | 1451 { |
1444 if (!open_) | 1452 if (!open_) |
1445 { | 1453 { |
1446 throw OrthancException(ErrorCode_BadSequenceOfCalls); | 1454 throw OrthancException(ErrorCode_BadSequenceOfCalls); |
1447 } | 1455 } |
1448 else | 1456 else |
1449 { | 1457 { |
1450 return hasRevisionsSupport_; | 1458 return dbCapabilities_; |
1451 } | 1459 } |
1452 } | 1460 } |
1453 | 1461 |
1454 | 1462 |
1455 bool OrthancPluginDatabaseV4::HasLabelsSupport() const | |
1456 { | |
1457 if (!open_) | |
1458 { | |
1459 throw OrthancException(ErrorCode_BadSequenceOfCalls); | |
1460 } | |
1461 else | |
1462 { | |
1463 return hasLabelsSupport_; | |
1464 } | |
1465 } | |
1466 } | 1463 } |