sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject svn commit: r1727533 - /sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
Date Fri, 29 Jan 2016 11:13:23 GMT
Author: desruisseaux
Date: Fri Jan 29 11:13:23 2016
New Revision: 1727533

URL: http://svn.apache.org/viewvc?rev=1727533&view=rev
Log:
More accurate detection of if a JNDI context is available.

Modified:
    sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java

Modified: sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java?rev=1727533&r1=1727532&r2=1727533&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] (original)
+++ sis/branches/JDK8/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] Fri Jan 29 11:13:23 2016
@@ -117,11 +117,14 @@ public abstract class Initializer {
      */
     public static synchronized DataSource getDataSource() throws Exception {
         if (source == null) {
-            if (NamingManager.hasInitialContextFactoryBuilder()) try {
+            if (hasJNDI()) try {
                 final Context env = (Context) InitialContext.doLookup("java:comp/env");
                 return source = (DataSource) env.lookup("jdbc/" + DATABASE);
             } catch (NameNotFoundException e) {
-                Logging.unexpectedException(Logging.getLogger(Loggers.SQL), Initializer.class,
"getDataSource", e);
+                final LogRecord record = Messages.getResources(null).getLogRecord(
+                        Level.CONFIG, Messages.Keys.JNDINotSpecified_1, "jdbc/" + DATABASE);
+                record.setLoggerName(Loggers.SQL);
+                Logging.log(Initializer.class, "getDataSource", record);
             }
             final Path dir = DataDirectory.DATABASES.getDirectory();
             if (dir != null) {
@@ -134,6 +137,16 @@ public abstract class Initializer {
     }
 
     /**
+     * Returns {@code true} if SIS will try to fetch the {@link DataSource} from JNDI.
+     *
+     * @return {@code true} if a JNDI environment seems to be present.
+     */
+    public static boolean hasJNDI() {
+        return NamingManager.hasInitialContextFactoryBuilder() ||
+               System.getProperty(Context.INITIAL_CONTEXT_FACTORY) != null;
+    }
+
+    /**
      * Returns a message for unspecified data source. The message will depend on whether
a JNDI context exists or not.
      * This message can be used for constructing an exception when {@link #getDataSource()}
returned {@code null}.
      *
@@ -143,7 +156,7 @@ public abstract class Initializer {
     public static String unspecified(final Locale locale) {
         final short key;
         final String value;
-        if (NamingManager.hasInitialContextFactoryBuilder()) {
+        if (hasJNDI()) {
             key = Messages.Keys.JNDINotSpecified_1;
             value = "jdbc/" + DATABASE;
         } else {



Mime
View raw message