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,28 +93,22 @@ 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 { try {
boolean jdbc4; // This is "more correct" than #isInstance, but not always supported.
try { return statement.isWrapperFor( type );
// 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;
} }
catch (SQLException e) {
// If the statement implements the JDBC 4 API, verify if the statement either implements // No operation
// the interface directly or is a wrapper for the specified type via the JDBC API
if (jdbc4) {
matches = statement.isWrapperFor(type);
} }
} catch (Exception e) { catch (Throwable e) {
// No operation. Note that this catches more than just SQLException to // 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 @Override