3 # BioPerl module for SimpleDBContext
5 # Please direct questions and support issues to <bioperl-l@bioperl.org>
7 # Cared for by Hilmar Lapp <hlapp at gmx.net>
9 # Copyright Hilmar Lapp
11 # You may distribute this module under the same terms as perl itself
14 # (c) Hilmar Lapp, hlapp at gmx.net, 2002.
15 # (c) GNF, Genomics Institute of the Novartis Research Foundation, 2002.
17 # You may distribute this module under the same terms as perl itself.
18 # Refer to the Perl Artistic License (see the license accompanying this
19 # software package, or see http://www.perl.com/language/misc/Artistic.html)
20 # for the terms under which you may use, modify, and redistribute this module.
22 # THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
23 # WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
24 # MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
27 # POD documentation - main docs before the code
31 Bio::DB::SimpleDBContext - a base implementation of Bio::DB::DBContextI
35 # See Bio::DB::DBContextI.
39 See Bio::DB::DBContextI.
45 User feedback is an integral part of the evolution of this and other
46 Bioperl modules. Send your comments and suggestions preferably to
47 the Bioperl mailing list. Your participation is much appreciated.
49 bioperl-l@bioperl.org - General discussion
50 http://bioperl.org/wiki/Mailing_lists - About the mailing lists
54 Please direct usage questions or support issues to the mailing list:
56 I<bioperl-l@bioperl.org>
58 rather than to the module maintainer directly. Many experienced and
59 reponsive experts will be able look at the problem and quickly
60 address it. Please include a thorough description of the problem
61 with code and data examples if at all possible.
65 Report bugs to the Bioperl bug tracking system to help us keep track
66 of the bugs and their resolution. Bug reports can be submitted via
69 http://redmine.open-bio.org/projects/bioperl/
71 =head1 AUTHOR - Hilmar Lapp
73 Email hlapp at gmx.net
75 Describe contact details here
79 Additional contributors names and emails here
83 The rest of the documentation details each of the object methods.
84 Internal methods are usually preceded with a _
89 # Let the code begin...
92 package Bio
::DB
::SimpleDBContext
;
96 # Object preamble - inherits from Bio::Root::Root
99 use Bio::DB::DBContextI;
102 @ISA = qw(Bio::Root::Root Bio::DB::DBContextI);
107 Usage : my $obj = Bio::DB::SimpleDBContext->new();
108 Function: Builds a new Bio::DB::SimpleDBContext object
109 Returns : an instance of Bio::DB::SimpleDBContext
110 Args : Named parameters. Currently recognized are
111 -dbname the name of the schema
112 -host the database host (to which to connect)
113 -port the port on the host to which to connect (optional)
114 -driver the DBI driver name for the RDBMS (e.g., mysql,
116 -user the username for connecting
117 -pass the password for the user
118 -dsn the DSN string to use verbatim for connecting;
119 if supplied, other parameters will not change
120 or add to the value (see method dsn())
121 -schema the schema under which the database tables
122 reside, if the driver needs this (for example,
128 my($class,@args) = @_;
130 my $self = $class->SUPER::new
(@args);
139 ) = $self->_rearrange([qw(DSN
149 $self->dsn($dsn) if $dsn;
150 $self->username( $user );
151 $self->host( $host ) if defined($host);
152 $self->dbname( $db ) if defined($db);
153 $self->driver($driver || "mysql") unless $self->driver();
154 $self->password($password) if defined($password);
155 $self->port($port) if defined($port);
156 $self->schema($schema) if defined($schema);
163 Usage : $obj->dsn($newval)
164 Function: Get/set the DSN for the database connection.
166 The DSN typically contains all non-credential information
167 necessary to connect to the database, like driver, database
168 or instance name, host, etc. Therefore, setting the DSN
169 overrides any other individual properties set before. We
170 make an attempt to parse those properties out of the DSN
171 string, but, in accordance with the interface contract,
172 advise any client to use the dsn verbatim for connecting if
173 set and not try to rebuild it from the parsed out
176 I.e., if you set this property, setting any other
177 individual properties will not alter the DSN used for
178 connecting to the database. If you query the property, a
179 value will not be automatically constructed if only
180 individual properties have been set.
183 Returns : value of dsn (a scalar)
184 Args : on set, new value (a scalar or undef, optional)
194 $self->{'dsn'} = $dsn;
196 my @elts = split(/:/,$dsn);
197 shift(@elts); # first element is dbi or DBI
198 $self->driver(shift(@elts)); # second is the driver
199 # the rest is less predictable ...
200 if (@elts && ($elts[0] =~ /^\w+$/)) { # just a plain dbname or sid?
201 $self->dbname(shift(@elts));
203 my @params = split(/;/,join(':',@elts));
204 foreach my $param (@params) {
206 if ($param =~ /^(dbname|database|sid)=(.+)/) {
211 if ($param =~ /^(host=|hostname=|\@)(.+)/) {
216 if ($param =~ /^(port=|:)(\d+)/) {
219 # anything else we could check for?
223 return $self->{'dsn'};
229 Usage : $obj->dbname($newval)
232 Returns : value of dbname (a scalar)
233 Args : new value (a scalar, optional)
241 return $self->{'dbname'} = shift if @_;
242 return $self->{'dbname'};
248 Usage : $obj->driver($newval)
251 Returns : value of driver (a scalar)
252 Args : new value (a scalar, optional)
260 return $self->{'driver'} = shift if @_;
261 return $self->{'driver'};
267 Usage : $obj->username($newval)
270 Returns : value of username (a scalar)
271 Args : new value (a scalar, optional)
279 return $self->{'username'} = shift if @_;
280 return $self->{'username'};
286 Usage : $obj->password($newval)
289 Returns : value of password (a scalar)
290 Args : new value (a scalar, optional)
298 return $self->{'password'} = shift if @_;
299 return $self->{'password'};
305 Usage : $obj->host($newval)
308 Returns : value of host (a scalar)
309 Args : new value (a scalar, optional)
317 return $self->{'host'} = shift if @_;
318 return $self->{'host'};
324 Usage : $obj->port($newval)
327 Returns : value of port (a scalar)
328 Args : new value (a scalar, optional)
336 return $self->{'port'} = shift if @_;
337 return $self->{'port'};
343 Usage : $dbadp = $dbc->dbadaptor();
346 Returns : An Bio::DB::DBAdaptorI implementing object (an object adaptor
348 Args : Optionally, on set an Bio::DB::DBAdaptorI implementing object (to
349 be used as the object adaptor factory for the respective database)
357 return $self->{'dbadaptor'} = shift if @_;
358 return $self->{'dbadaptor'};
367 Returns : A Bio::DB::DBI implementing object
368 Args : Optionally, on set a Bio::DB::DBI implementing object
374 my ($self,$value) = @_;
375 if( defined $value) {
376 $self->{'dbi'} = $value;
378 if(! exists($self->{'dbi'})) {
379 my $dbimod = "Bio::DB::DBI::".$self->driver();
380 $self->_load_module($dbimod);
381 $self->{'dbi'} = $dbimod->new(-dbcontext
=> $self);
383 return $self->{'dbi'};
389 Usage : $dbc->schema($newval)
390 Function: Get/set the schema in which the database tables reside.
392 Returns : value of schema (a scalar)
393 Args : on set, new value (a scalar or undef, optional)
401 return $self->{'schema'} = shift if @_;
402 return $self->{'schema'};