[MOBY-guts] biomoby commit
Mark Wilkinson
mwilkinson at pub.open-bio.org
Thu Jun 24 22:32:39 UTC 2004
mwilkinson
Thu Jun 24 18:32:38 EDT 2004
Update of /home/repository/moby/moby-live/Perl/MOBY
In directory pub.open-bio.org:/tmp/cvs-serv32274/MOBY
Modified Files:
Central.pm Config.pm OntologyServer.pm
central_db_connection.pm collection_input.pm
collection_output.pm service_instance.pm simple_input.pm
simple_output.pm
Added Files:
dbConfig.pm
Log Message:
stratifying the SQL away from the MOBY Central module so that we can have a variety of underlying databases or SW-based data stores with teh MOBY Central API on top of them
moby-live/Perl/MOBY dbConfig.pm,NONE,1.1 Central.pm,1.130,1.131 Config.pm,1.2,1.3 OntologyServer.pm,1.44,1.45 central_db_connection.pm,1.4,1.5 collection_input.pm,1.1,1.2 collection_output.pm,1.1,1.2 service_instance.pm,1.4,1.5 simple_input.pm,1.3,1.4 simple_output.pm,1.2,1.3
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Central.pm,v
retrieving revision 1.130
retrieving revision 1.131
diff -u -r1.130 -r1.131
--- /home/repository/moby/moby-live/Perl/MOBY/Central.pm 2004/06/16 01:15:30 1.130
+++ /home/repository/moby/moby-live/Perl/MOBY/Central.pm 2004/06/24 22:32:38 1.131
@@ -10,8 +10,6 @@
use strict;
use Carp;
use vars qw($AUTOLOAD $WSDL_TEMPLATE);
-use DBI;
-use DBD::mysql;
use XML::DOM;
use MOBY::OntologyServer;
use MOBY::service_type;
@@ -183,28 +181,6 @@
return 0;
}
-sub _dbAccess {
-
- my $conf = MOBY::Config->new;
-
- my $username = $conf->{mobycentral}->{username};
- my $password = $conf->{mobycentral}->{password};
- my $port = $conf->{mobycentral}->{port};
- my $dbname = $conf->{mobycentral}->{dbname};
- my $url = $conf->{mobycentral}->{url};
-
- #my $url = $ENV{MOBY_CENTRAL_URL}; chomp $url;
- #my $dbname = $ENV{MOBY_CENTRAL_DBNAME}; chomp $dbname;
- #my $username = $ENV{MOBY_CENTRAL_DBUSER}; chomp $username;
- #my $password = $ENV{MOBY_CENTRAL_DBPASS}; chomp $password;
- #my $port = $ENV{MOBY_CENTRAL_DBPORT}; chomp $port;
-
- my ($dsn) = "DBI:mysql:$dbname:$url:$port";
- my $dbh = DBI->connect($dsn, $username, $password, {RaiseError => 1}) or die "can't connect to database";
-
- return ($dbh);
-}
-
=head2 registerObjectClass
@@ -1264,7 +1240,7 @@
object_type_uri => $typeURI,
namespace_type_uris => $namespace_string,
article_name => $article,
- collection_input_id => $collid,
+ collection_output_id => $collid,
);
unless ($soutput){
$SVC->DELETE_THYSELF; return (-1,"registration failed during registration of output object $typeURI. Unknown reasons.");
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Config.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Perl/MOBY/Config.pm 2004/06/15 01:15:16 1.2
+++ /home/repository/moby/moby-live/Perl/MOBY/Config.pm 2004/06/24 22:32:38 1.3
@@ -6,8 +6,13 @@
use strict;
use Carp;
+use MOBY::dbConfig;
use vars qw($AUTOLOAD);
use Text::Shellwords;
+use vars '$VERSION','@ISA','@EXPORT','$CONFIG';
+
+ at ISA = qw(Exporter);
+ at EXPORT = ('$CONFIG');
{
#Encapsulated class data
@@ -16,6 +21,11 @@
#ATTRIBUTES
my %_attr_data = # DEFAULT ACCESSIBILITY
(
+ mobycentral => [undef, 'read/write'],
+ mobyobject => [undef, 'read/write'],
+ mobynamespace=> [undef, 'read/write'],
+ mobyservice => [undef, 'read/write'],
+ mobyrelationship => [undef, 'read/write'],
);
#_____________________________________________________________
@@ -41,15 +51,14 @@
}
-sub id {
- my ($self, $val) =@_;
- $self->registration_id($val) if defined $val;
- return $self->registration_id;
-}
+# the expected sectionons (listed above) will have their dbCOnfig objects available
+# as methods. The unexpected sections will have their dbConfig objects available
+# by $dbConfig = $CONFIG->{section_title}
sub new {
my ($caller, %args) = @_;
+#print STDERR "creating MOBY::Config\n";
my $caller_is_obj = ref($caller);
my $class = $caller_is_obj || $caller;
@@ -65,32 +74,69 @@
}
my $file = $ENV{MOBY_CENTRAL_CONFIG};
- chomp $file;
+ $file || die "can't open MOBY Configuration file $!\n";
+
+ chomp $file;
if ((-e $file) && (!(-d $file))){
open IN, $file || die "can't open MOBY Configuration file $!\n";
}
-
- while (my $l = <IN>){
- chomp $l;
- next if $l=~/\s*\#/; # ignore comments
-
- if ($l=~/\[(\w+)\]/){
- my $key = $1;
- while (my $l2 = <IN>){
- chomp $l2;
- last unless ($l2 =~ /\S/);
- my @terms = shellwords($l2);
- last unless (scalar @terms > 2);
-
- $self->{$key}->{$terms[0]} = $terms[2];
- }
- }
- }
+ my @sections = split /(\[\s*\S+\s*\][^\[]*)/s, join "", <IN>;
+#print STDERR "split into @sections\n";
+ foreach my $section (@sections){
+#print STDERR "calling MOBY::dbConfig\n";
+ my $dbConfig = MOBY::dbConfig->new(section => $section); # this is an object full of strings, no actual connections. It represents the information in the config file
+ next unless $dbConfig;
+ my $dbname = $dbConfig->section_title;
+ next unless $dbname;
+#print STDERR "setting the COnfig dbConfig for the title $dbname with object $dbConfig\n\n";
+ $self->{$dbname} = $dbConfig;
+ }
+ $CONFIG = $self;
return $self;
}
+sub getDataAdaptor {
+ my ($self, %args) = @_;
+
+ my $source = $args{datasource};
+ $source ||= $args{source};
+ $source ||="mobycentral";
+
+ if ($self->{"${source}Adaptor"}){return $self->{"${source}Adaptor"}}; # read from cache
+
+ my $username = $self->$source->{username}; # $self->source returns a MOBY::dbConfig object
+ my $password = $self->$source->{password};
+ my $port = $self->$source->{port};
+ my $dbname = $self->$source->{dbname};
+ my $url = $self->$source->{url};
+ my $adaptor = $self->$source->{adaptor};
+ my $sourcetype = $self->$source->{sourcetype};
+
+ eval "require $adaptor";
+ return undef if $@;
+ eval "require $sourcetype";
+ return undef if $@;
+
+ my $ADAPTOR = $adaptor->new( # by default, this is queryapi
+ source => $source,
+ username => $username,
+ password => $password,
+ port => $port,
+ dbname => $dbname,
+ url => $url,
+ sourcetype => $sourcetype,
+ );
+ if ($ADAPTOR){
+ $self->{"${source}Adaptor"} = $ADAPTOR; # cache it
+ return $ADAPTOR;
+ } else {
+ return undef
+ }
+
+}
+
sub DESTROY {}
sub AUTOLOAD {
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/OntologyServer.pm,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -r1.44 -r1.45
--- /home/repository/moby/moby-live/Perl/MOBY/OntologyServer.pm 2004/06/15 14:55:17 1.44
+++ /home/repository/moby/moby-live/Perl/MOBY/OntologyServer.pm 2004/06/24 22:32:38 1.45
@@ -140,20 +140,23 @@
$self->ontology eq 'service' && $self->database('mobyservice');
$self->ontology eq 'relationship' && $self->database('mobyrelationship');
-
- my $conf = MOBY::Config->new;
- $self->username($conf->{$self->database}->{username}) unless $self->username;
- $self->password($conf->{$self->database}->{password}) unless $self->password;
- $self->port($conf->{$self->database}->{port}) unless $self->port;
- $self->host($conf->{$self->database}->{url}) unless $self->host;
+#print STDERR "\n\nCONFIG object is $CONFIG\n\n";
+ $CONFIG ||=MOBY::Config->new;
+#print STDERR "got username ",($CONFIG->{mobycentral}->{username})," for mobycentral\n";
+ $self->username($CONFIG->{$self->database}->{username}) unless $self->username;
+ $self->password($CONFIG->{$self->database}->{password}) unless $self->password;
+ $self->port($CONFIG->{$self->database}->{port}) unless $self->port;
+ $self->host($CONFIG->{$self->database}->{url}) unless $self->host;
my $host = $self->host?$self->host:$ENV{MOBY_CENTRAL_URL}; chomp $host;
my $username = $self->username?$self->username:$ENV{MOBY_CENTRAL_DBUSER}; chomp $username;
my $password = $self->password?$self->password:$ENV{MOBY_CENTRAL_DBPASS}; chomp $password if $password; $password =~ s/\s//g if $password;
my $port = $self->port?$self->port:$ENV{MOBY_CENTRAL_DBPORT}; chomp $port;
- my ($dsn) = "DBI:mysql:".($conf->{$self->database}->{dbname}).":".($host).":".($port);
+ my ($dsn) = "DBI:mysql:".($CONFIG->{$self->database}->{dbname}).":".($host).":".($port);
+#print STDERR "\n\nDSN was $dsn\n\n";
+
my $dbh;
# $debug && &_LOG("connecting to db with params ",$self->database, $self->username, $self->password,"\n");
if (defined $password){
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/central_db_connection.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Perl/MOBY/central_db_connection.pm 2004/06/15 01:00:26 1.4
+++ /home/repository/moby/moby-live/Perl/MOBY/central_db_connection.pm 2004/06/24 22:32:38 1.5
@@ -47,6 +47,7 @@
my %_attr_data = # DEFAULT ACCESSIBILITY
(
db_connect_object => ["MOBY::mysql", 'read/write'],
+ datasource => ['mobycentral', 'read/write'],
#username => ["mobycentral", 'read/write'],
#password => ["mobycentral", 'read/write'],
#dbname => ["mobycentral", 'read/write'],
@@ -108,25 +109,11 @@
else {
$self->{$attrname} = $self->_default_for($attrname) }
}
- #my $dbobj = $self->db_connect_object;
- #my $dbh = &{$dbobj."::new"}(
- # $self->dbname,
- # $self->username,
- # $self->password,
- # $self->host,
- # $self->port);
-
-
- my $conf = MOBY::Config->new;
-
- my $username = $conf->{mobycentral}->{username};
- my $password = $conf->{mobycentral}->{password};
- my $port = $conf->{mobycentral}->{port};
- my $dbname = $conf->{mobycentral}->{dbname};
- my $url = $conf->{mobycentral}->{url};
-
- my ($dsn) = "DBI:mysql:$dbname:$url:$port";
- my $dbh = DBI->connect($dsn, $username, $password, {RaiseError => 1}) or die "can't connect to database";
+
+ $CONFIG ||= MOBY::Config->new;
+
+ # getting the dbh is bad bad bad!!!
+ my $dbh = $CONFIG->getDataAdaptor(datasource => 'mobycentral')->dbh;
$self->dbh($dbh);
return $self;
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/collection_input.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Perl/MOBY/collection_input.pm 2004/06/16 01:15:30 1.1
+++ /home/repository/moby/moby-live/Perl/MOBY/collection_input.pm 2004/06/24 22:32:38 1.2
@@ -1,9 +1,9 @@
-#!/usr/bin/perl -w
-
package MOBY::collection_input;
use strict;
use Carp;
use XML::DOM;
+use MOBY::Config;
+
use vars qw($AUTOLOAD @ISA);
@@ -76,17 +76,6 @@
}
-
-
-sub _dbh {
- my ($self) = @_;
-
- my $central_connect = MOBY::central_db_connection->new();
- $self->dbh($central_connect->dbh);
- return $central_connect->dbh;
-
-}
-
sub new {
my ($caller, %args) = @_;
@@ -106,6 +95,7 @@
$self->{$attrname} = $self->_default_for($attrname) }
}
+
my $id = $self->WRITE;
$self->collection_input_id($id) if defined $id;
return $self;
@@ -114,10 +104,13 @@
sub WRITE {
my ($self) = @_;
- my $dbh = $self->_dbh;
+ $CONFIG ||=MOBY::Config->new; # exported by Config.pm
+ my $adaptor = $CONFIG->getDataAdaptor(datasource => 'mobycentral');
+ my $id = $adaptor->insert_collection_input(
+ service_instance => $self->service_instance_id,
+ article_name => $self->article_name,
+ );
- $dbh->do("insert into collection_input (service_instance_id, article_name) values (?,?)", undef, ($self->service_instance_id, $self->article_name));
- my $id=$dbh->{mysql_insertid};
return $id;
}
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/collection_output.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Perl/MOBY/collection_output.pm 2004/06/16 01:15:30 1.1
+++ /home/repository/moby/moby-live/Perl/MOBY/collection_output.pm 2004/06/24 22:32:38 1.2
@@ -4,6 +4,8 @@
use strict;
use Carp;
use XML::DOM;
+use MOBY::Config;
+
use vars qw($AUTOLOAD @ISA);
@@ -76,17 +78,6 @@
}
-
-sub _dbh {
- my ($self) = @_;
-
- my $central_connect = MOBY::central_db_connection->new();
- $self->dbh($central_connect->dbh);
- return $central_connect->dbh;
-
-}
-
-
sub new {
my ($caller, %args) = @_;
@@ -115,10 +106,13 @@
sub WRITE {
my ($self) = @_;
- my $dbh = $self->_dbh;
+ $CONFIG ||=MOBY::Config->new; # exported by Config.pm
+ my $adaptor = $CONFIG->getDataAdaptor(datasource => 'mobycentral');
+ my $id = $adaptor->insert_collection_output(
+ service_instance => $self->service_instance_id,
+ article_name => $self->article_name,
+ );
- $dbh->do("insert into collection_output (service_instance_id, article_name) values (?,?)", undef, ($self->service_instance_id, $self->article_name));
- my $id=$dbh->{mysql_insertid};
return $id;
}
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/service_instance.pm,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- /home/repository/moby/moby-live/Perl/MOBY/service_instance.pm 2004/06/16 01:15:30 1.4
+++ /home/repository/moby/moby-live/Perl/MOBY/service_instance.pm 2004/06/24 22:32:38 1.5
@@ -349,7 +349,7 @@
namespace_type_uris => $a{'namespace_type_uris'},
article_name => $a{'article_name'},
service_instance_id => $self->service_instance_id,
- collection_input_id => $a{'collection_output_id'}
+ collection_output_id => $a{'collection_output_id'}
);
push @{$self->{outputs}}, $simple;
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/simple_input.pm,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/Perl/MOBY/simple_input.pm 2004/06/16 01:15:30 1.3
+++ /home/repository/moby/moby-live/Perl/MOBY/simple_input.pm 2004/06/24 22:32:38 1.4
@@ -4,6 +4,7 @@
use strict;
use Carp;
use XML::DOM;
+use MOBY::Config;
use vars qw($AUTOLOAD @ISA);
@@ -80,17 +81,6 @@
}
-
-sub _dbh {
- my ($self) = @_;
-
- my $central_connect = MOBY::central_db_connection->new();
- $self->dbh($central_connect->dbh);
- return $central_connect->dbh;
-
-}
-
-
sub new {
my ($caller, %args) = @_;
@@ -116,25 +106,20 @@
}
+
sub WRITE {
- my ($self) = @_;
- my $dbh = $self->_dbh;
+ my ($self) = @_;
+ $CONFIG ||=MOBY::Config->new; # exported by Config.pm
+ my $adaptor = $CONFIG->getDataAdaptor(datasource => 'mobycentral');
+ my $id = $adaptor->insert_simple_input(
+ object_type_uri => $self->object_type_uri,
+ namespace_type_uris => $self->namespace_type_uris,
+ article_name => $self->article_name,
+ service_instance_id => $self->service_instance_id,
+ collection_input_id => $self->collection_input_id,
+ );
- $dbh->do("insert into simple_input
- (object_type_uri,
- namespace_type_uris,
- article_name,
- service_instance_id,
- collection_input_id)
- values (?,?,?,?,?)",
- undef,
- ($self->object_type_uri,
- $self->namespace_type_uris,
- $self->article_name,
- $self->service_instance_id,
- $self->collection_input_id));
- my $id=$dbh->{mysql_insertid};
- return $id;
+ return $id;
}
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/simple_output.pm,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- /home/repository/moby/moby-live/Perl/MOBY/simple_output.pm 2004/06/16 01:15:30 1.2
+++ /home/repository/moby/moby-live/Perl/MOBY/simple_output.pm 2004/06/24 22:32:38 1.3
@@ -3,6 +3,7 @@
package MOBY::simple_output;
use strict;
use Carp;
+use MOBY::Config;
use XML::DOM;
use vars qw($AUTOLOAD @ISA);
@@ -80,17 +81,6 @@
}
-
-sub _dbh {
- my ($self) = @_;
-
- my $central_connect = MOBY::central_db_connection->new();
- $self->dbh($central_connect->dbh);
- return $central_connect->dbh;
-
-}
-
-
sub new {
my ($caller, %args) = @_;
@@ -118,25 +108,20 @@
sub WRITE {
my ($self) = @_;
- my $dbh = $self->_dbh;
- $dbh->do("insert into simple_output
- (object_type_uri,
- namespace_type_uris,
- article_name,
- service_instance_id,
- collection_output_id)
- values (?,?,?,?,?)",
- undef,
- ($self->object_type_uri,
- $self->namespace_type_uris,
- $self->article_name,
- $self->service_instance_id,
- $self->collection_output_id));
- my $id=$dbh->{mysql_insertid};
+ $CONFIG ||=MOBY::Config->new; # exported by Config.pm
+ my $adaptor = $CONFIG->getDataAdaptor(datasource => 'mobycentral');
+ my $id = $adaptor->insert_simple_output(
+ object_type_uri => $self->object_type_uri,
+ namespace_type_uris => $self->namespace_type_uris,
+ article_name => $self->article_name,
+ service_instance_id => $self->service_instance_id,
+ collection_output_id => $self->collection_output_id,
+ );
+
return $id;
-
}
+
sub AUTOLOAD {
no strict "refs";
my ($self, $newval) = @_;
More information about the MOBY-guts
mailing list