Mercurial > hg > orthanc-databases
annotate PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 369:557bc5ba3a5c
fix warnings
author | Alain Mazy <am@osimis.io> |
---|---|
date | Wed, 01 Feb 2023 16:25:37 +0100 |
parents | 16aac0287485 |
children | 3d6886f3e5b3 |
rev | line source |
---|---|
0 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
359
16aac0287485
copyright upgraded to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
16aac0287485
copyright upgraded to 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
336
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
0 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU Affero General Public License | |
10 * as published by the Free Software Foundation, either version 3 of | |
11 * the License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * Affero General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU Affero General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #include "PostgreSQLIndex.h" | |
24 | |
25 #include "../../Framework/Plugins/GlobalProperties.h" | |
26 #include "../../Framework/PostgreSQL/PostgreSQLDatabase.h" | |
27 #include "../../Framework/PostgreSQL/PostgreSQLTransaction.h" | |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
28 #include "PostgreSQLDefinitions.h" |
0 | 29 |
30 #include <EmbeddedResources.h> // Auto-generated file | |
31 | |
157
275e14f57f1e
replacing deprecated std::auto_ptr by std::unique_ptr
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
152
diff
changeset
|
32 #include <Compatibility.h> // For std::unique_ptr<> |
152 | 33 #include <Logging.h> |
34 #include <OrthancException.h> | |
0 | 35 |
36 | |
37 namespace Orthanc | |
38 { | |
39 // Some aliases for internal properties | |
40 static const GlobalProperty GlobalProperty_HasTrigramIndex = GlobalProperty_DatabaseInternal0; | |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
41 static const GlobalProperty GlobalProperty_HasCreateInstance = GlobalProperty_DatabaseInternal1; |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
42 static const GlobalProperty GlobalProperty_HasFastCountResources = GlobalProperty_DatabaseInternal2; |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
43 static const GlobalProperty GlobalProperty_GetLastChangeIndex = GlobalProperty_DatabaseInternal3; |
0 | 44 } |
45 | |
46 | |
47 namespace OrthancDatabases | |
48 { | |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
49 PostgreSQLIndex::PostgreSQLIndex(OrthancPluginContext* context, |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
50 const PostgreSQLParameters& parameters) : |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
51 IndexBackend(context), |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
52 parameters_(parameters), |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
53 clearAll_(false) |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
54 { |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
55 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
56 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
57 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
58 IDatabaseFactory* PostgreSQLIndex::CreateDatabaseFactory() |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
59 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
60 return PostgreSQLDatabase::CreateDatabaseFactory(parameters_); |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
61 } |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
62 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
63 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
64 void PostgreSQLIndex::ConfigureDatabase(DatabaseManager& manager) |
0 | 65 { |
66 uint32_t expectedVersion = 6; | |
199 | 67 |
68 if (GetContext()) // "GetContext()" can possibly be NULL in the unit tests | |
0 | 69 { |
199 | 70 expectedVersion = OrthancPluginGetExpectedDatabaseVersion(GetContext()); |
0 | 71 } |
72 | |
73 // Check the expected version of the database | |
74 if (expectedVersion != 6) | |
75 { | |
76 LOG(ERROR) << "This database plugin is incompatible with your version of Orthanc " | |
77 << "expecting the DB schema version " << expectedVersion | |
78 << ", but this plugin is only compatible with version 6"; | |
79 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); | |
80 } | |
81 | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
82 PostgreSQLDatabase& db = dynamic_cast<PostgreSQLDatabase&>(manager.GetDatabase()); |
0 | 83 |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
84 if (parameters_.HasLock()) |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
85 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
86 db.AdvisoryLock(POSTGRESQL_LOCK_INDEX); |
56
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
87 } |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
88 |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
89 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
90 PostgreSQLDatabase::TransientAdvisoryLock lock(db, POSTGRESQL_LOCK_DATABASE_SETUP); |
56
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
91 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
92 if (clearAll_) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
93 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
94 db.ClearAll(); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
95 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
96 |
0 | 97 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
98 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
99 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
100 if (!t.GetDatabaseTransaction().DoesTableExist("Resources")) |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
101 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
102 std::string query; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
103 |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
104 Orthanc::EmbeddedResources::GetFileResource |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
105 (query, Orthanc::EmbeddedResources::POSTGRESQL_PREPARE_INDEX); |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
106 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
107 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
108 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion, expectedVersion); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
109 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, 1); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
110 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasTrigramIndex, 0); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
111 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
112 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
113 if (!t.GetDatabaseTransaction().DoesTableExist("Resources")) |
0 | 114 { |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
115 LOG(ERROR) << "Corrupted PostgreSQL database"; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
116 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
117 } |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
118 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
119 int version = 0; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
120 if (!LookupGlobalIntegerProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion) || |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
121 version != 6) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
122 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
123 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema version: " << version; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
124 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
125 } |
56
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
126 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
127 int revision; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
128 if (!LookupGlobalIntegerProperty(revision, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel)) |
0 | 129 { |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
130 revision = 1; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
131 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel, revision); |
0 | 132 } |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
133 |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
134 if (revision != 1) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
135 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
136 LOG(ERROR) << "PostgreSQL plugin is incompatible with database schema revision: " << revision; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
137 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
138 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
139 |
77
a2134531473c
avoid warnings "An active PostgreSQL transaction was dismissed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
140 t.Commit(); |
a2134531473c
avoid warnings "An active PostgreSQL transaction was dismissed"
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
74
diff
changeset
|
141 } |
0 | 142 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
143 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
144 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
145 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
146 int hasTrigram = 0; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
147 if (!LookupGlobalIntegerProperty(hasTrigram, manager, MISSING_SERVER_IDENTIFIER, |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
148 Orthanc::GlobalProperty_HasTrigramIndex) || |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
149 hasTrigram != 1) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
150 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
151 /** |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
152 * Apply fix for performance issue (speed up wildcard search |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
153 * by using GIN trigrams). This implements the patch suggested |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
154 * in issue #47, BUT we also keep the original |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
155 * "DicomIdentifiersIndexValues", as it leads to better |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
156 * performance for "strict" searches (i.e. searches involving |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
157 * no wildcard). |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
158 * https://www.postgresql.org/docs/current/static/pgtrgm.html |
336
c0c12b3974b2
fix URLs to the old repositories
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
302
diff
changeset
|
159 * https://bugs.orthanc-server.com/show_bug.cgi?id=47 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
160 **/ |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
161 try |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
162 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
163 // We've observed 9 minutes on DB with 100000 studies |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
164 LOG(WARNING) << "Trying to enable trigram matching on the PostgreSQL database " |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
165 << "to speed up wildcard searches. This may take several minutes"; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
166 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
167 t.GetDatabaseTransaction().ExecuteMultiLines( |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
168 "CREATE EXTENSION IF NOT EXISTS pg_trgm; " |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
169 "CREATE INDEX DicomIdentifiersIndexValues2 ON DicomIdentifiers USING gin(value gin_trgm_ops);"); |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
170 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
171 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasTrigramIndex, 1); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
172 LOG(WARNING) << "Trigram index has been created"; |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
173 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
174 t.Commit(); |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
175 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
176 catch (Orthanc::OrthancException&) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
177 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
178 LOG(WARNING) << "Performance warning: Your PostgreSQL server does " |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
179 << "not support trigram matching"; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
180 LOG(WARNING) << "-> Consider installing the \"pg_trgm\" extension on the " |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
181 << "PostgreSQL server, e.g. on Debian: sudo apt install postgresql-contrib"; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
182 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
183 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
184 else |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
185 { |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
186 t.Commit(); |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
187 } |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
188 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
189 |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
190 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
191 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
192 |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
193 int property = 0; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
194 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
195 Orthanc::GlobalProperty_HasCreateInstance) || |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
196 property != 2) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
197 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
198 LOG(INFO) << "Installing the CreateInstance extension"; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
199 |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
200 if (property == 1) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
201 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
202 // Drop older, experimental versions of this extension |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
203 t.GetDatabaseTransaction().ExecuteMultiLines("DROP FUNCTION CreateInstance(" |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
204 "IN patient TEXT, IN study TEXT, IN series TEXT, in instance TEXT)"); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
205 } |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
206 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
207 std::string query; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
208 Orthanc::EmbeddedResources::GetFileResource |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
209 (query, Orthanc::EmbeddedResources::POSTGRESQL_CREATE_INSTANCE); |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
210 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
211 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
212 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasCreateInstance, 2); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
213 } |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
214 |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
215 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
216 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
217 Orthanc::GlobalProperty_GetTotalSizeIsFast) || |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
218 property != 1) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
219 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
220 LOG(INFO) << "Installing the FastTotalSize extension"; |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
221 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
222 std::string query; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
223 Orthanc::EmbeddedResources::GetFileResource |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
224 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_TOTAL_SIZE); |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
225 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
226 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
227 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_GetTotalSizeIsFast, 1); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
228 } |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
229 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
230 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
231 // Installing this extension requires the "GlobalIntegers" table |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
232 // created by the "FastTotalSize" extension |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
233 property = 0; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
234 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
235 Orthanc::GlobalProperty_HasFastCountResources) || |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
236 property != 1) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
237 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
238 LOG(INFO) << "Installing the FastCountResources extension"; |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
239 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
240 std::string query; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
241 Orthanc::EmbeddedResources::GetFileResource |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
242 (query, Orthanc::EmbeddedResources::POSTGRESQL_FAST_COUNT_RESOURCES); |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
243 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
244 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
245 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_HasFastCountResources, 1); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
246 } |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
247 |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
248 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
249 // Installing this extension requires the "GlobalIntegers" table |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
250 // created by the "GetLastChangeIndex" extension |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
251 property = 0; |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
252 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
253 Orthanc::GlobalProperty_GetLastChangeIndex) || |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
254 property != 1) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
255 { |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
256 LOG(INFO) << "Installing the GetLastChangeIndex extension"; |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
257 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
258 std::string query; |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
259 Orthanc::EmbeddedResources::GetFileResource |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
260 (query, Orthanc::EmbeddedResources::POSTGRESQL_GET_LAST_CHANGE_INDEX); |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
261 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
262 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
263 SetGlobalIntegerProperty(manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_GetLastChangeIndex, 1); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
264 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
265 |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
266 t.Commit(); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
267 } |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
268 |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
269 |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
270 { |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
271 // New in release 4.0 to deal with multiple writers |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
272 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
273 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
274 if (!t.GetDatabaseTransaction().DoesTableExist("ServerProperties")) |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
275 { |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
276 t.GetDatabaseTransaction().ExecuteMultiLines("CREATE TABLE ServerProperties(server VARCHAR(64) NOT NULL, " |
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
277 "property INTEGER, value TEXT, PRIMARY KEY(server, property))"); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
278 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
279 |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
280 /** |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
281 * PostgreSQL 9.5: "Adding a column with a default requires |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
282 * updating each row of the table (to store the new column |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
283 * value). However, if no default is specified, PostgreSQL is |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
284 * able to avoid the physical update." => We set no default |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
285 * for performance (older entries will be NULL) |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
286 * https://www.postgresql.org/docs/9.5/ddl-alter.html |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
287 **/ |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
288 if (!db.DoesColumnExist("Metadata", "revision")) |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
289 { |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
290 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE Metadata ADD COLUMN revision INTEGER"); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
291 } |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
292 |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
293 if (!db.DoesColumnExist("AttachedFiles", "revision")) |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
294 { |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
295 t.GetDatabaseTransaction().ExecuteMultiLines("ALTER TABLE AttachedFiles ADD COLUMN revision INTEGER"); |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
296 } |
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
297 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
298 t.Commit(); |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
299 } |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
300 } |
0 | 301 } |
302 | |
303 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
304 int64_t PostgreSQLIndex::CreateResource(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
305 const char* publicId, |
0 | 306 OrthancPluginResourceType type) |
307 { | |
308 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
309 STATEMENT_FROM_HERE, manager, |
302
3a52e27a2d80
in GenericFormatter, replaced ${} by ${AUTOINCREMENT}
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
266
diff
changeset
|
310 "INSERT INTO Resources VALUES(DEFAULT, ${type}, ${id}, NULL) RETURNING internalId"); |
0 | 311 |
312 statement.SetParameterType("id", ValueType_Utf8String); | |
313 statement.SetParameterType("type", ValueType_Integer64); | |
314 | |
315 Dictionary args; | |
316 args.SetUtf8Value("id", publicId); | |
317 args.SetIntegerValue("type", static_cast<int>(type)); | |
318 | |
319 statement.Execute(args); | |
320 | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
321 return statement.ReadInteger64(0); |
0 | 322 } |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
323 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
324 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
325 uint64_t PostgreSQLIndex::GetTotalCompressedSize(DatabaseManager& manager) |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
326 { |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
327 // Fast version if extension "./FastTotalSize.sql" is installed |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
328 uint64_t result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
329 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
330 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
331 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
332 STATEMENT_FROM_HERE, manager, |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
333 "SELECT value FROM GlobalIntegers WHERE key = 0"); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
334 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
335 statement.SetReadOnly(true); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
336 statement.Execute(); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
337 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
338 result = static_cast<uint64_t>(statement.ReadInteger64(0)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
339 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
340 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
341 assert(result == IndexBackend::GetTotalCompressedSize(manager)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
342 return result; |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
343 } |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
344 |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
345 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
346 uint64_t PostgreSQLIndex::GetTotalUncompressedSize(DatabaseManager& manager) |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
347 { |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
348 // Fast version if extension "./FastTotalSize.sql" is installed |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
349 uint64_t result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
350 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
351 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
352 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
353 STATEMENT_FROM_HERE, manager, |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
354 "SELECT value FROM GlobalIntegers WHERE key = 1"); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
355 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
356 statement.SetReadOnly(true); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
357 statement.Execute(); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
358 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
359 result = static_cast<uint64_t>(statement.ReadInteger64(0)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
360 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
361 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
362 assert(result == IndexBackend::GetTotalUncompressedSize(manager)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
363 return result; |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
364 } |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
365 |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
366 |
78 | 367 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
368 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
369 DatabaseManager& manager, |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
370 const char* hashPatient, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
371 const char* hashStudy, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
372 const char* hashSeries, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
373 const char* hashInstance) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
374 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
375 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
376 STATEMENT_FROM_HERE, manager, |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
377 "SELECT * FROM CreateInstance(${patient}, ${study}, ${series}, ${instance})"); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
378 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
379 statement.SetParameterType("patient", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
380 statement.SetParameterType("study", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
381 statement.SetParameterType("series", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
382 statement.SetParameterType("instance", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
383 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
384 Dictionary args; |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
385 args.SetUtf8Value("patient", hashPatient); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
386 args.SetUtf8Value("study", hashStudy); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
387 args.SetUtf8Value("series", hashSeries); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
388 args.SetUtf8Value("instance", hashInstance); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
389 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
390 statement.Execute(args); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
391 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
392 if (statement.IsDone() || |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
393 statement.GetResultFieldsCount() != 8) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
394 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
395 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
396 } |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
397 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
398 for (size_t i = 0; i < 8; i++) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
399 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
400 statement.SetResultFieldType(i, ValueType_Integer64); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
401 } |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
402 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
403 result.isNewInstance = (statement.ReadInteger64(3) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
404 result.instanceId = statement.ReadInteger64(7); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
405 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
406 if (result.isNewInstance) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
407 { |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
408 result.isNewPatient = (statement.ReadInteger64(0) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
409 result.isNewStudy = (statement.ReadInteger64(1) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
410 result.isNewSeries = (statement.ReadInteger64(2) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
411 result.patientId = statement.ReadInteger64(4); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
412 result.studyId = statement.ReadInteger64(5); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
413 result.seriesId = statement.ReadInteger64(6); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
414 } |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
415 } |
73
aa81c1c80c75
fix compatibility with older sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
72
diff
changeset
|
416 #endif |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
417 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
418 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
419 uint64_t PostgreSQLIndex::GetResourcesCount(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
420 OrthancPluginResourceType resourceType) |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
421 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
422 // Optimized version thanks to the "FastCountResources.sql" extension |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
423 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
424 assert(OrthancPluginResourceType_Patient == 0 && |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
425 OrthancPluginResourceType_Study == 1 && |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
426 OrthancPluginResourceType_Series == 2 && |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
427 OrthancPluginResourceType_Instance == 3); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
428 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
429 uint64_t result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
430 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
431 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
432 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
433 STATEMENT_FROM_HERE, manager, |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
434 "SELECT value FROM GlobalIntegers WHERE key = ${key}"); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
435 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
436 statement.SetParameterType("key", ValueType_Integer64); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
437 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
438 Dictionary args; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
439 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
440 // For an explanation of the "+ 2" below, check out "FastCountResources.sql" |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
441 args.SetIntegerValue("key", static_cast<int>(resourceType + 2)); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
442 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
443 statement.SetReadOnly(true); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
444 statement.Execute(args); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
445 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
446 result = static_cast<uint64_t>(statement.ReadInteger64(0)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
447 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
448 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
449 assert(result == IndexBackend::GetResourcesCount(manager, resourceType)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
450 return result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
451 } |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
452 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
453 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
454 int64_t PostgreSQLIndex::GetLastChangeIndex(DatabaseManager& manager) |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
455 { |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
456 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
457 STATEMENT_FROM_HERE, manager, |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
458 "SELECT value FROM GlobalIntegers WHERE key = 6"); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
459 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
460 statement.SetReadOnly(true); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
461 statement.Execute(); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
462 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
463 return statement.ReadInteger64(0); |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
464 } |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
465 |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
466 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
467 void PostgreSQLIndex::TagMostRecentPatient(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
468 int64_t patient) |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
469 { |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
470 // This behavior is implemented in "CreateInstance()", and no |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
471 // backward compatibility is necessary |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
472 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
473 } |
0 | 474 } |