Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/SQLiteDatabaseWrapper.h @ 4044:d25f4c0fa160 framework
splitting code into OrthancFramework and OrthancServer
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 10 Jun 2020 20:30:34 +0200 |
parents | OrthancServer/Database/SQLiteDatabaseWrapper.h@94f4a18a79cc |
children | 05b8fd21089c |
comparison
equal
deleted
inserted
replaced
4043:6c6239aec462 | 4044:d25f4c0fa160 |
---|---|
1 /** | |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics | |
4 * Department, University Hospital of Liege, Belgium | |
5 * Copyright (C) 2017-2020 Osimis S.A., Belgium | |
6 * | |
7 * This program is free software: you can redistribute it and/or | |
8 * modify it under the terms of the GNU General Public License as | |
9 * published by the Free Software Foundation, either version 3 of the | |
10 * License, or (at your option) any later version. | |
11 * | |
12 * In addition, as a special exception, the copyright holders of this | |
13 * program give permission to link the code of its release with the | |
14 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
15 * that use the same license as the "OpenSSL" library), and distribute | |
16 * the linked executables. You must obey the GNU General Public License | |
17 * in all respects for all of the code used other than "OpenSSL". If you | |
18 * modify file(s) with this exception, you may extend this exception to | |
19 * your version of the file(s), but you are not obligated to do so. If | |
20 * you do not wish to do so, delete this exception statement from your | |
21 * version. If you delete this exception statement from all source files | |
22 * in the program, then also delete it here. | |
23 * | |
24 * This program is distributed in the hope that it will be useful, but | |
25 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
27 * General Public License for more details. | |
28 * | |
29 * You should have received a copy of the GNU General Public License | |
30 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
31 **/ | |
32 | |
33 | |
34 #pragma once | |
35 | |
36 #include "IDatabaseWrapper.h" | |
37 | |
38 #include "../../Core/SQLite/Connection.h" | |
39 #include "Compatibility/ICreateInstance.h" | |
40 #include "Compatibility/IGetChildrenMetadata.h" | |
41 #include "Compatibility/ILookupResourceAndParent.h" | |
42 #include "Compatibility/ISetResourcesContent.h" | |
43 | |
44 namespace Orthanc | |
45 { | |
46 namespace Internals | |
47 { | |
48 class SignalRemainingAncestor; | |
49 } | |
50 | |
51 /** | |
52 * This class manages an instance of the Orthanc SQLite database. It | |
53 * translates low-level requests into SQL statements. Mutual | |
54 * exclusion MUST be implemented at a higher level. | |
55 **/ | |
56 class SQLiteDatabaseWrapper : | |
57 public IDatabaseWrapper, | |
58 public Compatibility::ICreateInstance, | |
59 public Compatibility::IGetChildrenMetadata, | |
60 public Compatibility::ILookupResourceAndParent, | |
61 public Compatibility::ISetResourcesContent | |
62 { | |
63 private: | |
64 class Transaction; | |
65 class LookupFormatter; | |
66 | |
67 IDatabaseListener* listener_; | |
68 SQLite::Connection db_; | |
69 Internals::SignalRemainingAncestor* signalRemainingAncestor_; | |
70 unsigned int version_; | |
71 | |
72 void GetChangesInternal(std::list<ServerIndexChange>& target, | |
73 bool& done, | |
74 SQLite::Statement& s, | |
75 uint32_t maxResults); | |
76 | |
77 void GetExportedResourcesInternal(std::list<ExportedResource>& target, | |
78 bool& done, | |
79 SQLite::Statement& s, | |
80 uint32_t maxResults); | |
81 | |
82 void ClearTable(const std::string& tableName); | |
83 | |
84 // Unused => could be removed | |
85 int GetGlobalIntegerProperty(GlobalProperty property, | |
86 int defaultValue); | |
87 | |
88 public: | |
89 SQLiteDatabaseWrapper(const std::string& path); | |
90 | |
91 SQLiteDatabaseWrapper(); | |
92 | |
93 virtual void Open() | |
94 ORTHANC_OVERRIDE; | |
95 | |
96 virtual void Close() | |
97 ORTHANC_OVERRIDE | |
98 { | |
99 db_.Close(); | |
100 } | |
101 | |
102 virtual void SetListener(IDatabaseListener& listener) | |
103 ORTHANC_OVERRIDE; | |
104 | |
105 virtual bool LookupParent(int64_t& parentId, | |
106 int64_t resourceId) | |
107 ORTHANC_OVERRIDE; | |
108 | |
109 virtual std::string GetPublicId(int64_t resourceId) | |
110 ORTHANC_OVERRIDE; | |
111 | |
112 virtual ResourceType GetResourceType(int64_t resourceId) | |
113 ORTHANC_OVERRIDE; | |
114 | |
115 virtual void DeleteResource(int64_t id) | |
116 ORTHANC_OVERRIDE; | |
117 | |
118 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, | |
119 bool& done /*out*/, | |
120 int64_t since, | |
121 uint32_t maxResults) | |
122 ORTHANC_OVERRIDE; | |
123 | |
124 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/) | |
125 ORTHANC_OVERRIDE; | |
126 | |
127 virtual IDatabaseWrapper::ITransaction* StartTransaction() | |
128 ORTHANC_OVERRIDE; | |
129 | |
130 virtual void FlushToDisk() | |
131 ORTHANC_OVERRIDE | |
132 { | |
133 db_.FlushToDisk(); | |
134 } | |
135 | |
136 virtual bool HasFlushToDisk() const | |
137 ORTHANC_OVERRIDE | |
138 { | |
139 return true; | |
140 } | |
141 | |
142 virtual void ClearChanges() | |
143 ORTHANC_OVERRIDE | |
144 { | |
145 ClearTable("Changes"); | |
146 } | |
147 | |
148 virtual void ClearExportedResources() | |
149 ORTHANC_OVERRIDE | |
150 { | |
151 ClearTable("ExportedResources"); | |
152 } | |
153 | |
154 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target, | |
155 int64_t id) | |
156 ORTHANC_OVERRIDE; | |
157 | |
158 virtual unsigned int GetDatabaseVersion() | |
159 ORTHANC_OVERRIDE | |
160 { | |
161 return version_; | |
162 } | |
163 | |
164 virtual void Upgrade(unsigned int targetVersion, | |
165 IStorageArea& storageArea) | |
166 ORTHANC_OVERRIDE; | |
167 | |
168 | |
169 /** | |
170 * The methods declared below are for unit testing only! | |
171 **/ | |
172 | |
173 const char* GetErrorMessage() const | |
174 { | |
175 return db_.GetErrorMessage(); | |
176 } | |
177 | |
178 void GetChildren(std::list<std::string>& childrenPublicIds, | |
179 int64_t id); | |
180 | |
181 int64_t GetTableRecordCount(const std::string& table); | |
182 | |
183 bool GetParentPublicId(std::string& target, | |
184 int64_t id); | |
185 | |
186 | |
187 | |
188 /** | |
189 * Until Orthanc 1.4.0, the methods below were part of the | |
190 * "DatabaseWrapperBase" class, that is now placed in the | |
191 * graveyard. | |
192 **/ | |
193 | |
194 virtual void SetGlobalProperty(GlobalProperty property, | |
195 const std::string& value) | |
196 ORTHANC_OVERRIDE; | |
197 | |
198 virtual bool LookupGlobalProperty(std::string& target, | |
199 GlobalProperty property) | |
200 ORTHANC_OVERRIDE; | |
201 | |
202 virtual int64_t CreateResource(const std::string& publicId, | |
203 ResourceType type) | |
204 ORTHANC_OVERRIDE; | |
205 | |
206 virtual bool LookupResource(int64_t& id, | |
207 ResourceType& type, | |
208 const std::string& publicId) | |
209 ORTHANC_OVERRIDE; | |
210 | |
211 virtual void AttachChild(int64_t parent, | |
212 int64_t child) | |
213 ORTHANC_OVERRIDE; | |
214 | |
215 virtual void SetMetadata(int64_t id, | |
216 MetadataType type, | |
217 const std::string& value) | |
218 ORTHANC_OVERRIDE; | |
219 | |
220 virtual void DeleteMetadata(int64_t id, | |
221 MetadataType type) | |
222 ORTHANC_OVERRIDE; | |
223 | |
224 virtual bool LookupMetadata(std::string& target, | |
225 int64_t id, | |
226 MetadataType type) | |
227 ORTHANC_OVERRIDE; | |
228 | |
229 virtual void AddAttachment(int64_t id, | |
230 const FileInfo& attachment) | |
231 ORTHANC_OVERRIDE; | |
232 | |
233 virtual void DeleteAttachment(int64_t id, | |
234 FileContentType attachment) | |
235 ORTHANC_OVERRIDE; | |
236 | |
237 virtual void ListAvailableAttachments(std::list<FileContentType>& target, | |
238 int64_t id) | |
239 ORTHANC_OVERRIDE; | |
240 | |
241 virtual bool LookupAttachment(FileInfo& attachment, | |
242 int64_t id, | |
243 FileContentType contentType) | |
244 ORTHANC_OVERRIDE; | |
245 | |
246 virtual void ClearMainDicomTags(int64_t id) | |
247 ORTHANC_OVERRIDE; | |
248 | |
249 virtual void SetMainDicomTag(int64_t id, | |
250 const DicomTag& tag, | |
251 const std::string& value) | |
252 ORTHANC_OVERRIDE; | |
253 | |
254 virtual void SetIdentifierTag(int64_t id, | |
255 const DicomTag& tag, | |
256 const std::string& value) | |
257 ORTHANC_OVERRIDE; | |
258 | |
259 virtual void GetMainDicomTags(DicomMap& map, | |
260 int64_t id) | |
261 ORTHANC_OVERRIDE; | |
262 | |
263 virtual void GetChildrenPublicId(std::list<std::string>& target, | |
264 int64_t id) | |
265 ORTHANC_OVERRIDE; | |
266 | |
267 virtual void GetChildrenInternalId(std::list<int64_t>& target, | |
268 int64_t id) | |
269 ORTHANC_OVERRIDE; | |
270 | |
271 virtual void LogChange(int64_t internalId, | |
272 const ServerIndexChange& change) | |
273 ORTHANC_OVERRIDE; | |
274 | |
275 virtual void LogExportedResource(const ExportedResource& resource) | |
276 ORTHANC_OVERRIDE; | |
277 | |
278 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, | |
279 bool& done /*out*/, | |
280 int64_t since, | |
281 uint32_t maxResults) | |
282 ORTHANC_OVERRIDE; | |
283 | |
284 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) | |
285 ORTHANC_OVERRIDE; | |
286 | |
287 virtual uint64_t GetTotalCompressedSize() | |
288 ORTHANC_OVERRIDE; | |
289 | |
290 virtual uint64_t GetTotalUncompressedSize() | |
291 ORTHANC_OVERRIDE; | |
292 | |
293 virtual uint64_t GetResourceCount(ResourceType resourceType) | |
294 ORTHANC_OVERRIDE; | |
295 | |
296 virtual void GetAllPublicIds(std::list<std::string>& target, | |
297 ResourceType resourceType) | |
298 ORTHANC_OVERRIDE; | |
299 | |
300 virtual void GetAllPublicIds(std::list<std::string>& target, | |
301 ResourceType resourceType, | |
302 size_t since, | |
303 size_t limit) | |
304 ORTHANC_OVERRIDE; | |
305 | |
306 virtual bool SelectPatientToRecycle(int64_t& internalId) | |
307 ORTHANC_OVERRIDE; | |
308 | |
309 virtual bool SelectPatientToRecycle(int64_t& internalId, | |
310 int64_t patientIdToAvoid) | |
311 ORTHANC_OVERRIDE; | |
312 | |
313 virtual bool IsProtectedPatient(int64_t internalId) | |
314 ORTHANC_OVERRIDE; | |
315 | |
316 virtual void SetProtectedPatient(int64_t internalId, | |
317 bool isProtected) | |
318 ORTHANC_OVERRIDE; | |
319 | |
320 virtual bool IsExistingResource(int64_t internalId) | |
321 ORTHANC_OVERRIDE; | |
322 | |
323 virtual bool IsDiskSizeAbove(uint64_t threshold) | |
324 ORTHANC_OVERRIDE; | |
325 | |
326 virtual void ApplyLookupResources(std::list<std::string>& resourcesId, | |
327 std::list<std::string>* instancesId, | |
328 const std::vector<DatabaseConstraint>& lookup, | |
329 ResourceType queryLevel, | |
330 size_t limit) | |
331 ORTHANC_OVERRIDE; | |
332 | |
333 virtual bool CreateInstance(CreateInstanceResult& result, | |
334 int64_t& instanceId, | |
335 const std::string& patient, | |
336 const std::string& study, | |
337 const std::string& series, | |
338 const std::string& instance) | |
339 ORTHANC_OVERRIDE | |
340 { | |
341 return ICreateInstance::Apply | |
342 (*this, result, instanceId, patient, study, series, instance); | |
343 } | |
344 | |
345 virtual void SetResourcesContent(const Orthanc::ResourcesContent& content) | |
346 ORTHANC_OVERRIDE | |
347 { | |
348 ISetResourcesContent::Apply(*this, content); | |
349 } | |
350 | |
351 virtual void GetChildrenMetadata(std::list<std::string>& target, | |
352 int64_t resourceId, | |
353 MetadataType metadata) | |
354 ORTHANC_OVERRIDE | |
355 { | |
356 IGetChildrenMetadata::Apply(*this, target, resourceId, metadata); | |
357 } | |
358 | |
359 virtual int64_t GetLastChangeIndex() ORTHANC_OVERRIDE; | |
360 | |
361 virtual void TagMostRecentPatient(int64_t patient) ORTHANC_OVERRIDE; | |
362 | |
363 virtual bool LookupResourceAndParent(int64_t& id, | |
364 ResourceType& type, | |
365 std::string& parentPublicId, | |
366 const std::string& publicId) | |
367 ORTHANC_OVERRIDE | |
368 { | |
369 return ILookupResourceAndParent::Apply(*this, id, type, parentPublicId, publicId); | |
370 } | |
371 }; | |
372 } |