changeset 4568:a3e6aa2b07b0 db-changes

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 08 Mar 2021 15:00:58 +0100
parents b812a5f2cef3
children 19ea4ecd6d9a
files OrthancServer/Sources/ServerIndex.cpp OrthancServer/Sources/ServerIndex.h
diffstat 2 files changed, 93 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerIndex.cpp	Mon Mar 08 14:41:29 2021 +0100
+++ b/OrthancServer/Sources/ServerIndex.cpp	Mon Mar 08 15:00:58 2021 +0100
@@ -1205,24 +1205,6 @@
   }
 
 
-  void ServerIndex::LogChange(ChangeType changeType,
-                              const std::string& publicId)
-  {
-    boost::mutex::scoped_lock lock(mutex_);
-    Transaction transaction(*this);
-
-    int64_t id;
-    ResourceType type;
-    if (!db_.LookupResource(id, type, publicId))
-    {
-      throw OrthancException(ErrorCode_UnknownResource);
-    }
-
-    LogChange(id, changeType, type, publicId);
-    transaction.Commit(0);
-  }
-
-
   void ServerIndex::UnstableResourcesMonitorThread(ServerIndex* that,
                                                    unsigned int threadSleep)
   {
@@ -1356,30 +1338,6 @@
   }
 
 
-  void ServerIndex::DeleteAttachment(const std::string& publicId,
-                                     FileContentType type)
-  {
-    boost::mutex::scoped_lock lock(mutex_);
-    Transaction t(*this);
-
-    ResourceType rtype;
-    int64_t id;
-    if (!db_.LookupResource(id, rtype, publicId))
-    {
-      throw OrthancException(ErrorCode_UnknownResource);
-    }
-
-    db_.DeleteAttachment(id, type);
-
-    if (IsUserContentType(type))
-    {
-      LogChange(id, ChangeType_UpdatedAttachment, rtype, publicId);
-    }
-
-    t.Commit(0);
-  }
-
-
   void ServerIndex::ReconstructInstance(const ParsedDicomFile& dicom)
   {
     DicomMap summary;
@@ -3403,4 +3361,85 @@
     Operations operations(property, value);
     Apply(operations);
   }
+
+
+  void ServerIndex::DeleteAttachment(const std::string& publicId,
+                                     FileContentType type)
+  {
+    class Operations : public IReadWriteOperations
+    {
+    private:
+      const std::string&  publicId_;
+      FileContentType     type_;
+      
+    public:
+      Operations(const std::string& publicId,
+                 FileContentType type) :
+        publicId_(publicId),
+        type_(type)
+      {
+      }
+        
+      virtual void Apply(ReadWriteTransaction& transaction,
+                         Listener& listener) ORTHANC_OVERRIDE
+      {
+        ResourceType rtype;
+        int64_t id;
+        if (!transaction.LookupResource(id, rtype, publicId_))
+        {
+          throw OrthancException(ErrorCode_UnknownResource);
+        }
+        else
+        {
+          transaction.DeleteAttachment(id, type_);
+          
+          if (IsUserContentType(type_))
+          {
+            transaction.LogChange(id, ChangeType_UpdatedAttachment, rtype, publicId_);
+          }
+        }
+      }
+    };
+
+    Operations operations(publicId, type);
+    Apply(operations);
+  }
+
+
+  void ServerIndex::LogChange(ChangeType changeType,
+                              const std::string& publicId)
+  {
+    class Operations : public IReadWriteOperations
+    {
+    private:
+      ChangeType          changeType_;
+      const std::string&  publicId_;
+      
+    public:
+      Operations(ChangeType changeType,
+                 const std::string& publicId) :
+        changeType_(changeType),
+        publicId_(publicId)
+      {
+      }
+        
+      virtual void Apply(ReadWriteTransaction& transaction,
+                         Listener& listener) ORTHANC_OVERRIDE
+      {
+        int64_t id;
+        ResourceType type;
+        if (!transaction.LookupResource(id, type, publicId_))
+        {
+          throw OrthancException(ErrorCode_UnknownResource);
+        }
+        else
+        {
+          transaction.LogChange(id, changeType_, type, publicId_);
+        }
+      }
+    };
+
+    Operations operations(changeType, publicId);
+    Apply(operations);
+  }
 }
--- a/OrthancServer/Sources/ServerIndex.h	Mon Mar 08 14:41:29 2021 +0100
+++ b/OrthancServer/Sources/ServerIndex.h	Mon Mar 08 15:00:58 2021 +0100
@@ -153,15 +153,9 @@
                       bool hasPixelDataOffset,
                       uint64_t pixelDataOffset);
 
-    void LogChange(ChangeType changeType,
-                   const std::string& publicId);
-
     StoreStatus AddAttachment(const FileInfo& attachment,
                               const std::string& publicId);
 
-    void DeleteAttachment(const std::string& publicId,
-                          FileContentType type);
-
     void ReconstructInstance(const ParsedDicomFile& dicom);
 
 
@@ -388,6 +382,12 @@
         db_.ClearExportedResources();
       }
 
+      void DeleteAttachment(int64_t id,
+                            FileContentType attachment)
+      {
+        return db_.DeleteAttachment(id, attachment);
+      }
+      
       void DeleteMetadata(int64_t id,
                           MetadataType type)
       {
@@ -595,5 +595,11 @@
 
     void SetGlobalProperty(GlobalProperty property,
                            const std::string& value);
+
+    void DeleteAttachment(const std::string& publicId,
+                          FileContentType type);
+
+    void LogChange(ChangeType changeType,
+                   const std::string& publicId);
   };
 }