Bio::EnsEMBL::Hive::DBSQL
DataflowRuleAdaptor
Toolbar
Summary
Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor
Package variables
No package variables defined.
Included modules
Inherit
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
Methods description
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 |
Arg : None Example : Description: Returntype : Exceptions : Caller : |
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 |
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 : ? |
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 |
Usage : $self->store( $rule ); Function: Stores a rule in db Sets adaptor and dbID in DataflowRule Returns : - Args : Bio::EnsEMBL::Hive::DataflowRule |
Methods code
sub _columns
{ my $self = shift;
return qw (r.dataflow_rule_id
r.from_analysis_id
r.to_analysis_url
r.branch_code
); } |
sub _default_where_clause
{ my $self = shift;
return ''; } |
sub _final_clause
{ my $self = shift;
return '';
}
} |
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});
}
}
}
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;
if($constraint) {
$sql .= " WHERE $constraint ";
if($default_where) {
$sql .= " AND $default_where ";
}
} elsif($default_where) {
$sql .= " WHERE $default_where ";
}
$sql .= " $final_clause";
my $sth = $self->prepare($sql);
$sth->execute;
return $self->_objs_from_sth($sth);
}
1; } |
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; } |
sub _tables
{ my $self = shift;
return (['dataflow_rule', 'r']); } |
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);
}
} |
sub fetch_all
{ my $self = shift;
return $self->_generic_fetch(); } |
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]};
my $constraint = "${syn}.${name}_id = $id";
my ($obj) = @{$self->_generic_fetch($constraint)};
return $obj; } |
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); } |
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; } |
sub store
{ my ( $self, $rule ) = @_;
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;
} else {
$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;
}
$rule->adaptor( $self );
return $newly_inserted_rule; } |
General documentation
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _