comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.h @ 4591:ff8170d17d90 db-changes

moving all accesses to databases from IDatabaseWrapper to ITransaction
author Sebastien Jodogne <s.jodogne@gmail.com>
date Mon, 15 Mar 2021 15:30:42 +0100
parents bec74e29f86b
children d494b4f1103e
comparison
equal deleted inserted replaced
4590:4a0bf1019335 4591:ff8170d17d90
94 { 94 {
95 private: 95 private:
96 ITransactionContext& context_; 96 ITransactionContext& context_;
97 97
98 protected: 98 protected:
99 IDatabaseWrapper& db_; 99 IDatabaseWrapper::ITransaction& transaction_;
100 100
101 public: 101 public:
102 explicit ReadOnlyTransaction(IDatabaseWrapper& db, 102 explicit ReadOnlyTransaction(IDatabaseWrapper::ITransaction& transaction,
103 ITransactionContext& context) : 103 ITransactionContext& context) :
104 context_(context), 104 context_(context),
105 db_(db) 105 transaction_(transaction)
106 { 106 {
107 } 107 }
108 108
109 ITransactionContext& GetTransactionContext() 109 ITransactionContext& GetTransactionContext()
110 { 110 {
127 std::list<std::string>* instancesId, // Can be NULL if not needed 127 std::list<std::string>* instancesId, // Can be NULL if not needed
128 const std::vector<DatabaseConstraint>& lookup, 128 const std::vector<DatabaseConstraint>& lookup,
129 ResourceType queryLevel, 129 ResourceType queryLevel,
130 size_t limit) 130 size_t limit)
131 { 131 {
132 return db_.ApplyLookupResources(resourcesId, instancesId, lookup, queryLevel, limit); 132 return transaction_.ApplyLookupResources(resourcesId, instancesId, lookup, queryLevel, limit);
133 } 133 }
134 134
135 void GetAllMetadata(std::map<MetadataType, std::string>& target, 135 void GetAllMetadata(std::map<MetadataType, std::string>& target,
136 int64_t id) 136 int64_t id)
137 { 137 {
138 db_.GetAllMetadata(target, id); 138 transaction_.GetAllMetadata(target, id);
139 } 139 }
140 140
141 void GetAllPublicIds(std::list<std::string>& target, 141 void GetAllPublicIds(std::list<std::string>& target,
142 ResourceType resourceType) 142 ResourceType resourceType)
143 { 143 {
144 return db_.GetAllPublicIds(target, resourceType); 144 return transaction_.GetAllPublicIds(target, resourceType);
145 } 145 }
146 146
147 void GetAllPublicIds(std::list<std::string>& target, 147 void GetAllPublicIds(std::list<std::string>& target,
148 ResourceType resourceType, 148 ResourceType resourceType,
149 size_t since, 149 size_t since,
150 size_t limit) 150 size_t limit)
151 { 151 {
152 return db_.GetAllPublicIds(target, resourceType, since, limit); 152 return transaction_.GetAllPublicIds(target, resourceType, since, limit);
153 } 153 }
154 154
155 void GetChanges(std::list<ServerIndexChange>& target /*out*/, 155 void GetChanges(std::list<ServerIndexChange>& target /*out*/,
156 bool& done /*out*/, 156 bool& done /*out*/,
157 int64_t since, 157 int64_t since,
158 uint32_t maxResults) 158 uint32_t maxResults)
159 { 159 {
160 db_.GetChanges(target, done, since, maxResults); 160 transaction_.GetChanges(target, done, since, maxResults);
161 } 161 }
162 162
163 void GetChildrenInternalId(std::list<int64_t>& target, 163 void GetChildrenInternalId(std::list<int64_t>& target,
164 int64_t id) 164 int64_t id)
165 { 165 {
166 db_.GetChildrenInternalId(target, id); 166 transaction_.GetChildrenInternalId(target, id);
167 } 167 }
168 168
169 void GetChildrenPublicId(std::list<std::string>& target, 169 void GetChildrenPublicId(std::list<std::string>& target,
170 int64_t id) 170 int64_t id)
171 { 171 {
172 db_.GetChildrenPublicId(target, id); 172 transaction_.GetChildrenPublicId(target, id);
173 } 173 }
174 174
175 void GetExportedResources(std::list<ExportedResource>& target /*out*/, 175 void GetExportedResources(std::list<ExportedResource>& target /*out*/,
176 bool& done /*out*/, 176 bool& done /*out*/,
177 int64_t since, 177 int64_t since,
178 uint32_t maxResults) 178 uint32_t maxResults)
179 { 179 {
180 return db_.GetExportedResources(target, done, since, maxResults); 180 return transaction_.GetExportedResources(target, done, since, maxResults);
181 } 181 }
182 182
183 void GetLastChange(std::list<ServerIndexChange>& target /*out*/) 183 void GetLastChange(std::list<ServerIndexChange>& target /*out*/)
184 { 184 {
185 db_.GetLastChange(target); 185 transaction_.GetLastChange(target);
186 } 186 }
187 187
188 void GetLastExportedResource(std::list<ExportedResource>& target /*out*/) 188 void GetLastExportedResource(std::list<ExportedResource>& target /*out*/)
189 { 189 {
190 return db_.GetLastExportedResource(target); 190 return transaction_.GetLastExportedResource(target);
191 } 191 }
192 192
193 int64_t GetLastChangeIndex() 193 int64_t GetLastChangeIndex()
194 { 194 {
195 return db_.GetLastChangeIndex(); 195 return transaction_.GetLastChangeIndex();
196 } 196 }
197 197
198 void GetMainDicomTags(DicomMap& map, 198 void GetMainDicomTags(DicomMap& map,
199 int64_t id) 199 int64_t id)
200 { 200 {
201 db_.GetMainDicomTags(map, id); 201 transaction_.GetMainDicomTags(map, id);
202 } 202 }
203 203
204 std::string GetPublicId(int64_t resourceId) 204 std::string GetPublicId(int64_t resourceId)
205 { 205 {
206 return db_.GetPublicId(resourceId); 206 return transaction_.GetPublicId(resourceId);
207 } 207 }
208 208
209 uint64_t GetResourceCount(ResourceType resourceType) 209 uint64_t GetResourceCount(ResourceType resourceType)
210 { 210 {
211 return db_.GetResourceCount(resourceType); 211 return transaction_.GetResourceCount(resourceType);
212 } 212 }
213 213
214 ResourceType GetResourceType(int64_t resourceId) 214 ResourceType GetResourceType(int64_t resourceId)
215 { 215 {
216 return db_.GetResourceType(resourceId); 216 return transaction_.GetResourceType(resourceId);
217 } 217 }
218 218
219 uint64_t GetTotalCompressedSize() 219 uint64_t GetTotalCompressedSize()
220 { 220 {
221 return db_.GetTotalCompressedSize(); 221 return transaction_.GetTotalCompressedSize();
222 } 222 }
223 223
224 uint64_t GetTotalUncompressedSize() 224 uint64_t GetTotalUncompressedSize()
225 { 225 {
226 return db_.GetTotalUncompressedSize(); 226 return transaction_.GetTotalUncompressedSize();
227 } 227 }
228 228
229 bool IsProtectedPatient(int64_t internalId) 229 bool IsProtectedPatient(int64_t internalId)
230 { 230 {
231 return db_.IsProtectedPatient(internalId); 231 return transaction_.IsProtectedPatient(internalId);
232 } 232 }
233 233
234 void ListAvailableAttachments(std::set<FileContentType>& target, 234 void ListAvailableAttachments(std::set<FileContentType>& target,
235 int64_t id) 235 int64_t id)
236 { 236 {
237 db_.ListAvailableAttachments(target, id); 237 transaction_.ListAvailableAttachments(target, id);
238 } 238 }
239 239
240 bool LookupAttachment(FileInfo& attachment, 240 bool LookupAttachment(FileInfo& attachment,
241 int64_t id, 241 int64_t id,
242 FileContentType contentType) 242 FileContentType contentType)
243 { 243 {
244 return db_.LookupAttachment(attachment, id, contentType); 244 return transaction_.LookupAttachment(attachment, id, contentType);
245 } 245 }
246 246
247 bool LookupGlobalProperty(std::string& target, 247 bool LookupGlobalProperty(std::string& target,
248 GlobalProperty property) 248 GlobalProperty property)
249 { 249 {
250 return db_.LookupGlobalProperty(target, property); 250 return transaction_.LookupGlobalProperty(target, property);
251 } 251 }
252 252
253 bool LookupMetadata(std::string& target, 253 bool LookupMetadata(std::string& target,
254 int64_t id, 254 int64_t id,
255 MetadataType type) 255 MetadataType type)
256 { 256 {
257 return db_.LookupMetadata(target, id, type); 257 return transaction_.LookupMetadata(target, id, type);
258 } 258 }
259 259
260 bool LookupParent(int64_t& parentId, 260 bool LookupParent(int64_t& parentId,
261 int64_t resourceId) 261 int64_t resourceId)
262 { 262 {
263 return db_.LookupParent(parentId, resourceId); 263 return transaction_.LookupParent(parentId, resourceId);
264 } 264 }
265 265
266 bool LookupResource(int64_t& id, 266 bool LookupResource(int64_t& id,
267 ResourceType& type, 267 ResourceType& type,
268 const std::string& publicId) 268 const std::string& publicId)
269 { 269 {
270 return db_.LookupResource(id, type, publicId); 270 return transaction_.LookupResource(id, type, publicId);
271 } 271 }
272 272
273 bool LookupResourceAndParent(int64_t& id, 273 bool LookupResourceAndParent(int64_t& id,
274 ResourceType& type, 274 ResourceType& type,
275 std::string& parentPublicId, 275 std::string& parentPublicId,
276 const std::string& publicId) 276 const std::string& publicId)
277 { 277 {
278 return db_.LookupResourceAndParent(id, type, parentPublicId, publicId); 278 return transaction_.LookupResourceAndParent(id, type, parentPublicId, publicId);
279 } 279 }
280 }; 280 };
281 281
282 282
283 class ReadWriteTransaction : public ReadOnlyTransaction 283 class ReadWriteTransaction : public ReadOnlyTransaction
284 { 284 {
285 public: 285 public:
286 ReadWriteTransaction(IDatabaseWrapper& db, 286 ReadWriteTransaction(IDatabaseWrapper::ITransaction& transaction,
287 ITransactionContext& context) : 287 ITransactionContext& context) :
288 ReadOnlyTransaction(db, context) 288 ReadOnlyTransaction(transaction, context)
289 { 289 {
290 } 290 }
291 291
292 void AddAttachment(int64_t id, 292 void AddAttachment(int64_t id,
293 const FileInfo& attachment) 293 const FileInfo& attachment)
294 { 294 {
295 db_.AddAttachment(id, attachment); 295 transaction_.AddAttachment(id, attachment);
296 } 296 }
297 297
298 void ClearChanges() 298 void ClearChanges()
299 { 299 {
300 db_.ClearChanges(); 300 transaction_.ClearChanges();
301 } 301 }
302 302
303 void ClearExportedResources() 303 void ClearExportedResources()
304 { 304 {
305 db_.ClearExportedResources(); 305 transaction_.ClearExportedResources();
306 } 306 }
307 307
308 void ClearMainDicomTags(int64_t id) 308 void ClearMainDicomTags(int64_t id)
309 { 309 {
310 return db_.ClearMainDicomTags(id); 310 return transaction_.ClearMainDicomTags(id);
311 } 311 }
312 312
313 bool CreateInstance(IDatabaseWrapper::CreateInstanceResult& result, /* out */ 313 bool CreateInstance(IDatabaseWrapper::CreateInstanceResult& result, /* out */
314 int64_t& instanceId, /* out */ 314 int64_t& instanceId, /* out */
315 const std::string& patient, 315 const std::string& patient,
316 const std::string& study, 316 const std::string& study,
317 const std::string& series, 317 const std::string& series,
318 const std::string& instance) 318 const std::string& instance)
319 { 319 {
320 return db_.CreateInstance(result, instanceId, patient, study, series, instance); 320 return transaction_.CreateInstance(result, instanceId, patient, study, series, instance);
321 } 321 }
322 322
323 void DeleteAttachment(int64_t id, 323 void DeleteAttachment(int64_t id,
324 FileContentType attachment) 324 FileContentType attachment)
325 { 325 {
326 return db_.DeleteAttachment(id, attachment); 326 return transaction_.DeleteAttachment(id, attachment);
327 } 327 }
328 328
329 void DeleteMetadata(int64_t id, 329 void DeleteMetadata(int64_t id,
330 MetadataType type) 330 MetadataType type)
331 { 331 {
332 db_.DeleteMetadata(id, type); 332 transaction_.DeleteMetadata(id, type);
333 } 333 }
334 334
335 void DeleteResource(int64_t id) 335 void DeleteResource(int64_t id)
336 { 336 {
337 db_.DeleteResource(id); 337 transaction_.DeleteResource(id);
338 } 338 }
339 339
340 void LogChange(int64_t internalId, 340 void LogChange(int64_t internalId,
341 ChangeType changeType, 341 ChangeType changeType,
342 ResourceType resourceType, 342 ResourceType resourceType,
343 const std::string& publicId); 343 const std::string& publicId);
344 344
345 void LogExportedResource(const ExportedResource& resource) 345 void LogExportedResource(const ExportedResource& resource)
346 { 346 {
347 db_.LogExportedResource(resource); 347 transaction_.LogExportedResource(resource);
348 } 348 }
349 349
350 void SetGlobalProperty(GlobalProperty property, 350 void SetGlobalProperty(GlobalProperty property,
351 const std::string& value) 351 const std::string& value)
352 { 352 {
353 db_.SetGlobalProperty(property, value); 353 transaction_.SetGlobalProperty(property, value);
354 } 354 }
355 355
356 void SetMetadata(int64_t id, 356 void SetMetadata(int64_t id,
357 MetadataType type, 357 MetadataType type,
358 const std::string& value) 358 const std::string& value)
359 { 359 {
360 return db_.SetMetadata(id, type, value); 360 return transaction_.SetMetadata(id, type, value);
361 } 361 }
362 362
363 void SetProtectedPatient(int64_t internalId, 363 void SetProtectedPatient(int64_t internalId,
364 bool isProtected) 364 bool isProtected)
365 { 365 {
366 db_.SetProtectedPatient(internalId, isProtected); 366 transaction_.SetProtectedPatient(internalId, isProtected);
367 } 367 }
368 368
369 void SetResourcesContent(const ResourcesContent& content) 369 void SetResourcesContent(const ResourcesContent& content)
370 { 370 {
371 db_.SetResourcesContent(content); 371 transaction_.SetResourcesContent(content);
372 } 372 }
373 373
374 void Recycle(uint64_t maximumStorageSize, 374 void Recycle(uint64_t maximumStorageSize,
375 unsigned int maximumPatients, 375 unsigned int maximumPatients,
376 uint64_t addedInstanceSize, 376 uint64_t addedInstanceSize,
421 protected: 421 protected:
422 void StandaloneRecycling(uint64_t maximumStorageSize, 422 void StandaloneRecycling(uint64_t maximumStorageSize,
423 unsigned int maximumPatientCount); 423 unsigned int maximumPatientCount);
424 424
425 public: 425 public:
426 StatelessDatabaseOperations(IDatabaseWrapper& database); 426 explicit StatelessDatabaseOperations(IDatabaseWrapper& database);
427 427
428 void SetTransactionContextFactory(ITransactionContextFactory* factory /* takes ownership */); 428 void SetTransactionContextFactory(ITransactionContextFactory* factory /* takes ownership */);
429 429
430 // It is assumed that "GetDatabaseVersion()" can run out of a 430 // It is assumed that "GetDatabaseVersion()" can run out of a
431 // database transaction 431 // database transaction