Commit dabde0fa authored by Leo Gordon's avatar Leo Gordon
Browse files

moved 'go_figure_dbc()' into Utils; supplied defaults for MySQLTransfer to make it quiet

parent 7085cc33
......@@ -90,7 +90,7 @@ use Bio::EnsEMBL::Registry;
use Bio::EnsEMBL::DBSQL::DBConnection;
use Bio::EnsEMBL::Utils::Argument;
use Bio::EnsEMBL::Utils::Exception ('throw');
use Bio::EnsEMBL::Hive::Utils ('url2dbconn_hash', 'stringify');
use Bio::EnsEMBL::Hive::Utils ('stringify', 'go_figure_dbc');
use Bio::EnsEMBL::Hive::Utils::Stopwatch;
use base ('Bio::EnsEMBL::Utils::Exception'); # provide these methods for deriving classes
......@@ -385,48 +385,13 @@ sub data_dbc {
if( !$self->{'_cached_db_signature'} or ($self->{'_cached_db_signature'} ne $given_signature) ) {
$self->{'_cached_db_signature'} = $given_signature;
$self->{'_cached_data_dbc'} = $self->go_figure_dbc( $given_db_conn );
$self->{'_cached_data_dbc'} = go_figure_dbc( $given_db_conn );
}
return $self->{'_cached_data_dbc'};
}
sub go_figure_dbc {
my ($self, $foo, $schema_type) = @_;
if(UNIVERSAL::isa($foo, 'Bio::EnsEMBL::DBSQL::DBConnection')) { # already a DBConnection, return it:
return $foo;
} elsif(UNIVERSAL::can($foo, 'dbc') and UNIVERSAL::isa($foo->dbc, 'Bio::EnsEMBL::DBSQL::DBConnection')) {
return $foo->dbc;
} elsif(UNIVERSAL::can($foo, 'db') and UNIVERSAL::can($foo->db, 'dbc') and UNIVERSAL::isa($foo->db->dbc, 'Bio::EnsEMBL::DBSQL::DBConnection')) { # another data adaptor or Runnable:
return $foo->db->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 );
} else {
unless(ref($foo)) { # maybe it is simply a registry key?
my $dba;
eval {
$schema_type ||= 'hive';
$dba = Bio::EnsEMBL::Registry->get_DBAdaptor($foo, $schema_type);
};
if(UNIVERSAL::can($dba, 'dbc')) {
return $dba->dbc;
}
}
die "Sorry, could not figure out how to make a DBConnection object out of '$foo'";
}
}
=head2 analysis
Title : analysis
......
......@@ -50,6 +50,9 @@ standaloneJob.pl RunnableDB/DatabaseDumper.pm -exclude_ehive 1 -exclude_list 1 -
package Bio::EnsEMBL::Hive::RunnableDB::DatabaseDumper;
use strict;
use warnings;
use Bio::EnsEMBL::Hive::Utils ('go_figure_dbc');
use base ('Bio::EnsEMBL::Hive::Process');
......@@ -68,7 +71,7 @@ sub fetch_input {
# Connection parameters
my $src_db_conn = $self->param('src_db_conn');
my $src_dbc = $src_db_conn ? $self->go_figure_dbc($src_db_conn) : $self->db->dbc;
my $src_dbc = $src_db_conn ? go_figure_dbc($src_db_conn) : $self->data_dbc;
$self->param('src_dbc', $src_dbc);
$self->input_job->transient_error(0);
......@@ -96,7 +99,7 @@ sub fetch_input {
# Output file / output database
$self->param('output_file') || $self->param('output_db') || die 'One of the parameters "output_file" and "output_db" is mandatory';
unless ($self->param('output_file')) {
$self->param('real_output_db', $self->go_figure_dbc( $self->param('output_db') ) );
$self->param('real_output_db', go_figure_dbc( $self->param('output_db') ) );
die 'Only the "mysql" driver is supported.' if $self->param('real_output_db')->driver ne 'mysql';
}
......
......@@ -27,9 +27,24 @@ Also, 'where' parameter allows to select subset of rows to be copied/merged over
package Bio::EnsEMBL::Hive::RunnableDB::MySQLTransfer;
use strict;
use warnings;
use Bio::EnsEMBL::Hive::Utils ('go_figure_dbc');
use base ('Bio::EnsEMBL::Hive::Process');
sub param_defaults {
return {
'src_db_conn' => '',
'dest_db_conn' => '',
'mode' => 'overwrite',
'table' => '',
'where' => undef,
'filter_cmd' => undef,
};
}
=head2 fetch_input
Description : Implements fetch_input() interface method of Bio::EnsEMBL::Hive::Process that is used to read in parameters and load data.
......@@ -60,20 +75,17 @@ sub fetch_input {
my $table = $self->param('table') or die "Please specify 'table' parameter\n";
$self->input_job->transient_error(1);
my $src_dbc = $src_db_conn ? $self->go_figure_dbc( $src_db_conn ) : $self->db->dbc;
my $dest_dbc = $dest_db_conn ? $self->go_figure_dbc( $dest_db_conn ) : $self->db->dbc;
my $src_dbc = $src_db_conn ? go_figure_dbc( $src_db_conn ) : $self->data_dbc;
my $dest_dbc = $dest_db_conn ? go_figure_dbc( $dest_db_conn ) : $self->data_dbc;
$self->param('src_dbc', $src_dbc);
$self->param('dest_dbc', $dest_dbc);
my $mode = $self->param('mode') || 'overwrite';
$self->param('mode', $self->param('mode'));
my $where = $self->param('where');
$self->param('src_before', $self->get_row_count($src_dbc, $table, $where) );
if($mode ne 'overwrite') {
if($self->param('mode') ne 'overwrite') {
$self->param('dest_before_all', $self->get_row_count($dest_dbc, $table) );
}
}
......@@ -91,10 +103,10 @@ sub run {
my $src_dbc = $self->param('src_dbc');
my $dest_dbc = $self->param('dest_dbc');
my $filter_cmd = $self->param('filter_cmd');
my $mode = $self->param('mode') || 'overwrite';
my $mode = $self->param('mode');
my $table = $self->param('table');
my $where = $self->param('where');
my $filter_cmd = $self->param('filter_cmd');
my $cmd = 'mysqldump '
. { 'overwrite' => '', 'topup' => '--no-create-info ', 'insertignore' => '--no-create-info --insert-ignore ' }->{$mode}
......
......@@ -41,9 +41,10 @@ package Bio::EnsEMBL::Hive::Utils;
use strict;
use warnings;
use Data::Dumper;
use Bio::EnsEMBL::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);
our @EXPORT_OK = qw(stringify destringify dir_revhash parse_cmdline_options find_submodules load_file_or_module script_usage url2dbconn_hash go_figure_dbc);
=head2 stringify
......@@ -273,5 +274,40 @@ sub url2dbconn_hash {
}
}
sub go_figure_dbc {
my ($foo, $schema_type) = @_;
if(UNIVERSAL::isa($foo, 'Bio::EnsEMBL::DBSQL::DBConnection')) { # already a DBConnection, return it:
return $foo;
} elsif(UNIVERSAL::can($foo, 'dbc') and UNIVERSAL::isa($foo->dbc, 'Bio::EnsEMBL::DBSQL::DBConnection')) {
return $foo->dbc;
} elsif(UNIVERSAL::can($foo, 'db') and UNIVERSAL::can($foo->db, 'dbc') and UNIVERSAL::isa($foo->db->dbc, 'Bio::EnsEMBL::DBSQL::DBConnection')) { # another data adaptor or Runnable:
return $foo->db->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 );
} else {
unless(ref($foo)) { # maybe it is simply a registry key?
my $dba;
eval {
$schema_type ||= 'hive';
$dba = Bio::EnsEMBL::Registry->get_DBAdaptor($foo, $schema_type);
};
if(UNIVERSAL::can($dba, 'dbc')) {
return $dba->dbc;
}
}
die "Sorry, could not figure out how to make a DBConnection object out of '$foo'";
}
}
1;
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