Bio::EnsEMBL::Pipeline::DBSQL DBAdaptor
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor -
adapter class for EnsEMBL Pipeline DB
Package variables
No package variables defined.
Included modules
Bio::EnsEMBL::DBSQL::DBAdaptor
Bio::EnsEMBL::Root
Inherit
Bio::EnsEMBL::DBSQL::DBAdaptor
Synopsis
    my $dbobj = new Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor;
$dbobj->do_funky_db_stuff;
Description
Interface for the connection to the analysis database
Methods
DESTROYDescriptionCode
_db_handleDescriptionCode
get_available_adaptors
No description
Code
get_meta_value_by_key
No description
Code
make_hash_from_meta_value
No description
Code
make_meta_value_from_hash
No description
Code
pipeline_lock
No description
Code
pipeline_unlock
No description
Code
prepare
No description
Code
remove_meta_key
No description
Code
store_meta_key_value
No description
Code
Methods description
DESTROYcode    nextTop
 Title   : DESTROY
Usage :
Function:
Example :
Returns :
Args :
_db_handlecodeprevnextTop
 Title   : _db_handle
Usage : $sth = $dbobj->_db_handle($dbh);
Function: Get/set method for the database handle
Example :
Returns : A database handle object
Args : A database handle object
Methods code
DESTROYdescriptionprevnextTop
sub DESTROY {
   my ($obj) = @_;

   if( $obj->{'_db_handle'} ) {
       $obj->{'_db_handle'}->disconnect;
       $obj->{'_db_handle'} = undef;
   }
}
_db_handledescriptionprevnextTop
sub _db_handle {
    my ($self,$arg) = @_;

    if (defined($arg)) {
	$self->{_db_handle} = $arg;
    }
    return $self->{_db_handle};
}
get_available_adaptorsdescriptionprevnextTop
sub get_available_adaptors {
  my ($self) = @_;

  my $pairs = $self->SUPER::get_available_adaptors();

  $pairs->{'Analysis'}                  = 'Bio::EnsEMBL::Pipeline::DBSQL::AnalysisAdaptor';
  $pairs->{'Job'}                       = 'Bio::EnsEMBL::Pipeline::DBSQL::JobAdaptor';
  $pairs->{'PmatchFeature'}             = 'Bio::EnsEMBL::Pipeline::DBSQL::PmatchFeatureAdaptor';
  $pairs->{'Rule'}                      = 'Bio::EnsEMBL::Pipeline::DBSQL::RuleAdaptor';
  $pairs->{'StateInfoContainer'}        = 'Bio::EnsEMBL::Pipeline::DBSQL::StateInfoContainer';
  $pairs->{'CompressedDnaAlignFeature'} = 'Bio::EnsEMBL::Pipeline::DBSQL::CompressedDnaAlignFeatureAdaptor';

  return $pairs;
}
get_meta_value_by_keydescriptionprevnextTop
sub get_meta_value_by_key {
    my ($self, $key, $value) = @_;
    $self->throw("No key to get supplied") unless $key;
    my $sth = $self->prepare(qq{
        SELECT meta_value
        FROM   meta
        WHERE  meta_key = ? LIMIT 1
    }); # ONLY RETRIEVES FIRST ENTRY,
# SHOULD THERE BE A UNIQUE KEY ON meta_key??
$sth->execute($key); my $row = $sth->fetchrow_arrayref(); $value = $row->[0] if $row; $sth->finish(); return $value;
}
make_hash_from_meta_valuedescriptionprevnextTop
sub make_hash_from_meta_value {
    my ($self,$string) = @_;
    if($string){
        my $hash = { eval $string };
        $@ ? die "error evaluating $string" : return $hash || {};
    }
    return {};
}
1;
}
make_meta_value_from_hashdescriptionprevnextTop
sub make_meta_value_from_hash {
    my ($self, $hash) = @_;
    my $dbh = $self->_db_handle();
    return join(",\n", map{ $dbh->quote($_)." => ".$dbh->quote($hash->{$_}) } keys(%$hash));
}
pipeline_lockdescriptionprevnextTop
sub pipeline_lock {
    my ($self, $string) = @_;
    my $lock = 'pipeline.lock';

    return $string ? $self->store_meta_key_value($lock, $string) : $self->get_meta_value_by_key($lock);
}
pipeline_unlockdescriptionprevnextTop
sub pipeline_unlock {
    my ($self) = @_;
    $self->remove_meta_key('pipeline.lock');
}
preparedescriptionprevnextTop
sub prepare {
  my ($self, @args) = @_;

  $self->dbc->prepare(@args);
}
remove_meta_keydescriptionprevnextTop
sub remove_meta_key {
    my ($self, $key) = @_;
    $self->throw("No key to remove supplied") unless $key;
    my $sth = $self->prepare(qq{
	DELETE
	FROM   meta
	WHERE  meta_key = ?
    });
    $sth->execute($key);
    $sth->finish;
    return undef;
}
store_meta_key_valuedescriptionprevnextTop
sub store_meta_key_value {
    my ($self, $key, $value) = @_;
    $self->throw("No key|value to insert supplied") unless $key && $value;
    my $sth = $self->prepare(qq{
        INSERT INTO meta (meta_key, meta_value) VALUES (?, ?)
    });
    $sth->execute($key, $value);
    $sth->finish();
    return undef;
}
General documentation
CONTACTTop
Post general queries to ensembl-dev@ebi.ac.uk
APPENDIXTop
The rest of the documentation details each of the object methods.
Internal methods are usually preceded with a _
get_JobAdaptorTop
 Title   : get_JobAdaptor
Usage : $db->get_JobAdaptor
Function: The Adaptor for Job objects in this db
Example :
Returns : Bio::EnsEMBL::Pipeline::DBSQL::JobAdaptor
Args : nothing
get_RuleAdaptorTop
 Title   : get_RuleAdaptor
Usage : $db->get_RuleAdaptor
Function: The Adaptor for Rule objects in this db
Example :
Returns : Bio::EnsEMBL::Pipeline::DBSQL::RuleAdaptor
Args : nothing
get_StateInfoContainerTop
 Title   : get_StateInfoContainer
Usage : $db->get_StateInfoContainer
Function:
Example :
Returns : Bio::EnsEMBL::Pipeline::DBSQL::StateInfoContainer
Args : nothing
Some Utility StuffTop
 Access to the meta table of the schema including

pipeline_lock - write a lock to the meta table
pipeline_unlock - remove the lock
get_meta_value_by_key - retrieve value by key
store_meta_key_value - write key, value pair
remove_meta_key - delete by key name
make_meta_value_from_hash - flatten a hash to a string (uses dbi->quote to escape)
make_hash_from_meta_value - returns a hash from a previously flattened string

$lock_string = 'whatever to lock';
$dbA->pipeline_lock($lock_string);
my $lock_string = $dbA->pipeline_lock();

$dbA->pipeline_unlock();

$dbA->store_meta_key_value('my_key', 'the value');
my $value = $dbA->get_meta_value_by_key('my_key'); $dbA->remove_meta_key('my_key'); my %hash = ('-host' => 'pfam', '-port' => '3306'...); my $flat = $dbA->make_meta_value_from_hash(\%hash); my %retrieved = %{$dbA->make_hash_from_meta_value($flat)};