Mercurial > hg > orthanc
comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5593:862b54b4cfe2 find-refactoring
implemented the default multi-stage find/expand
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Sat, 04 May 2024 11:35:34 +0200 |
parents | 1e2631b8b9af |
children | a87f2a56257d |
comparison
equal
deleted
inserted
replaced
5592:1e2631b8b9af | 5593:862b54b4cfe2 |
---|---|
3842 | 3842 |
3843 | 3843 |
3844 void StatelessDatabaseOperations::ExecuteFind(FindResponse& response, | 3844 void StatelessDatabaseOperations::ExecuteFind(FindResponse& response, |
3845 const FindRequest& request) | 3845 const FindRequest& request) |
3846 { | 3846 { |
3847 class Operations : public ReadOnlyOperationsT3<FindResponse&, const FindRequest&, const std::vector<DatabaseConstraint>&> | 3847 class IntegratedFind : public ReadOnlyOperationsT3<FindResponse&, const FindRequest&, const std::vector<DatabaseConstraint>&> |
3848 { | 3848 { |
3849 public: | 3849 public: |
3850 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | 3850 virtual void ApplyTuple(ReadOnlyTransaction& transaction, |
3851 const Tuple& tuple) ORTHANC_OVERRIDE | 3851 const Tuple& tuple) ORTHANC_OVERRIDE |
3852 { | 3852 { |
3853 transaction.ExecuteFind(tuple.get<0>(), tuple.get<1>(), tuple.get<2>()); | 3853 transaction.ExecuteFind(tuple.get<0>(), tuple.get<1>(), tuple.get<2>()); |
3854 } | 3854 } |
3855 }; | 3855 }; |
3856 | 3856 |
3857 class FindStage : public ReadOnlyOperationsT3<std::list<std::string>&, const FindRequest&, const std::vector<DatabaseConstraint>&> | |
3858 { | |
3859 public: | |
3860 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
3861 const Tuple& tuple) ORTHANC_OVERRIDE | |
3862 { | |
3863 transaction.ExecuteFind(tuple.get<0>(), tuple.get<1>(), tuple.get<2>()); | |
3864 } | |
3865 }; | |
3866 | |
3867 class ExpandStage : public ReadOnlyOperationsT3<FindResponse&, const FindRequest&, const std::string&> | |
3868 { | |
3869 public: | |
3870 virtual void ApplyTuple(ReadOnlyTransaction& transaction, | |
3871 const Tuple& tuple) ORTHANC_OVERRIDE | |
3872 { | |
3873 transaction.ExecuteExpand(tuple.get<0>(), tuple.get<1>(), tuple.get<2>()); | |
3874 } | |
3875 }; | |
3876 | |
3857 std::vector<DatabaseConstraint> normalized; | 3877 std::vector<DatabaseConstraint> normalized; |
3858 NormalizeLookup(normalized, request); | 3878 NormalizeLookup(normalized, request); |
3859 | 3879 |
3860 Operations operations; | 3880 if (db_.HasIntegratedFind()) |
3861 operations.Apply(*this, response, request, normalized); | 3881 { |
3882 /** | |
3883 * In this flavor, the "find" and the "expand" phases are | |
3884 * executed in one single transaction. | |
3885 **/ | |
3886 IntegratedFind operations; | |
3887 operations.Apply(*this, response, request, normalized); | |
3888 } | |
3889 else | |
3890 { | |
3891 /** | |
3892 * In this flavor, the "find" and the "expand" phases for each | |
3893 * found resource are executed in distinct transactions. This is | |
3894 * the compatibility mode equivalent to Orthanc <= 1.12.3. | |
3895 **/ | |
3896 std::list<std::string> identifiers; | |
3897 | |
3898 FindStage find; | |
3899 find.Apply(*this, identifiers, request, normalized); | |
3900 | |
3901 ExpandStage expand; | |
3902 | |
3903 for (std::list<std::string>::const_iterator it = identifiers.begin(); it != identifiers.end(); ++it) | |
3904 { | |
3905 /** | |
3906 * Not that the resource might have been deleted (as we are in | |
3907 * another transaction). The database engine must ignore such | |
3908 * error cases. | |
3909 **/ | |
3910 expand.Apply(*this, response, request, *it); | |
3911 } | |
3912 } | |
3862 } | 3913 } |
3863 | 3914 |
3864 // TODO-FIND: we reuse the ExpandedResource class to reuse Serialization code from ExpandedResource | 3915 // TODO-FIND: we reuse the ExpandedResource class to reuse Serialization code from ExpandedResource |
3865 // But, finally, we might just get rid of ExpandedResource and replace it by FindResponse | 3916 // But, finally, we might just get rid of ExpandedResource and replace it by FindResponse |
3866 ExpandedResource::ExpandedResource(const FindRequest& request, | 3917 ExpandedResource::ExpandedResource(const FindRequest& request, |