Mercurial > hg > orthanc-databases
annotate PostgreSQL/Plugins/PostgreSQLIndex.cpp @ 493:0a8168522165
news
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 22 Mar 2024 15:27:59 +0100 |
parents | 15e609c439d1 |
children | 0974a58fdc76 |
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 | |
459
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
426
diff
changeset
|
5 * Copyright (C) 2017-2024 Osimis S.A., Belgium |
ecd0b719cff5
update year to 2024
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
426
diff
changeset
|
6 * Copyright (C) 2021-2024 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<> |
436
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
33 #include <Toolbox.h> |
152 | 34 #include <Logging.h> |
35 #include <OrthancException.h> | |
0 | 36 |
37 | |
38 namespace Orthanc | |
39 { | |
40 // Some aliases for internal properties | |
41 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
|
42 static const GlobalProperty GlobalProperty_HasCreateInstance = GlobalProperty_DatabaseInternal1; |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
43 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
|
44 static const GlobalProperty GlobalProperty_GetLastChangeIndex = GlobalProperty_DatabaseInternal3; |
0 | 45 } |
46 | |
47 | |
48 namespace OrthancDatabases | |
49 { | |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
50 PostgreSQLIndex::PostgreSQLIndex(OrthancPluginContext* context, |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
51 const PostgreSQLParameters& parameters) : |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
52 IndexBackend(context), |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
53 parameters_(parameters), |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
54 clearAll_(false) |
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 |
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
58 |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
59 IDatabaseFactory* PostgreSQLIndex::CreateDatabaseFactory() |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
60 { |
255
d663d9e44f8d
reintroduction of IDatabaseFactory into DatabaseManager
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
241
diff
changeset
|
61 return PostgreSQLDatabase::CreateDatabaseFactory(parameters_); |
226
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 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
64 void PostgreSQLIndex::ApplyPrepareIndex(DatabaseManager::Transaction& t, DatabaseManager& manager) |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
65 { |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
66 std::string query; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
67 |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
68 Orthanc::EmbeddedResources::GetFileResource |
448
f2427f94d879
added downgrade script + renames version
Alain Mazy <am@osimis.io>
parents:
437
diff
changeset
|
69 (query, Orthanc::EmbeddedResources::POSTGRESQL_PREPARE_INDEX); |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
70 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
71 } |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
72 |
403
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
73 void PostgreSQLIndex::ConfigureDatabase(DatabaseManager& manager, |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
74 bool hasIdentifierTags, |
91124cc8a8c7
database plugins are informed about the identifier tags
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
396
diff
changeset
|
75 const std::list<IdentifierTag>& identifierTags) |
0 | 76 { |
77 uint32_t expectedVersion = 6; | |
199 | 78 |
79 if (GetContext()) // "GetContext()" can possibly be NULL in the unit tests | |
0 | 80 { |
199 | 81 expectedVersion = OrthancPluginGetExpectedDatabaseVersion(GetContext()); |
0 | 82 } |
83 | |
84 // Check the expected version of the database | |
85 if (expectedVersion != 6) | |
86 { | |
87 LOG(ERROR) << "This database plugin is incompatible with your version of Orthanc " | |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
88 << "expecting the Orthanc DB schema version " << expectedVersion |
0 | 89 << ", but this plugin is only compatible with version 6"; |
90 throw Orthanc::OrthancException(Orthanc::ErrorCode_Plugin); | |
91 } | |
92 | |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
93 PostgreSQLDatabase& db = dynamic_cast<PostgreSQLDatabase&>(manager.GetDatabase()); |
0 | 94 |
12
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
95 if (parameters_.HasLock()) |
41543239072d
transactions for storage area
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
0
diff
changeset
|
96 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
97 db.AdvisoryLock(POSTGRESQL_LOCK_INDEX); |
56
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
98 } |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
99 |
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
100 { |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
101 // lock the full DB while checking if it needs to be create/ugraded |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
102 PostgreSQLDatabase::TransientAdvisoryLock lock(db, POSTGRESQL_LOCK_DATABASE_SETUP); |
56
4f66bc893fc3
Fix Debian issue #906771
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
20
diff
changeset
|
103 |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
104 if (clearAll_) |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
105 { |
226
a4918d57435c
DatabaseManager doesn't IDatabaseFactory anymore
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
225
diff
changeset
|
106 db.ClearAll(); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
107 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
108 |
0 | 109 { |
237
35598014f140
refactoring to remove GlobalProperties.cpp
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
226
diff
changeset
|
110 DatabaseManager::Transaction t(manager, TransactionType_ReadWrite); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
111 |
241
a063bbf10a3e
simplification of class DatabaseManager::Transaction
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
237
diff
changeset
|
112 if (!t.GetDatabaseTransaction().DoesTableExist("Resources")) |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
113 { |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
114 LOG(WARNING) << "PostgreSQL is creating the database schema"; |
16
9e419261f1c9
mysql storage area working
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
15
diff
changeset
|
115 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
116 ApplyPrepareIndex(t, manager); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
117 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
118 if (!t.GetDatabaseTransaction().DoesTableExist("Resources")) |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
119 { |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
120 LOG(ERROR) << "Corrupted PostgreSQL database or failed to create the database schema"; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
121 throw Orthanc::OrthancException(Orthanc::ErrorCode_InternalError); |
136
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 } |
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
124 else |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
125 { |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
126 LOG(WARNING) << "The database schema already exists, checking if it needs to be updated"; |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
127 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
128 int version = 0; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
129 if (!LookupGlobalIntegerProperty(version, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabaseSchemaVersion) || |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
130 version != 6) |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
131 { |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
132 LOG(ERROR) << "PostgreSQL plugin is incompatible with Orthanc database schema version: " << version; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
133 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
134 } |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
135 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
136 bool needToRunUpgradeFromUnknownToV1 = false; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
137 bool needToRunUpgradeV1toV2 = false; |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
138 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
139 int revision; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
140 if (!LookupGlobalIntegerProperty(revision, manager, MISSING_SERVER_IDENTIFIER, Orthanc::GlobalProperty_DatabasePatchLevel)) |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
141 { |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
142 LOG(WARNING) << "No DatabasePatchLevel found, assuming it's 1"; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
143 revision = 1; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
144 needToRunUpgradeFromUnknownToV1 = true; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
145 needToRunUpgradeV1toV2 = true; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
146 } |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
147 else if (revision == 1) |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
148 { |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
149 needToRunUpgradeV1toV2 = true; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
150 } |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
151 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
152 int hasTrigram = 0; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
153 if (!LookupGlobalIntegerProperty(hasTrigram, manager, MISSING_SERVER_IDENTIFIER, |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
154 Orthanc::GlobalProperty_HasTrigramIndex) || |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
155 hasTrigram != 1) |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
156 { |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
157 // We've observed 9 minutes on DB with 100000 studies |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
158 LOG(WARNING) << "The DB schema update will try to enable trigram matching on the PostgreSQL database " |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
159 << "to speed up wildcard searches. This may take several minutes"; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
160 needToRunUpgradeV1toV2 = true; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
161 } |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
162 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
163 int property = 0; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
164 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
165 Orthanc::GlobalProperty_HasFastCountResources) || |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
166 property != 1) |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
167 { |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
168 needToRunUpgradeV1toV2 = true; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
169 } |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
170 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
171 Orthanc::GlobalProperty_GetTotalSizeIsFast) || |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
172 property != 1) |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
173 { |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
174 needToRunUpgradeV1toV2 = true; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
175 } |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
176 if (!LookupGlobalIntegerProperty(property, manager, MISSING_SERVER_IDENTIFIER, |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
177 Orthanc::GlobalProperty_GetLastChangeIndex) || |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
178 property != 1) |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
179 { |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
180 needToRunUpgradeV1toV2 = true; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
181 } |
136
3266785d5627
cleaning up PostgreSQL locks with constants
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
134
diff
changeset
|
182 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
183 if (needToRunUpgradeFromUnknownToV1) |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
184 { |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
185 LOG(WARNING) << "Upgrading DB schema from unknown to revision 1"; |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
186 std::string query; |
266
cc7af42d4f23
Store revisions for metadata and attachments in PostgreSQL
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
263
diff
changeset
|
187 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
188 Orthanc::EmbeddedResources::GetFileResource |
467
ff84104f7842
renamed v6.2 to REV2 + removed 'default' TransactionMode + renamed 'READ COMMITTED' into 'ReadCommitted'
Alain Mazy <am@osimis.io>
parents:
460
diff
changeset
|
189 (query, Orthanc::EmbeddedResources::POSTGRESQL_UPGRADE_UNKNOWN_TO_REV1); |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
190 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
191 } |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
192 |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
193 if (needToRunUpgradeV1toV2) |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
194 { |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
195 LOG(WARNING) << "Upgrading DB schema from revision 1 to revision 2"; |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
196 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
197 std::string query; |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
198 |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
199 Orthanc::EmbeddedResources::GetFileResource |
467
ff84104f7842
renamed v6.2 to REV2 + removed 'default' TransactionMode + renamed 'READ COMMITTED' into 'ReadCommitted'
Alain Mazy <am@osimis.io>
parents:
460
diff
changeset
|
200 (query, Orthanc::EmbeddedResources::POSTGRESQL_UPGRADE_REV1_TO_REV2); |
437
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
201 t.GetDatabaseTransaction().ExecuteMultiLines(query); |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
202 |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
203 // apply all idempotent changes that are in the PrepareIndexV2 |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
204 ApplyPrepareIndex(t, manager); |
d979f25e60cf
Re-organized DB creation/upgrade into standalone files
Alain Mazy <am@osimis.io>
parents:
436
diff
changeset
|
205 } |
396
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
206 } |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
207 |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
208 t.Commit(); |
7b3acfa95bd8
implementation of list/add/remove labels in postgresql
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
389
diff
changeset
|
209 } |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
210 } |
0 | 211 } |
212 | |
213 | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
214 int64_t PostgreSQLIndex::CreateResource(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
215 const char* publicId, |
0 | 216 OrthancPluginResourceType type) |
217 { | |
218 DatabaseManager::CachedStatement statement( | |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
219 STATEMENT_FROM_HERE, manager, |
302
3a52e27a2d80
in GenericFormatter, replaced ${} by ${AUTOINCREMENT}
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
266
diff
changeset
|
220 "INSERT INTO Resources VALUES(DEFAULT, ${type}, ${id}, NULL) RETURNING internalId"); |
0 | 221 |
222 statement.SetParameterType("id", ValueType_Utf8String); | |
223 statement.SetParameterType("type", ValueType_Integer64); | |
224 | |
225 Dictionary args; | |
226 args.SetUtf8Value("id", publicId); | |
227 args.SetIntegerValue("type", static_cast<int>(type)); | |
228 | |
229 statement.Execute(args); | |
230 | |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
231 return statement.ReadInteger64(0); |
0 | 232 } |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
233 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
234 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
235 uint64_t PostgreSQLIndex::GetTotalCompressedSize(DatabaseManager& manager) |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
236 { |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
237 // Fast version if extension "./FastTotalSize.sql" is installed |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
238 uint64_t result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
239 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
240 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
241 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
242 STATEMENT_FROM_HERE, manager, |
473
15e609c439d1
Fixed the MaximumStorageSize & MaximumPatientCount.
Alain Mazy <am@osimis.io>
parents:
467
diff
changeset
|
243 "SELECT * FROM UpdateSingleStatistic(0)"); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
244 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
245 statement.Execute(); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
246 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
247 result = static_cast<uint64_t>(statement.ReadInteger64(0)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
248 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
249 |
428
4d0bacbd0fba
rewrote CreateInstance to make it compatible with READ COMMITED transactions
Alain Mazy <am@osimis.io>
parents:
427
diff
changeset
|
250 // disabled because this is not alway true while transactions are being executed in READ COMITTED TRANSACTION. This is however true when no files are being delete/added |
4d0bacbd0fba
rewrote CreateInstance to make it compatible with READ COMMITED transactions
Alain Mazy <am@osimis.io>
parents:
427
diff
changeset
|
251 //assert(result == IndexBackend::GetTotalCompressedSize(manager)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
252 return result; |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
253 } |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
254 |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
255 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
256 uint64_t PostgreSQLIndex::GetTotalUncompressedSize(DatabaseManager& manager) |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
257 { |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
258 // Fast version if extension "./FastTotalSize.sql" is installed |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
259 uint64_t result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
260 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
261 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
262 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
263 STATEMENT_FROM_HERE, manager, |
473
15e609c439d1
Fixed the MaximumStorageSize & MaximumPatientCount.
Alain Mazy <am@osimis.io>
parents:
467
diff
changeset
|
264 "SELECT * FROM UpdateSingleStatistic(1)"); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
265 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
266 statement.Execute(); |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
267 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
268 result = static_cast<uint64_t>(statement.ReadInteger64(0)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
269 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
270 |
428
4d0bacbd0fba
rewrote CreateInstance to make it compatible with READ COMMITED transactions
Alain Mazy <am@osimis.io>
parents:
427
diff
changeset
|
271 // disabled because this is not alway true while transactions are being executed in READ COMITTED TRANSACTION. This is however true when no files are being delete/added |
4d0bacbd0fba
rewrote CreateInstance to make it compatible with READ COMMITED transactions
Alain Mazy <am@osimis.io>
parents:
427
diff
changeset
|
272 // assert(result == IndexBackend::GetTotalUncompressedSize(manager)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
273 return result; |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
274 } |
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
275 |
431 | 276 int64_t PostgreSQLIndex::IncrementGlobalProperty(DatabaseManager& manager, |
277 const char* serverIdentifier, | |
278 int32_t property, | |
279 int64_t increment) | |
280 { | |
281 if (serverIdentifier == NULL) | |
282 { | |
283 throw Orthanc::OrthancException(Orthanc::ErrorCode_NullPointer); | |
284 } | |
285 else | |
286 { | |
287 if (strlen(serverIdentifier) == 0) | |
288 { | |
289 DatabaseManager::CachedStatement statement( | |
290 STATEMENT_FROM_HERE, manager, | |
291 "INSERT INTO GlobalProperties (property, value) VALUES(${property}, ${increment}) " | |
292 " ON CONFLICT (property) DO UPDATE SET value = CAST(GlobalProperties.value AS BIGINT) + ${increment}" | |
293 " RETURNING CAST(value AS BIGINT)"); | |
294 | |
295 statement.SetParameterType("property", ValueType_Integer64); | |
296 statement.SetParameterType("increment", ValueType_Integer64); | |
297 | |
298 Dictionary args; | |
299 args.SetIntegerValue("property", property); | |
300 args.SetIntegerValue("increment", increment); | |
301 | |
302 statement.Execute(args); | |
303 | |
304 return statement.ReadInteger64(0); | |
305 } | |
306 else | |
307 { | |
308 DatabaseManager::CachedStatement statement( | |
309 STATEMENT_FROM_HERE, manager, | |
310 "INSERT INTO ServerProperties (server, property, value) VALUES(${server}, ${property}, ${increment}) " | |
311 " ON CONFLICT (server, property) DO UPDATE SET value = CAST(ServerProperties.value AS BIGINT) + ${increment}" | |
312 " RETURNING CAST(value AS BIGINT)"); | |
313 | |
314 statement.SetParameterType("server", ValueType_Utf8String); | |
315 statement.SetParameterType("property", ValueType_Integer64); | |
316 statement.SetParameterType("increment", ValueType_Integer64); | |
317 | |
318 Dictionary args; | |
319 args.SetUtf8Value("server", serverIdentifier); | |
320 args.SetIntegerValue("property", property); | |
321 args.SetIntegerValue("increment", increment); | |
322 | |
323 statement.Execute(args); | |
324 | |
325 return statement.ReadInteger64(0); | |
326 } | |
327 } | |
328 } | |
329 | |
436
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
330 void PostgreSQLIndex::UpdateAndGetStatistics(DatabaseManager& manager, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
331 int64_t& patientsCount, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
332 int64_t& studiesCount, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
333 int64_t& seriesCount, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
334 int64_t& instancesCount, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
335 int64_t& compressedSize, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
336 int64_t& uncompressedSize) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
337 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
338 DatabaseManager::CachedStatement statement( |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
339 STATEMENT_FROM_HERE, manager, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
340 "SELECT * FROM UpdateStatistics()"); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
341 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
342 statement.Execute(); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
343 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
344 patientsCount = statement.ReadInteger64(0); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
345 studiesCount = statement.ReadInteger64(1); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
346 seriesCount = statement.ReadInteger64(2); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
347 instancesCount = statement.ReadInteger64(3); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
348 compressedSize = statement.ReadInteger64(4); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
349 uncompressedSize = statement.ReadInteger64(5); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
350 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
351 |
433
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
352 void PostgreSQLIndex::ClearDeletedFiles(DatabaseManager& manager) |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
353 { |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
354 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
355 DatabaseManager::CachedStatement statement( |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
356 STATEMENT_FROM_HERE, manager, |
435
326f8304daa1
new creating temporary tables inside functions
Alain Mazy <am@osimis.io>
parents:
434
diff
changeset
|
357 "SELECT CreateDeletedFilesTemporaryTable()" |
433
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
358 ); |
435
326f8304daa1
new creating temporary tables inside functions
Alain Mazy <am@osimis.io>
parents:
434
diff
changeset
|
359 statement.ExecuteWithoutResult(); |
433
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
360 } |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
361 |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
362 } |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
363 |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
364 void PostgreSQLIndex::ClearDeletedResources(DatabaseManager& manager) |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
365 { |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
366 { // note: the temporary table lifespan is the session, not the transaction -> that's why we need the IF NOT EXISTS |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
367 DatabaseManager::CachedStatement statement( |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
368 STATEMENT_FROM_HERE, manager, |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
369 "CREATE TEMPORARY TABLE IF NOT EXISTS DeletedResources(" |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
370 "resourceType INTEGER NOT NULL," |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
371 "publicId VARCHAR(64) NOT NULL" |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
372 ");" |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
373 ); |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
374 statement.Execute(); |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
375 } |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
376 { |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
377 DatabaseManager::CachedStatement statement( |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
378 STATEMENT_FROM_HERE, manager, |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
379 "DELETE FROM DeletedResources;" |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
380 ); |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
381 |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
382 statement.Execute(); |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
383 } |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
384 |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
385 } |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
386 |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
387 void PostgreSQLIndex::ClearRemainingAncestor(DatabaseManager& manager) |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
388 { |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
389 } |
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
390 |
434
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
391 void PostgreSQLIndex::DeleteResource(IDatabaseBackendOutput& output, |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
392 DatabaseManager& manager, |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
393 int64_t id) |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
394 { |
435
326f8304daa1
new creating temporary tables inside functions
Alain Mazy <am@osimis.io>
parents:
434
diff
changeset
|
395 // clearing of temporary table is now implemented in the funcion DeleteResource |
434
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
396 DatabaseManager::CachedStatement statement( |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
397 STATEMENT_FROM_HERE, manager, |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
398 "SELECT * FROM DeleteResource(${id})"); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
399 |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
400 statement.SetParameterType("id", ValueType_Integer64); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
401 |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
402 Dictionary args; |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
403 args.SetIntegerValue("id", id); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
404 |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
405 statement.Execute(args); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
406 |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
407 if (statement.IsDone() || |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
408 statement.GetResultFieldsCount() != 2) |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
409 { |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
410 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
411 } |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
412 |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
413 statement.SetResultFieldType(0, ValueType_Integer64); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
414 statement.SetResultFieldType(1, ValueType_Utf8String); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
415 |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
416 if (!statement.IsNull(0)) |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
417 { |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
418 output.SignalRemainingAncestor( |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
419 statement.ReadString(1), |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
420 static_cast<OrthancPluginResourceType>(statement.ReadInteger32(0))); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
421 } |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
422 |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
423 SignalDeletedFiles(output, manager); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
424 SignalDeletedResources(output, manager); |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
425 } |
23c7af6f671a
DeleteResource does not need the RemainingAncestor table anymore
Alain Mazy <am@osimis.io>
parents:
433
diff
changeset
|
426 |
433
5964ce6385a5
use temporary tables for DeletedFiles, RemainingAncestor and DeletedResources
Alain Mazy <am@osimis.io>
parents:
432
diff
changeset
|
427 |
72
8dd29af7c844
new extension: FastTotalSize
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
71
diff
changeset
|
428 |
78 | 429 #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
|
430 void PostgreSQLIndex::CreateInstance(OrthancPluginCreateInstanceResult& result, |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
431 DatabaseManager& manager, |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
432 const char* hashPatient, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
433 const char* hashStudy, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
434 const char* hashSeries, |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
435 const char* hashInstance) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
436 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
437 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
438 STATEMENT_FROM_HERE, manager, |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
439 "SELECT * FROM CreateInstance(${patient}, ${study}, ${series}, ${instance})"); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
440 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
441 statement.SetParameterType("patient", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
442 statement.SetParameterType("study", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
443 statement.SetParameterType("series", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
444 statement.SetParameterType("instance", ValueType_Utf8String); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
445 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
446 Dictionary args; |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
447 args.SetUtf8Value("patient", hashPatient); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
448 args.SetUtf8Value("study", hashStudy); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
449 args.SetUtf8Value("series", hashSeries); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
450 args.SetUtf8Value("instance", hashInstance); |
418
a7f0f27fe33c
wip: advisory lock around CreateInstance: not ok see WO-139
Alain Mazy <am@osimis.io>
parents:
403
diff
changeset
|
451 |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
452 statement.Execute(args); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
453 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
454 if (statement.IsDone() || |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
455 statement.GetResultFieldsCount() != 8) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
456 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
457 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
458 } |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
459 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
460 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
|
461 { |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
462 statement.SetResultFieldType(i, ValueType_Integer64); |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
463 } |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
464 |
432
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
431
diff
changeset
|
465 // LOG(INFO) << statement.ReadInteger64(0) << statement.ReadInteger64(1) << statement.ReadInteger64(2) << statement.ReadInteger64(3); |
8b7c1c423367
new 'TransactionMode' config + rewrote ResourceDeletedFunc to avoid IF/THEN/ELSE pattern
Alain Mazy <am@osimis.io>
parents:
431
diff
changeset
|
466 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
467 result.isNewInstance = (statement.ReadInteger64(3) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
468 result.instanceId = statement.ReadInteger64(7); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
469 |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
470 if (result.isNewInstance) |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
471 { |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
472 result.isNewPatient = (statement.ReadInteger64(0) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
473 result.isNewStudy = (statement.ReadInteger64(1) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
474 result.isNewSeries = (statement.ReadInteger64(2) == 1); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
475 result.patientId = statement.ReadInteger64(4); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
476 result.studyId = statement.ReadInteger64(5); |
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
477 result.seriesId = statement.ReadInteger64(6); |
71
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
478 } |
d40c5fecd160
new extension implemented for PostgreSQL: CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
67
diff
changeset
|
479 } |
73
aa81c1c80c75
fix compatibility with older sdk
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
72
diff
changeset
|
480 #endif |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
481 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
482 |
436
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
483 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
484 static void ExecuteSetResourcesContentTags( |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
485 DatabaseManager& manager, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
486 const std::string& table, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
487 const std::string& variablePrefix, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
488 uint32_t count, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
489 const OrthancPluginResourcesContentTags* tags) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
490 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
491 std::string sql; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
492 Dictionary args; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
493 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
494 for (uint32_t i = 0; i < count; i++) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
495 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
496 std::string name = variablePrefix + boost::lexical_cast<std::string>(i); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
497 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
498 args.SetUtf8Value(name, tags[i].value); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
499 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
500 std::string insert = ("(" + boost::lexical_cast<std::string>(tags[i].resource) + ", " + |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
501 boost::lexical_cast<std::string>(tags[i].group) + ", " + |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
502 boost::lexical_cast<std::string>(tags[i].element) + ", " + |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
503 "${" + name + "})"); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
504 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
505 if (sql.empty()) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
506 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
507 sql = "INSERT INTO " + table + " VALUES " + insert; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
508 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
509 else |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
510 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
511 sql += ", " + insert; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
512 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
513 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
514 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
515 if (!sql.empty()) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
516 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
517 DatabaseManager::StandaloneStatement statement(manager, sql); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
518 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
519 for (uint32_t i = 0; i < count; i++) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
520 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
521 statement.SetParameterType(variablePrefix + boost::lexical_cast<std::string>(i), |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
522 ValueType_Utf8String); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
523 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
524 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
525 statement.Execute(args); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
526 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
527 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
528 #endif |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
529 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
530 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
531 #if ORTHANC_PLUGINS_HAS_DATABASE_CONSTRAINT == 1 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
532 static void ExecuteSetResourcesContentMetadata( |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
533 DatabaseManager& manager, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
534 bool hasRevisionsSupport, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
535 uint32_t count, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
536 const OrthancPluginResourcesContentMetadata* metadata) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
537 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
538 if (count < 1) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
539 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
540 return; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
541 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
542 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
543 std::vector<std::string> resourceIds; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
544 std::vector<std::string> metadataTypes; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
545 std::vector<std::string> metadataValues; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
546 std::vector<std::string> revisions; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
547 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
548 Dictionary args; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
549 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
550 for (uint32_t i = 0; i < count; i++) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
551 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
552 std::string argName = "m" + boost::lexical_cast<std::string>(i); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
553 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
554 args.SetUtf8Value(argName, metadata[i].value); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
555 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
556 resourceIds.push_back(boost::lexical_cast<std::string>(metadata[i].resource)); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
557 metadataTypes.push_back(boost::lexical_cast<std::string>(metadata[i].metadata)); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
558 metadataValues.push_back("${" + argName + "}"); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
559 revisions.push_back("0"); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
560 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
561 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
562 std::string joinedResourceIds; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
563 std::string joinedMetadataTypes; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
564 std::string joinedMetadataValues; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
565 std::string joinedRevisions; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
566 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
567 Orthanc::Toolbox::JoinStrings(joinedResourceIds, resourceIds, ","); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
568 Orthanc::Toolbox::JoinStrings(joinedMetadataTypes, metadataTypes, ","); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
569 Orthanc::Toolbox::JoinStrings(joinedMetadataValues, metadataValues, ","); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
570 Orthanc::Toolbox::JoinStrings(joinedRevisions, revisions, ","); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
571 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
572 std::string sql = std::string("SELECT InsertOrUpdateMetadata(ARRAY[") + |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
573 joinedResourceIds + "], ARRAY[" + |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
574 joinedMetadataTypes + "], ARRAY[" + |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
575 joinedMetadataValues + "], ARRAY[" + |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
576 joinedRevisions + "])"; |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
577 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
578 DatabaseManager::StandaloneStatement statement(manager, sql); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
579 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
580 for (uint32_t i = 0; i < count; i++) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
581 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
582 statement.SetParameterType("m" + boost::lexical_cast<std::string>(i), |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
583 ValueType_Utf8String); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
584 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
585 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
586 statement.Execute(args); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
587 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
588 #endif |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
589 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
590 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
591 void PostgreSQLIndex::SetResourcesContent(DatabaseManager& manager, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
592 uint32_t countIdentifierTags, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
593 const OrthancPluginResourcesContentTags* identifierTags, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
594 uint32_t countMainDicomTags, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
595 const OrthancPluginResourcesContentTags* mainDicomTags, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
596 uint32_t countMetadata, |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
597 const OrthancPluginResourcesContentMetadata* metadata) |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
598 { |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
599 ExecuteSetResourcesContentTags(manager, "DicomIdentifiers", "i", |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
600 countIdentifierTags, identifierTags); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
601 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
602 ExecuteSetResourcesContentTags(manager, "MainDicomTags", "t", |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
603 countMainDicomTags, mainDicomTags); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
604 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
605 ExecuteSetResourcesContentMetadata(manager, HasRevisionsSupport(), countMetadata, metadata); |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
606 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
607 } |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
608 |
f16faa1fdc46
InsertOrUpdateMetadata function + UpdateAndGetStatistics
Alain Mazy <am@osimis.io>
parents:
435
diff
changeset
|
609 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
610 uint64_t PostgreSQLIndex::GetResourcesCount(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
611 OrthancPluginResourceType resourceType) |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
612 { |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
613 // Optimized version thanks to the "FastCountResources.sql" extension |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
614 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
615 assert(OrthancPluginResourceType_Patient == 0 && |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
616 OrthancPluginResourceType_Study == 1 && |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
617 OrthancPluginResourceType_Series == 2 && |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
618 OrthancPluginResourceType_Instance == 3); |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
619 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
620 uint64_t result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
621 |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
622 { |
473
15e609c439d1
Fixed the MaximumStorageSize & MaximumPatientCount.
Alain Mazy <am@osimis.io>
parents:
467
diff
changeset
|
623 DatabaseManager::StandaloneStatement statement( |
15e609c439d1
Fixed the MaximumStorageSize & MaximumPatientCount.
Alain Mazy <am@osimis.io>
parents:
467
diff
changeset
|
624 manager, |
15e609c439d1
Fixed the MaximumStorageSize & MaximumPatientCount.
Alain Mazy <am@osimis.io>
parents:
467
diff
changeset
|
625 std::string("SELECT * FROM UpdateSingleStatistic(") + boost::lexical_cast<std::string>(resourceType + 2) + ")"); // For an explanation of the "+ 2" below, check out "PrepareIndex.sql" |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
626 |
473
15e609c439d1
Fixed the MaximumStorageSize & MaximumPatientCount.
Alain Mazy <am@osimis.io>
parents:
467
diff
changeset
|
627 statement.Execute(); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
628 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
629 result = static_cast<uint64_t>(statement.ReadInteger64(0)); |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
630 } |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
631 |
428
4d0bacbd0fba
rewrote CreateInstance to make it compatible with READ COMMITED transactions
Alain Mazy <am@osimis.io>
parents:
427
diff
changeset
|
632 // disabled because this is not alway true while transactions are being executed in READ COMITTED TRANSACTION. This is however true when no files are being delete/added |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
633 assert(result == IndexBackend::GetResourcesCount(manager, resourceType)); |
428
4d0bacbd0fba
rewrote CreateInstance to make it compatible with READ COMMITED transactions
Alain Mazy <am@osimis.io>
parents:
427
diff
changeset
|
634 |
79
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
635 return result; |
cb0aac9bbada
optimization for /statistics URI
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
78
diff
changeset
|
636 } |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
637 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
638 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
639 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
|
640 { |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
641 DatabaseManager::CachedStatement statement( |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
642 STATEMENT_FROM_HERE, manager, |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
643 "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
|
644 |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
645 statement.SetReadOnly(true); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
646 statement.Execute(); |
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
647 |
263
29d2b76516f6
fix mysql and postgresql builds
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
255
diff
changeset
|
648 return statement.ReadInteger64(0); |
85
1012fe77241c
new extension implemented for PostgreSQL and SQLite: GetLastChangeIndex
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
79
diff
changeset
|
649 } |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
650 |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
651 |
225
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
652 void PostgreSQLIndex::TagMostRecentPatient(DatabaseManager& manager, |
94c9908e6aca
removed DatabaseManager member out of class IndexBackend
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
221
diff
changeset
|
653 int64_t patient) |
90
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
654 { |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
655 // 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
|
656 // backward compatibility is necessary |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
657 throw Orthanc::OrthancException(Orthanc::ErrorCode_Database); |
e61587582cef
moved extension TagMostRecentPatient into stored procedure CreateInstance
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
88
diff
changeset
|
658 } |
0 | 659 } |