From 3c776321db3dcca4918557fabba4d02ea4d6aa9b Mon Sep 17 00:00:00 2001 From: begmandev Date: Fri, 25 Apr 2014 08:09:43 -0500 Subject: [PATCH] HHH-9145 Use JDBC Wrapper API for type checks --- .../jdbc/internal/ResultSetReturnImpl.java | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/ResultSetReturnImpl.java b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/ResultSetReturnImpl.java index baca8569a8..6f4c6468c2 100644 --- a/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/ResultSetReturnImpl.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/jdbc/internal/ResultSetReturnImpl.java @@ -65,7 +65,7 @@ public class ResultSetReturnImpl implements ResultSetReturn { @Override public ResultSet extract(PreparedStatement statement) { // IMPL NOTE : SQL logged by caller - if ( statement instanceof CallableStatement ) { + if (isTypeOf(statement, CallableStatement.class)) { // We actually need to extract from Callable statement. Although // this seems needless, Oracle can return an // OracleCallableStatementWrapper that finds its way to this method, @@ -90,6 +90,31 @@ public class ResultSetReturnImpl implements ResultSetReturn { } } + private boolean isTypeOf(final Statement statement, final Class type) { + // Default is to match based on class type + boolean matches = type.isInstance(statement); + + try { + boolean jdbc4; + try { + // Attempt to verify if the statement instance implements the JDBC 4 API + jdbc4 = (statement.getClass().getMethod("isWrapperFor", new Class[] { Class.class }) != null); + } catch (Exception e) { + jdbc4 = false; + } + + // If the statement implements the JDBC 4 API, verify if the statement either implements + // the interface directly or is a wrapper for the specified type via the JDBC API + if (jdbc4) { + matches = statement.isWrapperFor(type); + } + } catch (Exception e) { + // No operation. Note that this catches more than just SQLException to + // cover edge cases where a driver might throw an UnsupportedOperationException + } + return matches; + } + @Override public ResultSet extract(CallableStatement callableStatement) { // IMPL NOTE : SQL logged by caller