[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Fri Jul 9 00:21:54 UTC 2004


mwilkinson
Thu Jul  8 20:21:53 EDT 2004
Update of /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi
In directory pub.open-bio.org:/tmp/cvs-serv5633/MOBY/Adaptor/moby/queryapi

Modified Files:
	mysql.pm 
Log Message:
more refactoring of code to get SQL out of mobycentral.  Also created two new subroutines for Martin and Ben to add their XSD-generating code such that the WSDL from MOBY Central will be valid

moby-live/Perl/MOBY/Adaptor/moby/queryapi mysql.pm,1.1,1.2
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi/mysql.pm,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi/mysql.pm	2004/06/24 22:32:39	1.1
+++ /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi/mysql.pm	2004/07/09 00:21:53	1.2
@@ -1,8 +1,13 @@
 package MOBY::Adaptor::moby::queryapi::mysql;
 
 use strict;
-use vars qw($AUTOLOAD);
+use vars qw($AUTOLOAD @ISA);
 use Carp;
+use MOBY::Adaptor::moby::queryapi;
+use DBI;
+use DBD::mysql;
+
+ at ISA = qw{MOBY::Adaptor::moby::queryapi}; # implements the interface
 
 {
 	#Encapsulated class data
@@ -12,7 +17,6 @@
     my %_attr_data = #     				DEFAULT    	ACCESSIBILITY
                   (
                    driver       =>  ["DBI:mysql",  'read/write'],
-				   adaptor      =>  [undef,         'read/write'], # I think this causes a circular reference...
                    dbh		     =>  [undef,         'read/write'],
                    
                     );
@@ -38,15 +42,26 @@
 	keys %_attr_data;
     }
 
+	sub driver {
+		my ($self, $arg) = @_;
+		$self->{driver} = $arg if defined $arg;
+		return $self->{driver};
+	}
+	sub dbh {
+		my ($self, $arg) = @_;
+		$self->{dbh} = $arg if defined $arg;
+		return $self->{dbh};
+	}
+
 }
 
 sub new {
 	my ($caller, %args) = @_;
+	my $self = $caller->SUPER::new(%args);
+
 	my $caller_is_obj = ref($caller);
     my $class = $caller_is_obj || $caller;
 
-    my $self = bless {}, $class;
-
     foreach my $attrname ( $self->_standard_keys ) {
     	if (exists $args{$attrname} && defined $args{$attrname}) {
 		$self->{$attrname} = $args{$attrname} }
@@ -55,58 +70,194 @@
     else {
 		$self->{$attrname} = $self->_default_for($attrname) }
     }
-    
+
     return unless $self->driver;
-    my $driver = $self->driver;
-    my $username = $self->adaptor->username;
-    my $password = $self->adaptor->password;
-	my $port = $self->adaptor->port;
-	my $url = $self->adaptor->url;
-	my $dbname = $self->adaptor->dbname;
+    my $driver = $self->driver;  # inherited from the adaptorI (queryapi)
+    my $username = $self->username;
+    my $password = $self->password;
+	my $port = $self->port;
+	my $url = $self->url;
+	my $dbname = $self->dbname;
 	
 	my ($dsn) = "$driver:$dbname:$url:$port";
-	#my $dbh = DBI->connect($dsn, $username, $password, {RaiseError => 1}) or die "can't connect to database";
-
+# print STDERR "\n\nconnectiung to $driver:$dbname:$url:$port\n\n";
 	my $dbh = DBI->connect($dsn, $username, $password, {RaiseError => 1}) or die "can't connect to database";
-	return undef unless $dbh;
-	$self->dbh($dbh);
+
+
+	##############################################################
+	unless ($dbh) {
+		print STDERR "Couldn't connect to the datasource \n",($self->_dump()),"\n\n";
+		return undef;
+	}
+	
+    $self->dbh($dbh);
+	#############################################################
+
+	return undef unless $self->dbh;
     return $self;
     
 }
 
 
-sub DESTROY {}
+sub insert_collection_input {
+	my ($self, %args) = @_;	
+	my $dbh = $self->dbh;
+	if ($self->sourcetype eq "MOBY::Adaptor::moby::queryapi::mysql"){
+		# this should be dropped down into the mysql.pm module??  probably...
+		$self->dbh->do("insert into collection_input (service_instance_id, article_name) values (?,?)", undef, ($args{service_instance}, $args{article_name}));
+		my $id=$self->dbh->{mysql_insertid};
+		return $id;
+	}
+}
 
-sub AUTOLOAD {
-    no strict "refs";
-    my ($self, $newval) = @_;
-
-    $AUTOLOAD =~ /.*::(\w+)/;
-
-    my $attr=$1;
-    if ($self->_accessible($attr,'write')) {
-
-	*{$AUTOLOAD} = sub {
-	    if (defined $_[1]) { $_[0]->{$attr} = $_[1] }
-	    return $_[0]->{$attr};
-	};    ### end of created subroutine
-
-###  this is called first time only
-	if (defined $newval) {
-	    $self->{$attr} = $newval
+sub insert_collection_output {
+	my ($self, %args) = @_;	
+	my $dbh = $self->dbh;
+	if ($self->sourcetype eq "MOBY::Adaptor::moby::queryapi::mysql"){
+		# this should be dropped down into the mysql.pm module??  probably...
+		$self->dbh->do("insert into collection_output (service_instance_id, article_name) values (?,?)", undef, ($args{service_instance}, $args{article_name}));
+		my $id=$self->dbh->{mysql_insertid};
+		return $id;
 	}
-	return $self->{$attr};
+}
 
-    } elsif ($self->_accessible($attr,'read')) {
+sub insert_simple_input {
+	my ($self, %args) = @_;	
+	my $dbh = $self->dbh;
+	
+	$dbh->do("insert into simple_input
+				 (object_type_uri,
+				  namespace_type_uris,
+				  article_name,
+				  service_instance_id,
+				  collection_input_id)
+				 values (?,?,?,?,?)",
+		undef,
+		($args{object_type_uri},
+		$args{namespace_type_uris},
+		$args{article_name},
+		$args{service_instance_id},
+		$args{collection_input_id}));
+	my $id=$dbh->{mysql_insertid};
+	return $id;
+}
 
-	*{$AUTOLOAD} = sub {
-	    return $_[0]->{$attr} }; ### end of created subroutine
-	return $self->{$attr}  }
 
+sub insert_simple_output {
+	my ($self, %args) = @_;	
+	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,
+		($args{object_type_uri},
+		$args{namespace_type_uris},
+		$args{article_name},
+		$args{service_instance_id},
+		$args{collection_output_id}));
+	my $id=$dbh->{mysql_insertid};
+	return $id;
 
-    # Must have been a mistake then...
-    croak "No such method: $AUTOLOAD";
 }
 
+sub query_service_instance {
+	my ($self, %args) = @_;	
+	my $dbh = $self->dbh;
+
+    my ($serviceid, $category, $name, $typeURI, $authURI,$url,$email,$authoritative,$desc) = $dbh->selectrow_array( # does this service already exist?
+        q{select
+          service_instance_id,
+          category,
+          serviceName,
+          service_type_uri,
+          authority.authority_uri,
+          url,
+          service_instance.contact_email,
+          authoritative,
+          description 
+          from service_instance, authority
+		  where
+		      service_instance.authority_id = authority.authority_id
+			  and servicename=? and authority.authority_uri = ?
+		},
+        undef,($args{servicename}, $args{authURI}));
+	return undef unless $serviceid;
+	return {serviceid => $serviceid,
+			category => $category,
+			name => $name,
+			servcetype => $typeURI,
+			authURI => $authURI,
+			url	=> $url,
+			email => $email,
+			authoritative => $authoritative,
+			desc => $desc,
+		   };
+}
+
+
+sub insert_service_instance {
+	my ($self, %args) = @_;	
+	my $dbh = $self->dbh;
+
+	$dbh->do(q{insert into service_instance (category, servicename, service_type_uri, authority_id, url, contact_email, authoritative, description) values (?,?,?,?,?,?,?,?)},
+				 undef,
+				 $args{'category'},
+				 $args{'servicename'},
+				 $args{'service_type_uri'},
+				 $args{'authority_id'},
+				 $args{'url'},
+				 $args{'contact_email'},
+				 $args{'authoritative'},
+				 $args{'description'});
+	
+	my $id = $dbh->{mysql_insertid};
+	return $id;
+}
+
+
+
+sub _checkURI {
+	
+#	my $uri = "http://www.ics.uci.edu/pub/ietf/uri/#Related";
+#print "$1, $2, $3, $4, $5, $6, $7, $8, $9" if
+#  $uri =~ m{^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?};
+#
+#The license for this recipe is available here.
+#
+#Discussion:
+#
+#If the match is successful, a URL such as
+#
+#http://www.ics.uci.edu/pub/ietf/uri/#Related
+#
+#will be broken down into the following group match variables:
+#
+#$1 = http:
+#$2 = http
+#$3 = //www.ics.uci.edu
+#$4 = www.ics.uci.edu
+#$5 = /pub/ietf/uri/
+#$6 =
+#$7 =
+#$8 = #Related
+#$9 = Related
+#
+#In general, this regular expression breaks a URI down into the following parts,
+#as defined in the RFC:
+#
+#scheme = $2
+#authority = $4
+#path = $5
+#query = $7
+#fragment = $9
+
+}
+
+sub DESTROY {}
 
 1;




More information about the MOBY-guts mailing list