Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerIndex.h @ 4551:350a22c094f2 db-changes
testing replay of transactions
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 02 Mar 2021 19:36:59 +0100 |
parents | 5b929e6b3c36 |
children | efd90f778cd2 |
comparison
equal
deleted
inserted
replaced
4540:9c0cff7a6ca2 | 4551:350a22c094f2 |
---|---|
154 /* out */ uint64_t& countPatients, | 154 /* out */ uint64_t& countPatients, |
155 /* out */ uint64_t& countStudies, | 155 /* out */ uint64_t& countStudies, |
156 /* out */ uint64_t& countSeries, | 156 /* out */ uint64_t& countSeries, |
157 /* out */ uint64_t& countInstances); | 157 /* out */ uint64_t& countInstances); |
158 | 158 |
159 private: | |
159 bool LookupResource(Json::Value& result, | 160 bool LookupResource(Json::Value& result, |
160 const std::string& publicId, | 161 const std::string& publicId, |
161 ResourceType expectedType); | 162 ResourceType expectedType); |
162 | 163 |
164 public: | |
163 bool LookupAttachment(FileInfo& attachment, | 165 bool LookupAttachment(FileInfo& attachment, |
164 const std::string& instanceUuid, | 166 const std::string& instanceUuid, |
165 FileContentType contentType); | 167 FileContentType contentType); |
166 | 168 |
167 void GetAllUuids(std::list<std::string>& target, | 169 void GetAllUuids(std::list<std::string>& target, |
207 const std::string& value); | 209 const std::string& value); |
208 | 210 |
209 void DeleteMetadata(const std::string& publicId, | 211 void DeleteMetadata(const std::string& publicId, |
210 MetadataType type); | 212 MetadataType type); |
211 | 213 |
214 private: | |
212 void GetAllMetadata(std::map<MetadataType, std::string>& target, | 215 void GetAllMetadata(std::map<MetadataType, std::string>& target, |
213 const std::string& publicId, | 216 const std::string& publicId, |
214 ResourceType expectedType); | 217 ResourceType expectedType); |
215 | 218 |
219 public: | |
216 bool LookupMetadata(std::string& target, | 220 bool LookupMetadata(std::string& target, |
217 const std::string& publicId, | 221 const std::string& publicId, |
218 ResourceType expectedType, | 222 ResourceType expectedType, |
219 MetadataType type); | 223 MetadataType type); |
220 | 224 |
287 void ApplyLookupResources(std::vector<std::string>& resourcesId, | 291 void ApplyLookupResources(std::vector<std::string>& resourcesId, |
288 std::vector<std::string>* instancesId, // Can be NULL if not needed | 292 std::vector<std::string>* instancesId, // Can be NULL if not needed |
289 const DatabaseLookup& lookup, | 293 const DatabaseLookup& lookup, |
290 ResourceType queryLevel, | 294 ResourceType queryLevel, |
291 size_t limit); | 295 size_t limit); |
296 | |
297 | |
298 | |
299 /*** | |
300 ** PROTOTYPING FOR DB REFACTORING BELOW | |
301 ***/ | |
302 | |
303 public: | |
304 class ReadOnlyTransaction : public boost::noncopyable | |
305 { | |
306 protected: | |
307 ServerIndex& index_; | |
308 | |
309 public: | |
310 ReadOnlyTransaction(ServerIndex& index) : | |
311 index_(index) | |
312 { | |
313 } | |
314 | |
315 bool LookupResource(Json::Value& result, | |
316 const std::string& publicId, | |
317 ResourceType expectedType) | |
318 { | |
319 return index_.LookupResource(result, publicId, expectedType); | |
320 } | |
321 | |
322 void GetAllMetadata(std::map<MetadataType, std::string>& target, | |
323 const std::string& publicId, | |
324 ResourceType expectedType) | |
325 { | |
326 index_.GetAllMetadata(target, publicId, expectedType); | |
327 } | |
328 }; | |
329 | |
330 | |
331 class ReadWriteTransaction : public ReadOnlyTransaction | |
332 { | |
333 public: | |
334 ReadWriteTransaction(ServerIndex& index) : | |
335 ReadOnlyTransaction(index) | |
336 { | |
337 } | |
338 | |
339 StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata, | |
340 const DicomMap& dicomSummary, | |
341 const Attachments& attachments, | |
342 const MetadataMap& metadata, | |
343 const DicomInstanceOrigin& origin, | |
344 bool overwrite, | |
345 bool hasTransferSyntax, | |
346 DicomTransferSyntax transferSyntax, | |
347 bool hasPixelDataOffset, | |
348 uint64_t pixelDataOffset) | |
349 { | |
350 return index_.Store(instanceMetadata, dicomSummary, attachments, metadata, origin, | |
351 overwrite, hasTransferSyntax, transferSyntax, hasPixelDataOffset, pixelDataOffset); | |
352 } | |
353 }; | |
354 | |
355 | |
356 class IReadOnlyOperations : public boost::noncopyable | |
357 { | |
358 public: | |
359 virtual ~IReadOnlyOperations() | |
360 { | |
361 } | |
362 | |
363 virtual void Apply(ReadOnlyTransaction& transaction) = 0; | |
364 }; | |
365 | |
366 | |
367 class IReadWriteOperations : public boost::noncopyable | |
368 { | |
369 public: | |
370 virtual ~IReadWriteOperations() | |
371 { | |
372 } | |
373 | |
374 virtual void Apply(ReadWriteTransaction& transaction) = 0; | |
375 }; | |
376 | |
377 | |
378 class ExpandResourceOperation : public ServerIndex::IReadOnlyOperations | |
379 { | |
380 private: | |
381 Json::Value item_; | |
382 bool found_; | |
383 std::string resource_; | |
384 ResourceType level_; | |
385 | |
386 public: | |
387 ExpandResourceOperation(const std::string& resource, | |
388 ResourceType level); | |
389 | |
390 virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE; | |
391 | |
392 bool IsFound() const | |
393 { | |
394 return found_; | |
395 } | |
396 | |
397 const Json::Value& GetResource() const; | |
398 }; | |
399 | |
400 | |
401 typedef void (*ReadOnlyFunction) (ReadOnlyTransaction& transaction); | |
402 typedef void (*ReadWriteFunction) (ReadWriteTransaction& transaction); | |
403 | |
404 | |
405 private: | |
406 class ReadOnlyWrapper; | |
407 class ReadWriteWrapper; | |
408 | |
409 void ApplyInternal(IReadOnlyOperations* readOperations, | |
410 IReadWriteOperations* writeOperations); | |
411 | |
412 unsigned int maxRetries_; | |
413 | |
414 public: | |
415 void Apply(IReadOnlyOperations& operations); | |
416 | |
417 void Apply(IReadWriteOperations& operations); | |
418 | |
419 void Apply(ReadOnlyFunction func); | |
420 | |
421 void Apply(ReadWriteFunction func); | |
292 }; | 422 }; |
293 } | 423 } |