comparison OrthancServer/Database/SQLiteDatabaseWrapper.h @ 3093:2e1808b6146a db-changes

reorganization of folders
author Sebastien Jodogne <s.jodogne@gmail.com>
date Sat, 05 Jan 2019 16:09:21 +0100
parents OrthancServer/SQLiteDatabaseWrapper.h@476cba12c2b0
children 61da3c9b4121
comparison
equal deleted inserted replaced
3092:fc57988dbfd8 3093:2e1808b6146a
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-2019 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 "../ServerToolbox.h"
40 #include "Compatibility/ICreateInstance.h"
41 #include "Compatibility/IGetChildrenMetadata.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::ISetResourcesContent
61 {
62 private:
63 class Transaction;
64 class LookupFormatter;
65
66 IDatabaseListener* listener_;
67 SQLite::Connection db_;
68 Internals::SignalRemainingAncestor* signalRemainingAncestor_;
69 unsigned int version_;
70
71 void GetChangesInternal(std::list<ServerIndexChange>& target,
72 bool& done,
73 SQLite::Statement& s,
74 uint32_t maxResults);
75
76 void GetExportedResourcesInternal(std::list<ExportedResource>& target,
77 bool& done,
78 SQLite::Statement& s,
79 uint32_t maxResults);
80
81 void ClearTable(const std::string& tableName);
82
83 public:
84 SQLiteDatabaseWrapper(const std::string& path);
85
86 SQLiteDatabaseWrapper();
87
88 virtual void Open()
89 ORTHANC_OVERRIDE;
90
91 virtual void Close()
92 ORTHANC_OVERRIDE
93 {
94 db_.Close();
95 }
96
97 virtual void SetListener(IDatabaseListener& listener)
98 ORTHANC_OVERRIDE;
99
100 virtual bool LookupParent(int64_t& parentId,
101 int64_t resourceId)
102 ORTHANC_OVERRIDE;
103
104 virtual std::string GetPublicId(int64_t resourceId)
105 ORTHANC_OVERRIDE;
106
107 virtual ResourceType GetResourceType(int64_t resourceId)
108 ORTHANC_OVERRIDE;
109
110 virtual void DeleteResource(int64_t id)
111 ORTHANC_OVERRIDE;
112
113 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/,
114 bool& done /*out*/,
115 int64_t since,
116 uint32_t maxResults)
117 ORTHANC_OVERRIDE;
118
119 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/)
120 ORTHANC_OVERRIDE;
121
122 virtual IDatabaseWrapper::ITransaction* StartTransaction()
123 ORTHANC_OVERRIDE;
124
125 virtual void FlushToDisk()
126 ORTHANC_OVERRIDE
127 {
128 db_.FlushToDisk();
129 }
130
131 virtual bool HasFlushToDisk() const
132 ORTHANC_OVERRIDE
133 {
134 return true;
135 }
136
137 virtual void ClearChanges()
138 ORTHANC_OVERRIDE
139 {
140 ClearTable("Changes");
141 }
142
143 virtual void ClearExportedResources()
144 ORTHANC_OVERRIDE
145 {
146 ClearTable("ExportedResources");
147 }
148
149 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
150 int64_t id)
151 ORTHANC_OVERRIDE;
152
153 virtual unsigned int GetDatabaseVersion()
154 ORTHANC_OVERRIDE
155 {
156 return version_;
157 }
158
159 virtual void Upgrade(unsigned int targetVersion,
160 IStorageArea& storageArea)
161 ORTHANC_OVERRIDE;
162
163
164 /**
165 * The methods declared below are for unit testing only!
166 **/
167
168 const char* GetErrorMessage() const
169 {
170 return db_.GetErrorMessage();
171 }
172
173 void GetChildren(std::list<std::string>& childrenPublicIds,
174 int64_t id);
175
176 int64_t GetTableRecordCount(const std::string& table);
177
178 bool GetParentPublicId(std::string& target,
179 int64_t id);
180
181
182
183 /**
184 * Until Orthanc 1.4.0, the methods below were part of the
185 * "DatabaseWrapperBase" class, that is now placed in the
186 * graveyard.
187 **/
188
189 virtual void SetGlobalProperty(GlobalProperty property,
190 const std::string& value)
191 ORTHANC_OVERRIDE;
192
193 virtual bool LookupGlobalProperty(std::string& target,
194 GlobalProperty property)
195 ORTHANC_OVERRIDE;
196
197 virtual int64_t CreateResource(const std::string& publicId,
198 ResourceType type)
199 ORTHANC_OVERRIDE;
200
201 virtual bool LookupResource(int64_t& id,
202 ResourceType& type,
203 const std::string& publicId)
204 ORTHANC_OVERRIDE;
205
206 virtual void AttachChild(int64_t parent,
207 int64_t child)
208 ORTHANC_OVERRIDE;
209
210 virtual void SetMetadata(int64_t id,
211 MetadataType type,
212 const std::string& value)
213 ORTHANC_OVERRIDE;
214
215 virtual void DeleteMetadata(int64_t id,
216 MetadataType type)
217 ORTHANC_OVERRIDE;
218
219 virtual bool LookupMetadata(std::string& target,
220 int64_t id,
221 MetadataType type)
222 ORTHANC_OVERRIDE;
223
224 virtual void ListAvailableMetadata(std::list<MetadataType>& target,
225 int64_t id)
226 ORTHANC_OVERRIDE;
227
228 virtual void AddAttachment(int64_t id,
229 const FileInfo& attachment)
230 ORTHANC_OVERRIDE;
231
232 virtual void DeleteAttachment(int64_t id,
233 FileContentType attachment)
234 ORTHANC_OVERRIDE;
235
236 virtual void ListAvailableAttachments(std::list<FileContentType>& target,
237 int64_t id)
238 ORTHANC_OVERRIDE;
239
240 virtual bool LookupAttachment(FileInfo& attachment,
241 int64_t id,
242 FileContentType contentType)
243 ORTHANC_OVERRIDE;
244
245 virtual void ClearMainDicomTags(int64_t id)
246 ORTHANC_OVERRIDE;
247
248 virtual void SetMainDicomTag(int64_t id,
249 const DicomTag& tag,
250 const std::string& value)
251 ORTHANC_OVERRIDE;
252
253 virtual void SetIdentifierTag(int64_t id,
254 const DicomTag& tag,
255 const std::string& value)
256 ORTHANC_OVERRIDE;
257
258 virtual void GetMainDicomTags(DicomMap& map,
259 int64_t id)
260 ORTHANC_OVERRIDE;
261
262 virtual void GetChildrenPublicId(std::list<std::string>& target,
263 int64_t id)
264 ORTHANC_OVERRIDE;
265
266 virtual void GetChildrenInternalId(std::list<int64_t>& target,
267 int64_t id)
268 ORTHANC_OVERRIDE;
269
270 virtual void LogChange(int64_t internalId,
271 const ServerIndexChange& change)
272 ORTHANC_OVERRIDE;
273
274 virtual void LogExportedResource(const ExportedResource& resource)
275 ORTHANC_OVERRIDE;
276
277 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/,
278 bool& done /*out*/,
279 int64_t since,
280 uint32_t maxResults)
281 ORTHANC_OVERRIDE;
282
283 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/)
284 ORTHANC_OVERRIDE;
285
286 virtual uint64_t GetTotalCompressedSize()
287 ORTHANC_OVERRIDE;
288
289 virtual uint64_t GetTotalUncompressedSize()
290 ORTHANC_OVERRIDE;
291
292 virtual uint64_t GetResourceCount(ResourceType resourceType)
293 ORTHANC_OVERRIDE;
294
295 virtual void GetAllPublicIds(std::list<std::string>& target,
296 ResourceType resourceType)
297 ORTHANC_OVERRIDE;
298
299 virtual void GetAllPublicIds(std::list<std::string>& target,
300 ResourceType resourceType,
301 size_t since,
302 size_t limit)
303 ORTHANC_OVERRIDE;
304
305 virtual bool SelectPatientToRecycle(int64_t& internalId)
306 ORTHANC_OVERRIDE;
307
308 virtual bool SelectPatientToRecycle(int64_t& internalId,
309 int64_t patientIdToAvoid)
310 ORTHANC_OVERRIDE;
311
312 virtual bool IsProtectedPatient(int64_t internalId)
313 ORTHANC_OVERRIDE;
314
315 virtual void SetProtectedPatient(int64_t internalId,
316 bool isProtected)
317 ORTHANC_OVERRIDE;
318
319 virtual bool IsExistingResource(int64_t internalId)
320 ORTHANC_OVERRIDE;
321
322 virtual bool IsDiskSizeAbove(uint64_t threshold)
323 ORTHANC_OVERRIDE;
324
325 virtual void ApplyLookupResources(std::list<std::string>& resourcesId,
326 std::list<std::string>* instancesId,
327 const std::vector<DatabaseConstraint>& lookup,
328 ResourceType queryLevel,
329 size_t limit)
330 ORTHANC_OVERRIDE;
331
332 virtual bool CreateInstance(CreateInstanceResult& result,
333 int64_t& instanceId,
334 const std::string& patient,
335 const std::string& study,
336 const std::string& series,
337 const std::string& instance)
338 ORTHANC_OVERRIDE
339 {
340 return ICreateInstance::Apply
341 (*this, result, instanceId, patient, study, series, instance);
342 }
343
344 virtual void SetResourcesContent(const Orthanc::ResourcesContent& content)
345 ORTHANC_OVERRIDE
346 {
347 ISetResourcesContent::Apply(*this, content);
348 }
349
350 virtual void GetChildrenMetadata(std::list<std::string>& target,
351 int64_t resourceId,
352 MetadataType metadata)
353 ORTHANC_OVERRIDE
354 {
355 IGetChildrenMetadata::Apply(*this, target, resourceId, metadata);
356 }
357 };
358 }