changeset 76:a1c6238b26f8 db-changes

new extension implemented for PostgreSQL: GetChildrenMetadata
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 05 Jan 2019 15:51:25 +0100
parents 52c70007bb87
children a2134531473c
files Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h Framework/Plugins/OrthancCppDatabasePlugin.h
diffstat 3 files changed, 77 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/IndexBackend.cpp	Sat Jan 05 11:41:15 2019 +0100
+++ b/Framework/Plugins/IndexBackend.cpp	Sat Jan 05 15:51:25 2019 +0100
@@ -1860,4 +1860,28 @@
     ExecuteSetResourcesContentMetadata(GetManager(), countMetadata, metadata);
   }
 #endif
+
+
+#if ORTHANC_PLUGINS_HAS_DATABASE_OPTIMIZATIONS_1 == 1
+  // New primitive since Orthanc 1.5.2
+  void IndexBackend::GetChildrenMetadata(std::list<std::string>& target,
+                                         int64_t resourceId,
+                                         int32_t metadata)
+  {
+    DatabaseManager::CachedStatement statement(
+      STATEMENT_FROM_HERE, manager_,
+      "SELECT value FROM Metadata WHERE type=${metadata} AND "
+      "id IN (SELECT internalId FROM Resources WHERE parentId=${id})");
+      
+    statement.SetReadOnly(true);
+    statement.SetParameterType("id", ValueType_Integer64);
+    statement.SetParameterType("metadata", ValueType_Integer64);
+
+    Dictionary args;
+    args.SetIntegerValue("id", static_cast<int>(resourceId));
+    args.SetIntegerValue("metadata", static_cast<int>(metadata));
+
+    ReadListOfStrings(target, statement, args);
+  }
+#endif  
 }
--- a/Framework/Plugins/IndexBackend.h	Sat Jan 05 11:41:15 2019 +0100
+++ b/Framework/Plugins/IndexBackend.h	Sat Jan 05 15:51:25 2019 +0100
@@ -276,5 +276,12 @@
       uint32_t countMetadata,
       const OrthancPluginResourcesContentMetadata* metadata);
 #endif
+
+#if ORTHANC_PLUGINS_HAS_DATABASE_OPTIMIZATIONS_1 == 1
+    // New primitive since Orthanc 1.5.2
+    virtual void GetChildrenMetadata(std::list<std::string>& target,
+                                     int64_t resourceId,
+                                     int32_t metadata);
+#endif
   };
 }
--- a/Framework/Plugins/OrthancCppDatabasePlugin.h	Sat Jan 05 11:41:15 2019 +0100
+++ b/Framework/Plugins/OrthancCppDatabasePlugin.h	Sat Jan 05 15:51:25 2019 +0100
@@ -81,7 +81,8 @@
       AllowedAnswers_Change,
       AllowedAnswers_DicomTag,
       AllowedAnswers_ExportedResource,
-      AllowedAnswers_MatchingResource
+      AllowedAnswers_MatchingResource,
+      AllowedAnswers_String
     };
 
     OrthancPluginContext*         context_;
@@ -521,6 +522,13 @@
       uint32_t countMetadata,
       const OrthancPluginResourcesContentMetadata* metadata) = 0;
 #endif
+
+    
+#if ORTHANC_PLUGINS_HAS_DATABASE_OPTIMIZATIONS_1 == 1
+    virtual void GetChildrenMetadata(std::list<std::string>& target,
+                                     int64_t resourceId,
+                                     int32_t metadata) = 0;
+#endif
   };
 
 
@@ -1457,6 +1465,7 @@
                                                      void* payload)
     {
       IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload);
+      backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None);
       
       try
       {
@@ -1472,6 +1481,7 @@
                                                   OrthancPluginStorageArea* storageArea)
     {
       IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload);
+      backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None);
       
       try
       {
@@ -1486,6 +1496,7 @@
                                                      int64_t internalId)
     {
       IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload);
+      backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None);
       
       try
       {
@@ -1537,6 +1548,7 @@
                                                  const char* hashInstance)
     {
       IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload);
+      backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None);
 
       try
       {
@@ -1559,6 +1571,7 @@
       const OrthancPluginResourcesContentMetadata* metadata)
     {
       IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload);
+      backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None);
 
       try
       {
@@ -1572,6 +1585,37 @@
 #endif    
 
     
+
+#if ORTHANC_PLUGINS_HAS_DATABASE_OPTIMIZATIONS_1 == 1
+    // New primitive since Orthanc 1.5.2
+    static OrthancPluginErrorCode GetChildrenMetadata(OrthancPluginDatabaseContext* context,
+                                                      void* payload,
+                                                      int64_t resourceId,
+                                                      int32_t metadata)
+    {
+      IDatabaseBackend* backend = reinterpret_cast<IDatabaseBackend*>(payload);
+      backend->GetOutput().SetAllowedAnswers(DatabaseBackendOutput::AllowedAnswers_None);
+
+      try
+      {
+        std::list<std::string> values;
+        backend->GetChildrenMetadata(values, resourceId, metadata);
+
+        for (std::list<std::string>::const_iterator
+               it = values.begin(); it != values.end(); ++it)
+        {
+          OrthancPluginDatabaseAnswerString(backend->GetOutput().context_,
+                                            backend->GetOutput().database_,
+                                            it->c_str());
+        }
+
+        return OrthancPluginErrorCode_Success;
+      }
+      ORTHANC_PLUGINS_DATABASE_CATCH      
+    }
+#endif
+
+
   public:
     /**
      * Register a custom database back-end written in C++.
@@ -1655,6 +1699,7 @@
       // Optimizations brought by Orthanc 1.5.2
       extensions.lookupResources = LookupResources;          // Fast lookup
       extensions.setResourcesContent = SetResourcesContent;  // Fast setting tags/metadata
+      extensions.getChildrenMetadata = GetChildrenMetadata;
 
       if (backend.HasCreateInstance())
       {