# HG changeset patch # User Sebastien Jodogne # Date 1680524259 -7200 # Node ID 8b6da4fdf9fe7b30ea185092d9ad50a9ed8f6a38 # Parent a9d00b17a48ed962b46f3428f57cb9bc24118767 cleaning ResourcesContent::TagValue and ResourcesContent::Metadata diff -r a9d00b17a48e -r 8b6da4fdf9fe OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp --- a/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp Mon Apr 03 13:30:06 2023 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp Mon Apr 03 14:17:39 2023 +0200 @@ -825,7 +825,7 @@ std::list tmp; GetAllPublicIds(tmp, resourceType); - if (tmp.size() <= since) + if (tmp.size() <= static_cast(since)) { // Not enough results => empty answer return; @@ -1362,12 +1362,12 @@ it = content.GetListTags().begin(); it != content.GetListTags().end(); ++it) { OrthancPluginResourcesContentTags tmp; - tmp.resource = it->resourceId_; - tmp.group = it->tag_.GetGroup(); - tmp.element = it->tag_.GetElement(); - tmp.value = it->value_.c_str(); + tmp.resource = it->GetResourceId(); + tmp.group = it->GetTag().GetGroup(); + tmp.element = it->GetTag().GetElement(); + tmp.value = it->GetValue().c_str(); - if (it->isIdentifier_) + if (it->IsIdentifier()) { identifierTags.push_back(tmp); } @@ -1381,9 +1381,9 @@ it = content.GetListMetadata().begin(); it != content.GetListMetadata().end(); ++it) { OrthancPluginResourcesContentMetadata tmp; - tmp.resource = it->resourceId_; - tmp.metadata = it->metadata_; - tmp.value = it->value_.c_str(); + tmp.resource = it->GetResourceId(); + tmp.metadata = it->GetType(); + tmp.value = it->GetValue().c_str(); metadata.push_back(tmp); } diff -r a9d00b17a48e -r 8b6da4fdf9fe OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp --- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp Mon Apr 03 13:30:06 2023 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp Mon Apr 03 14:17:39 2023 +0200 @@ -901,12 +901,12 @@ it = content.GetListTags().begin(); it != content.GetListTags().end(); ++it) { OrthancPluginResourcesContentTags tmp; - tmp.resource = it->resourceId_; - tmp.group = it->tag_.GetGroup(); - tmp.element = it->tag_.GetElement(); - tmp.value = it->value_.c_str(); + tmp.resource = it->GetResourceId(); + tmp.group = it->GetTag().GetGroup(); + tmp.element = it->GetTag().GetElement(); + tmp.value = it->GetValue().c_str(); - if (it->isIdentifier_) + if (it->IsIdentifier()) { identifierTags.push_back(tmp); } @@ -920,9 +920,9 @@ it = content.GetListMetadata().begin(); it != content.GetListMetadata().end(); ++it) { OrthancPluginResourcesContentMetadata tmp; - tmp.resource = it->resourceId_; - tmp.metadata = it->metadata_; - tmp.value = it->value_.c_str(); + tmp.resource = it->GetResourceId(); + tmp.metadata = it->GetType(); + tmp.value = it->GetValue().c_str(); metadata.push_back(tmp); } diff -r a9d00b17a48e -r 8b6da4fdf9fe OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp --- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Mon Apr 03 13:30:06 2023 +0200 +++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp Mon Apr 03 14:17:39 2023 +0200 @@ -275,6 +275,12 @@ LOG(ERROR) << "Cannot finalize the database engine: " << e.What(); } } + + + void* GetTransactionObject() + { + return transaction_; + } virtual void Rollback() ORTHANC_OVERRIDE @@ -1024,28 +1030,26 @@ virtual void SetResourcesContent(const ResourcesContent& content) ORTHANC_OVERRIDE { - // TODO: "ResourcesContent" => getters - DatabasePluginMessages::TransactionRequest request; request.mutable_set_resources_content()->mutable_tags()->Reserve(content.GetListTags().size()); for (ResourcesContent::ListTags::const_iterator it = content.GetListTags().begin(); it != content.GetListTags().end(); ++it) { DatabasePluginMessages::SetResourcesContent_Request_Tag* tag = request.mutable_set_resources_content()->add_tags(); - tag->set_resource_id(it->resourceId_); - tag->set_is_identifier(it->isIdentifier_); - tag->set_group(it->tag_.GetGroup()); - tag->set_element(it->tag_.GetElement()); - tag->set_value(it->value_); + tag->set_resource_id(it->GetResourceId()); + tag->set_is_identifier(it->IsIdentifier()); + tag->set_group(it->GetTag().GetGroup()); + tag->set_element(it->GetTag().GetElement()); + tag->set_value(it->GetValue()); } request.mutable_set_resources_content()->mutable_metadata()->Reserve(content.GetListMetadata().size()); for (ResourcesContent::ListMetadata::const_iterator it = content.GetListMetadata().begin(); it != content.GetListMetadata().end(); ++it) { DatabasePluginMessages::SetResourcesContent_Request_Metadata* metadata = request.mutable_set_resources_content()->add_metadata(); - metadata->set_resource_id(it->resourceId_); - metadata->set_metadata(it->metadata_); - metadata->set_value(it->value_); + metadata->set_resource_id(it->GetResourceId()); + metadata->set_metadata(it->GetType()); + metadata->set_value(it->GetValue()); } ExecuteTransaction(DatabasePluginMessages::OPERATION_SET_RESOURCES_CONTENT, request); @@ -1275,6 +1279,7 @@ DatabasePluginMessages::DatabaseRequest request; request.mutable_upgrade()->set_target_version(targetVersion); request.mutable_upgrade()->set_storage_area(reinterpret_cast(&storageArea)); + request.mutable_upgrade()->set_transaction(reinterpret_cast(transaction.GetTransactionObject())); DatabasePluginMessages::DatabaseResponse response; diff -r a9d00b17a48e -r 8b6da4fdf9fe OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto --- a/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Mon Apr 03 13:30:06 2023 +0200 +++ b/OrthancServer/Plugins/Include/orthanc/OrthancDatabasePlugin.proto Mon Apr 03 14:17:39 2023 +0200 @@ -163,9 +163,14 @@ } message Upgrade { + /** + * It is guaranteed that a read-write transaction is created by the + * Orthanc core before executing this operation. + **/ message Request { uint32 target_version = 1; sfixed64 storage_area = 2; + sfixed64 transaction = 3; } message Response { } diff -r a9d00b17a48e -r 8b6da4fdf9fe OrthancServer/Sources/Database/ResourcesContent.cpp --- a/OrthancServer/Sources/Database/ResourcesContent.cpp Mon Apr 03 13:30:06 2023 +0200 +++ b/OrthancServer/Sources/Database/ResourcesContent.cpp Mon Apr 03 14:17:39 2023 +0200 @@ -140,13 +140,13 @@ for (std::list::const_iterator it = tags_.begin(); it != tags_.end(); ++it) { - if (it->isIdentifier_) + if (it->IsIdentifier()) { - compatibility.SetIdentifierTag(it->resourceId_, it->tag_, it->value_); + compatibility.SetIdentifierTag(it->GetResourceId(), it->GetTag(), it->GetValue()); } else { - compatibility.SetMainDicomTag(it->resourceId_, it->tag_, it->value_); + compatibility.SetMainDicomTag(it->GetResourceId(), it->GetTag(), it->GetValue()); } } @@ -154,7 +154,7 @@ it = metadata_.begin(); it != metadata_.end(); ++it) { assert(isNewResource_); - compatibility.SetMetadata(it->resourceId_, it->metadata_, it->value_, 0 /* initial revision number */); + compatibility.SetMetadata(it->GetResourceId(), it->GetType(), it->GetValue(), 0 /* initial revision number */); } } } diff -r a9d00b17a48e -r 8b6da4fdf9fe OrthancServer/Sources/Database/ResourcesContent.h --- a/OrthancServer/Sources/Database/ResourcesContent.h Mon Apr 03 13:30:06 2023 +0200 +++ b/OrthancServer/Sources/Database/ResourcesContent.h Mon Apr 03 14:17:39 2023 +0200 @@ -39,13 +39,15 @@ class ResourcesContent : public boost::noncopyable { public: - struct TagValue + class TagValue { + private: int64_t resourceId_; bool isIdentifier_; DicomTag tag_; std::string value_; + public: TagValue(int64_t resourceId, bool isIdentifier, const DicomTag& tag, @@ -56,22 +58,59 @@ value_(value) { } + + int64_t GetResourceId() const + { + return resourceId_; + } + + bool IsIdentifier() const + { + return isIdentifier_; + } + + const DicomTag& GetTag() const + { + return tag_; + } + + const std::string& GetValue() const + { + return value_; + } }; - struct Metadata + class Metadata { + private: int64_t resourceId_; - MetadataType metadata_; + MetadataType type_; std::string value_; + public: Metadata(int64_t resourceId, - MetadataType metadata, + MetadataType type, const std::string& value) : resourceId_(resourceId), - metadata_(metadata), + type_(type), value_(value) { } + + int64_t GetResourceId() const + { + return resourceId_; + } + + MetadataType GetType() const + { + return type_; + } + + const std::string& GetValue() const + { + return value_; + } }; typedef std::list ListTags;