Mercurial > hg > orthanc
annotate OrthancServer/DatabaseWrapper.h @ 1517:4f8c8ef114db
cont
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 11 Aug 2015 10:32:34 +0200 |
parents | 0586ed8897f1 |
children | c40fe92a68e7 |
rev | line source |
---|---|
183 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1288
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1286
diff
changeset
|
3 * Copyright (C) 2012-2015 Sebastien Jodogne, Medical Physics |
6e7e5ed91c2d
upgrade to year 2015
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1286
diff
changeset
|
4 * Department, University Hospital of Liege, Belgium |
183 | 5 * |
6 * This program is free software: you can redistribute it and/or | |
7 * modify it under the terms of the GNU General Public License as | |
8 * published by the Free Software Foundation, either version 3 of the | |
9 * License, or (at your option) any later version. | |
10 * | |
11 * In addition, as a special exception, the copyright holders of this | |
12 * program give permission to link the code of its release with the | |
13 * OpenSSL project's "OpenSSL" library (or with modified versions of it | |
14 * that use the same license as the "OpenSSL" library), and distribute | |
15 * the linked executables. You must obey the GNU General Public License | |
16 * in all respects for all of the code used other than "OpenSSL". If you | |
17 * modify file(s) with this exception, you may extend this exception to | |
18 * your version of the file(s), but you are not obligated to do so. If | |
19 * you do not wish to do so, delete this exception statement from your | |
20 * version. If you delete this exception statement from all source files | |
21 * in the program, then also delete it here. | |
22 * | |
23 * This program is distributed in the hope that it will be useful, but | |
24 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
26 * General Public License for more details. | |
27 * | |
28 * You should have received a copy of the GNU General Public License | |
29 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
30 **/ | |
31 | |
32 | |
33 #pragma once | |
34 | |
1247 | 35 #include "IDatabaseWrapper.h" |
36 | |
183 | 37 #include "../Core/SQLite/Connection.h" |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
38 #include "../Core/SQLite/Transaction.h" |
1242 | 39 |
183 | 40 namespace Orthanc |
41 { | |
42 namespace Internals | |
43 { | |
44 class SignalRemainingAncestor; | |
45 } | |
46 | |
47 /** | |
48 * This class manages an instance of the Orthanc SQLite database. It | |
49 * translates low-level requests into SQL statements. Mutual | |
50 * exclusion MUST be implemented at a higher level. | |
51 **/ | |
1247 | 52 class DatabaseWrapper : public IDatabaseWrapper |
183 | 53 { |
54 private: | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1306
diff
changeset
|
55 IDatabaseListener* listener_; |
183 | 56 SQLite::Connection db_; |
57 Internals::SignalRemainingAncestor* signalRemainingAncestor_; | |
58 | |
59 void Open(); | |
60 | |
1240 | 61 void GetChangesInternal(std::list<ServerIndexChange>& target, |
62 bool& done, | |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
63 SQLite::Statement& s, |
1302 | 64 uint32_t maxResults); |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
65 |
1244 | 66 void GetExportedResourcesInternal(std::list<ExportedResource>& target, |
67 bool& done, | |
742 | 68 SQLite::Statement& s, |
1302 | 69 uint32_t maxResults); |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
70 |
1286 | 71 void ClearTable(const std::string& tableName); |
72 | |
183 | 73 public: |
1247 | 74 DatabaseWrapper(const std::string& path); |
75 | |
76 DatabaseWrapper(); | |
77 | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1306
diff
changeset
|
78 virtual void SetListener(IDatabaseListener& listener); |
183 | 79 |
1247 | 80 virtual void SetGlobalProperty(GlobalProperty property, |
81 const std::string& value); | |
183 | 82 |
1247 | 83 virtual bool LookupGlobalProperty(std::string& target, |
84 GlobalProperty property); | |
85 | |
86 virtual int64_t CreateResource(const std::string& publicId, | |
87 ResourceType type); | |
183 | 88 |
1294 | 89 virtual bool LookupResource(int64_t& id, |
90 ResourceType& type, | |
91 const std::string& publicId); | |
183 | 92 |
1247 | 93 virtual bool LookupParent(int64_t& parentId, |
94 int64_t resourceId); | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
95 |
1247 | 96 virtual std::string GetPublicId(int64_t resourceId); |
97 | |
98 virtual ResourceType GetResourceType(int64_t resourceId); | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
99 |
1247 | 100 virtual void AttachChild(int64_t parent, |
101 int64_t child); | |
304 | 102 |
1247 | 103 virtual void DeleteResource(int64_t id); |
183 | 104 |
1247 | 105 virtual void SetMetadata(int64_t id, |
106 MetadataType type, | |
107 const std::string& value); | |
108 | |
109 virtual void DeleteMetadata(int64_t id, | |
110 MetadataType type); | |
183 | 111 |
1247 | 112 virtual bool LookupMetadata(std::string& target, |
113 int64_t id, | |
114 MetadataType type); | |
183 | 115 |
1247 | 116 virtual void ListAvailableMetadata(std::list<MetadataType>& target, |
117 int64_t id); | |
438 | 118 |
1247 | 119 virtual void AddAttachment(int64_t id, |
120 const FileInfo& attachment); | |
183 | 121 |
1247 | 122 virtual void DeleteAttachment(int64_t id, |
123 FileContentType attachment); | |
124 | |
1301 | 125 virtual void ListAvailableAttachments(std::list<FileContentType>& target, |
1247 | 126 int64_t id); |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
127 |
1247 | 128 virtual bool LookupAttachment(FileInfo& attachment, |
129 int64_t id, | |
130 FileContentType contentType); | |
183 | 131 |
1286 | 132 virtual void SetMainDicomTag(int64_t id, |
133 const DicomTag& tag, | |
134 const std::string& value); | |
699
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
135 |
1247 | 136 virtual void GetMainDicomTags(DicomMap& map, |
440
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
137 int64_t id); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
138 |
1301 | 139 virtual void GetChildrenPublicId(std::list<std::string>& target, |
1247 | 140 int64_t id); |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
141 |
1301 | 142 virtual void GetChildrenInternalId(std::list<int64_t>& target, |
1247 | 143 int64_t id); |
183 | 144 |
1247 | 145 virtual void LogChange(int64_t internalId, |
146 const ServerIndexChange& change); | |
183 | 147 |
1247 | 148 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, |
149 bool& done /*out*/, | |
150 int64_t since, | |
1302 | 151 uint32_t maxResults); |
183 | 152 |
1247 | 153 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/); |
204 | 154 |
1247 | 155 virtual void LogExportedResource(const ExportedResource& resource); |
183 | 156 |
1247 | 157 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, |
158 bool& done /*out*/, | |
159 int64_t since, | |
1302 | 160 uint32_t maxResults); |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
161 |
1247 | 162 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/); |
183 | 163 |
1247 | 164 virtual uint64_t GetTotalCompressedSize(); |
165 | |
166 virtual uint64_t GetTotalUncompressedSize(); | |
238 | 167 |
1247 | 168 virtual uint64_t GetResourceCount(ResourceType resourceType); |
190 | 169 |
1247 | 170 virtual void GetAllPublicIds(std::list<std::string>& target, |
171 ResourceType resourceType); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
172 |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
173 virtual void GetAllPublicIds(std::list<std::string>& target, |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
174 ResourceType resourceType, |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
175 size_t since, |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
176 size_t limit); |
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
177 |
1247 | 178 virtual bool SelectPatientToRecycle(int64_t& internalId); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
179 |
1247 | 180 virtual bool SelectPatientToRecycle(int64_t& internalId, |
181 int64_t patientIdToAvoid); | |
182 | |
183 virtual bool IsProtectedPatient(int64_t internalId); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
184 |
1247 | 185 virtual void SetProtectedPatient(int64_t internalId, |
186 bool isProtected); | |
183 | 187 |
1247 | 188 virtual SQLite::ITransaction* StartTransaction() |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
189 { |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
190 return new SQLite::Transaction(db_); |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
191 } |
202 | 192 |
1247 | 193 virtual void FlushToDisk() |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
194 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
195 db_.FlushToDisk(); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
196 } |
310 | 197 |
1306
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
198 virtual bool HasFlushToDisk() const |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
199 { |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
200 return true; |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
201 } |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
202 |
1286 | 203 virtual void ClearChanges() |
204 { | |
205 ClearTable("Changes"); | |
206 } | |
207 | |
208 virtual void ClearExportedResources() | |
209 { | |
210 ClearTable("ExportedResources"); | |
211 } | |
513 | 212 |
1247 | 213 virtual bool IsExistingResource(int64_t internalId); |
521 | 214 |
1301 | 215 virtual void LookupIdentifier(std::list<int64_t>& target, |
1247 | 216 const DicomTag& tag, |
217 const std::string& value); | |
521 | 218 |
1301 | 219 virtual void LookupIdentifier(std::list<int64_t>& target, |
1247 | 220 const std::string& value); |
1006
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
742
diff
changeset
|
221 |
1301 | 222 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target, |
1247 | 223 int64_t id); |
1241 | 224 |
225 | |
226 | |
227 | |
228 /** | |
229 * The methods declared below are for unit testing only! | |
230 **/ | |
231 | |
1247 | 232 const char* GetErrorMessage() const |
233 { | |
234 return db_.GetErrorMessage(); | |
235 } | |
236 | |
1286 | 237 void GetChildren(std::list<std::string>& childrenPublicIds, |
238 int64_t id); | |
1241 | 239 |
1286 | 240 int64_t GetTableRecordCount(const std::string& table); |
1241 | 241 |
1301 | 242 bool GetParentPublicId(std::string& target, |
1286 | 243 int64_t id); |
1241 | 244 |
183 | 245 }; |
246 } |