From 6e515886137444d925b95f805a469a61b4abf2af Mon Sep 17 00:00:00 2001
From: Leo Gordon <lg4@ebi.ac.uk>
Date: Thu, 3 Oct 2013 12:45:51 +0100
Subject: [PATCH] drop fetch_all_by_from_analysis_id_and_branch_code() method
 and rely on AUTOLOADed BaseAdaptor's methods instead

---
 modules/Bio/EnsEMBL/Hive/AnalysisJob.pm       | 10 ++++---
 .../EnsEMBL/Hive/DBSQL/AnalysisJobAdaptor.pm  |  7 +++--
 .../EnsEMBL/Hive/DBSQL/DataflowRuleAdaptor.pm | 26 -------------------
 3 files changed, 11 insertions(+), 32 deletions(-)

diff --git a/modules/Bio/EnsEMBL/Hive/AnalysisJob.pm b/modules/Bio/EnsEMBL/Hive/AnalysisJob.pm
index 90ec28047..32a4c9d93 100644
--- a/modules/Bio/EnsEMBL/Hive/AnalysisJob.pm
+++ b/modules/Bio/EnsEMBL/Hive/AnalysisJob.pm
@@ -164,11 +164,13 @@ sub dataflow_rules {    # if ever set will prevent the Job from fetching rules f
 
     my $branch_code = Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor::branch_name_2_code($branch_name_or_code);
 
-    $self->{'_dataflow_rules'}{$branch_code} = shift if(@_);
+    if(@_) {
+        $self->{'_dataflow_rules'}{$branch_code} = shift @_;
+    }
+
+    $self->{'_dataflow_rules'} ||= $self->adaptor->db->get_DataflowRuleAdaptor->fetch_all_by_from_analysis_id_HASHED_FROM_branch_code( $self->analysis_id );
 
-    return $self->{'_dataflow_rules'}
-        ? ( $self->{'_dataflow_rules'}{$branch_code} || [] )
-        : $self->adaptor->db->get_DataflowRuleAdaptor->fetch_all_by_from_analysis_id_and_branch_code($self->analysis_id, $branch_code);
+    return $self->{'_dataflow_rules'}{$branch_code} || [];
 }
 
 sub stdout_file {
diff --git a/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisJobAdaptor.pm b/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisJobAdaptor.pm
index 2d4b3b420..217998c17 100644
--- a/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisJobAdaptor.pm
+++ b/modules/Bio/EnsEMBL/Hive/DBSQL/AnalysisJobAdaptor.pm
@@ -48,6 +48,7 @@ use Bio::EnsEMBL::Utils::Exception ('throw');
 
 use Bio::EnsEMBL::Hive::DBSQL::AnalysisDataAdaptor;
 use Bio::EnsEMBL::Hive::AnalysisJob;
+use Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor;
 use Bio::EnsEMBL::Hive::Utils ('stringify');
 
 use base ('Bio::EnsEMBL::Hive::DBSQL::ObjectAdaptor');
@@ -553,8 +554,10 @@ sub release_and_age_job {
 sub gc_dataflow {
     my ($self, $analysis, $job_id, $branch_name) = @_;
 
-    unless(@{ $self->db->get_DataflowRuleAdaptor->fetch_all_by_from_analysis_id_and_branch_code($analysis->dbID, $branch_name) }) {
-        return 0;   # no corresponding gc_dataflow rule has been defined
+    my $branch_code = Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor::branch_name_2_code($branch_name);
+
+    unless( $self->db->get_DataflowRuleAdaptor->count_all_by_from_analysis_id_AND_branch_code($analysis->dbID, $branch_code) ) {
+        return 0;   # just return if no corresponding gc_dataflow rule has been defined
     }
 
     my $job = $self->fetch_by_dbID($job_id);
diff --git a/modules/Bio/EnsEMBL/Hive/DBSQL/DataflowRuleAdaptor.pm b/modules/Bio/EnsEMBL/Hive/DBSQL/DataflowRuleAdaptor.pm
index 21410642e..900e47751 100644
--- a/modules/Bio/EnsEMBL/Hive/DBSQL/DataflowRuleAdaptor.pm
+++ b/modules/Bio/EnsEMBL/Hive/DBSQL/DataflowRuleAdaptor.pm
@@ -84,31 +84,5 @@ sub branch_name_2_code {
     return defined($branch_code) ? $branch_code : die "Could not map the branch_name '$branch_name_or_code' to the internal code";
 }
 
-
-=head2 fetch_all_by_from_analysis_id_and_branch_code
-
-  Args       : unsigned int $analysis_id, unsigned int $branch_code
-  Example    : my @rules = @{$ruleAdaptor->fetch_all_by_from_analysis_id_and_branch_code($analysis_id, $branch_code)};
-  Description: searches database for rules with given from_analysis_id and branch_code
-               and returns all such rules in a list (by reference)
-  Returntype : reference to list of Bio::EnsEMBL::Hive::DataflowRule objects
-  Exceptions : none
-  Caller     : Bio::EnsEMBL::Hive::AnalysisJob::dataflow_output_id
-
-=cut
-
-sub fetch_all_by_from_analysis_id_and_branch_code {
-    my ($self, $analysis_id, $branch_name_or_code) = @_;
-
-    return [] unless($analysis_id);
-
-    my $branch_code = $self->branch_name_2_code($branch_name_or_code);
-
-    my $constraint = "from_analysis_id=${analysis_id} AND branch_code=${branch_code}";
-
-    return $self->fetch_all($constraint);
-}
-
-
 1;
 
-- 
GitLab