Mercurial > hg > orthanc-databases
comparison PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 241:a063bbf10a3e
simplification of class DatabaseManager::Transaction
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 13 Apr 2021 12:07:30 +0200 |
parents | 35598014f140 |
children | d663d9e44f8d |
comparison
equal
deleted
inserted
replaced
240:c82c2cf84ae8 | 241:a063bbf10a3e |
---|---|
94 } | 94 } |
95 | 95 |
96 { | 96 { |
97 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); | 97 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
98 | 98 |
99 if (!t.DoesTableExist("Resources")) | 99 if (!t.GetDatabaseTransaction().DoesTableExist("Resources")) |
100 { | 100 { |
101 std::string query; | 101 std::string query; |
102 | 102 |
103 Orthanc::EmbeddedResources::GetFileResource | 103 Orthanc::EmbeddedResources::GetFileResource |
104 (query, Orthanc::EmbeddedResources::POSTGRESQL_PREPARE_INDEX); | 104 (query, Orthanc::EmbeddedResources::POSTGRESQL_PREPARE_INDEX); |
105 t.ExecuteMultiLines(query); | 105 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
106 | 106 |
107 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); | 107 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); |
108 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, 1); | 108 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, 1); |
109 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasTrigramIndex, 0); | 109 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasTrigramIndex, 0); |
110 } | 110 } |
111 | 111 |
112 if (!t.DoesTableExist("Resources")) | 112 if (!t.GetDatabaseTransaction().DoesTableExist("Resources")) |
113 { | 113 { |
114 LOG(ERROR) << "Corrupted PostgreSQL database"; | 114 LOG(ERROR) << "Corrupted PostgreSQL database"; |
115 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); | 115 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
116 } | 116 } |
117 | 117 |
161 { | 161 { |
162 // We've observed 9 minutes on DB with 100000 studies | 162 // We've observed 9 minutes on DB with 100000 studies |
163 LOG(WARNING) << "Trying to enable trigram matching on the PostgreSQL database " | 163 LOG(WARNING) << "Trying to enable trigram matching on the PostgreSQL database " |
164 << "to speed up wildcard searches. This may take several minutes"; | 164 << "to speed up wildcard searches. This may take several minutes"; |
165 | 165 |
166 t.ExecuteMultiLines( | 166 t.GetDatabaseTransaction().ExecuteMultiLines( |
167 "CREATE EXTENSION IF NOT EXISTS pg_trgm; " | 167 "CREATE EXTENSION IF NOT EXISTS pg_trgm; " |
168 "CREATE INDEX DicomIdentifiersIndexValues2 ON DicomIdentifiers USING gin(value gin_trgm_ops);"); | 168 "CREATE INDEX DicomIdentifiersIndexValues2 ON DicomIdentifiers USING gin(value gin_trgm_ops);"); |
169 | 169 |
170 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasTrigramIndex, 1); | 170 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasTrigramIndex, 1); |
171 LOG(WARNING) << "Trigram index has been created"; | 171 LOG(WARNING) << "Trigram index has been created"; |
197 LOG(INFO) << "Installing the CreateInstance extension"; | 197 LOG(INFO) << "Installing the CreateInstance extension"; |
198 | 198 |
199 if (property == 1) | 199 if (property == 1) |
200 { | 200 { |
201 // Drop older, experimental versions of this extension | 201 // Drop older, experimental versions of this extension |
202 t.ExecuteMultiLines("DROP FUNCTION CreateInstance(" | 202 t.GetDatabaseTransaction().ExecuteMultiLines("DROP FUNCTION CreateInstance(" |
203 "IN patient TEXT, IN study TEXT, IN series TEXT, in instance TEXT)"); | 203 "IN patient TEXT, IN study TEXT, IN series TEXT, in instance TEXT)"); |
204 } | 204 } |
205 | 205 |
206 std::string query; | 206 std::string query; |
207 Orthanc::EmbeddedResources::GetFileResource | 207 Orthanc::EmbeddedResources::GetFileResource |
208 (query, Orthanc::EmbeddedResources::POSTGRESQL_CREATE_INSTANCE); | 208 (query, Orthanc::EmbeddedResources::POSTGRESQL_CREATE_INSTANCE); |
209 t.ExecuteMultiLines(query); | 209 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
210 | 210 |
211 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasCreateInstance, 2); | 211 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasCreateInstance, 2); |
212 } | 212 } |
213 | 213 |
214 | 214 |
219 LOG(INFO) << "Installing the FastTotalSize extension"; | 219 LOG(INFO) << "Installing the FastTotalSize extension"; |
220 | 220 |
221 std::string query; | 221 std::string query; |
222 Orthanc::EmbeddedResources::GetFileResource | 222 Orthanc::EmbeddedResources::GetFileResource |
223 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_TOTAL_SIZE); | 223 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_TOTAL_SIZE); |
224 t.ExecuteMultiLines(query); | 224 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
225 | 225 |
226 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_GetTotalSizeIsFast, 1); | 226 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_GetTotalSizeIsFast, 1); |
227 } | 227 } |
228 | 228 |
229 | 229 |
237 LOG(INFO) << "Installing the FastCountResources extension"; | 237 LOG(INFO) << "Installing the FastCountResources extension"; |
238 | 238 |
239 std::string query; | 239 std::string query; |
240 Orthanc::EmbeddedResources::GetFileResource | 240 Orthanc::EmbeddedResources::GetFileResource |
241 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_COUNT_RESOURCES); | 241 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_COUNT_RESOURCES); |
242 t.ExecuteMultiLines(query); | 242 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
243 | 243 |
244 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasFastCountResources, 1); | 244 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasFastCountResources, 1); |
245 } | 245 } |
246 | 246 |
247 | 247 |
255 LOG(INFO) << "Installing the GetLastChangeIndex extension"; | 255 LOG(INFO) << "Installing the GetLastChangeIndex extension"; |
256 | 256 |
257 std::string query; | 257 std::string query; |
258 Orthanc::EmbeddedResources::GetFileResource | 258 Orthanc::EmbeddedResources::GetFileResource |
259 (query, Orthanc::EmbeddedResources::POSTGRESQL_GET_LAST_CHANGE_INDEX); | 259 (query, Orthanc::EmbeddedResources::POSTGRESQL_GET_LAST_CHANGE_INDEX); |
260 t.ExecuteMultiLines(query); | 260 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
261 | 261 |
262 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_GetLastChangeIndex, 1); | 262 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_GetLastChangeIndex, 1); |
263 } | 263 } |
264 | 264 |
265 t.Commit(); | 265 t.Commit(); |
268 | 268 |
269 { | 269 { |
270 // New in release 4.0 to deal with multiple writers | 270 // New in release 4.0 to deal with multiple writers |
271 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); | 271 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
272 | 272 |
273 if (!t.DoesTableExist("ServerProperties")) | 273 if (!t.GetDatabaseTransaction().DoesTableExist("ServerProperties")) |
274 { | 274 { |
275 t.ExecuteMultiLines("CREATE TABLE ServerProperties(server VARCHAR(64) NOT NULL, " | 275 t.GetDatabaseTransaction().ExecuteMultiLines("CREATE TABLE ServerProperties(server VARCHAR(64) NOT NULL, " |
276 "property INTEGER, value TEXT, PRIMARY KEY(server, property))"); | 276 "property INTEGER, value TEXT, PRIMARY KEY(server, property))"); |
277 } | 277 } |
278 | 278 |
279 t.Commit(); | 279 t.Commit(); |
280 } | 280 } |
281 } | 281 } |