Mercurial > hg > orthanc
comparison OrthancServer/Sources/ServerIndex.cpp @ 4570:648defffc8cc db-changes
new enum: TransactionType
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Mon, 08 Mar 2021 16:04:56 +0100 |
parents | 19ea4ecd6d9a |
children | 9224e107d613 |
comparison
equal
deleted
inserted
replaced
4569:19ea4ecd6d9a | 4570:648defffc8cc |
---|---|
245 ServerIndex& index_; | 245 ServerIndex& index_; |
246 std::unique_ptr<IDatabaseWrapper::ITransaction> transaction_; | 246 std::unique_ptr<IDatabaseWrapper::ITransaction> transaction_; |
247 bool isCommitted_; | 247 bool isCommitted_; |
248 | 248 |
249 public: | 249 public: |
250 explicit Transaction(ServerIndex& index) : | 250 explicit Transaction(ServerIndex& index, |
251 TransactionType type) : | |
251 index_(index), | 252 index_(index), |
252 isCommitted_(false) | 253 isCommitted_(false) |
253 { | 254 { |
254 transaction_.reset(index_.db_.StartTransaction()); | 255 transaction_.reset(index_.db_.StartTransaction(type)); |
255 index_.listener_->StartTransaction(); | 256 index_.listener_->StartTransaction(); |
256 } | 257 } |
257 | 258 |
258 ~Transaction() | 259 ~Transaction() |
259 { | 260 { |
714 const std::string hashSeries = hasher.HashSeries(); | 715 const std::string hashSeries = hasher.HashSeries(); |
715 const std::string hashInstance = hasher.HashInstance(); | 716 const std::string hashInstance = hasher.HashInstance(); |
716 | 717 |
717 try | 718 try |
718 { | 719 { |
719 Transaction t(*this); | 720 Transaction t(*this, TransactionType_ReadWrite); |
720 | 721 |
721 IDatabaseWrapper::CreateInstanceResult status; | 722 IDatabaseWrapper::CreateInstanceResult status; |
722 int64_t instanceId; | 723 int64_t instanceId; |
723 | 724 |
724 // Check whether this instance is already stored | 725 // Check whether this instance is already stored |
1197 | 1198 |
1198 | 1199 |
1199 void ServerIndex::StandaloneRecycling() | 1200 void ServerIndex::StandaloneRecycling() |
1200 { | 1201 { |
1201 // WARNING: No mutex here, do not include this as a public method | 1202 // WARNING: No mutex here, do not include this as a public method |
1202 Transaction t(*this); | 1203 Transaction t(*this, TransactionType_ReadWrite); |
1203 Recycle(0, ""); | 1204 Recycle(0, ""); |
1204 t.Commit(0); | 1205 t.Commit(0); |
1205 } | 1206 } |
1206 | 1207 |
1207 | 1208 |
1290 StoreStatus ServerIndex::AddAttachment(const FileInfo& attachment, | 1291 StoreStatus ServerIndex::AddAttachment(const FileInfo& attachment, |
1291 const std::string& publicId) | 1292 const std::string& publicId) |
1292 { | 1293 { |
1293 boost::mutex::scoped_lock lock(mutex_); | 1294 boost::mutex::scoped_lock lock(mutex_); |
1294 | 1295 |
1295 Transaction t(*this); | 1296 Transaction t(*this, TransactionType_ReadWrite); |
1296 | 1297 |
1297 ResourceType resourceType; | 1298 ResourceType resourceType; |
1298 int64_t resourceId; | 1299 int64_t resourceId; |
1299 if (!db_.LookupResource(resourceId, resourceType, publicId)) | 1300 if (!db_.LookupResource(resourceId, resourceType, publicId)) |
1300 { | 1301 { |
1347 | 1348 |
1348 boost::mutex::scoped_lock lock(mutex_); | 1349 boost::mutex::scoped_lock lock(mutex_); |
1349 | 1350 |
1350 try | 1351 try |
1351 { | 1352 { |
1352 Transaction t(*this); | 1353 Transaction t(*this, TransactionType_ReadWrite); |
1353 | 1354 |
1354 int64_t patient = -1, study = -1, series = -1, instance = -1; | 1355 int64_t patient = -1, study = -1, series = -1, instance = -1; |
1355 | 1356 |
1356 ResourceType dummy; | 1357 ResourceType dummy; |
1357 if (!db_.LookupResource(patient, dummy, hasher.HashPatient()) || | 1358 if (!db_.LookupResource(patient, dummy, hasher.HashPatient()) || |
1658 { | 1659 { |
1659 try | 1660 try |
1660 { | 1661 { |
1661 boost::mutex::scoped_lock lock(mutex_); // TODO - REMOVE | 1662 boost::mutex::scoped_lock lock(mutex_); // TODO - REMOVE |
1662 | 1663 |
1663 Transaction transaction(*this); // TODO - Only if "TransactionType_SingleStatement" | |
1664 | |
1665 if (readOperations != NULL) | 1664 if (readOperations != NULL) |
1666 { | 1665 { |
1667 ReadOnlyTransaction t(db_); | 1666 /** |
1668 readOperations->Apply(t); | 1667 * IMPORTANT: In Orthanc <= 1.9.1, there was no transaction |
1668 * in this case. This was OK because of the presence of the | |
1669 * global mutex protecting the database. | |
1670 **/ | |
1671 | |
1672 Transaction transaction(*this, TransactionType_ReadOnly); // TODO - Only if not "TransactionType_Implicit" | |
1673 { | |
1674 ReadOnlyTransaction t(db_); | |
1675 readOperations->Apply(t); | |
1676 } | |
1677 transaction.Commit(0); | |
1669 } | 1678 } |
1670 else | 1679 else |
1671 { | 1680 { |
1672 assert(writeOperations != NULL); | 1681 assert(writeOperations != NULL); |
1673 ReadWriteTransaction t(db_, *this); | 1682 |
1674 writeOperations->Apply(t, *listener_); | 1683 Transaction transaction(*this, TransactionType_ReadWrite); |
1675 } | 1684 { |
1676 | 1685 ReadWriteTransaction t(db_, *this); |
1677 transaction.Commit(0); | 1686 writeOperations->Apply(t, *listener_); |
1687 } | |
1688 transaction.Commit(0); | |
1689 } | |
1678 | 1690 |
1679 return; // Success | 1691 return; // Success |
1680 } | 1692 } |
1681 catch (OrthancException& e) | 1693 catch (OrthancException& e) |
1682 { | 1694 { |
1999 { | 2011 { |
2000 public: | 2012 public: |
2001 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2013 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2002 const Tuple& tuple) ORTHANC_OVERRIDE | 2014 const Tuple& tuple) ORTHANC_OVERRIDE |
2003 { | 2015 { |
2004 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | 2016 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
2005 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>()); | 2017 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>()); |
2006 } | 2018 } |
2007 }; | 2019 }; |
2008 | 2020 |
2009 Operations operations; | 2021 Operations operations; |
2026 { | 2038 { |
2027 public: | 2039 public: |
2028 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2040 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2029 const Tuple& tuple) ORTHANC_OVERRIDE | 2041 const Tuple& tuple) ORTHANC_OVERRIDE |
2030 { | 2042 { |
2031 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | 2043 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
2032 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>(), tuple.get<2>(), tuple.get<3>()); | 2044 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>(), tuple.get<2>(), tuple.get<3>()); |
2033 } | 2045 } |
2034 }; | 2046 }; |
2035 | 2047 |
2036 Operations operations; | 2048 Operations operations; |
2140 { | 2152 { |
2141 public: | 2153 public: |
2142 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2154 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2143 const Tuple& tuple) ORTHANC_OVERRIDE | 2155 const Tuple& tuple) ORTHANC_OVERRIDE |
2144 { | 2156 { |
2145 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | 2157 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
2146 | 2158 |
2147 std::list<ExportedResource> exported; | 2159 std::list<ExportedResource> exported; |
2148 bool done; | 2160 bool done; |
2149 transaction.GetExportedResources(exported, done, tuple.get<1>(), tuple.get<2>()); | 2161 transaction.GetExportedResources(exported, done, tuple.get<1>(), tuple.get<2>()); |
2150 FormatLog(tuple.get<0>(), exported, "Exports", done, tuple.get<1>(), false, -1); | 2162 FormatLog(tuple.get<0>(), exported, "Exports", done, tuple.get<1>(), false, -1); |
2162 { | 2174 { |
2163 public: | 2175 public: |
2164 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2176 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2165 const Tuple& tuple) ORTHANC_OVERRIDE | 2177 const Tuple& tuple) ORTHANC_OVERRIDE |
2166 { | 2178 { |
2167 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | 2179 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
2168 | 2180 |
2169 std::list<ExportedResource> exported; | 2181 std::list<ExportedResource> exported; |
2170 transaction.GetLastExportedResource(exported); | 2182 transaction.GetLastExportedResource(exported); |
2171 FormatLog(tuple.get<0>(), exported, "Exports", true, 0, false, -1); | 2183 FormatLog(tuple.get<0>(), exported, "Exports", true, 0, false, -1); |
2172 } | 2184 } |
2587 { | 2599 { |
2588 } | 2600 } |
2589 | 2601 |
2590 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE | 2602 virtual void Apply(ReadOnlyTransaction& transaction) ORTHANC_OVERRIDE |
2591 { | 2603 { |
2592 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | 2604 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
2593 std::list<std::string> tmp; | 2605 std::list<std::string> tmp; |
2594 transaction.ApplyLookupResources(tmp, NULL, query_, level_, 0); | 2606 transaction.ApplyLookupResources(tmp, NULL, query_, level_, 0); |
2595 CopyListToVector(result_, tmp); | 2607 CopyListToVector(result_, tmp); |
2596 } | 2608 } |
2597 }; | 2609 }; |
2608 { | 2620 { |
2609 public: | 2621 public: |
2610 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2622 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2611 const Tuple& tuple) ORTHANC_OVERRIDE | 2623 const Tuple& tuple) ORTHANC_OVERRIDE |
2612 { | 2624 { |
2613 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | 2625 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
2614 tuple.get<0>() = transaction.LookupGlobalProperty(tuple.get<1>(), tuple.get<2>()); | 2626 tuple.get<0>() = transaction.LookupGlobalProperty(tuple.get<1>(), tuple.get<2>()); |
2615 } | 2627 } |
2616 }; | 2628 }; |
2617 | 2629 |
2618 bool found; | 2630 bool found; |
2795 { | 2807 { |
2796 public: | 2808 public: |
2797 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2809 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2798 const Tuple& tuple) ORTHANC_OVERRIDE | 2810 const Tuple& tuple) ORTHANC_OVERRIDE |
2799 { | 2811 { |
2800 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | 2812 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
2801 int64_t id; | 2813 int64_t id; |
2802 tuple.get<0>() = transaction.LookupResource(id, tuple.get<1>(), tuple.get<2>()); | 2814 tuple.get<0>() = transaction.LookupResource(id, tuple.get<1>(), tuple.get<2>()); |
2803 } | 2815 } |
2804 }; | 2816 }; |
2805 | 2817 |
2816 { | 2828 { |
2817 public: | 2829 public: |
2818 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2830 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2819 const Tuple& tuple) ORTHANC_OVERRIDE | 2831 const Tuple& tuple) ORTHANC_OVERRIDE |
2820 { | 2832 { |
2821 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | 2833 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
2822 tuple.get<0>() = transaction.GetDatabaseVersion(); | 2834 tuple.get<0>() = transaction.GetDatabaseVersion(); |
2823 } | 2835 } |
2824 }; | 2836 }; |
2825 | 2837 |
2826 unsigned int version; | 2838 unsigned int version; |
2898 } | 2910 } |
2899 | 2911 |
2900 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 2912 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
2901 const Tuple& tuple) ORTHANC_OVERRIDE | 2913 const Tuple& tuple) ORTHANC_OVERRIDE |
2902 { | 2914 { |
2903 // TODO - CANDIDATE FOR "TransactionType_SingleStatement" | 2915 // TODO - CANDIDATE FOR "TransactionType_Implicit" |
2904 if (tuple.get<0>()) | 2916 if (tuple.get<0>()) |
2905 { | 2917 { |
2906 transaction.ApplyLookupResources(resourcesList_, &instancesList_, tuple.get<1>(), tuple.get<2>(), tuple.get<3>()); | 2918 transaction.ApplyLookupResources(resourcesList_, &instancesList_, tuple.get<1>(), tuple.get<2>(), tuple.get<3>()); |
2907 } | 2919 } |
2908 else | 2920 else |