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
{
@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"
if (!(obj instanceof Reference)) {
return null;
}
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.");
}
if (obj instanceof Reference && "javax.sql.DataSource".equals(((Reference) obj).getClassName())) {
Reference ref = (Reference) obj;
Set<String> hikariPropSet = PropertyElf.getPropertyNames(HikariConfig.class);
Set<String> hikariPropSet = PropertyElf.getPropertyNames(HikariConfig.class);
Properties properties = new Properties();
Enumeration<RefAddr> enumeration = ref.getAll();
while (enumeration.hasMoreElements()) {
RefAddr element = enumeration.nextElement();
String type = element.getType();
if (type.startsWith("dataSource.") || hikariPropSet.contains(type)) {
properties.setProperty(type, element.getContent().toString());
Properties properties = new Properties();
Enumeration<RefAddr> enumeration = ref.getAll();
while (enumeration.hasMoreElements()) {
RefAddr element = enumeration.nextElement();
String type = element.getType();
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

Loading…
Cancel
Save