comparison OrthancServer/DatabaseWrapper.h @ 1670:16955f8fec4d db-changes

refactoring: DatabaseWrapperBase
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 01 Oct 2015 14:03:07 +0200
parents de1413733c97
children 2f2e2ec17bc4
comparison
equal deleted inserted replaced
1669:a412ad57f0f9 1670:16955f8fec4d
34 34
35 #include "IDatabaseWrapper.h" 35 #include "IDatabaseWrapper.h"
36 36
37 #include "../Core/SQLite/Connection.h" 37 #include "../Core/SQLite/Connection.h"
38 #include "../Core/SQLite/Transaction.h" 38 #include "../Core/SQLite/Transaction.h"
39 #include "DatabaseWrapperBase.h"
39 40
40 namespace Orthanc 41 namespace Orthanc
41 { 42 {
42 namespace Internals 43 namespace Internals
43 { 44 {
52 class DatabaseWrapper : public IDatabaseWrapper 53 class DatabaseWrapper : public IDatabaseWrapper
53 { 54 {
54 private: 55 private:
55 IDatabaseListener* listener_; 56 IDatabaseListener* listener_;
56 SQLite::Connection db_; 57 SQLite::Connection db_;
58 DatabaseWrapperBase base_;
57 Internals::SignalRemainingAncestor* signalRemainingAncestor_; 59 Internals::SignalRemainingAncestor* signalRemainingAncestor_;
58 unsigned int version_; 60 unsigned int version_;
59 61
60 void Open(); 62 void Open();
61 63
62 void GetChangesInternal(std::list<ServerIndexChange>& target,
63 bool& done,
64 SQLite::Statement& s,
65 uint32_t maxResults);
66
67 void GetExportedResourcesInternal(std::list<ExportedResource>& target,
68 bool& done,
69 SQLite::Statement& s,
70 uint32_t maxResults);
71
72 void ClearTable(const std::string& tableName); 64 void ClearTable(const std::string& tableName);
73 65
74 public: 66 public:
75 DatabaseWrapper(const std::string& path); 67 DatabaseWrapper(const std::string& path);
76 68
77 DatabaseWrapper(); 69 DatabaseWrapper();
78 70
79 virtual void SetListener(IDatabaseListener& listener); 71 virtual void SetListener(IDatabaseListener& listener);
80 72
81 virtual void SetGlobalProperty(GlobalProperty property, 73 virtual void SetGlobalProperty(GlobalProperty property,
82 const std::string& value); 74 const std::string& value)
75 {
76 base_.SetGlobalProperty(property, value);
77 }
83 78
84 virtual bool LookupGlobalProperty(std::string& target, 79 virtual bool LookupGlobalProperty(std::string& target,
85 GlobalProperty property); 80 GlobalProperty property)
81 {
82 return base_.LookupGlobalProperty(target, property);
83 }
86 84
87 virtual int64_t CreateResource(const std::string& publicId, 85 virtual int64_t CreateResource(const std::string& publicId,
88 ResourceType type); 86 ResourceType type)
87 {
88 return base_.CreateResource(publicId, type);
89 }
89 90
90 virtual bool LookupResource(int64_t& id, 91 virtual bool LookupResource(int64_t& id,
91 ResourceType& type, 92 ResourceType& type,
92 const std::string& publicId); 93 const std::string& publicId)
94 {
95 return base_.LookupResource(id, type, publicId);
96 }
93 97
94 virtual bool LookupParent(int64_t& parentId, 98 virtual bool LookupParent(int64_t& parentId,
95 int64_t resourceId); 99 int64_t resourceId)
96 100 {
97 virtual std::string GetPublicId(int64_t resourceId); 101 return base_.LookupParent(parentId, resourceId);
98 102 }
99 virtual ResourceType GetResourceType(int64_t resourceId); 103
104 virtual std::string GetPublicId(int64_t resourceId)
105 {
106 return base_.GetPublicId(resourceId);
107 }
108
109 virtual ResourceType GetResourceType(int64_t resourceId)
110 {
111 return base_.GetResourceType(resourceId);
112 }
100 113
101 virtual void AttachChild(int64_t parent, 114 virtual void AttachChild(int64_t parent,
102 int64_t child); 115 int64_t child)
116 {
117 base_.AttachChild(parent, child);
118 }
103 119
104 virtual void DeleteResource(int64_t id); 120 virtual void DeleteResource(int64_t id);
105 121
106 virtual void SetMetadata(int64_t id, 122 virtual void SetMetadata(int64_t id,
107 MetadataType type, 123 MetadataType type,
108 const std::string& value); 124 const std::string& value)
125 {
126 base_.SetMetadata(id, type, value);
127 }
109 128
110 virtual void DeleteMetadata(int64_t id, 129 virtual void DeleteMetadata(int64_t id,
111 MetadataType type); 130 MetadataType type)
131 {
132 base_.DeleteMetadata(id, type);
133 }
112 134
113 virtual bool LookupMetadata(std::string& target, 135 virtual bool LookupMetadata(std::string& target,
114 int64_t id, 136 int64_t id,
115 MetadataType type); 137 MetadataType type)
138 {
139 return base_.LookupMetadata(target, id, type);
140 }
116 141
117 virtual void ListAvailableMetadata(std::list<MetadataType>& target, 142 virtual void ListAvailableMetadata(std::list<MetadataType>& target,
118 int64_t id); 143 int64_t id)
144 {
145 base_.ListAvailableMetadata(target, id);
146 }
119 147
120 virtual void AddAttachment(int64_t id, 148 virtual void AddAttachment(int64_t id,
121 const FileInfo& attachment); 149 const FileInfo& attachment)
150 {
151 base_.AddAttachment(id, attachment);
152 }
122 153
123 virtual void DeleteAttachment(int64_t id, 154 virtual void DeleteAttachment(int64_t id,
124 FileContentType attachment); 155 FileContentType attachment)
156 {
157 base_.DeleteAttachment(id, attachment);
158 }
125 159
126 virtual void ListAvailableAttachments(std::list<FileContentType>& target, 160 virtual void ListAvailableAttachments(std::list<FileContentType>& target,
127 int64_t id); 161 int64_t id)
162 {
163 return base_.ListAvailableAttachments(target, id);
164 }
128 165
129 virtual bool LookupAttachment(FileInfo& attachment, 166 virtual bool LookupAttachment(FileInfo& attachment,
130 int64_t id, 167 int64_t id,
131 FileContentType contentType); 168 FileContentType contentType)
132 169 {
133 virtual void ClearMainDicomTags(int64_t id); 170 return base_.LookupAttachment(attachment, id, contentType);
171 }
172
173 virtual void ClearMainDicomTags(int64_t id)
174 {
175 base_.ClearMainDicomTags(id);
176 }
134 177
135 virtual void SetMainDicomTag(int64_t id, 178 virtual void SetMainDicomTag(int64_t id,
136 const DicomTag& tag, 179 const DicomTag& tag,
137 const std::string& value); 180 const std::string& value)
181 {
182 base_.SetMainDicomTag(id, tag, value);
183 }
138 184
139 virtual void GetMainDicomTags(DicomMap& map, 185 virtual void GetMainDicomTags(DicomMap& map,
140 int64_t id); 186 int64_t id)
187 {
188 base_.GetMainDicomTags(map, id);
189 }
141 190
142 virtual void GetChildrenPublicId(std::list<std::string>& target, 191 virtual void GetChildrenPublicId(std::list<std::string>& target,
143 int64_t id); 192 int64_t id)
193 {
194 base_.GetChildrenPublicId(target, id);
195 }
144 196
145 virtual void GetChildrenInternalId(std::list<int64_t>& target, 197 virtual void GetChildrenInternalId(std::list<int64_t>& target,
146 int64_t id); 198 int64_t id)
199 {
200 base_.GetChildrenInternalId(target, id);
201 }
147 202
148 virtual void LogChange(int64_t internalId, 203 virtual void LogChange(int64_t internalId,
149 const ServerIndexChange& change); 204 const ServerIndexChange& change)
205 {
206 base_.LogChange(internalId, change);
207 }
150 208
151 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/, 209 virtual void GetChanges(std::list<ServerIndexChange>& target /*out*/,
152 bool& done /*out*/, 210 bool& done /*out*/,
153 int64_t since, 211 int64_t since,
154 uint32_t maxResults); 212 uint32_t maxResults)
155 213 {
156 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/); 214 base_.GetChanges(target, done, since, maxResults);
157 215 }
158 virtual void LogExportedResource(const ExportedResource& resource); 216
217 virtual void GetLastChange(std::list<ServerIndexChange>& target /*out*/)
218 {
219 base_.GetLastChange(target);
220 }
221
222 virtual void LogExportedResource(const ExportedResource& resource)
223 {
224 base_.LogExportedResource(resource);
225 }
159 226
160 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/, 227 virtual void GetExportedResources(std::list<ExportedResource>& target /*out*/,
161 bool& done /*out*/, 228 bool& done /*out*/,
162 int64_t since, 229 int64_t since,
163 uint32_t maxResults); 230 uint32_t maxResults)
164 231 {
165 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/); 232 base_.GetExportedResources(target, done, since, maxResults);
166 233 }
167 virtual uint64_t GetTotalCompressedSize(); 234
235 virtual void GetLastExportedResource(std::list<ExportedResource>& target /*out*/)
236 {
237 base_.GetLastExportedResource(target);
238 }
239
240 virtual uint64_t GetTotalCompressedSize()
241 {
242 return base_.GetTotalCompressedSize();
243 }
168 244
169 virtual uint64_t GetTotalUncompressedSize(); 245 virtual uint64_t GetTotalUncompressedSize()
170 246 {
171 virtual uint64_t GetResourceCount(ResourceType resourceType); 247 return base_.GetTotalUncompressedSize();
248 }
249
250 virtual uint64_t GetResourceCount(ResourceType resourceType)
251 {
252 return base_.GetResourceCount(resourceType);
253 }
172 254
173 virtual void GetAllPublicIds(std::list<std::string>& target, 255 virtual void GetAllPublicIds(std::list<std::string>& target,
174 ResourceType resourceType); 256 ResourceType resourceType)
257 {
258 base_.GetAllPublicIds(target, resourceType);
259 }
175 260
176 virtual void GetAllPublicIds(std::list<std::string>& target, 261 virtual void GetAllPublicIds(std::list<std::string>& target,
177 ResourceType resourceType, 262 ResourceType resourceType,
178 size_t since, 263 size_t since,
179 size_t limit); 264 size_t limit)
180 265 {
181 virtual bool SelectPatientToRecycle(int64_t& internalId); 266 base_.GetAllPublicIds(target, resourceType, since, limit);
267 }
268
269 virtual bool SelectPatientToRecycle(int64_t& internalId)
270 {
271 return base_.SelectPatientToRecycle(internalId);
272 }
182 273
183 virtual bool SelectPatientToRecycle(int64_t& internalId, 274 virtual bool SelectPatientToRecycle(int64_t& internalId,
184 int64_t patientIdToAvoid); 275 int64_t patientIdToAvoid)
185 276 {
186 virtual bool IsProtectedPatient(int64_t internalId); 277 return base_.SelectPatientToRecycle(internalId, patientIdToAvoid);
278 }
279
280 virtual bool IsProtectedPatient(int64_t internalId)
281 {
282 return base_.IsProtectedPatient(internalId);
283 }
187 284
188 virtual void SetProtectedPatient(int64_t internalId, 285 virtual void SetProtectedPatient(int64_t internalId,
189 bool isProtected); 286 bool isProtected)
287 {
288 base_.SetProtectedPatient(internalId, isProtected);
289 }
190 290
191 virtual SQLite::ITransaction* StartTransaction() 291 virtual SQLite::ITransaction* StartTransaction()
192 { 292 {
193 return new SQLite::Transaction(db_); 293 return new SQLite::Transaction(db_);
194 } 294 }
211 virtual void ClearExportedResources() 311 virtual void ClearExportedResources()
212 { 312 {
213 ClearTable("ExportedResources"); 313 ClearTable("ExportedResources");
214 } 314 }
215 315
216 virtual bool IsExistingResource(int64_t internalId); 316 virtual bool IsExistingResource(int64_t internalId)
317 {
318 return base_.IsExistingResource(internalId);
319 }
217 320
218 virtual void LookupIdentifier(std::list<int64_t>& target, 321 virtual void LookupIdentifier(std::list<int64_t>& target,
219 const DicomTag& tag, 322 const DicomTag& tag,
220 const std::string& value); 323 const std::string& value)
324 {
325 base_.LookupIdentifier(target, tag, value);
326 }
221 327
222 virtual void LookupIdentifier(std::list<int64_t>& target, 328 virtual void LookupIdentifier(std::list<int64_t>& target,
223 const std::string& value); 329 const std::string& value)
330 {
331 base_.LookupIdentifier(target, value);
332 }
224 333
225 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target, 334 virtual void GetAllMetadata(std::map<MetadataType, std::string>& target,
226 int64_t id); 335 int64_t id);
227 336
228 virtual unsigned int GetDatabaseVersion() 337 virtual unsigned int GetDatabaseVersion()