comparison OrthancServer/SQLiteDatabaseWrapper.h @ 3017:517fc4767ae0 db-changes

renamed class DatabaseWrapper as SQLiteDatabaseWrapper
author Sebastien Jodogne <s.jodogne@gmail.com>
date Fri, 14 Dec 2018 14:55:49 +0100
parents OrthancServer/DatabaseWrapper.h@bb63068844ae
children 8336204d95dc
comparison
equal deleted inserted replaced
3016:777762336381 3017:517fc4767ae0
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-2018 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 "../Core/SQLite/Transaction.h"
40
41 namespace Orthanc
42 {
43 namespace Internals
44 {
45 class SignalRemainingAncestor;
46 }
47
48 /**
49 * This class manages an instance of the Orthanc SQLite database. It
50 * translates low-level requests into SQL statements. Mutual
51 * exclusion MUST be implemented at a higher level.
52 **/
53 class SQLiteDatabaseWrapper : public IDatabaseWrapper
54 {
55 private:
56 IDatabaseListener* listener_;
57 SQLite::Connection db_;
58 Internals::SignalRemainingAncestor* signalRemainingAncestor_;
59 unsigned int version_;
60
61 void GetChangesInternal(std::list<ServerIndexChange>& target,
62 bool& done,
63 SQLite::Statement& s,
64 uint32_t maxResults);
65
66 void GetExportedResourcesInternal(std::list<ExportedResource>& target,
67 bool& done,
68 SQLite::Statement& s,
69 uint32_t maxResults);
70
71 void ClearTable(const std::string& tableName);
72
73 public:
74 SQLiteDatabaseWrapper(const std::string& path);
75
76 SQLiteDatabaseWrapper();
77
78 virtual void Open();
79
80 virtual void Close()
81 {
82 db_.Close();
83 }
84
85 virtual void SetListener(IDatabaseListener& listener);
86
87 virtual bool LookupParent(int64_t& parentId,
88 int64_t resourceId);
89
90 virtual std::string GetPublicId(int64_t resourceId);
91
92 virtual ResourceType GetResourceType(int64_t resourceId);
93
94 virtual void DeleteResource(int64_t id);
95
96 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/,
97 bool& done /*out*/,
98 int64_t since,
99 uint32_t maxResults);
100
101 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/);
102
103 virtual SQLite::ITransaction* StartTransaction()
104 {
105 return new SQLite::Transaction(db_);
106 }
107
108 virtual void FlushToDisk()
109 {
110 db_.FlushToDisk();
111 }
112
113 virtual bool HasFlushToDisk() const
114 {
115 return true;
116 }
117
118 virtual void ClearChanges()
119 {
120 ClearTable("Changes");
121 }
122
123 virtual void ClearExportedResources()
124 {
125 ClearTable("ExportedResources");
126 }
127
128 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
129 int64_t id);
130
131 virtual unsigned int GetDatabaseVersion()
132 {
133 return version_;
134 }
135
136 virtual void Upgrade(unsigned int targetVersion,
137 IStorageArea& storageArea);
138
139
140 /**
141 * The methods declared below are for unit testing only!
142 **/
143
144 const char* GetErrorMessage() const
145 {
146 return db_.GetErrorMessage();
147 }
148
149 void GetChildren(std::list<std::string>& childrenPublicIds,
150 int64_t id);
151
152 int64_t GetTableRecordCount(const std::string& table);
153
154 bool GetParentPublicId(std::string& target,
155 int64_t id);
156
157
158
159 /**
160 * Until Orthanc 1.4.0, the methods below were part of the
161 * "DatabaseWrapperBase" class, that is now placed in the
162 * graveyard.
163 **/
164
165 virtual void SetGlobalProperty(GlobalProperty property,
166 const std::string& value);
167
168 virtual bool LookupGlobalProperty(std::string& target,
169 GlobalProperty property);
170
171 virtual int64_t CreateResource(const std::string& publicId,
172 ResourceType type);
173
174 virtual bool LookupResource(int64_t& id,
175 ResourceType& type,
176 const std::string& publicId);
177
178 virtual void AttachChild(int64_t parent,
179 int64_t child);
180
181 virtual void SetMetadata(int64_t id,
182 MetadataType type,
183 const std::string& value);
184
185 virtual void DeleteMetadata(int64_t id,
186 MetadataType type);
187
188 virtual bool LookupMetadata(std::string& target,
189 int64_t id,
190 MetadataType type);
191
192 virtual void ListAvailableMetadata(std::list<MetadataType>& target,
193 int64_t id);
194
195 virtual void AddAttachment(int64_t id,
196 const FileInfo& attachment);
197
198 virtual void DeleteAttachment(int64_t id,
199 FileContentType attachment);
200
201 virtual void ListAvailableAttachments(std::list<FileContentType>& target,
202 int64_t id);
203
204 virtual bool LookupAttachment(FileInfo& attachment,
205 int64_t id,
206 FileContentType contentType);
207
208 virtual void ClearMainDicomTags(int64_t id);
209
210 virtual void SetMainDicomTag(int64_t id,
211 const DicomTag& tag,
212 const std::string& value);
213
214 virtual void SetIdentifierTag(int64_t id,
215 const DicomTag& tag,
216 const std::string& value);
217
218 virtual void GetMainDicomTags(DicomMap& map,
219 int64_t id);
220
221 virtual void GetChildrenPublicId(std::list<std::string>& target,
222 int64_t id);
223
224 virtual void GetChildrenInternalId(std::list<int64_t>& target,
225 int64_t id);
226
227 virtual void LogChange(int64_t internalId,
228 const ServerIndexChange& change);
229
230 virtual void LogExportedResource(const ExportedResource& resource);
231
232 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/,
233 bool& done /*out*/,
234 int64_t since,
235 uint32_t maxResults);
236
237 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/);
238
239 virtual uint64_t GetTotalCompressedSize();
240
241 virtual uint64_t GetTotalUncompressedSize();
242
243 virtual uint64_t GetResourceCount(ResourceType resourceType);
244
245 virtual void GetAllInternalIds(std::list<int64_t>& target,
246 ResourceType resourceType);
247
248 virtual void GetAllPublicIds(std::list<std::string>& target,
249 ResourceType resourceType);
250
251 virtual void GetAllPublicIds(std::list<std::string>& target,
252 ResourceType resourceType,
253 size_t since,
254 size_t limit);
255
256 virtual bool SelectPatientToRecycle(int64_t& internalId);
257
258 virtual bool SelectPatientToRecycle(int64_t& internalId,
259 int64_t patientIdToAvoid);
260
261 virtual bool IsProtectedPatient(int64_t internalId);
262
263 virtual void SetProtectedPatient(int64_t internalId,
264 bool isProtected);
265
266 virtual bool IsExistingResource(int64_t internalId);
267
268 virtual void LookupIdentifier(std::list<int64_t>& result,
269 ResourceType level,
270 const DicomTag& tag,
271 IdentifierConstraintType type,
272 const std::string& value);
273
274 virtual void LookupIdentifierRange(std::list<int64_t>& result,
275 ResourceType level,
276 const DicomTag& tag,
277 const std::string& start,
278 const std::string& end);
279 };
280 }