BioMart::Configuration DBLocation
SummaryIncluded librariesPackage variablesSynopsisDescriptionGeneral documentationMethods
Toolbar
WebCvsRaw content
Summary
BioMart::Configuration::DBLocation
Package variables
No package variables defined.
Included modules
BioMart::Exception
DBI
Inherit
BioMart::Configuration::Location
Synopsis
A Location that represents the configuration for a mart database accessed
directly from the DB server
Description
Methods
_newDescriptionCode
dbh
No description
Code
dbhDC
No description
Code
openConnection
No description
Code
Methods description
_newcode    nextTop
  Usage      : see Usage for BioMart::Configuration::Location.
Description: creates a new MartDBLocation object which ...
Returntype : BioMart::Configuration::MartDBLocation
Exceptions : none
Caller : general
Methods code
_newdescriptionprevnextTop
sub _new {
  my ($self, @param) = @_;
  $self->SUPER::_new(@param);
  $self->attr('dbh', undef);
 

  $self->openConnection();
}
dbhdescriptionprevnextTop
sub dbh {
  my ($self, $dbh) = @_;

  if ($dbh) {
     $self->set('dbh',$dbh);
  }

  return $self->get('dbh');
}
dbhDCdescriptionprevnextTop
sub dbhDC {
	my ($self, $dbh) = @_;	
	$dbh = $self->get('dbh');
	$dbh->disconnect();##->disconnect; assuming all statement handles have already called respective ->finish()
$self->set('dbh',undef); } 1;
}
openConnectiondescriptionprevnextTop
sub openConnection {
  my $self = shift; 

  unless (defined($self->host ) && defined ($self->databaseType)  
	    && defined($self->database) && defined($self->user)) { 
	BioMart::Exception::Database->throw("Database Specifications must contain at least the database type (".$self->databaseType.") host (".$self->host."), database (".$self->database."), and user (".$self->user.")"); 
  }
  
  my $dsn;
  if ($self->databaseType eq 'oracle'){
      $dsn=sprintf(ORACLEDSNTEMPLATE, $self->host, $self->database,
      	   $self->port);
  } elsif ($self->databaseType eq 'mysql') {
      $dsn=sprintf(MYSQLDNSTEMPLATE, $self->database, $self->host, 
		   $self->port);
  } elsif ($self->databaseType eq 'postgres') {
      $dsn=sprintf(POSTGRESTEMPLATE, $self->database, $self->host, 
		   $self->port);
   } elsif ($self->databaseType eq 'odbc') {
      $dsn=sprintf(ODBCDNSTEMPLATE, $self->database);
  } else {
      warn("unsupported RDBMS type:\"  $self->databaseType\" - please use the correct name or supported RDBMS ...... skipping connection");
  }

  $self->dsn($dsn); 
 
  my $dbh;
      
  eval {
      $dbh = DBI->connect(
			  $dsn,
			  $self->user,
			  $self->password,
			  {InactiveDestroy => 1, RaiseError => 1, PrintError => 1}
			  );
  };
  if($@ || !$dbh) {
      BioMart::Exception::Database->throw("Could not connect to ".$self->databaseType." database ".$self->database.": ".$@);
  }
      
  $self->dbh($dbh);
}
General documentation
AUTHOR - Arek Kasprzyk, Damian SmedleyTop
CONTACTTop
This module is part of the BioMart project http://www.biomart.org
Questions can be posted to the mart-dev mailing list: mart-dev@ebi.ac.uk