Mercurial > hg > orthanc
annotate OrthancServer/Resources/Graveyard/DatabasePluginSample/Database.h @ 5141:023569e7155b
moved DicomModification thread safety into ResourceModificationJob (trying to avoid mutex in OrthancFramework as much as possible)
author | Alain Mazy <am@osimis.io> |
---|---|
date | Fri, 20 Jan 2023 18:10:42 +0100 |
parents | 6eff25f70121 |
children | 0ea402b4d901 |
rev | line source |
---|---|
1671 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
1900 | 3 * Copyright (C) 2012-2016 Sebastien Jodogne, Medical Physics |
1671 | 4 * Department, University Hospital of Liege, Belgium |
4870
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
5 * Copyright (C) 2017-2022 Osimis S.A., Belgium |
43e613a7756b
upgrade to year 2022
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
4831
diff
changeset
|
6 * Copyright (C) 2021-2022 Sebastien Jodogne, ICTEAM UCLouvain, Belgium |
1671 | 7 * |
8 * This program is free software: you can redistribute it and/or | |
9 * modify it under the terms of the GNU General Public License as | |
10 * published by the Free Software Foundation, either version 3 of the | |
11 * License, or (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program. If not, see <http://www.gnu.org/licenses/>. | |
20 **/ | |
21 | |
22 | |
23 #pragma once | |
24 | |
4050 | 25 #include "OrthancCppDatabasePlugin.h" |
1671 | 26 |
4050 | 27 #include "../../../../OrthancFramework/Sources/SQLite/Connection.h" |
28 #include "../../../../OrthancFramework/Sources/SQLite/Transaction.h" | |
29 #include "../../../Plugins/Engine/PluginsEnumerations.h" | |
30 #include "DatabaseWrapperBase.h" | |
1671 | 31 |
32 #include <memory> | |
33 | |
34 class Database : public OrthancPlugins::IDatabaseBackend | |
35 { | |
36 private: | |
37 class SignalRemainingAncestor; | |
38 | |
39 std::string path_; | |
40 Orthanc::SQLite::Connection db_; | |
41 Orthanc::DatabaseWrapperBase base_; | |
42 SignalRemainingAncestor* signalRemainingAncestor_; | |
43 | |
44 std::auto_ptr<Orthanc::SQLite::Transaction> transaction_; | |
45 | |
46 public: | |
47 Database(const std::string& path); | |
48 | |
49 virtual void Open(); | |
50 | |
51 virtual void Close(); | |
52 | |
53 virtual void AddAttachment(int64_t id, | |
54 const OrthancPluginAttachment& attachment); | |
55 | |
56 virtual void AttachChild(int64_t parent, | |
57 int64_t child) | |
58 { | |
59 base_.AttachChild(parent, child); | |
60 } | |
61 | |
62 virtual void ClearChanges() | |
63 { | |
64 db_.Execute("DELETE FROM Changes"); | |
65 } | |
66 | |
67 virtual void ClearExportedResources() | |
68 { | |
69 db_.Execute("DELETE FROM ExportedResources"); | |
70 } | |
71 | |
72 virtual int64_t CreateResource(const char* publicId, | |
73 OrthancPluginResourceType type) | |
74 { | |
75 return base_.CreateResource(publicId, Orthanc::Plugins::Convert(type)); | |
76 } | |
77 | |
78 virtual void DeleteAttachment(int64_t id, | |
79 int32_t attachment) | |
80 { | |
81 base_.DeleteAttachment(id, static_cast<Orthanc::FileContentType>(attachment)); | |
82 } | |
83 | |
84 virtual void DeleteMetadata(int64_t id, | |
85 int32_t metadataType) | |
86 { | |
87 base_.DeleteMetadata(id, static_cast<Orthanc::MetadataType>(metadataType)); | |
88 } | |
89 | |
90 virtual void DeleteResource(int64_t id); | |
91 | |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
92 virtual void GetAllInternalIds(std::list<int64_t>& target, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
93 OrthancPluginResourceType resourceType) |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
94 { |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
95 base_.GetAllInternalIds(target, Orthanc::Plugins::Convert(resourceType)); |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
96 } |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
97 |
1671 | 98 virtual void GetAllPublicIds(std::list<std::string>& target, |
99 OrthancPluginResourceType resourceType) | |
100 { | |
101 base_.GetAllPublicIds(target, Orthanc::Plugins::Convert(resourceType)); | |
102 } | |
103 | |
104 virtual void GetAllPublicIds(std::list<std::string>& target, | |
105 OrthancPluginResourceType resourceType, | |
106 uint64_t since, | |
107 uint64_t limit) | |
108 { | |
109 base_.GetAllPublicIds(target, Orthanc::Plugins::Convert(resourceType), since, limit); | |
110 } | |
111 | |
112 virtual void GetChanges(bool& done /*out*/, | |
113 int64_t since, | |
114 uint32_t maxResults); | |
115 | |
116 virtual void GetChildrenInternalId(std::list<int64_t>& target /*out*/, | |
117 int64_t id) | |
118 { | |
119 base_.GetChildrenInternalId(target, id); | |
120 } | |
121 | |
122 virtual void GetChildrenPublicId(std::list<std::string>& target /*out*/, | |
123 int64_t id) | |
124 { | |
125 base_.GetChildrenPublicId(target, id); | |
126 } | |
127 | |
128 virtual void GetExportedResources(bool& done /*out*/, | |
129 int64_t since, | |
130 uint32_t maxResults); | |
131 | |
132 virtual void GetLastChange(); | |
133 | |
134 virtual void GetLastExportedResource(); | |
135 | |
136 virtual void GetMainDicomTags(int64_t id); | |
137 | |
138 virtual std::string GetPublicId(int64_t resourceId); | |
139 | |
140 virtual uint64_t GetResourceCount(OrthancPluginResourceType resourceType) | |
141 { | |
142 return base_.GetResourceCount(Orthanc::Plugins::Convert(resourceType)); | |
143 } | |
144 | |
145 virtual OrthancPluginResourceType GetResourceType(int64_t resourceId); | |
146 | |
147 virtual uint64_t GetTotalCompressedSize() | |
148 { | |
149 return base_.GetTotalCompressedSize(); | |
150 } | |
151 | |
152 virtual uint64_t GetTotalUncompressedSize() | |
153 { | |
154 return base_.GetTotalUncompressedSize(); | |
155 } | |
156 | |
157 virtual bool IsExistingResource(int64_t internalId) | |
158 { | |
159 return base_.IsExistingResource(internalId); | |
160 } | |
161 | |
162 virtual bool IsProtectedPatient(int64_t internalId) | |
163 { | |
164 return base_.IsProtectedPatient(internalId); | |
165 } | |
166 | |
167 virtual void ListAvailableMetadata(std::list<int32_t>& target /*out*/, | |
168 int64_t id); | |
169 | |
170 virtual void ListAvailableAttachments(std::list<int32_t>& target /*out*/, | |
171 int64_t id); | |
172 | |
173 virtual void LogChange(const OrthancPluginChange& change); | |
174 | |
175 virtual void LogExportedResource(const OrthancPluginExportedResource& resource); | |
176 | |
177 virtual bool LookupAttachment(int64_t id, | |
178 int32_t contentType); | |
179 | |
180 virtual bool LookupGlobalProperty(std::string& target /*out*/, | |
181 int32_t property) | |
182 { | |
183 return base_.LookupGlobalProperty(target, static_cast<Orthanc::GlobalProperty>(property)); | |
184 } | |
185 | |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
186 virtual void LookupIdentifier(std::list<int64_t>& target /*out*/, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
187 OrthancPluginResourceType level, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
188 uint16_t group, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
189 uint16_t element, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
190 OrthancPluginIdentifierConstraint constraint, |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
191 const char* value) |
1671 | 192 { |
1761
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
193 base_.LookupIdentifier(target, Orthanc::Plugins::Convert(level), |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
194 Orthanc::DicomTag(group, element), |
f4286d99ee0a
fix sample database plugin
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
1728
diff
changeset
|
195 Orthanc::Plugins::Convert(constraint), value); |
1671 | 196 } |
197 | |
198 virtual bool LookupMetadata(std::string& target /*out*/, | |
199 int64_t id, | |
200 int32_t metadataType) | |
201 { | |
202 return base_.LookupMetadata(target, id, static_cast<Orthanc::MetadataType>(metadataType)); | |
203 } | |
204 | |
205 virtual bool LookupParent(int64_t& parentId /*out*/, | |
206 int64_t resourceId); | |
207 | |
208 virtual bool LookupResource(int64_t& id /*out*/, | |
209 OrthancPluginResourceType& type /*out*/, | |
210 const char* publicId); | |
211 | |
212 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/) | |
213 { | |
214 return base_.SelectPatientToRecycle(internalId); | |
215 } | |
216 | |
217 virtual bool SelectPatientToRecycle(int64_t& internalId /*out*/, | |
218 int64_t patientIdToAvoid) | |
219 { | |
220 return base_.SelectPatientToRecycle(internalId, patientIdToAvoid); | |
221 } | |
222 | |
223 | |
224 virtual void SetGlobalProperty(int32_t property, | |
225 const char* value) | |
226 { | |
227 base_.SetGlobalProperty(static_cast<Orthanc::GlobalProperty>(property), value); | |
228 } | |
229 | |
230 virtual void SetMainDicomTag(int64_t id, | |
231 uint16_t group, | |
232 uint16_t element, | |
233 const char* value) | |
234 { | |
235 base_.SetMainDicomTag(id, Orthanc::DicomTag(group, element), value); | |
236 } | |
237 | |
238 virtual void SetIdentifierTag(int64_t id, | |
239 uint16_t group, | |
240 uint16_t element, | |
241 const char* value) | |
242 { | |
1714 | 243 base_.SetIdentifierTag(id, Orthanc::DicomTag(group, element), value); |
1671 | 244 } |
245 | |
246 virtual void SetMetadata(int64_t id, | |
247 int32_t metadataType, | |
248 const char* value) | |
249 { | |
250 base_.SetMetadata(id, static_cast<Orthanc::MetadataType>(metadataType), value); | |
251 } | |
252 | |
253 virtual void SetProtectedPatient(int64_t internalId, | |
254 bool isProtected) | |
255 { | |
256 base_.SetProtectedPatient(internalId, isProtected); | |
257 } | |
258 | |
259 virtual void StartTransaction(); | |
260 | |
261 virtual void RollbackTransaction(); | |
262 | |
263 virtual void CommitTransaction(); | |
264 | |
265 virtual uint32_t GetDatabaseVersion(); | |
266 | |
267 virtual void UpgradeDatabase(uint32_t targetVersion, | |
268 OrthancPluginStorageArea* storageArea); | |
269 | |
270 virtual void ClearMainDicomTags(int64_t internalId) | |
271 { | |
272 base_.ClearMainDicomTags(internalId); | |
273 } | |
274 }; |