changeset 3056:6c5d4281da4a db-changes

removal of SQLiteDatabaseWrapper::GetAllInternalIds
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 21 Dec 2018 13:48:04 +0100
parents 71ac4f28176f
children 87f52703ebbc
files OrthancServer/IDatabaseWrapper.h OrthancServer/SQLiteDatabaseWrapper.cpp OrthancServer/SQLiteDatabaseWrapper.h OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.h OrthancServer/Search/Compatibility/SetOfResources.cpp OrthancServer/Search/Compatibility/SetOfResources.h
diffstat 6 files changed, 119 insertions(+), 133 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/IDatabaseWrapper.h	Fri Dec 21 13:36:30 2018 +0100
+++ b/OrthancServer/IDatabaseWrapper.h	Fri Dec 21 13:48:04 2018 +0100
@@ -102,10 +102,6 @@
     virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
                                 int64_t id) = 0;
 
-    // TODO: REMOVE THIS
-    virtual void GetAllInternalIds(std::list<int64_t>& target,
-                                   ResourceType resourceType) = 0;
-
     virtual void GetAllPublicIds(std::list<std::string>& target,
                                  ResourceType resourceType) = 0;
 
--- a/OrthancServer/SQLiteDatabaseWrapper.cpp	Fri Dec 21 13:36:30 2018 +0100
+++ b/OrthancServer/SQLiteDatabaseWrapper.cpp	Fri Dec 21 13:48:04 2018 +0100
@@ -993,20 +993,6 @@
   }
 
 
-  void SQLiteDatabaseWrapper::GetAllInternalIds(std::list<int64_t>& target,
-                                                ResourceType resourceType)
-  {
-    SQLite::Statement s(db_, SQLITE_FROM_HERE, "SELECT internalId FROM Resources WHERE resourceType=?");
-    s.BindInt(0, resourceType);
-
-    target.clear();
-    while (s.Step())
-    {
-      target.push_back(s.ColumnInt64(0));
-    }
-  }
-
-
   void SQLiteDatabaseWrapper::GetAllPublicIds(std::list<std::string>& target,
                                               ResourceType resourceType)
   {
--- a/OrthancServer/SQLiteDatabaseWrapper.h	Fri Dec 21 13:36:30 2018 +0100
+++ b/OrthancServer/SQLiteDatabaseWrapper.h	Fri Dec 21 13:48:04 2018 +0100
@@ -283,10 +283,6 @@
     virtual uint64_t GetResourceCount(ResourceType resourceType)
       ORTHANC_OVERRIDE;
 
-    virtual void GetAllInternalIds(std::list<int64_t>& target,
-                                   ResourceType resourceType)
-      ORTHANC_OVERRIDE;
-
     virtual void GetAllPublicIds(std::list<std::string>& target,
                                  ResourceType resourceType)
       ORTHANC_OVERRIDE;
--- a/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.h	Fri Dec 21 13:36:30 2018 +0100
+++ b/OrthancServer/Search/Compatibility/CompatibilityDatabaseWrapper.h	Fri Dec 21 13:48:04 2018 +0100
@@ -55,6 +55,9 @@
     class CompatibilityDatabaseWrapper : public IDatabaseWrapper
     {
     public:
+      virtual void GetAllInternalIds(std::list<int64_t>& target,
+                                     ResourceType resourceType) = 0;
+
       virtual void LookupIdentifier(std::list<int64_t>& result,
                                     ResourceType level,
                                     const DicomTag& tag,
--- a/OrthancServer/Search/Compatibility/SetOfResources.cpp	Fri Dec 21 13:36:30 2018 +0100
+++ b/OrthancServer/Search/Compatibility/SetOfResources.cpp	Fri Dec 21 13:48:04 2018 +0100
@@ -39,118 +39,121 @@
 
 namespace Orthanc
 {
-  void SetOfResources::Intersect(const std::list<int64_t>& resources)
+  namespace Compatibility
   {
-    if (resources_.get() == NULL)
+    void SetOfResources::Intersect(const std::list<int64_t>& resources)
     {
-      resources_.reset(new Resources);
-
-      for (std::list<int64_t>::const_iterator
-             it = resources.begin(); it != resources.end(); ++it)
+      if (resources_.get() == NULL)
       {
-        resources_->insert(*it);
-      }
-    }
-    else
-    {
-      std::auto_ptr<Resources> filtered(new Resources);
+        resources_.reset(new Resources);
 
-      for (std::list<int64_t>::const_iterator
-             it = resources.begin(); it != resources.end(); ++it)
-      {
-        if (resources_->find(*it) != resources_->end())
+        for (std::list<int64_t>::const_iterator
+               it = resources.begin(); it != resources.end(); ++it)
         {
-          filtered->insert(*it);
+          resources_->insert(*it);
         }
       }
-
-      resources_ = filtered;
-    }
-  }
-
+      else
+      {
+        std::auto_ptr<Resources> filtered(new Resources);
 
-  void SetOfResources::GoDown()
-  {
-    if (level_ == ResourceType_Instance)
-    {
-      throw OrthancException(ErrorCode_BadSequenceOfCalls);
+        for (std::list<int64_t>::const_iterator
+               it = resources.begin(); it != resources.end(); ++it)
+        {
+          if (resources_->find(*it) != resources_->end())
+          {
+            filtered->insert(*it);
+          }
+        }
+
+        resources_ = filtered;
+      }
     }
 
-    if (resources_.get() != NULL)
+
+    void SetOfResources::GoDown()
     {
-      std::auto_ptr<Resources> children(new Resources);
-
-      for (Resources::const_iterator it = resources_->begin(); 
-           it != resources_->end(); ++it)
+      if (level_ == ResourceType_Instance)
       {
-        std::list<int64_t> tmp;
-        database_.GetChildrenInternalId(tmp, *it);
-
-        for (std::list<int64_t>::const_iterator
-               child = tmp.begin(); child != tmp.end(); ++child)
-        {
-          children->insert(*child);
-        }
+        throw OrthancException(ErrorCode_BadSequenceOfCalls);
       }
 
-      resources_ = children;
-    }
+      if (resources_.get() != NULL)
+      {
+        std::auto_ptr<Resources> children(new Resources);
 
-    switch (level_)
-    {
-      case ResourceType_Patient:
-        level_ = ResourceType_Study;
-        break;
+        for (Resources::const_iterator it = resources_->begin(); 
+             it != resources_->end(); ++it)
+        {
+          std::list<int64_t> tmp;
+          database_.GetChildrenInternalId(tmp, *it);
+
+          for (std::list<int64_t>::const_iterator
+                 child = tmp.begin(); child != tmp.end(); ++child)
+          {
+            children->insert(*child);
+          }
+        }
 
-      case ResourceType_Study:
-        level_ = ResourceType_Series;
-        break;
+        resources_ = children;
+      }
+
+      switch (level_)
+      {
+        case ResourceType_Patient:
+          level_ = ResourceType_Study;
+          break;
 
-      case ResourceType_Series:
-        level_ = ResourceType_Instance;
-        break;
+        case ResourceType_Study:
+          level_ = ResourceType_Series;
+          break;
 
-      default:
-        throw OrthancException(ErrorCode_InternalError);
+        case ResourceType_Series:
+          level_ = ResourceType_Instance;
+          break;
+
+        default:
+          throw OrthancException(ErrorCode_InternalError);
+      }
     }
-  }
 
 
-  void SetOfResources::Flatten(std::list<std::string>& result)
-  {
-    result.clear();
-      
-    if (resources_.get() == NULL)
+    void SetOfResources::Flatten(std::list<std::string>& result)
     {
-      // All the resources of this level are part of the filter
-      database_.GetAllPublicIds(result, level_);
-    }
-    else
-    {
-      for (Resources::const_iterator it = resources_->begin(); 
-           it != resources_->end(); ++it)
+      result.clear();
+      
+      if (resources_.get() == NULL)
       {
-        result.push_back(database_.GetPublicId(*it));
+        // All the resources of this level are part of the filter
+        database_.GetAllPublicIds(result, level_);
+      }
+      else
+      {
+        for (Resources::const_iterator it = resources_->begin(); 
+             it != resources_->end(); ++it)
+        {
+          result.push_back(database_.GetPublicId(*it));
+        }
       }
     }
-  }
 
 
-  void SetOfResources::Flatten(std::list<int64_t>& result)
-  {
-    result.clear();
-      
-    if (resources_.get() == NULL)
+    void SetOfResources::Flatten(std::list<int64_t>& result)
     {
-      // All the resources of this level are part of the filter
-      database_.GetAllInternalIds(result, level_);
-    }
-    else
-    {
-      for (Resources::const_iterator it = resources_->begin(); 
-           it != resources_->end(); ++it)
+      result.clear();
+      
+      if (resources_.get() == NULL)
       {
-        result.push_back(*it);
+        // All the resources of this level are part of the filter
+        database_.GetAllInternalIds(result, level_);
+      }
+      else
+      {
+        for (Resources::const_iterator it = resources_->begin(); 
+             it != resources_->end(); ++it)
+        {
+          result.push_back(*it);
+        }
       }
     }
   }
--- a/OrthancServer/Search/Compatibility/SetOfResources.h	Fri Dec 21 13:36:30 2018 +0100
+++ b/OrthancServer/Search/Compatibility/SetOfResources.h	Fri Dec 21 13:48:04 2018 +0100
@@ -33,47 +33,49 @@
 
 #pragma once
 
-#include "../../IDatabaseWrapper.h"
+#include "CompatibilityDatabaseWrapper.h"
 
 #include <set>
-#include <boost/noncopyable.hpp>
 #include <memory>
 
 namespace Orthanc
 {
-  class SetOfResources : public boost::noncopyable
+  namespace Compatibility
   {
-  private:
-    typedef std::set<int64_t>  Resources;
+    class SetOfResources : public boost::noncopyable
+    {
+    private:
+      typedef std::set<int64_t>  Resources;
 
-    IDatabaseWrapper&         database_;
-    ResourceType              level_;
-    std::auto_ptr<Resources>  resources_;
+      CompatibilityDatabaseWrapper&  database_;
+      ResourceType                   level_;
+      std::auto_ptr<Resources>       resources_;
     
-  public:
-    SetOfResources(IDatabaseWrapper& database,
-                   ResourceType level) : 
-      database_(database),
-      level_(level)
-    {
-    }
+    public:
+      SetOfResources(CompatibilityDatabaseWrapper& database,
+                     ResourceType level) : 
+        database_(database),
+        level_(level)
+      {
+      }
 
-    ResourceType GetLevel() const
-    {
-      return level_;
-    }
+      ResourceType GetLevel() const
+      {
+        return level_;
+      }
 
-    void Intersect(const std::list<int64_t>& resources);
+      void Intersect(const std::list<int64_t>& resources);
 
-    void GoDown();
+      void GoDown();
 
-    void Flatten(std::list<int64_t>& result);
+      void Flatten(std::list<int64_t>& result);
 
-    void Flatten(std::list<std::string>& result);
+      void Flatten(std::list<std::string>& result);
 
-    void Clear()
-    {
-      resources_.reset(NULL);
-    }
-  };
+      void Clear()
+      {
+        resources_.reset(NULL);
+      }
+    };
+  }
 }