changeset 4556:2a0f8031fb93 db-changes

removed abstraction IDatabaseWrapper::ITransaction::Begin(), must be done by IDatabaseWrapper::StartTransaction()
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 03 Mar 2021 17:31:30 +0100
parents 456ed3fcff81
children b6d4b735eb4d
files OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp OrthancServer/Sources/Database/IDatabaseWrapper.h OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp OrthancServer/Sources/ServerIndex.cpp
diffstat 4 files changed, 22 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Wed Mar 03 17:13:41 2021 +0100
+++ b/OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp	Wed Mar 03 17:31:30 2021 +0100
@@ -67,7 +67,7 @@
     {
     }
 
-    virtual void Begin() ORTHANC_OVERRIDE
+    void Begin()
     {
       CheckSuccess(that_.backend_.startTransaction(that_.payload_));
     }
@@ -891,7 +891,9 @@
 
   IDatabaseWrapper::ITransaction* OrthancPluginDatabase::StartTransaction()
   {
-    return new Transaction(*this);
+    std::unique_ptr<Transaction> transaction(new Transaction(*this));
+    transaction->Begin();
+    return transaction.release();
   }
 
 
--- a/OrthancServer/Sources/Database/IDatabaseWrapper.h	Wed Mar 03 17:13:41 2021 +0100
+++ b/OrthancServer/Sources/Database/IDatabaseWrapper.h	Wed Mar 03 17:31:30 2021 +0100
@@ -61,8 +61,6 @@
       {
       }
 
-      virtual void Begin() = 0;
-
       virtual void Rollback() = 0;
 
       virtual void Commit(int64_t fileSizeDelta) = 0;
--- a/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Wed Mar 03 17:13:41 2021 +0100
+++ b/OrthancServer/Sources/Database/SQLiteDatabaseWrapper.cpp	Wed Mar 03 17:31:30 2021 +0100
@@ -60,17 +60,17 @@
       {
       }
 
-      virtual const char* GetName() const
+      virtual const char* GetName() const ORTHANC_OVERRIDE
       {
         return "SignalFileDeleted";
       }
 
-      virtual unsigned int GetCardinality() const
+      virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE
       {
         return 7;
       }
 
-      virtual void Compute(SQLite::FunctionContext& context)
+      virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE
       {
         std::string uncompressedMD5, compressedMD5;
 
@@ -107,17 +107,17 @@
       {
       }
 
-      virtual const char* GetName() const
+      virtual const char* GetName() const ORTHANC_OVERRIDE
       {
         return "SignalResourceDeleted";
       }
 
-      virtual unsigned int GetCardinality() const
+      virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE
       {
         return 2;
       }
 
-      virtual void Compute(SQLite::FunctionContext& context)
+      virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE
       {
         ResourceType type = static_cast<ResourceType>(context.GetIntValue(1));
         ServerIndexChange change(ChangeType_Deleted, type, context.GetStringValue(0));
@@ -143,17 +143,17 @@
         hasRemainingAncestor_ = false;
       }
 
-      virtual const char* GetName() const
+      virtual const char* GetName() const ORTHANC_OVERRIDE
       {
         return "SignalRemainingAncestor";
       }
 
-      virtual unsigned int GetCardinality() const
+      virtual unsigned int GetCardinality() const ORTHANC_OVERRIDE
       {
         return 2;
       }
 
-      virtual void Compute(SQLite::FunctionContext& context)
+      virtual void Compute(SQLite::FunctionContext& context) ORTHANC_OVERRIDE
       {
         CLOG(TRACE, SQLITE) << "There exists a remaining ancestor with public ID \""
                             << context.GetStringValue(0) << "\" of type "
@@ -617,17 +617,17 @@
 #endif
     }
 
-    virtual void Begin()
+    void Begin()
     {
       transaction_->Begin();
     }
 
-    virtual void Rollback() 
+    virtual void Rollback() ORTHANC_OVERRIDE
     {
       transaction_->Rollback();
     }
 
-    virtual void Commit(int64_t fileSizeDelta /* only used in debug */)
+    virtual void Commit(int64_t fileSizeDelta /* only used in debug */) ORTHANC_OVERRIDE
     {
       transaction_->Commit();
 
@@ -639,7 +639,9 @@
 
   IDatabaseWrapper::ITransaction* SQLiteDatabaseWrapper::StartTransaction()
   {
-    return new Transaction(*this);
+    std::unique_ptr<Transaction> transaction(new Transaction(*this));
+    transaction->Begin();
+    return transaction.release();
   }
 
 
@@ -1160,18 +1162,18 @@
     std::list<std::string>  values_;
 
   public:
-    virtual std::string GenerateParameter(const std::string& value)
+    virtual std::string GenerateParameter(const std::string& value) ORTHANC_OVERRIDE
     {
       values_.push_back(value);
       return "?";
     }
     
-    virtual std::string FormatResourceType(ResourceType level)
+    virtual std::string FormatResourceType(ResourceType level) ORTHANC_OVERRIDE
     {
       return boost::lexical_cast<std::string>(level);
     }
 
-    virtual std::string FormatWildcardEscape()
+    virtual std::string FormatWildcardEscape() ORTHANC_OVERRIDE
     {
       return "ESCAPE '\\'";
     }
--- a/OrthancServer/Sources/ServerIndex.cpp	Wed Mar 03 17:13:41 2021 +0100
+++ b/OrthancServer/Sources/ServerIndex.cpp	Wed Mar 03 17:31:30 2021 +0100
@@ -251,8 +251,6 @@
       isCommitted_(false)
     {
       transaction_.reset(index_.db_.StartTransaction());
-      transaction_->Begin();
-
       index_.listener_->StartTransaction();
     }