sis-commits mailing list archives

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

URL: http://svn.apache.org/viewvc?rev=1727536&view=rev
Log:
Merge JNDI fix from the JDK8 branch.

Modified:
    sis/branches/JDK7/   (props changed)
    sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java

Propchange: sis/branches/JDK7/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Jan 29 11:16:40 2016
@@ -1,4 +1,4 @@
 /sis/branches/Android:1430670-1480699
 /sis/branches/JDK6:1394913-1508480
-/sis/branches/JDK8:1584960-1727364
+/sis/branches/JDK8:1584960-1727534
 /sis/trunk:1394364-1508466,1519089-1519674

Modified: sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java?rev=1727536&r1=1727535&r2=1727536&view=diff
==============================================================================
--- sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] (original)
+++ sis/branches/JDK7/core/sis-metadata/src/main/java/org/apache/sis/internal/metadata/sql/Initializer.java
[UTF-8] Fri Jan 29 11:16:40 2016
@@ -118,11 +118,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) {
@@ -135,6 +138,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}.
      *
@@ -144,7 +157,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