brettwooldridge / HikariCP

光 HikariCP・A solid, high-performance, JDBC connection pool at last.
Apache License 2.0
19.86k stars 2.92k forks source link

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

Open h-thurow opened 7 years ago

h-thurow commented 7 years ago

The JavaDoc of ObjectFactory.getObjectInstance(Object, Name, Context, Hashtable<?,?>) : Object specifies this behaviour:

"An object factory should only throw an exception if it is sure that it is the only intended factory and that no other object factories should be tried. If this factory cannot create an object using the arguments supplied, it should return null."

So if one configured multiple ObjectFactories to be asked if they can create a specific type by setting java.naming.factory.object to a list of object factories HikariJNDIFactory will prevent other factories from being consulted.

org.apache.commons.dbcp2.BasicDataSourceFactory does it this way:

    if (!"javax.sql.DataSource".equals(ref.getClassName())) {
        return null;
    }
brettwooldridge commented 7 years ago

Can you please submit a pull request?