comparison 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
comparison
equal deleted inserted replaced
4583:42a846166fa3 4584:b25941dcdbbe
120 /*** 120 /***
121 ** PROTOTYPING FOR DB REFACTORING BELOW 121 ** PROTOTYPING FOR DB REFACTORING BELOW
122 ***/ 122 ***/
123 123
124 public: 124 public:
125 class ITransactionContext : public boost::noncopyable
126 {
127 public:
128 virtual ~ITransactionContext()
129 {
130 }
131
132 virtual bool IsUnstableResource(int64_t id) = 0;
133
134 virtual bool LookupRemainingLevel(std::string& remainingPublicId /* out */,
135 ResourceType& remainingLevel /* out */) = 0;
136
137 virtual void MarkAsUnstable(int64_t id,
138 Orthanc::ResourceType type,
139 const std::string& publicId) = 0;
140
141 virtual void SignalAttachmentsAdded(uint64_t compressedSize) = 0;
142
143 virtual void SignalChange(const ServerIndexChange& change) = 0;
144 };
145
146
125 class ReadOnlyTransaction : public boost::noncopyable 147 class ReadOnlyTransaction : public boost::noncopyable
126 { 148 {
149 private:
150 ITransactionContext& context_;
151
127 protected: 152 protected:
128 IDatabaseWrapper& db_; 153 IDatabaseWrapper& db_;
129 154
130 public: 155 public:
131 explicit ReadOnlyTransaction(IDatabaseWrapper& db) : 156 explicit ReadOnlyTransaction(IDatabaseWrapper& db,
157 ITransactionContext& context) :
158 context_(context),
132 db_(db) 159 db_(db)
133 { 160 {
161 }
162
163 ITransactionContext& GetTransactionContext()
164 {
165 return context_;
134 } 166 }
135 167
136 /** 168 /**
137 * Higher-level constructions 169 * Higher-level constructions
138 **/ 170 **/
305 }; 337 };
306 338
307 339
308 class ReadWriteTransaction : public ReadOnlyTransaction 340 class ReadWriteTransaction : public ReadOnlyTransaction
309 { 341 {
310 private:
311 Listener& listener_;
312
313 public: 342 public:
314 ReadWriteTransaction(IDatabaseWrapper& db, 343 ReadWriteTransaction(IDatabaseWrapper& db,
315 Listener& listener) : 344 ITransactionContext& context) :
316 ReadOnlyTransaction(db), 345 ReadOnlyTransaction(db, context)
317 listener_(listener) 346 {
318 {
319 }
320
321 Listener& GetListener()
322 {
323 return listener_;
324 } 347 }
325 348
326 void AddAttachment(int64_t id, 349 void AddAttachment(int64_t id,
327 const FileInfo& attachment) 350 const FileInfo& attachment)
328 { 351 {