[MOBY-guts] biomoby commit

Mark Wilkinson mwilkinson at pub.open-bio.org
Mon Jul 25 19:53:36 UTC 2005


mwilkinson
Mon Jul 25 15:53:36 EDT 2005
Update of /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi
In directory pub.open-bio.org:/tmp/cvs-serv20961/MOBY/Adaptor/moby/queryapi

Modified Files:
	mysql.pm 
Log Message:
changing the adaptor API to be more perlish. Pass the service LSID rather than the database key to be more generic.  Lots more of these to come, but committing now so that Dennis can see what I am doing

moby-live/Perl/MOBY/Adaptor/moby/queryapi mysql.pm,1.30,1.31
===================================================================
RCS file: /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi/mysql.pm,v
retrieving revision 1.30
retrieving revision 1.31
diff -u -r1.30 -r1.31
--- /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi/mysql.pm	2005/07/25 18:17:44	1.30
+++ /home/repository/moby/moby-live/Perl/MOBY/Adaptor/moby/queryapi/mysql.pm	2005/07/25 19:53:36	1.31
@@ -162,7 +162,17 @@
 	}
 }
 
+sub _getSIIDFromLSID {
+    my ($self, $lsid) = @_;
+    my $dbh = $self->dbh;
+    my $sth = $dbh->prepare("select service_instance_id from service_instance were lsid=?");
+    $sth->execute($lsid);
+    my ($siid)  = $sth->fetchrow_array();
+    return $siid;
+}
+
 # this should NOT retun a collection ID... needs more work...
+# args passed in:  service_lsid
 sub query_collection_input{
 	my ($self, %args) = @_;	
 	my $dbh = $self->dbh;
@@ -176,144 +186,132 @@
  	return $result;
 }
 
+# args passed in:  service_instance_lsid, article_name
 sub insert_collection_input {
-	my ($self, %args) = @_;	
-	my $dbh = $self->dbh;
-		$self->dbh->do("insert into collection_input (service_instance_id, article_name) values (?,?)", 
-		undef, $args{'service_instance_id'},$args{'article_name'});
-		my $id=$self->dbh->{mysql_insertid};
-		return $id;
+    my ($self, %args) = @_;
+    my $article = $args{article_name};
+    my ($siid) = $self->getSIIDFromLSID($args{service_instance_lsid});
+    
+    $self->dbh->do("insert into collection_input (service_instance_id, article_name) values (?,?)", 
+    undef, $siid, $article);
+    my $id=$self->dbh->{mysql_insertid};
+    return $id;
 }
 
+# pass in service_instance_lsid
 sub delete_collection_input{
-	my ($self, @args) = @_;	
-	my $dbh = $self->dbh;
-	my $statement = "delete from collection_input ";
-	my @bindvalues = ();
-	($statement, @bindvalues) =_add_condition($statement, @args); 
-	$dbh->do( $statement,
-			  undef, @bindvalues );
-	
-	if ($dbh->err){
-		return (1, $dbh->errstr);
-	}
-	else{
-		return 0;
-	}	
+    my ($self, %args) = @_;	
+    my ($siid) = $self->getSIIDFromLSID($args{service_instance_lsid});
+    
+    my $statement = "delete from collection_input where service_instance_id = ?";
+    $self->dbh->do( $statement, undef, $siid);
+    
+    if ($self->dbh->err){
+	    return (1, $self->dbh->errstr);
+    }
+    else{
+	    return 0;
+    }	
 }
 
-# query subroutine selects all columns
+# pass service_instance_lsid
 sub query_collection_output{
-	my ($self, @args) = @_;	
-	my $dbh = $self->dbh;
-	
-	my $statement = "select
+    my ($self, %args) = @_;	
+    my ($siid) = $self->getSIIDFromLSID($args{service_instance_lsid});
+    my $dbh = $self->dbh;
+    
+    my $statement = "select
        collection_output_id,
        article_name,
        service_instance_id
-       from collection_output ";   
-    my @bindvalues = (); 
-          
-	if  (@args > 0) 
- 	{
- 		($statement, @bindvalues) =_add_condition($statement, @args);
- 	}
- 	
- 	my $result = do_query($dbh, $statement, @bindvalues);
- 	return $result;
+       from collection_output where service_instance_id = ? ";       
+    my $result = do_query($dbh, $statement, [$siid]);
+    return $result;
 }
 
+# pass service_instance_lsid, article_name
 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, (get_value('service_instance_id', @args), get_value('article_name', @args)));
-		my $id=$self->dbh->{mysql_insertid};
-		return $id;
-#	}
+    my ($self, %args) = @_;	
+    my ($siid) = $self->getSIIDFromLSID($args{service_instance_lsid});
+    my $dbh = $self->dbh;
+    $self->dbh->do("insert into collection_output (service_instance_id, article_name) values (?,?)", 
+    undef, $siid,$args{'article_name'});
+    my $id=$self->dbh->{mysql_insertid};
+    return $id;
 }
 
+# pass argument service_instance_lsid
 sub delete_collection_output{
-	my ($self, @args) = @_;	
-	my $dbh = $self->dbh;
-	my $statement = "delete from collection_output ";
-	my @bindvalues = ();
-	($statement, @bindvalues) =_add_condition($statement, @args); 
-	$dbh->do( $statement,
-			  undef, @bindvalues );
-	
-	if ($dbh->err){
-		return (1, $dbh->errstr);
-	}
-	else{
-		return 0;
-	}	
+    my ($self, %args) = @_;	
+    my ($siid) = $self->getSIIDFromLSID($args{service_instance_lsid});
+    my $dbh = $self->dbh;
+    my $statement = "delete from collection_output where service_instance_id = ?";
+    my @bindvalues = ();
+    $dbh->do( $statement, undef, ($siid));
+
+    if ($dbh->err){
+	    return (1, $dbh->errstr);
+    }
+    else{
+	    return 0;
+    }	
 }
 
-
+# pass service_instance_lsid 
 sub query_simple_input{
-	my ($self, @args) = @_;	
-	my $dbh = $self->dbh;
-	
-	my $statement = "select
-          simple_input_id,
-          object_type_uri,
-          namespace_type_uris,
-          article_name,
-          service_instance_id,
-          collection_input_id
-          from simple_input ";
-    my @bindvalues = (); 
-          
-	if  (@args > 0) 
- 	{
- 		($statement, @bindvalues) =_add_condition($statement, @args);
- 	}
- 	
- 	my $result = do_query($dbh, $statement, @bindvalues);
- 	return $result;
+    my ($self, %args) = @_;	
+    my ($siid) = $self->getSIIDFromLSID($args{service_instance_lsid});
+    my $dbh = $self->dbh;
+    
+    my $statement = "select
+      simple_input_id,
+      object_type_uri,
+      namespace_type_uris,
+      article_name,
+      service_instance_id,
+      collection_input_id
+      from simple_input where service_instance_id = ? and collection_input_id IS NULL";
+    my $result = do_query($dbh, $statement, ($siid));
+    return $result;
 }
 	
-
+# pass service_instance_lsid, object_type_uri, namespace_type_uris, article_name, collection_input_id
 sub insert_simple_input {
-	my ($self, @args) = @_;	
-	my $dbh = $self->dbh;
-	my $si = get_value('collection_input_id', @args)?undef:get_value('service_instance_id', @args);
-		
-	$dbh->do("insert into simple_input
-				 (object_type_uri,
-				  namespace_type_uris,
-				  article_name,
-				  service_instance_id,
-				  collection_input_id)
-				 values (?,?,?,?,?)",
-		undef,
-		(get_value('object_type_uri', @args),
-		get_value('namespace_type_uris', @args),
-		get_value('article_name', @args),
-# here
-        $si,
-		get_value('collection_input_id', @args)));
-	my $id=$dbh->{mysql_insertid};
-	return $id;
+    my ($self, %args) = @_;
+    my ($siid) = $self->getSIIDFromLSID($args{service_instance_lsid});
+    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'},
+	    $siid,
+	    $args{'collection_input_id'});
+    my $id=$dbh->{mysql_insertid};
+    return $id;
 }
 
 sub delete_simple_input{
-	my ($self, @args) = @_;	
-	my $dbh = $self->dbh;
-	my $statement = "delete from simple_input ";
-	my @bindvalues = ();
-	($statement, @bindvalues) =_add_condition($statement, @args); 
-	$dbh->do( $statement,
-			  undef, @bindvalues );
-	if ($dbh->err){
-		return (1, $dbh->errstr);
-	}
-	else{
-		return 0;
-	}			  
+    my ($self, @args) = @_;	
+    my $dbh = $self->dbh;
+    my ($siid) = $self->getSIIDFromLSID($args{service_instance_lsid});
+    my $statement = "delete from simple_input ";
+    my @bindvalues = ();
+    ($statement, @bindvalues) =_add_condition($statement, @args); 
+    $dbh->do( $statement,
+		      undef, @bindvalues );
+    if ($dbh->err){
+	    return (1, $dbh->errstr);
+    }
+    else{
+	    return 0;
+    }			  
 }
 
 sub query_simple_output{




More information about the MOBY-guts mailing list