[MOBY-guts] biomoby commit

Gary Schiltz gss at pub.open-bio.org
Wed Nov 23 23:59:37 UTC 2005


gss
Wed Nov 23 18:59:37 EST 2005
Update of /home/repository/moby/s-moby/ref-impl/semanticmoby.org/src/org/semanticmoby/ref/tools/db
In directory pub.open-bio.org:/tmp/cvs-serv18546/src/org/semanticmoby/ref/tools/db

Modified Files:
	StorageManager.java 
Log Message:
Use the new MetadataRetriever to find keywords to register

s-moby/ref-impl/semanticmoby.org/src/org/semanticmoby/ref/tools/db StorageManager.java,1.10,1.11
===================================================================
RCS file: /home/repository/moby/s-moby/ref-impl/semanticmoby.org/src/org/semanticmoby/ref/tools/db/StorageManager.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- /home/repository/moby/s-moby/ref-impl/semanticmoby.org/src/org/semanticmoby/ref/tools/db/StorageManager.java	2005/11/15 22:34:08	1.10
+++ /home/repository/moby/s-moby/ref-impl/semanticmoby.org/src/org/semanticmoby/ref/tools/db/StorageManager.java	2005/11/23 23:59:36	1.11
@@ -12,6 +12,7 @@
 import org.semanticmoby.vocabulary.*;
 
 import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.SQLException;
 
 import java.util.*;
@@ -93,14 +94,11 @@
 
                 Statement stmt       = it.nextStatement();
                 Resource  subject    = stmt.getSubject();
-                String    subjectURI = subject.getURI();
-
-                if (subject.isAnon() ||
-                        (
-                            (subjectURI != null) &&
-                            subjectURI.startsWith(uriString)
-                        )) {
+                String subjectURI = subject.getURI();
 
+                if ((subject.isAnon()) ||
+                    ((subjectURI != null) &&
+                     (subjectURI.startsWith(uriString)))) {
                     dbModel.add(stmt);
                 }
             }
@@ -117,9 +115,14 @@
 
             // Add keywords associated with the resource
             //
-            KeywordFinder finder = new KeywordFinder(resource);
-            addKeywords(resource.getResource().getURI(), finder.getKeywords(),
-                        dbModel);
+            MetadataRetriever retriever = new MetadataRetriever(
+                resource.getJenaModel(), 10000);
+            
+            Set words = retriever.getKeywords();
+            
+            if (! words.isEmpty()) {
+                addKeywords(words, uriString, dbModel);
+            }
 
             // Commit the transaction on the database model
             //
@@ -141,71 +144,65 @@
         }
     }
 
-
-    private void addKeywords(String resourceURI, KeywordList list, Model model)
+    private void addKeywords(Set keywords, String resourceURI, Model model)
                       throws StorageException {
-
+        
+        PreparedStatement stmt = null;
+        
         try {
 
-            ModelRDB           dbModel = (ModelRDB) model;
-            Connection         conn = dbModel.getConnection().getConnection();
+            ModelRDB dbModel = (ModelRDB) model;
+            Connection conn = dbModel.getConnection().getConnection();
 
-            java.sql.Statement sql = conn.createStatement();
-
-            doAddKeywords(resourceURI, list.getResourceKeywords(), "P", sql);
-            doAddKeywords(resourceURI, list.getSubjectKeywords(), "S", sql);
-            doAddKeywords(resourceURI, list.getObjectKeywords(), "O", sql);
+            stmt = conn.prepareStatement(
+                "INSERT INTO MOBY_KEYWORD " +
+                "  (keyword, resource_uri, applies_to) " +
+                "VALUES ( ?, ?, '' )");
+            
+            for (Iterator it = keywords.iterator(); it.hasNext();) {
+                String keyword = (String) it.next();
+                stmt.setString(1, keyword);
+                stmt.setString(2, resourceURI);
+                stmt.execute();
+            }
+            
         } catch (Throwable t) {
-
             t.printStackTrace();
             throw new StorageException(t);
+        } finally {
+            if (stmt != null) {
+                try {
+                    stmt.close();
+                } catch (Throwable t) {}
+            }
         }
     }
 
-
-    private void doAddKeywords(String resourceURI, Iterator it,
-                               String appliesTo, java.sql.Statement sql)
-                        throws SQLException {
-
-        while (it.hasNext()) {
-
-            String       keyword = it.next().toString();
-
-            StringBuffer sb = new StringBuffer();
-
-            sb.append("INSERT INTO MOBY_KEYWORD\n");
-            sb.append("       (keyword, resource_uri, applies_to)\n");
-            sb.append("values ('");
-            sb.append(keyword.toLowerCase().trim());
-            sb.append("', '");
-            sb.append(resourceURI);
-            sb.append("', '");
-            sb.append(appliesTo);
-            sb.append("')");
-
-            String queryString = sb.toString();
-
-            sql.execute(queryString);
-        }
-    }
-
-
     private void removeKeywords(String resourceURI, Model model)
                          throws StorageException {
-
+        
+        PreparedStatement stmt = null;
+        
         try {
 
-            ModelRDB           dbModel = (ModelRDB) model;
-            Connection         conn = dbModel.getConnection().getConnection();
-
-            java.sql.Statement sql = conn.createStatement();
+            ModelRDB dbModel = (ModelRDB) model;
+            Connection conn = dbModel.getConnection().getConnection();
 
-            sql.execute("DELETE FROM MOBY_KEYWORD WHERE resource_uri = '" +
-                        resourceURI + "'");
+            stmt = conn.prepareStatement(
+                "DELETE FROM MOBY_KEYWORD WHERE resource_uri = '?'");
+            
+            stmt.setString(1, resourceURI);
+            stmt.execute();
+            
         } catch (Throwable t) {
-
             t.printStackTrace();
             throw new StorageException(t);
+        } finally {
+            if (stmt != null) {
+                try {
+                    stmt.close();
+                } catch (Throwable t) {}
+            }
         }
     }
 




More information about the MOBY-guts mailing list