Mercurial > hg > orthanc
diff 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 |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerIndex.h Tue Mar 02 16:51:19 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.h Tue Mar 02 19:36:59 2021 +0100 @@ -156,10 +156,12 @@ /* out */ uint64_t& countSeries, /* out */ uint64_t& countInstances); + private: bool LookupResource(Json::Value& result, const std::string& publicId, ResourceType expectedType); + public: bool LookupAttachment(FileInfo& attachment, const std::string& instanceUuid, FileContentType contentType); @@ -209,10 +211,12 @@ void DeleteMetadata(const std::string& publicId, MetadataType type); + private: void GetAllMetadata(std::map<MetadataType, std::string>& target, const std::string& publicId, ResourceType expectedType); + public: bool LookupMetadata(std::string& target, const std::string& publicId, ResourceType expectedType, @@ -289,5 +293,131 @@ const DatabaseLookup& lookup, ResourceType queryLevel, size_t limit); + + + + /*** + ** PROTOTYPING FOR DB REFACTORING BELOW + ***/ + + public: + class ReadOnlyTransaction : public boost::noncopyable + { + protected: + ServerIndex& index_; + + public: + ReadOnlyTransaction(ServerIndex& index) : + index_(index) + { + } + + bool LookupResource(Json::Value& result, + const std::string& publicId, + ResourceType expectedType) + { + return index_.LookupResource(result, publicId, expectedType); + } + + void GetAllMetadata(std::map<MetadataType, std::string>& target, + const std::string& publicId, + ResourceType expectedType) + { + index_.GetAllMetadata(target, publicId, expectedType); + } + }; + + + class ReadWriteTransaction : public ReadOnlyTransaction + { + public: + ReadWriteTransaction(ServerIndex& index) : + ReadOnlyTransaction(index) + { + } + + StoreStatus Store(std::map<MetadataType, std::string>& instanceMetadata, + const DicomMap& dicomSummary, + const Attachments& attachments, + const MetadataMap& metadata, + const DicomInstanceOrigin& origin, + bool overwrite, + bool hasTransferSyntax, + DicomTransferSyntax transferSyntax, + bool hasPixelDataOffset, + uint64_t pixelDataOffset) + { + return index_.Store(instanceMetadata, dicomSummary, attachments, metadata, origin, + overwrite, hasTransferSyntax, transferSyntax, hasPixelDataOffset, pixelDataOffset); + } + }; + + + class IReadOnlyOperations : public boost::noncopyable + { + public: + virtual ~IReadOnlyOperations() + { + } + + virtual void Apply(ReadOnlyTransaction& transaction) = 0; + }; + + + class IReadWriteOperations : public boost::noncopyable + { + public: + virtual ~IReadWriteOperations() + { + } + + virtual void Apply(ReadWriteTransaction& transaction) = 0; + }; + + + class ExpandResourceOperation : public ServerIndex::IReadOnlyOperations + { + private: + Json::Value item_; + bool found_; + std::string resource_; + ResourceType level_; + + public: + ExpandResourceOperation(const std::string& resource, + ResourceType level); + + virtual void Apply(ServerIndex::ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE; + + bool IsFound() const + { + return found_; + } + + const Json::Value& GetResource() const; + }; + + + typedef void (*ReadOnlyFunction) (ReadOnlyTransaction& transaction); + typedef void (*ReadWriteFunction) (ReadWriteTransaction& transaction); + + + private: + class ReadOnlyWrapper; + class ReadWriteWrapper; + + void ApplyInternal(IReadOnlyOperations* readOperations, + IReadWriteOperations* writeOperations); + + unsigned int maxRetries_; + + public: + void Apply(IReadOnlyOperations& operations); + + void Apply(IReadWriteOperations& operations); + + void Apply(ReadOnlyFunction func); + + void Apply(ReadWriteFunction func); }; }