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 SqlExceptionHelper sqlExceptionHelper;
private boolean isJdbc4 = true;
/**
* Constructs a ResultSetReturnImpl
*
@ -91,28 +93,22 @@ public class ResultSetReturnImpl implements ResultSetReturn {
}
private boolean isTypeOf(final Statement statement, final Class<? extends Statement> type) {
// Default is to match based on class type
boolean matches = type.isInstance(statement);
if (isJdbc4) {
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;
// This is "more correct" than #isInstance, but not always supported.
return statement.isWrapperFor( type );
}
// 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 (SQLException e) {
// No operation
}
} catch (Exception e) {
catch (Throwable e) {
// No operation. Note that this catches more than just SQLException to
// cover edge cases where a driver might throw an UnsupportedOperationException
// cover edge cases where a driver might throw an UnsupportedOperationException, AbstractMethodError,
// etc. If so, skip permanently.
isJdbc4 = false;
}
return matches;
}
return type.isInstance( statement );
}
@Override