Commit 0ec4ee16 authored by Leo Gordon's avatar Leo Gordon
Browse files

moved Hive's extensions to DBConnection into a separate Hive::DBSQL::DBConnection class

parent b2fb955f
......@@ -38,6 +38,7 @@ package Bio::EnsEMBL::Hive::DBSQL::DBAdaptor;
use strict;
use Bio::EnsEMBL::Utils::Argument;
use Bio::EnsEMBL::Hive::URLFactory;
use Bio::EnsEMBL::Hive::DBSQL::DBConnection;
use base ('Bio::EnsEMBL::DBSQL::DBAdaptor');
......@@ -54,6 +55,16 @@ sub new {
}
sub dbc {
my $self = shift @_;
my $dbc = $self->SUPER::dbc( @_ );
bless $dbc, 'Bio::EnsEMBL::Hive::DBSQL::DBConnection' if( $dbc );
return $dbc;
}
sub hive_use_triggers { # getter only, not setter
my $self = shift @_;
......
=pod
=head1 NAME
Bio::EnsEMBL::Hive::DBSQL::DBConnection
=head1 SYNOPSIS
my $url = $dbc->url();
=head1 DESCRIPTION
Extends the functionality of Bio::EnsEMBL::DBSQL::DBConnection with things needed by the Hive
=head1 CONTACT
Please contact ehive-users@ebi.ac.uk mailing list with questions/suggestions.
=cut
package Bio::EnsEMBL::Hive::DBSQL::DBConnection;
use strict;
use warnings;
use base ('Bio::EnsEMBL::DBSQL::DBConnection');
=head2 url
Arg [1] : String $environment_variable_name_to_store_password_in (optional)
Example : $url = $dbc->url;
Description: Constructs a URL string for this database connection.
Returntype : string of format mysql://<user>:<pass>@<host>:<port>/<dbname>
or sqlite:///<dbname>
Exceptions : none
Caller : general
=cut
sub url {
my ($self, $psw_env_var_name) = @_;
my $url = $self->driver . '://';
if($self->username) {
$url .= $self->username;
if(my $psw_expression = $self->password) {
if($psw_env_var_name) {
$ENV{$psw_env_var_name} = $psw_expression;
$psw_expression = '${'.$psw_env_var_name.'}';
}
$url .= ':'.$psw_expression if($psw_expression);
}
$url .= '@';
}
if($self->host) {
$url .= $self->host;
if($self->port) {
$url .= ':'.$self->port;
}
}
$url .= '/' . $self->dbname;
return $url;
}
1;
......@@ -29,51 +29,6 @@
use strict;
use Bio::EnsEMBL::DBSQL::DBConnection;
=head2 Bio::EnsEMBL::DBSQL::DBConnection::url
Arg [1] : String $environment_variable_name_to_store_password_in (optional)
Example : $url = $dbc->url;
Description: Constructs a URL string for this database connection.
Returntype : string of format mysql://<user>:<pass>@<host>:<port>/<dbname>
or sqlite:///<dbname>
Exceptions : none
Caller : general
=cut
sub Bio::EnsEMBL::DBSQL::DBConnection::url {
my ($self, $psw_env_var_name) = @_;
my $url = $self->driver . '://';
if($self->username) {
$url .= $self->username;
if(my $psw_expression = $self->password) {
if($psw_env_var_name) {
$ENV{$psw_env_var_name} = $psw_expression;
$psw_expression = '${'.$psw_env_var_name.'}';
}
$url .= ':'.$psw_expression if($psw_expression);
}
$url .= '@';
}
if($self->host) {
$url .= $self->host;
if($self->port) {
$url .= ':'.$self->port;
}
}
$url .= '/' . $self->dbname;
return $url;
}
#######################################
# extensions to
# Bio::EnsEMBL::Pipeline::RunnableDB
......
......@@ -87,9 +87,9 @@ package Bio::EnsEMBL::Hive::Process;
use strict;
use warnings;
use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::DBSQL::DBConnection;
use Bio::EnsEMBL::Utils::Argument;
use Bio::EnsEMBL::Utils::Exception ('throw');
use Bio::EnsEMBL::Hive::DBSQL::DBConnection;
use Bio::EnsEMBL::Hive::Utils ('stringify', 'go_figure_dbc');
use Bio::EnsEMBL::Hive::Utils::Stopwatch;
......@@ -356,7 +356,7 @@ sub db {
Title : dbc
Usage : my $hiveDBConnection = $self->dbc;
Function: returns DBConnection to Hive database
Returns : Bio::EnsEMBL::DBSQL::DBConnection
Returns : Bio::EnsEMBL::Hive::DBSQL::DBConnection
=cut
......@@ -371,7 +371,7 @@ sub dbc {
Title : data_dbc
Usage : my $data_dbc = $self->data_dbc;
Function: returns a Bio::EnsEMBL::DBSQL::DBConnection object (the "current" one by default, but can be set up otherwise)
Function: returns a Bio::EnsEMBL::Hive::DBSQL::DBConnection object (the "current" one by default, but can be set up otherwise)
Returns : Bio::EnsEMBL::DBSQL::DBConnection
=cut
......
......@@ -41,7 +41,7 @@ package Bio::EnsEMBL::Hive::Utils;
use strict;
use warnings;
use Data::Dumper;
use Bio::EnsEMBL::DBSQL::DBConnection;
use Bio::EnsEMBL::Hive::DBSQL::DBConnection;
use Exporter 'import';
our @EXPORT_OK = qw(stringify destringify dir_revhash parse_cmdline_options find_submodules load_file_or_module script_usage url2dbconn_hash go_figure_dbc);
......@@ -292,7 +292,7 @@ sub go_figure_dbc {
} elsif(my $db_conn = (ref($foo) eq 'HASH') ? $foo : url2dbconn_hash( $foo ) ) { # either a hash or a URL that translates into a hash
return Bio::EnsEMBL::DBSQL::DBConnection->new( %$db_conn );
return Bio::EnsEMBL::Hive::DBSQL::DBConnection->new( %$db_conn );
} else {
unless(ref($foo)) { # maybe it is simply a registry key?
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment