Mercurial > hg > orthanc
annotate OrthancServer/DatabaseWrapper.h @ 1699:8ca0e89798b2
"/modify" can insert/modify sequences
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 09 Oct 2015 13:31:22 +0200 |
parents | c40fe92a68e7 |
children | 0c58f189782d |
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_; | |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
58 unsigned int version_; |
183 | 59 |
60 void Open(); | |
61 | |
1240 | 62 void GetChangesInternal(std::list<ServerIndexChange>& target, |
63 bool& done, | |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
64 SQLite::Statement& s, |
1302 | 65 uint32_t maxResults); |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
66 |
1244 | 67 void GetExportedResourcesInternal(std::list<ExportedResource>& target, |
68 bool& done, | |
742 | 69 SQLite::Statement& s, |
1302 | 70 uint32_t maxResults); |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
71 |
1286 | 72 void ClearTable(const std::string& tableName); |
73 | |
183 | 74 public: |
1247 | 75 DatabaseWrapper(const std::string& path); |
76 | |
77 DatabaseWrapper(); | |
78 | |
1432
0ac74fa21db8
rename IServerIndexListener as IDatabaseListener
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1306
diff
changeset
|
79 virtual void SetListener(IDatabaseListener& listener); |
183 | 80 |
1247 | 81 virtual void SetGlobalProperty(GlobalProperty property, |
82 const std::string& value); | |
183 | 83 |
1247 | 84 virtual bool LookupGlobalProperty(std::string& target, |
85 GlobalProperty property); | |
86 | |
87 virtual int64_t CreateResource(const std::string& publicId, | |
88 ResourceType type); | |
183 | 89 |
1294 | 90 virtual bool LookupResource(int64_t& id, |
91 ResourceType& type, | |
92 const std::string& publicId); | |
183 | 93 |
1247 | 94 virtual bool LookupParent(int64_t& parentId, |
95 int64_t resourceId); | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
96 |
1247 | 97 virtual std::string GetPublicId(int64_t resourceId); |
98 | |
99 virtual ResourceType GetResourceType(int64_t resourceId); | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
100 |
1247 | 101 virtual void AttachChild(int64_t parent, |
102 int64_t child); | |
304 | 103 |
1247 | 104 virtual void DeleteResource(int64_t id); |
183 | 105 |
1247 | 106 virtual void SetMetadata(int64_t id, |
107 MetadataType type, | |
108 const std::string& value); | |
109 | |
110 virtual void DeleteMetadata(int64_t id, | |
111 MetadataType type); | |
183 | 112 |
1247 | 113 virtual bool LookupMetadata(std::string& target, |
114 int64_t id, | |
115 MetadataType type); | |
183 | 116 |
1247 | 117 virtual void ListAvailableMetadata(std::list<MetadataType>& target, |
118 int64_t id); | |
438 | 119 |
1247 | 120 virtual void AddAttachment(int64_t id, |
121 const FileInfo& attachment); | |
183 | 122 |
1247 | 123 virtual void DeleteAttachment(int64_t id, |
124 FileContentType attachment); | |
125 | |
1301 | 126 virtual void ListAvailableAttachments(std::list<FileContentType>& target, |
1247 | 127 int64_t id); |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
128 |
1247 | 129 virtual bool LookupAttachment(FileInfo& attachment, |
130 int64_t id, | |
131 FileContentType contentType); | |
183 | 132 |
1286 | 133 virtual void SetMainDicomTag(int64_t id, |
134 const DicomTag& tag, | |
135 const std::string& value); | |
699
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
136 |
1247 | 137 virtual void GetMainDicomTags(DicomMap& map, |
440
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
138 int64_t id); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
139 |
1301 | 140 virtual void GetChildrenPublicId(std::list<std::string>& target, |
1247 | 141 int64_t id); |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
142 |
1301 | 143 virtual void GetChildrenInternalId(std::list<int64_t>& target, |
1247 | 144 int64_t id); |
183 | 145 |
1247 | 146 virtual void LogChange(int64_t internalId, |
147 const ServerIndexChange& change); | |
183 | 148 |
1247 | 149 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, |
150 bool& done /*out*/, | |
151 int64_t since, | |
1302 | 152 uint32_t maxResults); |
183 | 153 |
1247 | 154 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/); |
204 | 155 |
1247 | 156 virtual void LogExportedResource(const ExportedResource& resource); |
183 | 157 |
1247 | 158 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, |
159 bool& done /*out*/, | |
160 int64_t since, | |
1302 | 161 uint32_t maxResults); |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
162 |
1247 | 163 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/); |
183 | 164 |
1247 | 165 virtual uint64_t GetTotalCompressedSize(); |
166 | |
167 virtual uint64_t GetTotalUncompressedSize(); | |
238 | 168 |
1247 | 169 virtual uint64_t GetResourceCount(ResourceType resourceType); |
190 | 170 |
1247 | 171 virtual void GetAllPublicIds(std::list<std::string>& target, |
172 ResourceType resourceType); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
173 |
1509
0586ed8897f1
limit and since arguments while retrieving DICOM resources in the REST API
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1432
diff
changeset
|
174 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
|
175 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
|
176 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
|
177 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
|
178 |
1247 | 179 virtual bool SelectPatientToRecycle(int64_t& internalId); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
180 |
1247 | 181 virtual bool SelectPatientToRecycle(int64_t& internalId, |
182 int64_t patientIdToAvoid); | |
183 | |
184 virtual bool IsProtectedPatient(int64_t internalId); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
185 |
1247 | 186 virtual void SetProtectedPatient(int64_t internalId, |
187 bool isProtected); | |
183 | 188 |
1247 | 189 virtual SQLite::ITransaction* StartTransaction() |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
190 { |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
191 return new SQLite::Transaction(db_); |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
192 } |
202 | 193 |
1247 | 194 virtual void FlushToDisk() |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
195 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
196 db_.FlushToDisk(); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
197 } |
310 | 198 |
1306
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
199 virtual bool HasFlushToDisk() const |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
200 { |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
201 return true; |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
202 } |
8cd5784a6d80
IDatabaseWrapper::HasFlushToDisk()
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1302
diff
changeset
|
203 |
1286 | 204 virtual void ClearChanges() |
205 { | |
206 ClearTable("Changes"); | |
207 } | |
208 | |
209 virtual void ClearExportedResources() | |
210 { | |
211 ClearTable("ExportedResources"); | |
212 } | |
513 | 213 |
1247 | 214 virtual bool IsExistingResource(int64_t internalId); |
521 | 215 |
1301 | 216 virtual void LookupIdentifier(std::list<int64_t>& target, |
1247 | 217 const DicomTag& tag, |
218 const std::string& value); | |
521 | 219 |
1301 | 220 virtual void LookupIdentifier(std::list<int64_t>& target, |
1247 | 221 const std::string& value); |
1006
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
742
diff
changeset
|
222 |
1301 | 223 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target, |
1247 | 224 int64_t id); |
1241 | 225 |
1615
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
226 virtual unsigned int GetDatabaseVersion() |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
227 { |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
228 return version_; |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
229 } |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
230 |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
231 virtual void Upgrade(unsigned int targetVersion, |
c40fe92a68e7
Primitives to upgrade the database version in plugins
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1509
diff
changeset
|
232 IStorageArea& storageArea); |
1241 | 233 |
234 | |
235 | |
236 /** | |
237 * The methods declared below are for unit testing only! | |
238 **/ | |
239 | |
1247 | 240 const char* GetErrorMessage() const |
241 { | |
242 return db_.GetErrorMessage(); | |
243 } | |
244 | |
1286 | 245 void GetChildren(std::list<std::string>& childrenPublicIds, |
246 int64_t id); | |
1241 | 247 |
1286 | 248 int64_t GetTableRecordCount(const std::string& table); |
1241 | 249 |
1301 | 250 bool GetParentPublicId(std::string& target, |
1286 | 251 int64_t id); |
1241 | 252 |
183 | 253 }; |
254 } |