changeset 5522:dd430a1b21fe pg-transactions

simplifying StatelessDatabaseOperations
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 30 Jan 2024 09:41:06 +0100
parents 0d0f8788884a
children d82cc7c9720a
files OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.h
diffstat 2 files changed, 21 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Jan 30 09:29:12 2024 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Jan 30 09:41:06 2024 +0100
@@ -607,7 +607,7 @@
           
           Transaction transaction(db_, *factory_, TransactionType_ReadOnly);  // TODO - Only if not "TransactionType_Implicit"
           {
-            ReadOnlyTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext(), db_.GetDatabaseCapabilities());
+            ReadOnlyTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext());
             readOperations->Apply(t);
           }
           transaction.Commit();
@@ -618,7 +618,7 @@
           
           Transaction transaction(db_, *factory_, TransactionType_ReadWrite);
           {
-            ReadWriteTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext(), db_.GetDatabaseCapabilities());
+            ReadWriteTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext());
             writeOperations->Apply(t);
           }
           transaction.Commit();
@@ -721,7 +721,8 @@
       bool&, ExpandedResource&, const std::string&, ResourceType, const std::set<DicomTag>&, ExpandResourceFlags>
     {
     private:
-  
+      bool hasLabelsSupport_;
+
       static bool LookupStringMetadata(std::string& result,
                                        const std::map<MetadataType, std::string>& metadata,
                                        MetadataType type)
@@ -763,6 +764,11 @@
 
 
     public:
+      Operations(bool hasLabelsSupport) :
+        hasLabelsSupport_(hasLabelsSupport)
+      {
+      }
+
       virtual void ApplyTuple(ReadOnlyTransaction& transaction,
                               const Tuple& tuple) ORTHANC_OVERRIDE
       {
@@ -939,7 +945,7 @@
           }
 
           if ((expandFlags & ExpandResourceFlags_IncludeLabels) &&
-              transaction.GetDatabaseCapabilities().HasLabelsSupport())
+              hasLabelsSupport_)
           {
             transaction.ListLabels(target.labels_, internalId);
           }
@@ -978,7 +984,7 @@
     };
 
     bool found;
-    Operations operations;
+    Operations operations(db_.GetDatabaseCapabilities().HasLabelsSupport());
     operations.Apply(*this, found, target, publicId, level, requestedTags, expandFlags);
     return found;
   }
@@ -2471,13 +2477,16 @@
       uint64_t       newValue_;
       GlobalProperty sequence_;
       bool           shared_;
+      bool           hasAtomicIncrementGlobalProperty_;
 
     public:
       Operations(GlobalProperty sequence,
-                 bool shared) :
+                 bool shared,
+                 bool hasAtomicIncrementGlobalProperty) :
         newValue_(0),  // Dummy initialization
         sequence_(sequence),
-        shared_(shared)
+        shared_(shared),
+        hasAtomicIncrementGlobalProperty_(hasAtomicIncrementGlobalProperty)
       {
       }
 
@@ -2488,7 +2497,7 @@
 
       virtual void Apply(ReadWriteTransaction& transaction) ORTHANC_OVERRIDE
       {
-        if (transaction.GetDatabaseCapabilities().HasAtomicIncrementGlobalProperty())
+        if (hasAtomicIncrementGlobalProperty_)
         {
           newValue_ = static_cast<uint64_t>(transaction.IncrementGlobalProperty(sequence_, shared_, 1));
         }
@@ -2524,7 +2533,7 @@
       }
     };
 
-    Operations operations(sequence, shared);
+    Operations operations(sequence, shared, GetDatabaseCapabilities().HasAtomicIncrementGlobalProperty());
     Apply(operations);
     assert(operations.GetNewValue() != 0);
     return operations.GetNewValue();
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Tue Jan 30 09:29:12 2024 +0100
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Tue Jan 30 09:41:06 2024 +0100
@@ -176,17 +176,14 @@
     {
     private:
       ITransactionContext&  context_;
-      const IDatabaseWrapper::Capabilities& dbCapabilities_;
 
     protected:
       IDatabaseWrapper::ITransaction&  transaction_;
       
     public:
       explicit ReadOnlyTransaction(IDatabaseWrapper::ITransaction& transaction,
-                                   ITransactionContext& context,
-                                   const IDatabaseWrapper::Capabilities& dbCapabilities) :
+                                   ITransactionContext& context) :
         context_(context),
-        dbCapabilities_(dbCapabilities),
         transaction_(transaction)
       {
       }
@@ -196,11 +193,6 @@
         return context_;
       }
 
-      const IDatabaseWrapper::Capabilities& GetDatabaseCapabilities() const
-      {
-        return dbCapabilities_;
-      }
-
       /**
        * Higher-level constructions
        **/
@@ -391,9 +383,8 @@
     {
     public:
       ReadWriteTransaction(IDatabaseWrapper::ITransaction& transaction,
-                           ITransactionContext& context,
-                           const IDatabaseWrapper::Capabilities& dbCapabilities) :
-        ReadOnlyTransaction(transaction, context, dbCapabilities)
+                           ITransactionContext& context) :
+        ReadOnlyTransaction(transaction, context)
       {
       }