From 37cb4af35de27c75ac6f5acffaed0f1ba82cc12f Mon Sep 17 00:00:00 2001 From: Pinaki Poddar Date: Thu, 19 Jun 2008 01:41:32 +0000 Subject: [PATCH] OPENJPA-581: Print WARN level message on JNDI lookup failure git-svn-id: https://svn.apache.org/repos/asf/openjpa/trunk@669356 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/openjpa/conf/OpenJPAConfigurationImpl.java | 11 +++++++---- .../org/apache/openjpa/lib/conf/Configurations.java | 7 +++++-- .../org/apache/openjpa/lib/conf/localizer.properties | 1 + 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java index 2b59f1818..917d6c48e 100644 --- a/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java +++ b/openjpa-kernel/src/main/java/org/apache/openjpa/conf/OpenJPAConfigurationImpl.java @@ -944,19 +944,21 @@ public class OpenJPAConfigurationImpl public Object getConnectionFactory() { if (connectionFactory.get() == null) connectionFactory.set( - lookupConnectionFactory(getConnectionFactoryName()), true); + lookupConnectionFactory(getConnectionFactoryName(), + connectionFactory.getProperty()), true); return connectionFactory.get(); } /** * Lookup the connection factory at the given name. */ - private Object lookupConnectionFactory(String name) { + private Object lookupConnectionFactory(String name, String userKey) { name = StringUtils.trimToNull(name); if (name == null) return null; try { - return Configurations.lookup(name); + return Configurations.lookup(name, userKey, + getLog(OpenJPAConfiguration.LOG_RUNTIME)); } catch (Exception ex) { return null; } @@ -1027,7 +1029,8 @@ public class OpenJPAConfigurationImpl public Object getConnectionFactory2() { if (connectionFactory2.get() == null) connectionFactory2.set( - lookupConnectionFactory(getConnectionFactory2Name()), false); + lookupConnectionFactory(getConnectionFactory2Name(), + connectionFactory2.getProperty()), false); return connectionFactory2.get(); } diff --git a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java index c2854589c..d4e4202c3 100644 --- a/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java +++ b/openjpa-lib/src/main/java/org/apache/openjpa/lib/conf/Configurations.java @@ -609,14 +609,17 @@ public class Configurations { /** * Looks up the given name in JNDI. If the name is null, null is returned. */ - public static Object lookup(String name) { + public static Object lookup(String name, String userKey, Log log) { if (StringUtils.isEmpty(name)) return null; Context ctx = null; try { ctx = new InitialContext(); - return ctx.lookup(name); + Object result = ctx.lookup(name); + if (result == null && log != null && log.isWarnEnabled()) + log.warn(_loc.get("jndi-lookup-failed", userKey, name)); + return result; } catch (NamingException ne) { throw new NestableRuntimeException( _loc.get("naming-err", name).getMessage(), ne); diff --git a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties index abb9327fb..e9a98f316 100644 --- a/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties +++ b/openjpa-lib/src/main/resources/org/apache/openjpa/lib/conf/localizer.properties @@ -114,3 +114,4 @@ Id-expert: true veto-change: Can not modify "{0}" because the property is not dynamic and the \ current configuration is read-only. +jndi-lookup-failed: JNDI lookup for "{0}" with key "{1}" returned null. \ No newline at end of file