comparison OrthancServer/Sources/Database/StatelessDatabaseOperations.cpp @ 5843:7df3d533c294 find-refactoring-clean

integration find-refactoring->find-refactoring-clean
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 29 Oct 2024 13:11:40 +0000
parents 58c549b881ae 08e47734328e
children c1b9eb21bd61
comparison
equal deleted inserted replaced
5833:58c549b881ae 5843:7df3d533c294
584 584
585 void StatelessDatabaseOperations::GetAllMetadata(std::map<MetadataType, std::string>& target, 585 void StatelessDatabaseOperations::GetAllMetadata(std::map<MetadataType, std::string>& target,
586 const std::string& publicId, 586 const std::string& publicId,
587 ResourceType level) 587 ResourceType level)
588 { 588 {
589 class Operations : public ReadOnlyOperationsT3<std::map<MetadataType, std::string>&, const std::string&, ResourceType> 589 FindRequest request(level);
590 { 590 request.SetOrthancId(level, publicId);
591 public: 591 request.SetRetrieveMetadata(true);
592 virtual void ApplyTuple(ReadOnlyTransaction& transaction, 592
593 const Tuple& tuple) ORTHANC_OVERRIDE 593 FindResponse response;
594 { 594 ExecuteFind(response, request);
595 ResourceType type; 595
596 int64_t id; 596 if (response.GetSize() == 0)
597 if (!transaction.LookupResource(id, type, tuple.get<1>()) || 597 {
598 tuple.get<2>() != type) 598 throw OrthancException(ErrorCode_UnknownResource);
599 { 599 }
600 throw OrthancException(ErrorCode_UnknownResource); 600 else if (response.GetSize() == 1)
601 } 601 {
602 else 602 target = response.GetResourceByIndex(0).GetMetadata(level);
603 { 603 }
604 transaction.GetAllMetadata(tuple.get<0>(), id); 604 else
605 } 605 {
606 } 606 throw OrthancException(ErrorCode_DatabasePlugin);
607 }; 607 }
608
609 Operations operations;
610 operations.Apply(*this, target, publicId, level);
611 } 608 }
612 609
613 610
614 bool StatelessDatabaseOperations::LookupAttachment(FileInfo& attachment, 611 bool StatelessDatabaseOperations::LookupAttachment(FileInfo& attachment,
615 int64_t& revision, 612 int64_t& revision,
648 645
649 646
650 void StatelessDatabaseOperations::GetAllUuids(std::list<std::string>& target, 647 void StatelessDatabaseOperations::GetAllUuids(std::list<std::string>& target,
651 ResourceType resourceType) 648 ResourceType resourceType)
652 { 649 {
653 class Operations : public ReadOnlyOperationsT2<std::list<std::string>&, ResourceType> 650 // This method is tested by "orthanc-tests/Plugins/WebDav/Run.py"
654 { 651 FindRequest request(resourceType);
655 public: 652
656 virtual void ApplyTuple(ReadOnlyTransaction& transaction, 653 FindResponse response;
657 const Tuple& tuple) ORTHANC_OVERRIDE 654 ExecuteFind(response, request);
658 { 655
659 // TODO - CANDIDATE FOR "TransactionType_Implicit" 656 target.clear();
660 transaction.GetAllPublicIds(tuple.get<0>(), tuple.get<1>()); 657 for (size_t i = 0; i < response.GetSize(); i++)
661 } 658 {
662 }; 659 target.push_back(response.GetResourceByIndex(i).GetIdentifier());
663 660 }
664 Operations operations;
665 operations.Apply(*this, target, resourceType);
666 } 661 }
667 662
668 663
669 void StatelessDatabaseOperations::GetAllUuids(std::list<std::string>& target, 664 void StatelessDatabaseOperations::GetAllUuids(std::list<std::string>& target,
670 ResourceType resourceType, 665 ResourceType resourceType,
3375 { 3370 {
3376 boost::shared_lock<boost::shared_mutex> lock(mutex_); 3371 boost::shared_lock<boost::shared_mutex> lock(mutex_);
3377 return db_.GetDatabaseCapabilities().HasFindSupport(); 3372 return db_.GetDatabaseCapabilities().HasFindSupport();
3378 } 3373 }
3379 3374
3375 void StatelessDatabaseOperations::ExecuteCount(uint64_t& count,
3376 const FindRequest& request)
3377 {
3378 class IntegratedCount : public ReadOnlyOperationsT3<uint64_t&, const FindRequest&,
3379 const IDatabaseWrapper::Capabilities&>
3380 {
3381 public:
3382 virtual void ApplyTuple(ReadOnlyTransaction& transaction,
3383 const Tuple& tuple) ORTHANC_OVERRIDE
3384 {
3385 transaction.ExecuteCount(tuple.get<0>(), tuple.get<1>(), tuple.get<2>());
3386 }
3387 };
3388
3389 IDatabaseWrapper::Capabilities capabilities = db_.GetDatabaseCapabilities();
3390
3391 if (db_.HasIntegratedFind())
3392 {
3393 IntegratedCount operations;
3394 operations.Apply(*this, count, request, capabilities);
3395 }
3396 else
3397 {
3398 throw OrthancException(ErrorCode_NotImplemented);
3399 }
3400 }
3401
3380 void StatelessDatabaseOperations::ExecuteFind(FindResponse& response, 3402 void StatelessDatabaseOperations::ExecuteFind(FindResponse& response,
3381 const FindRequest& request) 3403 const FindRequest& request)
3382 { 3404 {
3383 class IntegratedFind : public ReadOnlyOperationsT3<FindResponse&, const FindRequest&, 3405 class IntegratedFind : public ReadOnlyOperationsT3<FindResponse&, const FindRequest&,
3384 const IDatabaseWrapper::Capabilities&> 3406 const IDatabaseWrapper::Capabilities&>