changeset 5237:cd2258ca7894 db-protobuf

log about missing support for labels
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 05 Apr 2023 09:07:47 +0200
parents 5e0db9eac1f8
children 367e8af46cfd
files OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp OrthancServer/Sources/Database/StatelessDatabaseOperations.h OrthancServer/Sources/main.cpp
diffstat 3 files changed, 22 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Tue Apr 04 21:43:37 2023 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp	Wed Apr 05 09:07:47 2023 +0200
@@ -607,7 +607,7 @@
           
           Transaction transaction(db_, *factory_, TransactionType_ReadOnly);  // TODO - Only if not "TransactionType_Implicit"
           {
-            ReadOnlyTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext());
+            ReadOnlyTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext(), db_.HasLabelsSupport());
             readOperations->Apply(t);
           }
           transaction.Commit();
@@ -618,7 +618,7 @@
           
           Transaction transaction(db_, *factory_, TransactionType_ReadWrite);
           {
-            ReadWriteTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext());
+            ReadWriteTransaction t(transaction.GetDatabaseTransaction(), transaction.GetContext(), db_.HasLabelsSupport());
             writeOperations->Apply(t);
           }
           transaction.Commit();
@@ -938,7 +938,8 @@
             }
           }
 
-          if (expandFlags & ExpandResourceFlags_IncludeLabels)
+          if ((expandFlags & ExpandResourceFlags_IncludeLabels) &&
+              transaction.HasLabelsSupport())
           {
             transaction.ListLabels(target.labels_, internalId);
           }
--- a/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Tue Apr 04 21:43:37 2023 +0200
+++ b/OrthancServer/Sources/Database/StatelessDatabaseOperations.h	Wed Apr 05 09:07:47 2023 +0200
@@ -166,14 +166,17 @@
     {
     private:
       ITransactionContext&  context_;
+      bool                  hasLabelsSupport_;
       
     protected:
       IDatabaseWrapper::ITransaction&  transaction_;
       
     public:
       explicit ReadOnlyTransaction(IDatabaseWrapper::ITransaction& transaction,
-                                   ITransactionContext& context) :
+                                   ITransactionContext& context,
+                                   bool hasLabelsSupport) :
         context_(context),
+        hasLabelsSupport_(hasLabelsSupport),
         transaction_(transaction)
       {
       }
@@ -183,6 +186,11 @@
         return context_;
       }
 
+      bool HasLabelsSupport() const
+      {
+        return hasLabelsSupport_;
+      }
+
       /**
        * Higher-level constructions
        **/
@@ -367,8 +375,9 @@
     {
     public:
       ReadWriteTransaction(IDatabaseWrapper::ITransaction& transaction,
-                           ITransactionContext& context) :
-        ReadOnlyTransaction(transaction, context)
+                           ITransactionContext& context,
+                           bool hasLabelsSupport) :
+        ReadOnlyTransaction(transaction, context, hasLabelsSupport)
       {
       }
 
--- a/OrthancServer/Sources/main.cpp	Tue Apr 04 21:43:37 2023 +0200
+++ b/OrthancServer/Sources/main.cpp	Wed Apr 05 09:07:47 2023 +0200
@@ -1664,8 +1664,12 @@
     }
   }
 
-  bool success = ConfigureServerContext
-    (database, storageArea, plugins, loadJobsFromDatabase);
+  if (!database.HasLabelsSupport())
+  {
+    LOG(WARNING) << "The custom database back-end has *no* support for labels";
+  }
+
+  bool success = ConfigureServerContext(database, storageArea, plugins, loadJobsFromDatabase);
 
   database.Close();