Mercurial > hg > orthanc
diff OrthancServer/Sources/ServerIndex.h @ 4554:efd90f778cd2 db-changes
simplification
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Wed, 03 Mar 2021 16:31:57 +0100 |
parents | 350a22c094f2 |
children | 456ed3fcff81 |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerIndex.h Wed Mar 03 13:44:01 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.h Wed Mar 03 16:31:57 2021 +0100 @@ -79,9 +79,11 @@ static void UnstableResourcesMonitorThread(ServerIndex* that, unsigned int threadSleep); - void MainDicomTagsToJson(Json::Value& result, - int64_t resourceId, - ResourceType resourceType); + // A transaction must be running + static void MainDicomTagsToJson(Json::Value& result, + IDatabaseWrapper& db, + int64_t resourceId, + ResourceType resourceType); bool IsRecyclingNeeded(uint64_t instanceSize); @@ -110,8 +112,12 @@ const DatabaseLookup& source, ResourceType level) const; - SeriesStatus GetSeriesStatus(int64_t id, - int64_t expectedNumberOfInstances); + // A transaction must be running + static SeriesStatus GetSeriesStatus(IDatabaseWrapper& db, + int64_t id, + int64_t expectedNumberOfInstances); + + bool IsUnstableResource(int64_t id); public: ServerIndex(ServerContext& context, @@ -156,12 +162,6 @@ /* 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); @@ -211,12 +211,6 @@ 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, @@ -304,26 +298,73 @@ class ReadOnlyTransaction : public boost::noncopyable { protected: - ServerIndex& index_; + IDatabaseWrapper& db_; public: - ReadOnlyTransaction(ServerIndex& index) : - index_(index) + ReadOnlyTransaction(IDatabaseWrapper& db) : + db_(db) + { + } + + /** + * Higher-level constructions + **/ + + SeriesStatus GetSeriesStatus(int64_t id, + int64_t expectedNumberOfInstances) + { + return ServerIndex::GetSeriesStatus(db_, id, expectedNumberOfInstances); + } + + void MainDicomTagsToJson(Json::Value& result, + int64_t resourceId, + ResourceType resourceType) { + ServerIndex::MainDicomTagsToJson(result, db_, resourceId, resourceType); + } + + /** + * Read-only methods from "IDatabaseWrapper" + **/ + + void GetAllMetadata(std::map<MetadataType, std::string>& target, + int64_t id) + { + db_.GetAllMetadata(target, id); + } + + void GetChildrenPublicId(std::list<std::string>& target, + int64_t id) + { + db_.GetChildrenPublicId(target, id); + } + + void GetMainDicomTags(DicomMap& map, + int64_t id) + { + db_.GetMainDicomTags(map, id); } - bool LookupResource(Json::Value& result, - const std::string& publicId, - ResourceType expectedType) + bool LookupAttachment(FileInfo& attachment, + int64_t id, + FileContentType contentType) { - return index_.LookupResource(result, publicId, expectedType); + return db_.LookupAttachment(attachment, id, contentType); } - - void GetAllMetadata(std::map<MetadataType, std::string>& target, - const std::string& publicId, - ResourceType expectedType) + + bool LookupResource(int64_t& id, + ResourceType& type, + const std::string& publicId) { - index_.GetAllMetadata(target, publicId, expectedType); + return db_.LookupResource(id, type, publicId); + } + + bool LookupResourceAndParent(int64_t& id, + ResourceType& type, + std::string& parentPublicId, + const std::string& publicId) + { + return db_.LookupResourceAndParent(id, type, parentPublicId, publicId); } }; @@ -331,25 +372,11 @@ class ReadWriteTransaction : public ReadOnlyTransaction { public: - ReadWriteTransaction(ServerIndex& index) : - ReadOnlyTransaction(index) + ReadWriteTransaction(IDatabaseWrapper& db) : + ReadOnlyTransaction(db) { } - 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); - } }; @@ -375,29 +402,6 @@ }; - 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); @@ -419,5 +423,13 @@ void Apply(ReadOnlyFunction func); void Apply(ReadWriteFunction func); + + bool ExpandResource(Json::Value& target, + const std::string& publicId, + ResourceType level); + + void GetAllMetadata(std::map<MetadataType, std::string>& target, + const std::string& publicId, + ResourceType level); }; }