changeset 5517:0d433132b249 pg-transactions

refactoring IDatabaseWrapper::Capabilities
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 29 Jan 2024 19:19:52 +0100
parents d9c9f3c57f4f
children bbe45a71f5cd
files OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp OrthancServer/Plugins/Engine/OrthancPluginDatabase.h OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.h OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.h OrthancServer/Sources/Database/IDatabaseWrapper.h OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h OrthancServer/Sources/Database/StatelessDatabaseOperations.h
diffstat 10 files changed, 72 insertions(+), 70 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Mon Jan 29 19:19:52 2024 +0100
@@ -243,7 +243,7 @@
       that_.activeTransaction_ = NULL;
     }
 
-    virtual const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const ORTHANC_OVERRIDE
+    virtual const Capabilities GetDatabaseCapabilities() const ORTHANC_OVERRIDE
     {
       return that_.GetDatabaseCapabilities();
     }
@@ -1477,8 +1477,7 @@
     payload_(payload),
     activeTransaction_(NULL),
     fastGetTotalSize_(false),
-    currentDiskSize_(0),
-    dbCapabilities_(false, false, false, false, false, false)
+    currentDiskSize_(0)
   {
     static const char* const MISSING = "  Missing extension in database index plugin: ";
     
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabase.h	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabase.h	Mon Jan 29 19:19:52 2024 +0100
@@ -104,7 +104,7 @@
     virtual void Upgrade(unsigned int targetVersion,
                          IStorageArea& storageArea) ORTHANC_OVERRIDE;    
 
-    const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const ORTHANC_OVERRIDE
+    virtual const Capabilities GetDatabaseCapabilities() const ORTHANC_OVERRIDE
     {
       return dbCapabilities_;
     }
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.cpp	Mon Jan 29 19:19:52 2024 +0100
@@ -278,7 +278,7 @@
       }
     }
     
-    virtual const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const ORTHANC_OVERRIDE
+    virtual const Capabilities GetDatabaseCapabilities() const ORTHANC_OVERRIDE
     {
       return that_.GetDatabaseCapabilities();
     }
@@ -1087,13 +1087,7 @@
     library_(library),
     errorDictionary_(errorDictionary),
     database_(database),
-    serverIdentifier_(serverIdentifier),
-    dbCapabilities_(false,  /* hasFlushToDisk */
-                    false,  /* revision support is updated in open() */ 
-                    false,  /* hasLabelsSupport */
-                    false,  /* hasAtomicIncrementGlobalProperty */
-                    false, /* hasUpdateAndGetStatistics */
-                    false  /* hasMeasureLatency */)
+    serverIdentifier_(serverIdentifier)
 
   {
     CLOG(INFO, PLUGINS) << "Identifier of this Orthanc server for the global properties "
@@ -1205,7 +1199,7 @@
     // update the db capabilities
     uint8_t hasRevisions;
     CheckSuccess(backend_.hasRevisionsSupport(database_, &hasRevisions));
-    dbCapabilities_.hasRevisionsSupport_ = (hasRevisions != 0);
+    dbCapabilities_.SetRevisionsSupport(hasRevisions != 0);
   }
 
 
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.h	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV3.h	Mon Jan 29 19:19:52 2024 +0100
@@ -82,11 +82,10 @@
       throw OrthancException(ErrorCode_NotImplemented);  // only implemented in V4
     }
 
-    const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const ORTHANC_OVERRIDE
+    virtual const Capabilities GetDatabaseCapabilities() const ORTHANC_OVERRIDE
     {
       return dbCapabilities_;
     }
-
   };
 }
 
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.cpp	Mon Jan 29 19:19:52 2024 +0100
@@ -305,7 +305,7 @@
       }
     }
 
-    virtual const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const ORTHANC_OVERRIDE
+    virtual const Capabilities GetDatabaseCapabilities() const ORTHANC_OVERRIDE
     {
       return database_.GetDatabaseCapabilities();
     }
@@ -1292,8 +1292,7 @@
     definition_(database),
     serverIdentifier_(serverIdentifier),
     open_(false),
-    databaseVersion_(0),
-    dbCapabilities_(false, false, false, false, false, false) // updated in Open()
+    databaseVersion_(0)
   {
     CLOG(INFO, PLUGINS) << "Identifier of this Orthanc server for the global properties "
                         << "of the custom database: \"" << serverIdentifier << "\"";
@@ -1363,12 +1362,12 @@
       
       const ::Orthanc::DatabasePluginMessages::GetSystemInformation_Response& systemInfo = response.get_system_information();
       databaseVersion_ = systemInfo.database_version();
-      dbCapabilities_.hasFlushToDisk_ = systemInfo.supports_flush_to_disk();
-      dbCapabilities_.hasRevisionsSupport_ = systemInfo.supports_revisions();
-      dbCapabilities_.hasLabelsSupport_ = systemInfo.supports_labels();
-      dbCapabilities_.hasAtomicIncrementGlobalProperty_ = systemInfo.supports_increment_global_property();
-      dbCapabilities_.hasUpdateAndGetStatistics_ = systemInfo.has_update_and_get_statistics();
-      dbCapabilities_.hasMeasureLatency_ = systemInfo.has_measure_latency();
+      dbCapabilities_.SetFlushToDisk(systemInfo.supports_flush_to_disk());
+      dbCapabilities_.SetRevisionsSupport(systemInfo.supports_revisions());
+      dbCapabilities_.SetLabelsSupport(systemInfo.supports_labels());
+      dbCapabilities_.SetAtomicIncrementGlobalProperty(systemInfo.supports_increment_global_property());
+      dbCapabilities_.SetUpdateAndGetStatistics(systemInfo.has_update_and_get_statistics());
+      dbCapabilities_.SetMeasureLatency(systemInfo.has_measure_latency());
     }
 
     open_ = true;
@@ -1491,7 +1490,8 @@
     }
   }
 
-  const IDatabaseWrapper::Capabilities& OrthancPluginDatabaseV4::GetDatabaseCapabilities() const
+
+  const IDatabaseWrapper::Capabilities OrthancPluginDatabaseV4::GetDatabaseCapabilities() const
   {
     if (!open_)
     {
@@ -1502,6 +1502,4 @@
       return dbCapabilities_;
     }
   }
-
-
 }
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.h	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabaseV4.h	Mon Jan 29 19:19:52 2024 +0100
@@ -91,7 +91,7 @@
 
     virtual uint64_t MeasureLatency() ORTHANC_OVERRIDE;
 
-    virtual const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const ORTHANC_OVERRIDE;
+    virtual const Capabilities GetDatabaseCapabilities() const ORTHANC_OVERRIDE;
   };
 }
 
--- a/OrthancServer/Sources/Database/IDatabaseWrapper.h	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Sources/Database/IDatabaseWrapper.h	Mon Jan 29 19:19:52 2024 +0100
@@ -39,19 +39,12 @@
   class DatabaseConstraint;
   class ResourcesContent;
 
-  class OrthancPluginDatabaseV3;
-  class OrthancPluginDatabaseV4;
-  
   class IDatabaseWrapper : public boost::noncopyable
   {
   public:
-
-    struct Capabilities
+    class Capabilities
     {
-      friend OrthancPluginDatabaseV3;
-      friend OrthancPluginDatabaseV4;
-
-    protected:
+    private:
       bool hasFlushToDisk_;
       bool hasRevisionsSupport_;
       bool hasLabelsSupport_;
@@ -60,52 +53,77 @@
       bool hasMeasureLatency_;
 
     public:
-      Capabilities(bool hasFlushToDisk,
-                   bool hasRevisionsSupport,
-                   bool hasLabelsSupport,
-                   bool hasAtomicIncrementGlobalProperty,
-                   bool hasUpdateAndGetStatistics,
-                   bool hasMeasureLatency)
-      : hasFlushToDisk_(hasFlushToDisk),
-        hasRevisionsSupport_(hasRevisionsSupport),
-        hasLabelsSupport_(hasLabelsSupport),
-        hasAtomicIncrementGlobalProperty_(hasAtomicIncrementGlobalProperty),
-        hasUpdateAndGetStatistics_(hasUpdateAndGetStatistics),
-        hasMeasureLatency_(hasMeasureLatency)
+      Capabilities() :
+        hasFlushToDisk_(false),
+        hasRevisionsSupport_(false),
+        hasLabelsSupport_(false),
+        hasAtomicIncrementGlobalProperty_(false),
+        hasUpdateAndGetStatistics_(false),
+        hasMeasureLatency_(false)
       {
       }
 
+      void SetFlushToDisk(bool value)
+      {
+        hasFlushToDisk_ = value;
+      }
+
       bool HasFlushToDisk() const
       {
         return hasFlushToDisk_;
       }
 
+      void SetRevisionsSupport(bool value)
+      {
+        hasRevisionsSupport_ = value;
+      }
+
       bool HasRevisionsSupport() const
       {
         return hasRevisionsSupport_;
       }
 
+      void SetLabelsSupport(bool value)
+      {
+        hasLabelsSupport_ = value;
+      }
+
       bool HasLabelsSupport() const
       {
         return hasLabelsSupport_;
       }
 
+      void SetAtomicIncrementGlobalProperty(bool value)
+      {
+        hasAtomicIncrementGlobalProperty_ = value;
+      }
+
       bool HasAtomicIncrementGlobalProperty() const
       {
         return hasAtomicIncrementGlobalProperty_;
       }
 
+      void SetUpdateAndGetStatistics(bool value)
+      {
+        hasUpdateAndGetStatistics_ = value;
+      }
+
       bool HasUpdateAndGetStatistics() const
       {
         return hasUpdateAndGetStatistics_;
       }
 
+      void SetMeasureLatency(bool value)
+      {
+        hasMeasureLatency_ = value;
+      }
+
       bool HasMeasureLatency() const
       {
         return hasMeasureLatency_;
       }
+    };
 
-    };
 
     struct CreateInstanceResult : public boost::noncopyable
     {
@@ -321,8 +339,8 @@
 
       // List all the labels that are present in any resource
       virtual void ListAllLabels(std::set<std::string>& target) = 0;
-    
-      virtual const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const = 0;
+
+      virtual const Capabilities GetDatabaseCapabilities() const = 0;
 
       virtual int64_t IncrementGlobalProperty(GlobalProperty property,
                                               int64_t increment,
@@ -355,7 +373,7 @@
     virtual void Upgrade(unsigned int targetVersion,
                          IStorageArea& storageArea) = 0;
 
-    virtual const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const = 0;
+    virtual const Capabilities GetDatabaseCapabilities() const = 0;
 
     virtual uint64_t MeasureLatency() = 0;
   };
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Mon Jan 29 19:19:52 2024 +0100
@@ -316,7 +316,7 @@
     {
     }
 
-    virtual const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const ORTHANC_OVERRIDE
+    virtual const Capabilities GetDatabaseCapabilities() const ORTHANC_OVERRIDE
     {
       return dbCapabilities_;
     }
@@ -1331,14 +1331,11 @@
   SQLiteDatabaseWrapper::SQLiteDatabaseWrapper(const std::string& path) : 
     activeTransaction_(NULL), 
     signalRemainingAncestor_(NULL),
-    version_(0),
-    dbCapabilities_(true,  /* hasFlushToDisk */
-                    false, /* hasRevisionsSupport TODO: implement revisions in SQLite */ 
-                    true,  /* hasLabelsSupport */
-                    false, /* hasAtomicIncrementGlobalProperty */
-                    false, /* hasUpdateAndGetStatistics */
-                    false  /* hasMeasureLatency */)
+    version_(0)
   {
+    // TODO: implement revisions in SQLite
+    dbCapabilities_.SetFlushToDisk(true);
+    dbCapabilities_.SetLabelsSupport(true);
     db_.Open(path);
   }
 
@@ -1346,14 +1343,11 @@
   SQLiteDatabaseWrapper::SQLiteDatabaseWrapper() : 
     activeTransaction_(NULL), 
     signalRemainingAncestor_(NULL),
-    version_(0),
-    dbCapabilities_(true,  /* hasFlushToDisk */
-                    false, /* hasRevisionsSupport TODO: implement revisions in SQLite */ 
-                    true,  /* hasLabelsSupport */
-                    false, /* hasAtomicIncrementGlobalProperty */
-                    false, /* hasUpdateAndGetStatistics */
-                    false  /* hasMeasureLatency */)
+    version_(0)
   {
+    // TODO: implement revisions in SQLite
+    dbCapabilities_.SetFlushToDisk(true);
+    dbCapabilities_.SetLabelsSupport(true);
     db_.OpenInMemory();
   }
 
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h	Mon Jan 29 19:19:52 2024 +0100
@@ -88,7 +88,7 @@
     virtual void Upgrade(unsigned int targetVersion,
                          IStorageArea& storageArea) ORTHANC_OVERRIDE;
 
-    virtual const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const ORTHANC_OVERRIDE
+    virtual const Capabilities GetDatabaseCapabilities() const ORTHANC_OVERRIDE
     {
       return dbCapabilities_;
     }
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Mon Jan 29 18:18:07 2024 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Mon Jan 29 19:19:52 2024 +0100
@@ -591,7 +591,7 @@
       return db_.GetDatabaseVersion();
     }
 
-    const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const
+    const IDatabaseWrapper::Capabilities GetDatabaseCapabilities() const
     {
       return db_.GetDatabaseCapabilities();
     }