changeset 532:25cfcb752af6 large-queries

merged find-refactoring -> large-queries
author Alain Mazy <am@orthanc.team>
date Fri, 06 Sep 2024 15:31:33 +0200
parents 48aba35fe64e (current diff) 61338585e7f7 (diff)
children 2d3163d992fd f3738a6351c2
files Framework/Common/DatabaseManager.cpp Framework/Plugins/DatabaseBackendAdapterV4.cpp Framework/Plugins/IDatabaseBackend.h Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h PostgreSQL/Plugins/PostgreSQLIndex.cpp
diffstat 13 files changed, 180 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Common/DatabaseManager.cpp	Tue Jul 09 16:30:52 2024 +0200
+++ b/Framework/Common/DatabaseManager.cpp	Fri Sep 06 15:31:33 2024 +0200
@@ -663,13 +663,11 @@
       statement_.reset(GetManager().GetDatabase().Compile(*query));
       assert(statement_.get() != NULL);
 
+      std::unique_ptr<IResult> result(GetTransaction().Execute(*statement_, parameters));
+
       if (withResults)
       {
-        SetResult(GetTransaction().Execute(*statement_, parameters));
-      }
-      else
-      {
-        GetTransaction().Execute(*statement_, parameters);
+        SetResult(result.release());
       }
     }
     catch (Orthanc::OrthancException& e)
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Tue Jul 09 16:30:52 2024 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Fri Sep 06 15:31:33 2024 +0200
@@ -439,9 +439,11 @@
         response.mutable_get_system_information()->set_has_measure_latency(accessor.GetBackend().HasMeasureLatency());
 #endif
 
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 13, 0)
-        response.mutable_get_system_information()->set_has_extended_api_v1(accessor.GetBackend().HasExtendedApiV1());
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+        response.mutable_get_system_information()->set_supports_find(accessor.GetBackend().HasFindSupport());
+        response.mutable_get_system_information()->set_has_extended_changes(accessor.GetBackend().HasExtendedChanges());
 #endif
+
         break;
       }
 
@@ -786,15 +788,15 @@
         response.mutable_get_changes()->set_done(done);
         break;
       }
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 13, 0)
-      case Orthanc::DatabasePluginMessages::OPERATION_GET_CHANGES_2:
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+      case Orthanc::DatabasePluginMessages::OPERATION_GET_CHANGES_EXTENDED:
       {
         Output output(*response.mutable_get_changes());
 
         bool done;
-        backend.GetChanges2(output, done, manager, request.get_changes2().since(), request.get_changes2().to(), static_cast<OrthancPluginChangeType>(request.get_changes2().change_type()), request.get_changes2().limit());
+        backend.GetChangesExtended(output, done, manager, request.get_changes_extended().since(), request.get_changes_extended().to(), static_cast<OrthancPluginChangeType>(request.get_changes_extended().change_type()), request.get_changes_extended().limit());
 
-        response.mutable_get_changes()->set_done(done);
+        response.mutable_get_changes_extended()->set_done(done);
         break;
       }
 #endif
@@ -1313,6 +1315,12 @@
         break;
       }
       
+      case Orthanc::DatabasePluginMessages::OPERATION_FIND:
+      {
+        backend.ExecuteFind(response, manager, request.find());
+        break;
+      }
+
       default:
         LOG(ERROR) << "Not implemented transaction operation from protobuf: " << request.operation();
         throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
--- a/Framework/Plugins/IDatabaseBackend.h	Tue Jul 09 16:30:52 2024 +0200
+++ b/Framework/Plugins/IDatabaseBackend.h	Fri Sep 06 15:31:33 2024 +0200
@@ -32,6 +32,14 @@
 
 #include <list>
 
+#include <orthanc/OrthancCPlugin.h>
+
+#if defined(ORTHANC_PLUGINS_VERSION_IS_ABOVE)         // Macro introduced in Orthanc 1.3.1
+#  if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+#    include <OrthancDatabasePlugin.pb.h>  // Include protobuf messages for "Find()"
+#  endif
+#endif
+
 namespace OrthancDatabases
 {
   class IDatabaseBackend : public boost::noncopyable
@@ -110,13 +118,13 @@
                             int64_t since,
                             uint32_t limit) = 0;
 
-    virtual void GetChanges2(IDatabaseBackendOutput& output,
-                             bool& done /*out*/,
-                             DatabaseManager& manager,
-                             int64_t since,
-                             int64_t to,
-                             int32_t changeType,
-                             uint32_t limit) = 0;
+    virtual void GetChangesExtended(IDatabaseBackendOutput& output,
+                                    bool& done /*out*/,
+                                    DatabaseManager& manager,
+                                    int64_t since,
+                                    int64_t to,
+                                    int32_t changeType,
+                                    uint32_t limit) = 0;
 
     virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/,
                                        DatabaseManager& manager,
@@ -385,8 +393,16 @@
     // New in Orthanc 1.12.3
     virtual uint64_t MeasureLatency(DatabaseManager& manager) = 0;
 
-    // New in Orthanc 1.13.0
-    virtual bool HasExtendedApiV1() = 0;
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    virtual bool HasFindSupport() const = 0;
+    virtual bool HasExtendedChanges() const = 0;
+#endif
 
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    // New in Orthanc 1.12.5
+    virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                             DatabaseManager& manager,
+                             const Orthanc::DatabasePluginMessages::Find_Request& request) = 0;
+#endif
   };
 }
--- a/Framework/Plugins/IndexBackend.cpp	Tue Jul 09 16:30:52 2024 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Fri Sep 06 15:31:33 2024 +0200
@@ -592,21 +592,21 @@
                                 int64_t since,
                                 uint32_t limit)
   {
-#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 13, 0)    
-    GetChanges2(output, done, manager, since, -1, _OrthancPluginChangeType_All, limit);
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)    
+    GetChangesExtended(output, done, manager, since, -1, _OrthancPluginChangeType_All, limit);
 #else
-    GetChanges2(output, done, manager, since, -1, 65535, limit);
+    GetChangesExtended(output, done, manager, since, -1, 65535, limit);
 #endif
   }
 
   /* Use GetOutput().AnswerChange() */
-  void IndexBackend::GetChanges2(IDatabaseBackendOutput& output,
-                                 bool& done /*out*/,
-                                 DatabaseManager& manager,
-                                 int64_t since,
-                                 int64_t to,
-                                 int32_t changeType,
-                                 uint32_t limit)
+  void IndexBackend::GetChangesExtended(IDatabaseBackendOutput& output,
+                                        bool& done /*out*/,
+                                        DatabaseManager& manager,
+                                        int64_t since,
+                                        int64_t to,
+                                        int32_t changeType,
+                                        uint32_t limit)
   {
     std::string limitSuffix;
     if (manager.GetDialect() == Dialect_MSSQL)
--- a/Framework/Plugins/IndexBackend.h	Tue Jul 09 16:30:52 2024 +0200
+++ b/Framework/Plugins/IndexBackend.h	Fri Sep 06 15:31:33 2024 +0200
@@ -132,13 +132,13 @@
                             int64_t since,
                             uint32_t limit) ORTHANC_OVERRIDE;
 
-    virtual void GetChanges2(IDatabaseBackendOutput& output,
-                             bool& done /*out*/,
-                             DatabaseManager& manager,
-                             int64_t since,
-                             int64_t to,
-                             int32_t changeType,
-                             uint32_t limit) ORTHANC_OVERRIDE;
+    virtual void GetChangesExtended(IDatabaseBackendOutput& output,
+                                    bool& done /*out*/,
+                                    DatabaseManager& manager,
+                                    int64_t since,
+                                    int64_t to,
+                                    int32_t changeType,
+                                    uint32_t limit) ORTHANC_OVERRIDE;
 
     virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/,
                                        DatabaseManager& manager,
@@ -429,8 +429,8 @@
 
     virtual uint64_t MeasureLatency(DatabaseManager& manager) ORTHANC_OVERRIDE;
 
-    // New primitive since Orthanc 1.13.0
-    virtual bool HasExtendedApiV1() ORTHANC_OVERRIDE
+    // New primitive since Orthanc 1.12.5
+    virtual bool HasExtendedChanges() const ORTHANC_OVERRIDE
     {
       return true;
     }
--- a/MySQL/Plugins/MySQLIndex.cpp	Tue Jul 09 16:30:52 2024 +0200
+++ b/MySQL/Plugins/MySQLIndex.cpp	Fri Sep 06 15:31:33 2024 +0200
@@ -593,4 +593,24 @@
     }   
   }
 #endif
+
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+  bool MySQLIndex::HasFindSupport() const
+  {
+    // TODO-FIND
+    return false;
+  }
+#endif
+
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+  void MySQLIndex::ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                               DatabaseManager& manager,
+                               const Orthanc::DatabasePluginMessages::Find_Request& request)
+  {
+    // TODO-FIND
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+#endif
 }
--- a/MySQL/Plugins/MySQLIndex.h	Tue Jul 09 16:30:52 2024 +0200
+++ b/MySQL/Plugins/MySQLIndex.h	Fri Sep 06 15:31:33 2024 +0200
@@ -85,5 +85,15 @@
     {
       return true;
     }
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    virtual bool HasFindSupport() const ORTHANC_OVERRIDE;
+#endif
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                             DatabaseManager& manager,
+                             const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
+#endif
   };
 }
--- a/Odbc/Plugins/OdbcIndex.cpp	Tue Jul 09 16:30:52 2024 +0200
+++ b/Odbc/Plugins/OdbcIndex.cpp	Fri Sep 06 15:31:33 2024 +0200
@@ -695,4 +695,24 @@
 
     SignalDeletedFiles(output, manager);
   }
+
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+  bool OdbcIndex::HasFindSupport() const
+  {
+    // TODO-FIND
+    return false;
+  }
+#endif
+
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+  void OdbcIndex::ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                              DatabaseManager& manager,
+                              const Orthanc::DatabasePluginMessages::Find_Request& request)
+  {
+    // TODO-FIND
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+#endif
 }
--- a/Odbc/Plugins/OdbcIndex.h	Tue Jul 09 16:30:52 2024 +0200
+++ b/Odbc/Plugins/OdbcIndex.h	Fri Sep 06 15:31:33 2024 +0200
@@ -92,5 +92,15 @@
     {
       return false;
     }
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    virtual bool HasFindSupport() const ORTHANC_OVERRIDE;
+#endif
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                             DatabaseManager& manager,
+                             const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
+#endif
   };
 }
--- a/PostgreSQL/Plugins/PostgreSQLIndex.cpp	Tue Jul 09 16:30:52 2024 +0200
+++ b/PostgreSQL/Plugins/PostgreSQLIndex.cpp	Fri Sep 06 15:31:33 2024 +0200
@@ -682,4 +682,24 @@
     // backward compatibility is necessary
     throw Orthanc::OrthancException(Orthanc::ErrorCode_Database);
   }
+
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+  bool PostgreSQLIndex::HasFindSupport() const
+  {
+    // TODO-FIND
+    return false;
+  }
+#endif
+
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+  void PostgreSQLIndex::ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                                    DatabaseManager& manager,
+                                    const Orthanc::DatabasePluginMessages::Find_Request& request)
+  {
+    // TODO-FIND
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+#endif
 }
--- a/PostgreSQL/Plugins/PostgreSQLIndex.h	Tue Jul 09 16:30:52 2024 +0200
+++ b/PostgreSQL/Plugins/PostgreSQLIndex.h	Fri Sep 06 15:31:33 2024 +0200
@@ -135,5 +135,14 @@
                                         int64_t& compressedSize,
                                         int64_t& uncompressedSize) ORTHANC_OVERRIDE;
 
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    virtual bool HasFindSupport() const ORTHANC_OVERRIDE;
+#endif
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                             DatabaseManager& manager,
+                             const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
+#endif
   };
 }
--- a/SQLite/Plugins/SQLiteIndex.cpp	Tue Jul 09 16:30:52 2024 +0200
+++ b/SQLite/Plugins/SQLiteIndex.cpp	Fri Sep 06 15:31:33 2024 +0200
@@ -259,4 +259,24 @@
       }
     }
   }
+
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+  bool SQLiteIndex::HasFindSupport() const
+  {
+    // TODO-FIND
+    return false;
+  }
+#endif
+
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+  void SQLiteIndex::ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                                DatabaseManager& manager,
+                                const Orthanc::DatabasePluginMessages::Find_Request& request)
+  {
+    // TODO-FIND
+    throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
+  }
+#endif
 }
--- a/SQLite/Plugins/SQLiteIndex.h	Tue Jul 09 16:30:52 2024 +0200
+++ b/SQLite/Plugins/SQLiteIndex.h	Fri Sep 06 15:31:33 2024 +0200
@@ -67,5 +67,15 @@
     {
       return true;
     }
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    virtual bool HasFindSupport() const ORTHANC_OVERRIDE;
+#endif
+
+#if ORTHANC_PLUGINS_VERSION_IS_ABOVE(1, 12, 5)
+    virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                             DatabaseManager& manager,
+                             const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
+#endif
   };
 }