You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by jo...@apache.org on 2012/03/05 14:19:04 UTC

svn commit: r1297045 - /opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorporaStore.java

Author: joern
Date: Mon Mar  5 13:19:04 2012
New Revision: 1297045

URL: http://svn.apache.org/viewvc?rev=1297045&view=rev
Log:
OPENNLP-458 Now checks that corpus exists instead of just assuming that it exists.

Modified:
    opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorporaStore.java

Modified: opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorporaStore.java
URL: http://svn.apache.org/viewvc/opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorporaStore.java?rev=1297045&r1=1297044&r2=1297045&view=diff
==============================================================================
--- opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorporaStore.java (original)
+++ opennlp/sandbox/corpus-server/src/main/java/org/apache/opennlp/corpus_server/store/DerbyCorporaStore.java Mon Mar  5 13:19:04 2012
@@ -145,7 +145,40 @@ public class DerbyCorporaStore extends A
   
   @Override
   public CorpusStore getCorpus(String corpusId) {
-    return new DerbyCorpusStore(dataSource, this, corpusId);
+    
+    // It must be ensured that the table exist, otherwise
+    // null must be returned, because there is no corpus
+    // matching the provided id.
+    
+    // Note:
+    // A table might be deleted later on, that case must be handled well!
+    
+    DerbyCorpusStore corpusStore = null;
+    
+    try {
+      DatabaseMetaData metadata = null;
+      metadata = dataSource.getConnection().getMetaData();
+      String[] names = { "TABLE" };
+      ResultSet tableNames = metadata.getTables(null, null, null, names);
+
+      while (tableNames.next()) {
+        String tab = tableNames.getString("TABLE_NAME");
+        System.out.println("Table: " + tab);
+        if (tab.equalsIgnoreCase(corpusId)) {
+          corpusStore = new DerbyCorpusStore(dataSource, this, corpusId);
+          break;
+        }
+      }
+    } catch (SQLException e) {
+      
+      if (LOGGER.isLoggable(Level.SEVERE)) {
+        LOGGER.log(Level.SEVERE, "Failed to check if corpus exists!", e);
+      }
+      
+      return null;
+    }
+    
+    return corpusStore;
   }
 
   @Override