Skip to content

Commit

Permalink
Merge branch 'master' of github.com:GeoLatte/geolatte-geom
Browse files Browse the repository at this point in the history
  • Loading branch information
maesenka committed May 8, 2023
2 parents 3d3b3e3 + 4ab5d56 commit 48fb46c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.sql.Connection;
import java.sql.SQLException;

/**
* Default <code>ConnectionFinder</code> implementation.
Expand All @@ -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.");
}
Expand All @@ -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(
Expand Down

0 comments on commit 48fb46c

Please sign in to comment.