diff Framework/Common/DatabaseManager.cpp @ 226:a4918d57435c

DatabaseManager doesn't IDatabaseFactory anymore
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 02 Apr 2021 19:23:36 +0200
parents 90eb271f85b2
children 0a9b48d19643
line wrap: on
line diff
--- a/Framework/Common/DatabaseManager.cpp	Thu Apr 01 19:18:19 2021 +0200
+++ b/Framework/Common/DatabaseManager.cpp	Fri Apr 02 19:23:36 2021 +0200
@@ -31,56 +31,6 @@
 
 namespace OrthancDatabases
 {
-  IDatabase& DatabaseManager::GetDatabase()
-  {
-    unsigned int maxConnectionRetries = 10;
-    unsigned int connectionRetryInterval = 5;
-    unsigned int count = 0;
-
-    factory_->GetConnectionRetriesParameters(maxConnectionRetries, connectionRetryInterval);
-      
-    while (database_.get() == NULL)
-    {
-      transaction_.reset(NULL);
-
-      try
-      {
-        database_.reset(factory_->Open());
-      }
-      catch (Orthanc::OrthancException& e)
-      {
-        if (e.GetErrorCode() == Orthanc::ErrorCode_DatabaseUnavailable)
-        {
-          count ++;
-
-          if (count <= maxConnectionRetries)
-          {
-            LOG(WARNING) << "Database is currently unavailable, retrying...";
-            boost::this_thread::sleep(boost::posix_time::seconds(connectionRetryInterval));
-            continue;
-          }
-          else
-          {
-            LOG(ERROR) << "Timeout when connecting to the database, giving up";
-          }
-        }
-
-        throw;
-      }
-    }
-
-    if (database_.get() == NULL ||
-        database_->GetDialect() != dialect_)
-    {
-      throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError);
-    }
-    else
-    {
-      return *database_;
-    }
-  }
-
-
   void DatabaseManager::Close()
   {
     LOG(TRACE) << "Closing the connection to the database";
@@ -200,15 +150,15 @@
   }
 
     
-  DatabaseManager::DatabaseManager(IDatabaseFactory* factory) :  // Takes ownership
-    factory_(factory)
+  DatabaseManager::DatabaseManager(IDatabase* database) :
+    database_(database)
   {
-    if (factory == NULL)
+    if (database == NULL)
     {
       throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer);
     }
 
-    dialect_ = factory->GetDialect();
+    dialect_ = database->GetDialect();
   }