changeset 580:35d2df9572b1 find-refactoring

count-resources
author Alain Mazy <am@orthanc.team>
date Tue, 15 Oct 2024 15:52:39 +0200
parents e99ca3508757
children a80775ee5eea
files Framework/Plugins/DatabaseBackendAdapterV4.cpp Framework/Plugins/IDatabaseBackend.h Framework/Plugins/IndexBackend.cpp Framework/Plugins/IndexBackend.h MySQL/Plugins/MySQLIndex.cpp MySQL/Plugins/MySQLIndex.h Odbc/Plugins/OdbcIndex.cpp Odbc/Plugins/OdbcIndex.h SQLite/Plugins/SQLiteIndex.cpp SQLite/Plugins/SQLiteIndex.h
diffstat 10 files changed, 69 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Tue Oct 08 17:57:22 2024 +0200
+++ b/Framework/Plugins/DatabaseBackendAdapterV4.cpp	Tue Oct 15 15:52:39 2024 +0200
@@ -1327,6 +1327,12 @@
         backend.ExecuteFind(response, manager, request.find());
         break;
       }
+
+      case Orthanc::DatabasePluginMessages::OPERATION_COUNT_RESOURCES:
+      {
+        backend.ExecuteCount(response, manager, request.find());
+        break;
+      }
 #endif
 
       default:
--- a/Framework/Plugins/IDatabaseBackend.h	Tue Oct 08 17:57:22 2024 +0200
+++ b/Framework/Plugins/IDatabaseBackend.h	Tue Oct 15 15:52:39 2024 +0200
@@ -395,6 +395,11 @@
     virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
                              DatabaseManager& manager,
                              const Orthanc::DatabasePluginMessages::Find_Request& request) = 0;
+
+    // New in Orthanc 1.12.5
+    virtual void ExecuteCount(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                              DatabaseManager& manager,
+                              const Orthanc::DatabasePluginMessages::Find_Request& request) = 0;
 #endif
   };
 }
--- a/Framework/Plugins/IndexBackend.cpp	Tue Oct 08 17:57:22 2024 +0200
+++ b/Framework/Plugins/IndexBackend.cpp	Tue Oct 15 15:52:39 2024 +0200
@@ -3187,6 +3187,24 @@
 #define STRINGIFY(x) #x
 #define TOSTRING(x) STRINGIFY(x)
 
+  void IndexBackend::ExecuteCount(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                                  DatabaseManager& manager,
+                                  const Orthanc::DatabasePluginMessages::Find_Request& request)
+  {
+    std::string sql;
+
+    LookupFormatter formatter(manager.GetDialect());
+    std::string lookupSql;
+    ISqlLookupFormatter::Apply(lookupSql, formatter, request);
+
+    sql = "WITH Lookup AS (" + lookupSql + ") SELECT COUNT(*) FROM Lookup";
+
+    DatabaseManager::StandaloneStatement statement(manager, sql);  // TODO-FIND: cache dynamic statement ?  Probably worth it since it can be very complex queries !
+    formatter.PrepareStatement(statement);
+    statement.Execute(formatter.GetDictionary());
+    response.mutable_count_resources()->set_count(statement.ReadInteger64(0));
+  }
+
   void IndexBackend::ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
                                     DatabaseManager& manager,
                                     const Orthanc::DatabasePluginMessages::Find_Request& request)
--- a/Framework/Plugins/IndexBackend.h	Tue Oct 08 17:57:22 2024 +0200
+++ b/Framework/Plugins/IndexBackend.h	Tue Oct 15 15:52:39 2024 +0200
@@ -445,6 +445,10 @@
     virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
                              DatabaseManager& manager,
                              const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
+
+    virtual void ExecuteCount(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                              DatabaseManager& manager,
+                              const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
 #endif
 
 
--- a/MySQL/Plugins/MySQLIndex.cpp	Tue Oct 08 17:57:22 2024 +0200
+++ b/MySQL/Plugins/MySQLIndex.cpp	Tue Oct 15 15:52:39 2024 +0200
@@ -612,5 +612,13 @@
     // TODO-FIND
     throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
   }
+
+  void MySQLIndex::ExecuteCount(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 Oct 08 17:57:22 2024 +0200
+++ b/MySQL/Plugins/MySQLIndex.h	Tue Oct 15 15:52:39 2024 +0200
@@ -94,6 +94,10 @@
     virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
                              DatabaseManager& manager,
                              const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
+
+    virtual void ExecuteCount(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                              DatabaseManager& manager,
+                              const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
 #endif
   };
 }
--- a/Odbc/Plugins/OdbcIndex.cpp	Tue Oct 08 17:57:22 2024 +0200
+++ b/Odbc/Plugins/OdbcIndex.cpp	Tue Oct 15 15:52:39 2024 +0200
@@ -714,5 +714,13 @@
     // TODO-FIND
     throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
   }
+
+  void OdbcIndex::ExecuteCount(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 Oct 08 17:57:22 2024 +0200
+++ b/Odbc/Plugins/OdbcIndex.h	Tue Oct 15 15:52:39 2024 +0200
@@ -101,6 +101,10 @@
     virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
                              DatabaseManager& manager,
                              const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
+
+    virtual void ExecuteCount(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                              DatabaseManager& manager,
+                              const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
 #endif
   };
 }
--- a/SQLite/Plugins/SQLiteIndex.cpp	Tue Oct 08 17:57:22 2024 +0200
+++ b/SQLite/Plugins/SQLiteIndex.cpp	Tue Oct 15 15:52:39 2024 +0200
@@ -278,5 +278,13 @@
     // TODO-FIND
     throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
   }
+
+  void SQLiteIndex::ExecuteCount(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 Oct 08 17:57:22 2024 +0200
+++ b/SQLite/Plugins/SQLiteIndex.h	Tue Oct 15 15:52:39 2024 +0200
@@ -76,6 +76,10 @@
     virtual void ExecuteFind(Orthanc::DatabasePluginMessages::TransactionResponse& response,
                              DatabaseManager& manager,
                              const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
+
+    virtual void ExecuteCount(Orthanc::DatabasePluginMessages::TransactionResponse& response,
+                              DatabaseManager& manager,
+                              const Orthanc::DatabasePluginMessages::Find_Request& request) ORTHANC_OVERRIDE;
 #endif
   };
 }