Mercurial > hg > orthanc
comparison OrthancServer/Plugins/Engine/OrthancPluginDatabase.cpp @ 4589:bec74e29f86b db-changes
attaching the listener to transactions in IDatabaseWrapper
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Fri, 12 Mar 2021 15:33:47 +0100 |
parents | 9224e107d613 |
children | ff8170d17d90 |
comparison
equal
deleted
inserted
replaced
4588:94147ce2f097 | 4589:bec74e29f86b |
---|---|
60 throw OrthancException(static_cast<ErrorCode>(code)); | 60 throw OrthancException(static_cast<ErrorCode>(code)); |
61 } | 61 } |
62 } | 62 } |
63 | 63 |
64 public: | 64 public: |
65 explicit Transaction(OrthancPluginDatabase& that) : | 65 explicit Transaction(OrthancPluginDatabase& that, |
66 IDatabaseListener& listener) : | |
66 that_(that) | 67 that_(that) |
67 { | 68 { |
69 assert(that_.listener_ == NULL); | |
70 that_.listener_ = &listener; // TODO - STORE IN TRANSACTION | |
71 } | |
72 | |
73 virtual ~Transaction() | |
74 { | |
75 assert(that_.listener_ != NULL); | |
76 that_.listener_ = NULL; // TODO - STORE IN TRANSACTION | |
68 } | 77 } |
69 | 78 |
70 void Begin() | 79 void Begin() |
71 { | 80 { |
72 CheckSuccess(that_.backend_.startTransaction(that_.payload_)); | 81 CheckSuccess(that_.backend_.startTransaction(that_.payload_)); |
308 << "(affected by issue 58)"; | 317 << "(affected by issue 58)"; |
309 } | 318 } |
310 } | 319 } |
311 | 320 |
312 | 321 |
322 namespace | |
323 { | |
324 class VoidListener : public IDatabaseListener | |
325 { | |
326 public: | |
327 virtual void SignalRemainingAncestor(ResourceType parentType, | |
328 const std::string& publicId) | |
329 { | |
330 throw OrthancException(ErrorCode_InternalError); // Should be read-only transaction | |
331 } | |
332 | |
333 virtual void SignalAttachmentDeleted(const FileInfo& info) | |
334 { | |
335 throw OrthancException(ErrorCode_InternalError); // Should be read-only transaction | |
336 } | |
337 | |
338 virtual void SignalResourceDeleted(ResourceType type, | |
339 const std::string& publicId) | |
340 { | |
341 throw OrthancException(ErrorCode_InternalError); // Should be read-only transaction | |
342 } | |
343 }; | |
344 } | |
345 | |
346 | |
313 void OrthancPluginDatabase::Open() | 347 void OrthancPluginDatabase::Open() |
314 { | 348 { |
315 CheckSuccess(backend_.open(payload_)); | 349 CheckSuccess(backend_.open(payload_)); |
316 | 350 |
317 { | 351 VoidListener listener; |
318 Transaction transaction(*this); | 352 |
353 { | |
354 Transaction transaction(*this, listener); | |
319 transaction.Begin(); | 355 transaction.Begin(); |
320 | 356 |
321 std::string tmp; | 357 std::string tmp; |
322 fastGetTotalSize_ = | 358 fastGetTotalSize_ = |
323 (LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast) && | 359 (LookupGlobalProperty(tmp, GlobalProperty_GetTotalSizeIsFast) && |
887 { | 923 { |
888 CheckSuccess(backend_.setProtectedPatient(payload_, internalId, isProtected)); | 924 CheckSuccess(backend_.setProtectedPatient(payload_, internalId, isProtected)); |
889 } | 925 } |
890 | 926 |
891 | 927 |
892 IDatabaseWrapper::ITransaction* OrthancPluginDatabase::StartTransaction(TransactionType type) | 928 IDatabaseWrapper::ITransaction* OrthancPluginDatabase::StartTransaction(TransactionType type, |
929 IDatabaseListener& listener) | |
893 { | 930 { |
894 // TODO - Take advantage of "type" | 931 // TODO - Take advantage of "type" |
895 | 932 |
896 std::unique_ptr<Transaction> transaction(new Transaction(*this)); | 933 std::unique_ptr<Transaction> transaction(new Transaction(*this, listener)); |
897 transaction->Begin(); | 934 transaction->Begin(); |
898 return transaction.release(); | 935 return transaction.release(); |
899 } | 936 } |
900 | 937 |
901 | 938 |
951 | 988 |
952 | 989 |
953 void OrthancPluginDatabase::Upgrade(unsigned int targetVersion, | 990 void OrthancPluginDatabase::Upgrade(unsigned int targetVersion, |
954 IStorageArea& storageArea) | 991 IStorageArea& storageArea) |
955 { | 992 { |
993 VoidListener listener; | |
994 | |
956 if (extensions_.upgradeDatabase != NULL) | 995 if (extensions_.upgradeDatabase != NULL) |
957 { | 996 { |
958 Transaction transaction(*this); | 997 Transaction transaction(*this, listener); |
959 transaction.Begin(); | 998 transaction.Begin(); |
960 | 999 |
961 OrthancPluginErrorCode code = extensions_.upgradeDatabase( | 1000 OrthancPluginErrorCode code = extensions_.upgradeDatabase( |
962 payload_, targetVersion, | 1001 payload_, targetVersion, |
963 reinterpret_cast<OrthancPluginStorageArea*>(&storageArea)); | 1002 reinterpret_cast<OrthancPluginStorageArea*>(&storageArea)); |