9 $url_string1 =
'mysql://ensadmin:<pass>@ecs2:3362/compara_hive_23c'; # type=hive by
default 10 $url_string2 =
'mysql://ensadmin:<pass>@ecs2:3362/ensembl_compara_22_1;type=compara' 11 $url_string3 =
'mysql://ensadmin:<pass>@ecs2:3362/ensembl_core_homo_sapiens_22_34;type=core' 19 Module to parse URL strings and
return EnsEMBL objects.
20 At the moment, DBAdaptors as well as Analyses, Jobs and NakedTables are supported.
24 Copyright [1999-2015] Wellcome Trust Sanger Institute and the EMBL-European Bioinformatics Institute
25 Copyright [2016-2022] EMBL-European Bioinformatics Institute
27 Licensed under the Apache License,
Version 2.0 (the
"License"); you may not use
this file except in compliance with the License.
28 You may obtain a copy of the License at
32 Unless required by applicable law or agreed to in writing, software distributed under the License
33 is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
34 See the License
for the specific language governing permissions and limitations under the License.
38 Please subscribe to the
Hive mailing list: http:
42 package Bio::EnsEMBL::Hive::URLFactory;
54 # global instance to cache connections and limit the number of open DB connections: 55 my $_URLFactory_global_instance;
61 unless($_URLFactory_global_instance) {
62 $_URLFactory_global_instance = bless {}, $class;
64 return $_URLFactory_global_instance;
70 foreach my $key (keys(%$_URLFactory_global_instance)) {
71 $_URLFactory_global_instance->{$key} = undef;
78 Example : $url =
'mysql://user:pass@host:3306/dbname/table_name?tparam_name=tparam_value;type=compara;disconnect_when_inactive=1' 80 Description: parses the URL, connects to appropriate DBAdaptor,
81 determines appropriate object_adaptor, fetches the
object 82 Returntype : blessed instance of the
object refered to or a DBAdaptor
if simple URL
90 my $url = shift @_ or
return;
91 my $default_dba = shift @_;
97 my $table_name = $parsed_url->{
'table_name'};
98 my $tparam_name = $parsed_url->{
'tparam_name'};
99 my $tparam_value = $parsed_url->{
'tparam_value'};
101 unless($table_name=~/^(analysis|job|accu)$/) { #
do not check schema version version when performing table dataflow:
102 $parsed_url->{
'conn_params'}{
'no_sql_schema_version_check'} = 1;
105 my $dba = ($parsed_url->{
'dbconn_part'} =~ m{^\w*:
107 : $class->create_cached_dba( @$parsed_url{qw(dbconn_part driver user pass host port dbname conn_params)} );
110 if(not $table_name) {
114 } elsif($table_name eq
'analysis') {
116 return $dba->get_AnalysisAdaptor->fetch_by_url_query($tparam_name, $tparam_value);
118 } elsif($table_name eq
'job') {
120 return $dba->get_AnalysisJobAdaptor->fetch_by_url_query($tparam_name, $tparam_value);
122 } elsif($table_name eq
'accu') {
125 $dba ? (adaptor => $dba->get_AccumulatorAdaptor) : (),
126 accu_name => $tparam_name,
127 accu_address => $tparam_value,
133 $dba ? (adaptor => $dba->get_NakedTableAdaptor(
'table_name' => $table_name ) ) : (),
134 table_name => $table_name,
135 $tparam_value ? (insertion_method => $tparam_value) : (),
139 warn
"Could not parse URL '$url'\n";
145 sub create_cached_dba {
146 my ($class, $dbconn_part, $driver, $user, $pass, $host, $port, $dbname, $conn_params) = @_;
148 my $type = $conn_params->{
'type'};
149 my $disconnect_when_inactive = $conn_params->{
'disconnect_when_inactive'};
150 my $no_sql_schema_version_check = $conn_params->{
'no_sql_schema_version_check'};
152 my $connectionKey = $driver.
'://'.($user
153 my $dba = $_URLFactory_global_instance->{$connectionKey};
158 'hive' =>
'Bio::EnsEMBL::Hive::DBSQL::DBAdaptor',
159 'compara' =>
'Bio::EnsEMBL::Compara::DBSQL::DBAdaptor',
160 'core' =>
'Bio::EnsEMBL::DBSQL::DBAdaptor',
161 'pipeline' =>
'Bio::EnsEMBL::Pipeline::DBSQL::DBAdaptor',
164 eval
"require $module";
166 $_URLFactory_global_instance->{$connectionKey} = $dba =
169 -url => $dbconn_part,
170 -disconnect_when_inactive => $disconnect_when_inactive,
171 -no_sql_schema_version_check=> $no_sql_schema_version_check,
180 -disconnect_when_inactive => $disconnect_when_inactive,
public Bio::EnsEMBL::Hive::Storable new()