sub _check_alias
{ my $self = shift;
my $host = shift;
my $port = shift;
my $key = "$host:$port";
my $alias = $self->{'_aliases'}->{$key};
return ($host,$port) unless($alias);
($host,$port) = split(/:/, $alias);
return ($host,$port);
}
1; } |
sub _get_db_connection
{
my $class = shift;
my $url = shift;
my $type = shift;
return undef unless($url);
my $user = 'ensro';
my $pass = '';
my $host = '';
my $port = 3306;
my $dbname = undef;
my $path = '';
my $module = "Bio::EnsEMBL::Hive::DBSQL::DBAdaptor";
$type = 'hive' unless($type);
my $discon = 0;
my ($p, $p2, $p3);
return undef unless $url =~ s/^mysql\:\/\///;
$p = index($url, "/");
return undef if($p == -1);
my $conn = substr($url, 0, $p);
$dbname = substr($url, $p+1, length($url));
my $params = undef;
if(($p2=index($dbname, ";")) != -1) {
$params = substr($dbname, $p2+1, length($dbname));
$dbname = substr($dbname, 0, $p2);
}
if(($p2=index($dbname, "/")) != -1) {
$path = substr($dbname, $p2+1, length($dbname));
$dbname = substr($dbname, 0, $p2);
}
while($params) {
my $token = $params;
if(($p2=rindex($params, ";")) != -1) {
$token = substr($params, 0, $p2);
$params = substr($params, $p2+1, length($params));
} else { $params= undef; }
if($token =~ /type=(.*)/) {
$type = $1;
}
if($token =~ /discon=(.*)/) {
$discon = $1;
}
}
my($hostPort, $userPass);
if(($p=index($conn, "@")) != -1) {
$userPass = substr($conn,0, $p);
$hostPort = substr($conn,$p+1,length($conn));
if(($p2 = index($userPass, ':')) != -1) {
$pass = substr($userPass, $p2+1, length($userPass));
$user = substr($userPass, 0, $p2);
} elsif(defined($userPass)) { $user = $userPass; }
}
else {
$hostPort = $conn;
}
if(($p3 = index($hostPort, ':')) != -1) {
$port = substr($hostPort, $p3+1, length($hostPort)) ;
$host = substr($hostPort, 0, $p3);
} else { $host=$hostPort; }
return undef unless($host and $dbname);
($host,$port) = $_URLFactory_global_instance->_check_alias($host,$port);
my $connectionKey = "$user:$pass\@$host:$port/$dbname;$type";
my $dba;
$dba = $_URLFactory_global_instance->{$connectionKey};
return ($dba,$path) if($dba);
switch ($type) {
case 'core' { $module = "Bio::EnsEMBL::DBSQL::DBAdaptor"; }
case 'pipeline' { $module = "Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor"; }
case 'compara' {
eval "require Bio::EnsEMBL::Compara::DBSQL::DBAdaptor";
$module = "Bio::EnsEMBL::Compara::DBSQL::DBAdaptor";
}
}
$dba = "$module"->new (
-disconnect_when_inactive => $discon,
-driver => 'mysql',
-user => $user,
-pass => $pass,
-host => $host,
-port => $port,
-dbname => $dbname,
-species => $dbname
);
$_URLFactory_global_instance->{$connectionKey} = $dba;
return ($dba,$path); } |
sub fetch
{
my $class = shift;
my $url = shift;
my $type = shift;
return undef unless($url);
new Bio::EnsEMBL::Hive::URLFactory;
my ($dba, $path) = $class->_get_db_connection($url, $type);
return $dba unless($path);
if((my $p=index($path, "?")) != -1) {
my $table = substr($path,0, $p);
my $query = substr($path,$p+1,length($path));
if($table eq 'analysis') {
my $adaptor = $dba->get_AnalysisAdaptor;
return $adaptor->fetch_by_url_query($query);
}
if($table eq 'analysis_job') {
my $adaptor = $dba->get_AnalysisJobAdaptor;
return $adaptor->fetch_by_url_query($query);
}
}
return undef; } |