Mercurial > hg > orthanc-databases
comparison 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 |
comparison
equal
deleted
inserted
replaced
254:8a4ce70f456a | 255:d663d9e44f8d |
---|---|
32 #include <Logging.h> | 32 #include <Logging.h> |
33 #include <OrthancException.h> | 33 #include <OrthancException.h> |
34 | 34 |
35 namespace OrthancDatabases | 35 namespace OrthancDatabases |
36 { | 36 { |
37 IDatabase* SQLiteIndex::OpenDatabaseConnection() | 37 IDatabaseFactory* SQLiteIndex::CreateDatabaseFactory() |
38 { | 38 { |
39 std::unique_ptr<SQLiteDatabase> db(new SQLiteDatabase); | 39 class Factory : public IDatabaseFactory |
40 | 40 { |
41 if (path_.empty()) | 41 private: |
42 { | 42 std::string path_; |
43 db->OpenInMemory(); | 43 bool fast_; |
44 } | 44 |
45 else | 45 public: |
46 { | 46 Factory(const std::string& path, |
47 db->Open(path_); | 47 bool fast) : |
48 } | 48 path_(path), |
49 | 49 fast_(fast) |
50 db->Execute("PRAGMA ENCODING=\"UTF-8\";"); | 50 { |
51 | 51 } |
52 if (fast_) | 52 |
53 { | 53 virtual IDatabase* Open() ORTHANC_OVERRIDE |
54 // Performance tuning of SQLite with PRAGMAs | 54 { |
55 // http://www.sqlite.org/pragma.html | 55 std::unique_ptr<SQLiteDatabase> db(new SQLiteDatabase); |
56 db->Execute("PRAGMA SYNCHRONOUS=NORMAL;"); | 56 |
57 db->Execute("PRAGMA JOURNAL_MODE=WAL;"); | 57 if (path_.empty()) |
58 db->Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); | 58 { |
59 db->Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); | 59 db->OpenInMemory(); |
60 //db->Execute("PRAGMA TEMP_STORE=memory"); | 60 } |
61 } | 61 else |
62 | 62 { |
63 return db.release(); | 63 db->Open(path_); |
64 } | |
65 | |
66 db->Execute("PRAGMA ENCODING=\"UTF-8\";"); | |
67 | |
68 if (fast_) | |
69 { | |
70 // Performance tuning of SQLite with PRAGMAs | |
71 // http://www.sqlite.org/pragma.html | |
72 db->Execute("PRAGMA SYNCHRONOUS=NORMAL;"); | |
73 db->Execute("PRAGMA JOURNAL_MODE=WAL;"); | |
74 db->Execute("PRAGMA LOCKING_MODE=EXCLUSIVE;"); | |
75 db->Execute("PRAGMA WAL_AUTOCHECKPOINT=1000;"); | |
76 //db->Execute("PRAGMA TEMP_STORE=memory"); | |
77 } | |
78 | |
79 return db.release(); | |
80 } | |
81 }; | |
82 | |
83 return new Factory(path_, fast_); | |
64 } | 84 } |
65 | 85 |
66 | 86 |
67 void SQLiteIndex::ConfigureDatabase(DatabaseManager& manager) | 87 void SQLiteIndex::ConfigureDatabase(DatabaseManager& manager) |
68 { | 88 { |