diff --git a/geom/src/main/java/org/geolatte/geom/codec/db/oracle/ConnectionFinder.java b/geom/src/main/java/org/geolatte/geom/codec/db/oracle/ConnectionFinder.java index da7acab..8efb96c 100644 --- a/geom/src/main/java/org/geolatte/geom/codec/db/oracle/ConnectionFinder.java +++ b/geom/src/main/java/org/geolatte/geom/codec/db/oracle/ConnectionFinder.java @@ -45,7 +45,7 @@ public interface ConnectionFinder extends Serializable { * * @param conn the object that is being searched for an OracleConnection * @return the object sought - * @throws RuntimeException thrown when the feature can be found; + * @throws RuntimeException thrown when the feature cannot be found; */ Connection find(Connection conn); diff --git a/geom/src/main/java/org/geolatte/geom/codec/db/oracle/DefaultConnectionFinder.java b/geom/src/main/java/org/geolatte/geom/codec/db/oracle/DefaultConnectionFinder.java index e962d64..4d27d52 100644 --- a/geom/src/main/java/org/geolatte/geom/codec/db/oracle/DefaultConnectionFinder.java +++ b/geom/src/main/java/org/geolatte/geom/codec/db/oracle/DefaultConnectionFinder.java @@ -24,6 +24,7 @@ import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.sql.Connection; +import java.sql.SQLException; /** * Default ConnectionFinder implementation. @@ -41,10 +42,12 @@ public class DefaultConnectionFinder implements ConnectionFinder { private static final Class ORACLE_CONNECTION_CLASS; + private static final Class ORACLE_CONNECTION_INTERFACE; static { try { ORACLE_CONNECTION_CLASS = Class.forName("oracle.jdbc.driver.OracleConnection"); + ORACLE_CONNECTION_INTERFACE = Class.forName("oracle.jdbc.OracleConnection"); } catch (ClassNotFoundException e) { throw new RuntimeException("Can't find Oracle JDBC Driver on classpath."); } @@ -59,6 +62,15 @@ public Connection find(Connection con) { if (ORACLE_CONNECTION_CLASS.isInstance(con)) { return con; } + + try { + if (con.isWrapperFor(ORACLE_CONNECTION_INTERFACE)) { + return (Connection) con.unwrap(ORACLE_CONNECTION_INTERFACE); + } + } catch (SQLException e) { + // Unwrapping failed, falling back on reflection + } + // try to find the Oracleconnection recursively for (Method method : con.getClass().getMethods()) { if (java.sql.Connection.class.isAssignableFrom(