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
This commit is contained in:
Pinaki Poddar 2008-06-19 01:41:32 +00:00
parent d1a165bc61
commit 37cb4af35d
3 changed files with 13 additions and 6 deletions

View File

@ -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();
}

View File

@ -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);

View File

@ -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.