changeset 497:8e6a95629a22

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Apr 2024 10:54:26 +0200
parents 4a76aca03774
children 832a902770ba
files Framework/PostgreSQL/PostgreSQLDatabase.h Framework/PostgreSQL/PostgreSQLParameters.cpp Framework/PostgreSQL/PostgreSQLParameters.h Framework/PostgreSQL/PostgreSQLTransaction.cpp
diffstat 4 files changed, 42 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/Framework/PostgreSQL/PostgreSQLDatabase.h	Tue Apr 02 20:21:04 2024 +0200
+++ b/Framework/PostgreSQL/PostgreSQLDatabase.h	Wed Apr 03 10:54:26 2024 +0200
@@ -109,15 +109,14 @@
     static PostgreSQLDatabase* CreateDatabaseConnection(const PostgreSQLParameters& parameters);
 
   protected:
-    const char* GetReadWriteTransactionStatement() const
+    const std::string GetReadWriteTransactionStatement() const
     {
       return parameters_.GetReadWriteTransactionStatement();
     }
 
-    const char* GetReadOnlyTransactionStatement() const
+    const std::string GetReadOnlyTransactionStatement() const
     {
       return parameters_.GetReadOnlyTransactionStatement();
     }
-
   };
 }
--- a/Framework/PostgreSQL/PostgreSQLParameters.cpp	Tue Apr 02 20:21:04 2024 +0200
+++ b/Framework/PostgreSQL/PostgreSQLParameters.cpp	Wed Apr 03 10:54:26 2024 +0200
@@ -199,6 +199,36 @@
     database_ = database;
   }
 
+  const std::string PostgreSQLParameters::GetReadWriteTransactionStatement() const
+  {
+    switch (isolationMode_)
+    {
+      case IsolationMode_ReadCommited:
+        return "SET TRANSACTION ISOLATION LEVEL READ COMMITTED READ WRITE";
+
+      case IsolationMode_Serializable:
+        return "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE";
+
+      default:
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+    }
+  }
+
+  const std::string PostgreSQLParameters::GetReadOnlyTransactionStatement() const
+  {
+    switch (isolationMode_)
+    {
+      case IsolationMode_ReadCommited:
+        return "SET TRANSACTION ISOLATION LEVEL READ COMMITTED READ ONLY";
+
+      case IsolationMode_Serializable:
+        return "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY";
+
+      default:
+        throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);
+    }
+  }
+
   void PostgreSQLParameters::Format(std::string& target) const
   {
     if (uri_.empty())
--- a/Framework/PostgreSQL/PostgreSQLParameters.h	Tue Apr 02 20:21:04 2024 +0200
+++ b/Framework/PostgreSQL/PostgreSQLParameters.h	Wed Apr 03 10:54:26 2024 +0200
@@ -137,31 +137,9 @@
       isolationMode_ = isolationMode;
     }
 
-    const char* GetReadWriteTransactionStatement() const
-    {
-      switch (isolationMode_)
-      {
-        case IsolationMode_ReadCommited:
-          return "SET TRANSACTION ISOLATION LEVEL READ COMMITTED READ WRITE";
-        case IsolationMode_Serializable:
-          return "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ WRITE";
-        default:
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
-      }
-    }
+    const std::string GetReadWriteTransactionStatement() const;
 
-    const char* GetReadOnlyTransactionStatement() const
-    {
-      switch (isolationMode_)
-      {
-        case IsolationMode_ReadCommited:
-          return "SET TRANSACTION ISOLATION LEVEL READ COMMITTED READ ONLY";
-        case IsolationMode_Serializable:
-          return "SET TRANSACTION ISOLATION LEVEL SERIALIZABLE READ ONLY";
-        default:
-          throw Orthanc::OrthancException(Orthanc::ErrorCode_NotImplemented);
-      }
-    }
+    const std::string GetReadOnlyTransactionStatement() const;
 
     void SetVerboseEnabled(bool enabled)
     {
--- a/Framework/PostgreSQL/PostgreSQLTransaction.cpp	Tue Apr 02 20:21:04 2024 +0200
+++ b/Framework/PostgreSQL/PostgreSQLTransaction.cpp	Wed Apr 03 10:54:26 2024 +0200
@@ -71,21 +71,25 @@
     {
       case TransactionType_ReadWrite:
       {
-        const std::string& statement = database_.GetReadWriteTransactionStatement();
+        std::string statement = database_.GetReadWriteTransactionStatement();
         if (!statement.empty()) // if not defined, will use the default DB transaction isolation level
         {
           database_.ExecuteMultiLines(statement);
         }
-       }; break;
+
+        break;
+      }
 
       case TransactionType_ReadOnly:
       {
-        const std::string& statement = database_.GetReadOnlyTransactionStatement();
+        std::string statement = database_.GetReadOnlyTransactionStatement();
         if (!statement.empty()) // if not defined, will use the default DB transaction isolation level
         {
           database_.ExecuteMultiLines(statement);
         }
-       }; break;
+
+        break;
+      }
 
       default:
         throw Orthanc::OrthancException(Orthanc::ErrorCode_ParameterOutOfRange);