HHH-9145 simplified JDBC check

This commit is contained in:
Brett Meyer 2014-05-23 17:49:47 -04:00
parent 3c776321db
commit ab8dd7966a
1 changed files with 19 additions and 23 deletions

View File

@ -45,6 +45,8 @@ public class ResultSetReturnImpl implements ResultSetReturn {
private final SqlStatementLogger sqlStatementLogger; private final SqlStatementLogger sqlStatementLogger;
private final SqlExceptionHelper sqlExceptionHelper; private final SqlExceptionHelper sqlExceptionHelper;
private boolean isJdbc4 = true;
/** /**
* Constructs a ResultSetReturnImpl * Constructs a ResultSetReturnImpl
* *
@ -91,29 +93,23 @@ public class ResultSetReturnImpl implements ResultSetReturn {
} }
private boolean isTypeOf(final Statement statement, final Class<? extends Statement> type) { private boolean isTypeOf(final Statement statement, final Class<? extends Statement> type) {
// Default is to match based on class type if (isJdbc4) {
boolean matches = type.isInstance(statement); try {
// This is "more correct" than #isInstance, but not always supported.
try { return statement.isWrapperFor( type );
boolean jdbc4; }
try { catch (SQLException e) {
// Attempt to verify if the statement instance implements the JDBC 4 API // No operation
jdbc4 = (statement.getClass().getMethod("isWrapperFor", new Class<?>[] { Class.class }) != null); }
} catch (Exception e) { catch (Throwable e) {
jdbc4 = false; // No operation. Note that this catches more than just SQLException to
} // cover edge cases where a driver might throw an UnsupportedOperationException, AbstractMethodError,
// etc. If so, skip permanently.
// If the statement implements the JDBC 4 API, verify if the statement either implements isJdbc4 = false;
// the interface directly or is a wrapper for the specified type via the JDBC API }
if (jdbc4) { }
matches = statement.isWrapperFor(type); return type.isInstance( statement );
} }
} 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 @Override
public ResultSet extract(CallableStatement callableStatement) { public ResultSet extract(CallableStatement callableStatement) {