Mercurial > hg > orthanc
annotate OrthancServer/DatabaseWrapper.h @ 1284:21ea32170764
Option "DicomAssociationCloseDelay" to set delay before closing DICOM association
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 03 Feb 2015 14:07:07 +0100 |
parents | ee43f0d611a8 |
children | b4acdb37e43b |
rev | line source |
---|---|
183 | 1 /** |
2 * Orthanc - A Lightweight, RESTful DICOM Store | |
689 | 3 * Copyright (C) 2012-2014 Medical Physics Department, CHU of Liege, |
183 | 4 * Belgium |
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: | |
1247 | 55 IServerIndexListener* 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, |
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
64 unsigned int maxResults); |
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, |
69 unsigned int maxResults); | |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
70 |
183 | 71 public: |
1247 | 72 DatabaseWrapper(const std::string& path); |
73 | |
74 DatabaseWrapper(); | |
75 | |
76 virtual void SetListener(IServerIndexListener& listener); | |
183 | 77 |
1247 | 78 virtual void SetGlobalProperty(GlobalProperty property, |
79 const std::string& value); | |
183 | 80 |
1247 | 81 virtual bool LookupGlobalProperty(std::string& target, |
82 GlobalProperty property); | |
83 | |
84 virtual int64_t CreateResource(const std::string& publicId, | |
85 ResourceType type); | |
183 | 86 |
1247 | 87 virtual bool LookupResource(const std::string& publicId, |
88 int64_t& id, | |
89 ResourceType& type); | |
183 | 90 |
1247 | 91 virtual bool LookupParent(int64_t& parentId, |
92 int64_t resourceId); | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
93 |
1247 | 94 virtual std::string GetPublicId(int64_t resourceId); |
95 | |
96 virtual ResourceType GetResourceType(int64_t resourceId); | |
198
663cc6c46d0a
before refactoring of ServerIndex::GetXXX
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
197
diff
changeset
|
97 |
1247 | 98 virtual void AttachChild(int64_t parent, |
99 int64_t child); | |
304 | 100 |
1247 | 101 virtual void DeleteResource(int64_t id); |
183 | 102 |
1247 | 103 virtual void SetMetadata(int64_t id, |
104 MetadataType type, | |
105 const std::string& value); | |
106 | |
107 virtual void DeleteMetadata(int64_t id, | |
108 MetadataType type); | |
183 | 109 |
1247 | 110 virtual bool LookupMetadata(std::string& target, |
111 int64_t id, | |
112 MetadataType type); | |
183 | 113 |
1247 | 114 virtual void ListAvailableMetadata(std::list<MetadataType>& target, |
115 int64_t id); | |
438 | 116 |
1247 | 117 virtual void AddAttachment(int64_t id, |
118 const FileInfo& attachment); | |
183 | 119 |
1247 | 120 virtual void DeleteAttachment(int64_t id, |
121 FileContentType attachment); | |
122 | |
123 virtual void ListAvailableAttachments(std::list<FileContentType>& result, | |
124 int64_t id); | |
436
d51186bf7602
read access to metadata
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
413
diff
changeset
|
125 |
1247 | 126 virtual bool LookupAttachment(FileInfo& attachment, |
127 int64_t id, | |
128 FileContentType contentType); | |
183 | 129 |
1247 | 130 virtual void SetMainDicomTags(int64_t id, |
131 const DicomMap& tags); | |
699
2929e17f8447
add attachments to resources
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
689
diff
changeset
|
132 |
1247 | 133 virtual void GetMainDicomTags(DicomMap& map, |
440
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
134 int64_t id); |
23e5b35e3c5c
statistics for patient/studies/series/instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
438
diff
changeset
|
135 |
1247 | 136 virtual void GetChildrenPublicId(std::list<std::string>& result, |
137 int64_t id); | |
200
9c58b2b03cf0
refactoring of read operations
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
199
diff
changeset
|
138 |
1247 | 139 virtual void GetChildrenInternalId(std::list<int64_t>& result, |
140 int64_t id); | |
183 | 141 |
1247 | 142 virtual void LogChange(int64_t internalId, |
143 const ServerIndexChange& change); | |
183 | 144 |
1247 | 145 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, |
146 bool& done /*out*/, | |
147 int64_t since, | |
148 unsigned int maxResults); | |
183 | 149 |
1247 | 150 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/); |
204 | 151 |
1247 | 152 virtual void LogExportedResource(const ExportedResource& resource); |
183 | 153 |
1247 | 154 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, |
155 bool& done /*out*/, | |
156 int64_t since, | |
157 unsigned int maxResults); | |
237
16a4ac70bd8a
last change and export
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
233
diff
changeset
|
158 |
1247 | 159 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/); |
183 | 160 |
1247 | 161 virtual uint64_t GetTotalCompressedSize(); |
162 | |
163 virtual uint64_t GetTotalUncompressedSize(); | |
238 | 164 |
1247 | 165 virtual uint64_t GetResourceCount(ResourceType resourceType); |
190 | 166 |
1247 | 167 virtual void GetAllPublicIds(std::list<std::string>& target, |
168 ResourceType resourceType); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
169 |
1247 | 170 virtual bool SelectPatientToRecycle(int64_t& internalId); |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
171 |
1247 | 172 virtual bool SelectPatientToRecycle(int64_t& internalId, |
173 int64_t patientIdToAvoid); | |
174 | |
175 virtual bool IsProtectedPatient(int64_t internalId); | |
262
2354560daf2f
primitives for recycling patients
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
238
diff
changeset
|
176 |
1247 | 177 virtual void SetProtectedPatient(int64_t internalId, |
178 bool isProtected); | |
183 | 179 |
1247 | 180 virtual SQLite::ITransaction* StartTransaction() |
187
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
181 { |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
182 return new SQLite::Transaction(db_); |
8e673a65564d
refactoring of storing new instances
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
183
diff
changeset
|
183 } |
202 | 184 |
1247 | 185 virtual void FlushToDisk() |
206
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
186 { |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
187 db_.FlushToDisk(); |
4453a010d0db
flush to disk thread
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
204
diff
changeset
|
188 } |
310 | 189 |
1247 | 190 virtual void ClearTable(const std::string& tableName); |
513 | 191 |
1247 | 192 virtual bool IsExistingResource(int64_t internalId); |
521 | 193 |
1247 | 194 virtual void LookupIdentifier(std::list<int64_t>& result, |
195 const DicomTag& tag, | |
196 const std::string& value); | |
521 | 197 |
1247 | 198 virtual void LookupIdentifier(std::list<int64_t>& result, |
199 const std::string& value); | |
1006
649d47854314
proper handling of metadata in Store
Sebastien Jodogne <s.jodogne@gmail.com>
parents:
742
diff
changeset
|
200 |
1247 | 201 virtual void GetAllMetadata(std::map<MetadataType, std::string>& result, |
202 int64_t id); | |
1241 | 203 |
204 | |
205 | |
206 | |
207 /** | |
208 * The methods declared below are for unit testing only! | |
209 **/ | |
210 | |
1247 | 211 const char* GetErrorMessage() const |
212 { | |
213 return db_.GetErrorMessage(); | |
214 } | |
215 | |
1252 | 216 virtual void GetChildren(std::list<std::string>& childrenPublicIds, |
217 int64_t id); | |
1241 | 218 |
1252 | 219 virtual int64_t GetTableRecordCount(const std::string& table); |
1241 | 220 |
1252 | 221 virtual bool GetParentPublicId(std::string& result, |
222 int64_t id); | |
1241 | 223 |
183 | 224 }; |
225 } |