ctakes-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seanfi...@apache.org
Subject svn commit: r1653329 - /ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java
Date Tue, 20 Jan 2015 18:31:22 GMT
Author: seanfinan
Date: Tue Jan 20 18:31:22 2015
New Revision: 1653329

URL: http://svn.apache.org/r1653329
Log:
CTAKES-345 enhancement to use $CTAKES_HOME in finding dictionary database when cwd is not
associated with the ctakes installation

Modified:
    ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java

Modified: ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java
URL: http://svn.apache.org/viewvc/ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java?rev=1653329&r1=1653328&r2=1653329&view=diff
==============================================================================
--- ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java
(original)
+++ ctakes/trunk/ctakes-dictionary-lookup-fast/src/main/java/org/apache/ctakes/dictionary/lookup2/util/JdbcConnectionFactory.java
Tue Jan 20 18:31:22 2015
@@ -20,6 +20,8 @@ import java.util.*;
 public enum JdbcConnectionFactory {
    INSTANCE;
 
+   static private final String CTAKES_HOME = "CTAKES_HOME";
+
    static final private Logger LOGGER = Logger.getLogger( "JdbcConnectionFactory" );
    static final private Logger DOT_LOGGER = Logger.getLogger( "ProgressAppender" );
    static final private Logger EOL_LOGGER = Logger.getLogger( "ProgressDone" );
@@ -54,25 +56,7 @@ public enum JdbcConnectionFactory {
       String trueJdbcUrl = jdbcUrl;
       if ( jdbcUrl.startsWith( HSQL_FILE_PREFIX ) ) {
          // Hack for hsqldb file needing to be absolute or relative to current working directory
-         final String urlDbPath = jdbcUrl.substring( HSQL_FILE_PREFIX.length() );
-         final String urlFilePath = urlDbPath + HSQL_DB_EXT;
-         File file = new File( urlFilePath );
-         if ( !file.exists() ) {
-            // file url is not absolute, check for relative directly under current working
directory
-            final String cwd = System.getProperty( "user.dir" );
-            file = new File( cwd, urlFilePath );
-            if ( !file.exists() ) {
-               // Users running projects out of an ide may have the module directory as cwd
-               final String cwdParent = new File( cwd ).getParent();
-               file = new File( cwdParent, urlFilePath );
-               if ( file.exists() ) {
-                  trueJdbcUrl = HSQL_FILE_PREFIX + "../" + urlDbPath;
-               } else {
-                  LOGGER.error( "Could not find " + urlFilePath + " as absolute or in " +
cwd + " or in " + cwdParent );
-                  throw new SQLException( "No HsqlDB script file exists at Url" );
-               }
-            }
-         }
+         trueJdbcUrl = getConnectionUrl( jdbcUrl );
       }
       try {
          // DO NOT use try with resources here.
@@ -107,6 +91,37 @@ public enum JdbcConnectionFactory {
       return connection;
    }
 
+   static private String getConnectionUrl( final String jdbcUrl ) throws SQLException {
+      final String urlDbPath = jdbcUrl.substring( HSQL_FILE_PREFIX.length() );
+      final String urlFilePath = urlDbPath + HSQL_DB_EXT;
+      File file = new File( urlFilePath );
+      if ( file.exists() ) {
+         return file.getPath();
+      }
+      // file url is not absolute, check for relative directly under current working directory
+      final String cwd = System.getProperty( "user.dir" );
+      file = new File( cwd, urlFilePath );
+      if ( file.exists() ) {
+         return file.getPath();
+      }
+      // Users running projects out of an ide may have the module directory as cwd
+      final String cwdParent = new File( cwd ).getParent();
+      file = new File( cwdParent, urlFilePath );
+      if ( file.exists() ) {
+         return file.getPath();
+      }
+      final String cTakesHome = System.getenv( CTAKES_HOME );
+      if ( cTakesHome != null && !cTakesHome.isEmpty() ) {
+         file = new File( cTakesHome, urlFilePath );
+         if ( file.exists() ) {
+            return file.getPath();
+         }
+      }
+      LOGGER.error( "Could not find " + urlFilePath + " as absolute or in \n" + cwd + " or
in \n"
+              + cwdParent + " or in \n" + cTakesHome );
+      throw new SQLException( "No HsqlDB script file exists at Url" );
+   }
+
    static private class DotPlotter extends TimerTask {
       private int _count = 0;
 



Mime
View raw message