DBAdaptor.pm 2.97 KB
Newer Older
1 2 3 4 5 6 7 8 9
#
# BioPerl module for DBSQL::Obj
#
# Cared for by Ewan Birney <birney@sanger.ac.uk>
#
# Copyright Ewan Birney
#
# You may distribute this module under the same terms as perl itself

10
=pod
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25

=head1 NAME

Bio::EnsEMBL::Hive::DBSQL::DBAdaptor

=head1 SYNOPSIS

    $db = Bio::EnsEMBL::Hive::DBSQL::DBAdaptor->new(
        -user   => 'root',
        -dbname => 'pog',
        -host   => 'caldy',
        -driver => 'mysql',
        );

=head1 DESCRIPTION
26

27
  This object represents the handle for a Hive system enabled database
28 29 30

=head1 CONTACT

31
  Please contact ehive-users@ebi.ac.uk mailing list with questions/suggestions.
32 33 34 35 36 37 38

=cut


package Bio::EnsEMBL::Hive::DBSQL::DBAdaptor;

use strict;
39 40 41

use Bio::EnsEMBL::Utils::Argument ('rearrange');

42
use Bio::EnsEMBL::Hive::URLFactory;
43
use Bio::EnsEMBL::Hive::DBSQL::DBConnection;
44

Leo Gordon's avatar
Leo Gordon committed
45
use base ('Bio::EnsEMBL::DBSQL::DBAdaptor');
46

47

48 49 50 51 52 53 54 55 56 57 58 59
sub new {
    my ($class, @args) = @_;

    my ($url) = rearrange(['URL'], @args);
    if($url) {
        return Bio::EnsEMBL::Hive::URLFactory->fetch($url) || die "Unable to connect to '$url'\n";
    } else {
        return $class->SUPER::new(@args);
    }
}


60 61 62 63 64 65 66 67 68 69
sub dbc {
    my $self = shift @_;

    my $dbc = $self->SUPER::dbc( @_ );
    bless $dbc, 'Bio::EnsEMBL::Hive::DBSQL::DBConnection' if( $dbc );

    return $dbc;
}


70 71 72 73
sub hive_use_triggers {  # getter only, not setter
    my $self = shift @_;

    unless( defined($self->{'_hive_use_triggers'}) ) {
74 75
        my ($hive_use_triggers) = @{ $self->get_MetaContainer->list_value_by_key( 'hive_use_triggers' ) };
        $self->{'_hive_use_triggers'} = $hive_use_triggers || 0;
76 77 78 79 80
    } 
    return $self->{'_hive_use_triggers'};
}


Leo Gordon's avatar
Leo Gordon committed
81
sub get_available_adaptors {
82
 
Leo Gordon's avatar
Leo Gordon committed
83
    my %pairs =  (
84 85
            # Core adaptors extended with Hive stuff:
        'MetaContainer'       => 'Bio::EnsEMBL::Hive::DBSQL::MetaContainer',
86 87

            # "new" Hive adaptors (sharing the same fetching/storing code inherited from the BaseAdaptor class) :
Leo Gordon's avatar
Leo Gordon committed
88 89 90
        'AnalysisCtrlRule'    => 'Bio::EnsEMBL::Hive::DBSQL::AnalysisCtrlRuleAdaptor',
        'DataflowRule'        => 'Bio::EnsEMBL::Hive::DBSQL::DataflowRuleAdaptor',
        'ResourceDescription' => 'Bio::EnsEMBL::Hive::DBSQL::ResourceDescriptionAdaptor',
91
        'ResourceClass'       => 'Bio::EnsEMBL::Hive::DBSQL::ResourceClassAdaptor',
92
        'LogMessage'          => 'Bio::EnsEMBL::Hive::DBSQL::LogMessageAdaptor',
93
        'NakedTable'          => 'Bio::EnsEMBL::Hive::DBSQL::NakedTableAdaptor',
94 95 96
        'Analysis'            => 'Bio::EnsEMBL::Hive::DBSQL::AnalysisAdaptor',
        'Queen'               => 'Bio::EnsEMBL::Hive::Queen',
        'AnalysisData'        => 'Bio::EnsEMBL::Hive::DBSQL::AnalysisDataAdaptor',
97 98 99 100

            # "old" Hive adaptors (having their own fetching/storing code) :
        'AnalysisJob'         => 'Bio::EnsEMBL::Hive::DBSQL::AnalysisJobAdaptor',
        'AnalysisStats'       => 'Bio::EnsEMBL::Hive::DBSQL::AnalysisStatsAdaptor',
101
        'Accumulator'         => 'Bio::EnsEMBL::Hive::DBSQL::AccumulatorAdaptor',
Leo Gordon's avatar
Leo Gordon committed
102
    );
103
    return \%pairs;
104
}
105

106
1;