Issue #928: HikariJNDIFactory should not throw a NamingException when !"javax.sql.DataSource".equals(ref.getClassName()).

pull/1022/head
h-thurow 7 years ago
parent 7e0e467c80
commit bd14bc9a66

@ -40,31 +40,26 @@ import com.zaxxer.hikari.util.PropertyElf;
public class HikariJNDIFactory implements ObjectFactory public class HikariJNDIFactory implements ObjectFactory
{ {
@Override @Override
synchronized public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception synchronized public Object getObjectInstance(Object obj, Name name, Context nameCtx, Hashtable<?, ?> environment) throws Exception {
{
// We only know how to deal with <code>javax.naming.Reference</code> that specify a class name of "javax.sql.DataSource" // We only know how to deal with <code>javax.naming.Reference</code> that specify a class name of "javax.sql.DataSource"
if (!(obj instanceof Reference)) { if (obj instanceof Reference && "javax.sql.DataSource".equals(((Reference) obj).getClassName())) {
return null; Reference ref = (Reference) obj;
} Set<String> hikariPropSet = PropertyElf.getPropertyNames(HikariConfig.class);
Reference ref = (Reference) obj;
if (!"javax.sql.DataSource".equals(ref.getClassName())) {
throw new NamingException(ref.getClassName() + " is not a valid class name/type for this JNDI factory.");
}
Set<String> hikariPropSet = PropertyElf.getPropertyNames(HikariConfig.class); Properties properties = new Properties();
Enumeration<RefAddr> enumeration = ref.getAll();
Properties properties = new Properties(); while (enumeration.hasMoreElements()) {
Enumeration<RefAddr> enumeration = ref.getAll(); RefAddr element = enumeration.nextElement();
while (enumeration.hasMoreElements()) { String type = element.getType();
RefAddr element = enumeration.nextElement(); if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) {
String type = element.getType(); properties.setProperty(type, element.getContent().toString());
if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) { }
properties.setProperty(type, element.getContent().toString());
} }
return createDataSource(properties, nameCtx);
}
else {
return null;
} }
return createDataSource(properties, nameCtx);
} }
private DataSource createDataSource(final Properties properties, final Context context) throws NamingException private DataSource createDataSource(final Properties properties, final Context context) throws NamingException

Loading…
Cancel
Save