Bio::EnsEMBL::Hive::DBSQL DataflowRuleAdaptor
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
  Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor
Package variables
No package variables defined.
Included modules
Bio::EnsEMBL::DBSQL::BaseAdaptor
Bio::EnsEMBL::Hive::DataflowRule
Bio::EnsEMBL::Utils::Argument
Bio::EnsEMBL::Utils::Exception
Carp
Inherit
Bio::EnsEMBL::DBSQL::BaseAdaptor
Synopsis
  $dataflowRuleAdaptor = $db_adaptor->get_DataflowRuleAdaptor;
$dataflowRuleAdaptor = $dataflowRuleObj->adaptor;
Description
  Module to encapsulate all db access for persistent class DataflowRule.
There should be just one per application and database connection.
Methods
_columns
No description
Code
_default_where_clause
No description
Code
_final_clause
No description
Code
_generic_fetch
No description
Code
_objs_from_sth
No description
Code
_tables
No description
Code
create_ruleDescriptionCode
fetch_allDescriptionCode
fetch_by_dbIDDescriptionCode
fetch_from_analysis_jobDescriptionCode
removeDescriptionCode
storeDescriptionCode
Methods description
create_rulecode    nextTop
  Title   : create_rule
Usage : $self->create_rule( $from_analysis, $to_analysis );
Function: Creates and stores a new rule in the DB.
Returns : Bio::EnsEMBL::Hive::DataflowRule
Args[1] : Bio::EnsEMBL::Analysis $from_analysis
Args[1] : Bio::EnsEMBL::Analysis $to_analysis
Args[1] : (optional) int $branch_code
fetch_allcodeprevnextTop
  Arg        : None
Example :
Description:
Returntype :
Exceptions :
Caller :
fetch_by_dbIDcodeprevnextTop
  
Arg [1] : int $id
the unique database identifier for the feature to be obtained
Example : $feat = $adaptor->fetch_by_dbID(1234);
Description: Returns the Member created from the database defined by the
the id $id.
Returntype : Bio::EnsEMBL::Hive::DataflowRule
Exceptions : thrown if $id is not defined
Caller : general
fetch_from_analysis_jobcodeprevnextTop
  Args       : Bio::EnsEMBL::Hive::AnalysisJob
Example : my @rules = @{$ruleAdaptor->fetch_from_analysis_job($job)};
Description: searches database for rules with given 'from' analysis
returns all such rules in a list (by reference)
Returntype : reference to list of Bio::EnsEMBL::Hive::DataflowRule objects
Exceptions : none
Caller : ?
removecodeprevnextTop
  Title   : remove
Usage : $self->remove( $rule );
Function: removes given object from database.
Returns : -
Args : Bio::EnsEMBL::Hive::DataflowRule which must be persistent with a valid dbID
storecodeprevnextTop
  Usage   : $self->store( $rule );
Function: Stores a rule in db
Sets adaptor and dbID in DataflowRule
Returns : -
Args : Bio::EnsEMBL::Hive::DataflowRule
Methods code
_columnsdescriptionprevnextTop
sub _columns {
  my $self = shift;

  return qw (r.dataflow_rule_id
             r.from_analysis_id
             r.to_analysis_url
             r.branch_code
            );
}
_default_where_clausedescriptionprevnextTop
sub _default_where_clause {
  my $self = shift;
  return '';
}
_final_clausedescriptionprevnextTop
sub _final_clause {
  my $self = shift;
  return '';
}

###############################################################################
#
# General access methods that could be moved
# into a superclass
#
###############################################################################
}
_generic_fetchdescriptionprevnextTop
sub _generic_fetch {
  my ($self, $constraint, $join) = @_;

  my @tables = $self->_tables;
  my $columns = join(', ', $self->_columns());

  if ($join) {
    foreach my $single_join (@{$join}) {
      my ($tablename, $condition, $extra_columns) = @{$single_join};
      if ($tablename && $condition) {
        push @tables, $tablename;

        if($constraint) {
          $constraint .= " AND $condition";
        } else {
          $constraint = " $condition";
        }
      }
      if ($extra_columns) {
        $columns .= ", " . join(', ', @{$extra_columns});
      }
    }
  }

  #construct a nice table string like 'table1 t1, table2 t2'
my $tablenames = join(', ', map({ join(' ', @$_) } @tables)); my $sql = "SELECT $columns FROM $tablenames"; my $default_where = $self->_default_where_clause; my $final_clause = $self->_final_clause; #append a where clause if it was defined
if($constraint) { $sql .= " WHERE $constraint "; if($default_where) { $sql .= " AND $default_where "; } } elsif($default_where) { $sql .= " WHERE $default_where "; } #append additional clauses which may have been defined
$sql .= " $final_clause"; my $sth = $self->prepare($sql); $sth->execute; # print STDERR $sql,"\n";
return $self->_objs_from_sth($sth); } 1;
}
_objs_from_sthdescriptionprevnextTop
sub _objs_from_sth {
  my ($self, $sth) = @_;
  my @rules = ();

  my ($dataflow_rule_id, $from_analysis_id, $to_analysis_url, $branch_code);
  $sth->bind_columns(\$dataflow_rule_id,\$ from_analysis_id,\$ to_analysis_url,\$ branch_code);

  while ($sth->fetch()) {
    my $rule = Bio::EnsEMBL::Hive::DataflowRule->new;
    $rule->adaptor($self);
    $rule->dbID($dataflow_rule_id);
    $rule->from_analysis_id($from_analysis_id);
    $rule->to_analysis_url($to_analysis_url);
    $rule->branch_code($branch_code);
    push @rules, $rule;
  }
  return\@ rules;
}
_tablesdescriptionprevnextTop
sub _tables {
  my $self = shift;

  return (['dataflow_rule', 'r']);
}
create_ruledescriptionprevnextTop
sub create_rule {
  my ($self, $fromAnalysis, $toAnalysis, $branchCode) = @_;

  return unless($fromAnalysis and $toAnalysis);
  
  my $rule = Bio::EnsEMBL::Hive::DataflowRule->new();
  $rule->from_analysis($fromAnalysis);
  $rule->to_analysis($toAnalysis);
  $rule->branch_code($branchCode) if(defined($branchCode));
  
  return $self->store($rule);
}

############################
#
# INTERNAL METHODS
# (pseudo subclass methods)
#
############################
#internal method used in multiple calls above to build objects from table data
}
fetch_alldescriptionprevnextTop
sub fetch_all {
  my $self = shift;
  return $self->_generic_fetch();
}
fetch_by_dbIDdescriptionprevnextTop
sub fetch_by_dbID {
  my ($self,$id) = @_;

  unless(defined $id) {
    throw("fetch_by_dbID must have an id");
  }

  my @tabs = $self->_tables;

  my ($name, $syn) = @{$tabs[0]};

  #construct a constraint like 't1.table1_id = 1'
my $constraint = "${syn}.${name}_id = $id"; #return first element of _generic_fetch list
my ($obj) = @{$self->_generic_fetch($constraint)}; return $obj;
}
fetch_from_analysis_jobdescriptionprevnextTop
sub fetch_from_analysis_job {
  my $self = shift;
  my $fromAnalysisJob = shift;
  
  throw("arg is required\n") unless($fromAnalysisJob);
  throw("arg must be a [Bio::EnsEMBL::Hive::AnalysisJob] not a $fromAnalysisJob")
    unless ($fromAnalysisJob->isa('Bio::EnsEMBL::Hive::AnalysisJob'));
  return [] unless($fromAnalysisJob->analysis_id);
      
  my $constraint = "r.from_analysis_id = '".$fromAnalysisJob->analysis_id."'"
                  ." AND r.branch_code=". $fromAnalysisJob->branch_code;

  return $self->_generic_fetch($constraint);
}
removedescriptionprevnextTop
sub remove {
  my ( $self, $rule ) = @_;

  my $dbID = $rule->dbID;
  if( !defined $dbID ) {
    throw( "DataflowRuleAdaptor->remove called with non persistent DataflowRule" );
  }

  my $sth = $self->prepare("DELETE FROM dataflow_rule WHERE dataflow_rule_id = $dbID");
  $sth->execute;
}
storedescriptionprevnextTop
sub store {
  my ( $self, $rule ) = @_;

  #print("\nDataflowRuleAdaptor->store()\n");
my $dataflow_rule_id; my $newly_inserted_rule = 0; my $sth = $self->prepare( q{INSERT ignore INTO dataflow_rule
(from_analysis_id, to_analysis_url, branch_code) VALUES (?,?,?) }
); my $rtnCode = $sth->execute($rule->from_analysis_id, $rule->to_analysis_url, $rule->branch_code); if($rtnCode and $rtnCode != 0E0) { $dataflow_rule_id = $sth->{'mysql_insertid'}; $sth->finish(); $rule->dbID($dataflow_rule_id); $newly_inserted_rule = 1; #print(" stored with dbID = $dataflow_rule_id\n");
} else { #print(" already inserted -> need to get dbID\n");
$sth->finish(); $sth = $self->prepare(q{SELECT dataflow_rule_id FROM dataflow_rule WHERE
from_analysis_id = ? AND to_analysis_url = ? }
); $sth->execute($rule->from_analysis_id, $rule->to_analysis_url); $sth->bind_columns(\$dataflow_rule_id); if($sth->fetch()) { $rule->dbID($dataflow_rule_id); } $sth->finish; } #print(" dataflow_rule_id = '".$rule->dbID."'\n");
$rule->adaptor( $self ); return $newly_inserted_rule;
}
General documentation
CONTACTTop
  Contact Jessica Severin on implemetation/design detail: jessica@ebi.ac.uk
Contact Ewan Birney on EnsEMBL in general: birney@sanger.ac.uk
APPENDIXTop
  The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _