[MOBY-guts] biomoby commit

Gary Schlitz gss at pub.open-bio.org
Wed Jun 16 23:33:00 UTC 2004


gss
Wed Jun 16 19:33:00 EDT 2004
Update of /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/db
In directory pub.open-bio.org:/tmp/cvs-serv22777/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/db

Modified Files:
	StorageManager.java 
Log Message:
No longer cache separate model

moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/db StorageManager.java,1.3,1.4
===================================================================
RCS file: /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/db/StorageManager.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/db/StorageManager.java	2004/05/19 18:26:41	1.3
+++ /home/repository/moby/moby-live/S-MOBY/ref-impl/server/src/org/smoby/ref/tools/db/StorageManager.java	2004/06/16 23:33:00	1.4
@@ -1,7 +1,7 @@
 package org.smoby.ref.tools.db;
 
 import org.smoby.graph.*;
-import org.smoby.graph.impl.MOBYProviderImpl;
+import org.smoby.graph.impl.*;
 import org.smoby.ref.tools.*;
 import org.smoby.vocabulary.*;
 import com.hp.hpl.jena.db.*;
@@ -17,19 +17,6 @@
 public class StorageManager
 {
     /**
-     * Return whether or not the database contains a provider with a
-     * given URI.
-     * @param providerURI URI of the provider in question
-     * @return boolean flag indicating if the database contains the provider in question
-     * @throws StorageException if unable to access the model in the database
-     */
-    public boolean containsProvider(String providerURI)
-        throws StorageException
-    {
-        return getModelMaker().hasModel(providerURI);
-    }
-    
-    /**
      * Return the date when a given provider was registered
      * @param providerURL URI of the provider
      * @return the registration date if the provider has been registered in
@@ -41,20 +28,19 @@
     {
         Date registrationDate = null;
         
-        ModelMaker maker = getModelMaker();
+        Model dbModel = openDBModel();
         
-        Model model = maker.openModel(providerURI);
+        Resource provider = dbModel.createResource(providerURI);
         
-        Resource provider = model.createResource(providerURI);
-        
-        NodeIterator it = model.listObjectsOfProperty(provider, MOBY.lastModifiedDate);
+        NodeIterator it = dbModel.listObjectsOfProperty(
+        	provider, MOBY.lastModifiedDate);
         
         if (it.hasNext()) {
             Literal lit = (Literal) it.nextNode().as(Literal.class);
             registrationDate = new Date(lit.getLong());
         }
         
-        model.close();
+        dbModel.close();
         
         return registrationDate;
     }
@@ -73,7 +59,8 @@
 	{
 	    Model model = ((MOBYProviderImpl) provider).getUnderlying();
         Model dbModel = null;
-        Resource uri = model.createResource(provider.getURI());
+        String uriString = provider.getURI();
+        Resource uri = model.createResource(uriString);
         
         try
         {
@@ -84,50 +71,32 @@
             // Open the database model
             //
             dbModel = openDBModel(maker);
-            
-            // First check if the database already has a graph registered under
-            // the URI of the new graph. If so, then throw an exception
-            //
-            if (dbModel.contains(null, MOBY.registeredBy, uri)) {
-                throw new StorageException("Graph already exists for " + uri);
-            }
 
             // Start a transaction on the database model
             //
             dbModel.begin();
             
-            // Add to the database the statements from providerGraph whose
-            // subjects are in the same namespace as the provider
+            // Add to the database all statements whose subjects are
+            // at the URI or deeper
             //
-            String providerNameSpace = uri.getNameSpace();
+            StmtIterator it = model.listStatements();
+            while (it.hasNext()) {
+            	Statement stmt = it.nextStatement();
+            	Resource subject = stmt.getSubject();
+            	if (subject.isAnon() || subject.getURI().startsWith(uriString)) {
+            		dbModel.add(stmt);
+            	}
+            }
             
-            for (StmtIterator it = model.listStatements(); it.hasNext();)
-            {
-                Statement stmt = it.nextStatement();
-                Resource subject = stmt.getSubject();
-                String nameSpace = subject.getNameSpace();
-                
-                if (subject.isAnon() || providerNameSpace.equals(nameSpace)) {
-                    dbModel.add(stmt);
-                }
+            // Add a statement asserting when the model was added
+            //
+            if (lastModifiedDate != null) {
+            	dbModel.add(uri, MOBY.lastModifiedDate, lastModifiedDate.getTime());
             }
             
             // Commit the transaction on the database model
             //
             dbModel.commit();
-            
-            // Add to the database another model, with the provider URL as its name
-            //
-            Model providerModel = maker.createModel(uri.getURI());
-            providerModel.add(model);
-            providerModel.setNsPrefixes(model.getNsPrefixMap());
-            
-            // Add a statement asserting when the model was added to the database
-            //
-            if (lastModifiedDate != null) {
-                providerModel.add(uri, MOBY.lastModifiedDate, lastModifiedDate.getTime());
-            }
-            providerModel.close();
         }
         catch (StorageException se) {
             throw se;
@@ -160,21 +129,16 @@
             Resource provider = dbModel.createResource(providerURI);
             String providerNameSpace = provider.getNameSpace();
             
-            Model modelToRemove = maker.openModel(providerURI);
-            
+            // Start a transaction on the database
+            //
             dbModel.begin();
-            for (StmtIterator it = modelToRemove.listStatements(); it.hasNext();)
-            {
-                Statement stmt = it.nextStatement();
-                Resource subject = stmt.getSubject();
-                String nameSpace = subject.getNameSpace();
-                
-                if (subject.isAnon() || providerNameSpace.equals(nameSpace)) {
-                	dbModel.remove(stmt);
-                }
-            }
-            modelToRemove.close();
-            maker.removeModel(providerURI);
+            
+            // Remove all statements that are reachable from the provider URI
+            //
+            ProviderRemover.remove(dbModel, providerURI);
+            
+            // Commit the transaction on the database
+            //
             dbModel.commit();
         }
         catch (StorageException se) {




More information about the MOBY-guts mailing list