Commit 3f3a86a8 authored by Web Admin's avatar Web Admin
Browse files

changes to ensembl code to handle disconnecting databases properly -...

changes to ensembl code to handle disconnecting databases properly - disconnect_all, checking for reconnection when doing do and prepare and finishing statement handles in generic_fetch
parent 39e2c760
......@@ -309,7 +309,7 @@ sub generic_fetch {
my $sth = $db->dbc->prepare($sql);
$sth->execute;
my $res = $self->_objs_from_sth($sth, $mapper, $slice);
$sth->finish();
return $res;
}
......
......@@ -197,7 +197,6 @@ sub connect {
my $self = shift;
return if($self->connected);
$self->connected(1);
if(defined($self->db_handle()) and $self->db_handle()->ping()) {
warning("unconnected db_handle is still pingable, reseting connected boolean\n");
......@@ -210,21 +209,19 @@ sub connect {
my $dbh;
eval{
$dbh = DBI->connect($dsn,
$self->username(),
$self->password(),
{'RaiseError' => 1});
$dbh = DBI->connect($dsn, $self->username(), $self->password(), {'RaiseError' => 1});
};
if(!$dbh || $@ || !$dbh->ping()) {
warn("Could not connect to database " . $self->dbname() .
" as user " . $self->username() .
" using [$dsn] as a locator:\n" . $DBI::errstr);
" as user " . $self->username() .
" using [$dsn] as a locator:\n" . $DBI::errstr);
throw("Could not connect to database " . $self->dbname() .
" as user " . $self->username() .
" using [$dsn] as a locator:\n" . $DBI::errstr);
}
$self->connected(1);
$self->db_handle($dbh);
#print("CONNECT\n");
}
......@@ -564,6 +561,7 @@ sub prepare {
# print STDERR "SQL(".$self->dbname."):$string\n";
$self->connect() unless $self->connected();
my $sth = $self->db_handle->prepare($string);
# return an overridden statement handle that provides us with
......@@ -598,6 +596,7 @@ sub do {
#info("SQL(".$self->dbname."):$string");
$self->connect() unless $self->connected();
my $result = $self->db_handle->do($string);
# disconnect if the disconnect when inactive flag is set and
......@@ -659,6 +658,7 @@ sub disconnect_if_idle {
$self->connected(undef);
$self->disconnect_count($self->disconnect_count()+1);
#print("DISCONNECT\n");
$self->db_handle(undef);
return 0;
}
......
......@@ -604,19 +604,21 @@ sub alias_exists{
}
sub set_disconnect_when_inactive{
foreach my $dba ( @{$registry_register{'_DBA'}}){
foreach my $dba ( @{get_all_DBAdaptors()}){
my $dbc = $dba->dbc;
#disconnect if connected
if($dbc->connected()){
$dbc->disconnect();
$dbc->connected(undef);
}
$dbc->disconnect_if_idle() if $dbc->connected();
$dbc->disconnect_when_inactive(1);
}
}
sub disconnect_all {
foreach my $dba ( get_all_DBAdaptors() ){
my $dbc = $dba->dbc;
#disconnect if connected
$dbc->disconnect_if_idle() if $dbc->connected();
}
}
=head2 change_access
Will change the username and password for a set of databases.
......
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