Mercurial > hg > orthanc
diff OrthancServer/Sources/ServerIndex.h @ 4584:b25941dcdbbe db-changes
ITransactionContext to uncouple ServerIndex from database wrapper
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 09 Mar 2021 16:18:24 +0100 |
parents | 42a846166fa3 |
children | f0bdd99f3d81 |
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerIndex.h Tue Mar 09 15:37:47 2021 +0100 +++ b/OrthancServer/Sources/ServerIndex.h Tue Mar 09 16:18:24 2021 +0100 @@ -122,17 +122,49 @@ ***/ public: + class ITransactionContext : public boost::noncopyable + { + public: + virtual ~ITransactionContext() + { + } + + virtual bool IsUnstableResource(int64_t id) = 0; + + virtual bool LookupRemainingLevel(std::string& remainingPublicId /* out */, + ResourceType& remainingLevel /* out */) = 0; + + virtual void MarkAsUnstable(int64_t id, + Orthanc::ResourceType type, + const std::string& publicId) = 0; + + virtual void SignalAttachmentsAdded(uint64_t compressedSize) = 0; + + virtual void SignalChange(const ServerIndexChange& change) = 0; + }; + + class ReadOnlyTransaction : public boost::noncopyable { + private: + ITransactionContext& context_; + protected: IDatabaseWrapper& db_; public: - explicit ReadOnlyTransaction(IDatabaseWrapper& db) : + explicit ReadOnlyTransaction(IDatabaseWrapper& db, + ITransactionContext& context) : + context_(context), db_(db) { } + ITransactionContext& GetTransactionContext() + { + return context_; + } + /** * Higher-level constructions **/ @@ -307,22 +339,13 @@ class ReadWriteTransaction : public ReadOnlyTransaction { - private: - Listener& listener_; - public: ReadWriteTransaction(IDatabaseWrapper& db, - Listener& listener) : - ReadOnlyTransaction(db), - listener_(listener) + ITransactionContext& context) : + ReadOnlyTransaction(db, context) { } - Listener& GetListener() - { - return listener_; - } - void AddAttachment(int64_t id, const FileInfo& attachment) {