diff SQLite/Plugins/SQLiteIndex.cpp @ 255:d663d9e44f8d

reintroduction of IDatabaseFactory into DatabaseManager
author Sebastien Jodogne <s.jodogne@gmail.com>
date Wed, 14 Apr 2021 17:57:08 +0200
parents a063bbf10a3e
children 16aac0287485 cd9521e04249
line wrap: on
line diff
--- a/SQLite/Plugins/SQLiteIndex.cpp	Wed Apr 14 15:33:57 2021 +0200
+++ b/SQLite/Plugins/SQLiteIndex.cpp	Wed Apr 14 17:57:08 2021 +0200
@@ -34,33 +34,53 @@
 
 namespace OrthancDatabases
 {
-  IDatabase* SQLiteIndex::OpenDatabaseConnection()
+  IDatabaseFactory* SQLiteIndex::CreateDatabaseFactory()
   {
-    std::unique_ptr<SQLiteDatabase> db(new SQLiteDatabase);
-
-    if (path_.empty())
+    class Factory : public IDatabaseFactory
     {
-      db->OpenInMemory();
-    }
-    else
-    {
-      db->Open(path_);
-    }
+    private:
+      std::string  path_;
+      bool         fast_;
+      
+    public:
+      Factory(const std::string& path,
+              bool fast) :
+        path_(path),
+        fast_(fast)
+      {
+      }
+      
+      virtual IDatabase* Open() ORTHANC_OVERRIDE
+      {
+        std::unique_ptr<SQLiteDatabase> db(new SQLiteDatabase);
 
-    db->Execute("PRAGMA ENCODING=\"UTF-8\";");
+        if (path_.empty())
+        {
+          db->OpenInMemory();
+        }
+        else
+        {
+          db->Open(path_);
+        }
+
+        db->Execute("PRAGMA ENCODING=\"UTF-8\";");
 
-    if (fast_)
-    {
-      // Performance tuning of SQLite with PRAGMAs
-      // http://www.sqlite.org/pragma.html
-      db->Execute("PRAGMA SYNCHRONOUS=NORMAL;");
-      db->Execute("PRAGMA JOURNAL_MODE=WAL;");
-      db->Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;");
-      db->Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;");
-      //db->Execute("PRAGMA TEMP_STORE=memory");
-    }
+        if (fast_)
+        {
+          // Performance tuning of SQLite with PRAGMAs
+          // http://www.sqlite.org/pragma.html
+          db->Execute("PRAGMA SYNCHRONOUS=NORMAL;");
+          db->Execute("PRAGMA JOURNAL_MODE=WAL;");
+          db->Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;");
+          db->Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;");
+          //db->Execute("PRAGMA TEMP_STORE=memory");
+        }
 
-    return db.release();
+        return db.release();
+      }
+    };
+
+    return new Factory(path_, fast_);
   }