HHH-14282 StandardRefCursorSupport can rely on having JDK8 as baseline today
This commit is contained in:
parent
99f299f76d
commit
55eba6320b
|
@ -86,18 +86,7 @@ public class StandardRefCursorSupport implements RefCursorSupport {
|
|||
public ResultSet getResultSet(CallableStatement statement, int position) {
|
||||
if ( jdbcServices.getExtractedMetaDataSupport().supportsRefCursors() ) {
|
||||
try {
|
||||
return (ResultSet) getResultSetByPositionMethod().invoke( statement, position, ResultSet.class );
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
if ( e.getTargetException() instanceof SQLException ) {
|
||||
throw jdbcServices.getSqlExceptionHelper().convert(
|
||||
(SQLException) e.getTargetException(),
|
||||
"Error extracting REF_CURSOR parameter [" + position + "]"
|
||||
);
|
||||
}
|
||||
else {
|
||||
throw new HibernateException( "Unexpected error extracting REF_CURSOR parameter [" + position + "]", e.getTargetException() );
|
||||
}
|
||||
return statement.getObject( position, ResultSet.class );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new HibernateException( "Unexpected error extracting REF_CURSOR parameter [" + position + "]", e );
|
||||
|
@ -120,18 +109,7 @@ public class StandardRefCursorSupport implements RefCursorSupport {
|
|||
public ResultSet getResultSet(CallableStatement statement, String name) {
|
||||
if ( jdbcServices.getExtractedMetaDataSupport().supportsRefCursors() ) {
|
||||
try {
|
||||
return (ResultSet) getResultSetByNameMethod().invoke( statement, name, ResultSet.class );
|
||||
}
|
||||
catch (InvocationTargetException e) {
|
||||
if ( e.getTargetException() instanceof SQLException ) {
|
||||
throw jdbcServices.getSqlExceptionHelper().convert(
|
||||
(SQLException) e.getTargetException(),
|
||||
"Error extracting REF_CURSOR parameter [" + name + "]"
|
||||
);
|
||||
}
|
||||
else {
|
||||
throw new HibernateException( "Unexpected error extracting REF_CURSOR parameter [" + name + "]", e.getTargetException() );
|
||||
}
|
||||
return statement.getObject( name, ResultSet.class );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new HibernateException( "Unexpected error extracting REF_CURSOR parameter [" + name + "]", e );
|
||||
|
@ -158,58 +136,17 @@ public class StandardRefCursorSupport implements RefCursorSupport {
|
|||
* @return {@code true} if the metadata indicates that the driver defines REF_CURSOR support
|
||||
*/
|
||||
public static boolean supportsRefCursors(DatabaseMetaData meta) {
|
||||
// Standard JDBC REF_CURSOR support was not added until Java 8, so we need to use reflection to attempt to
|
||||
// access these fields/methods...
|
||||
try {
|
||||
return (Boolean) meta.getClass().getMethod( "supportsRefCursors" ).invoke( meta );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
log.trace( "JDBC DatabaseMetaData class does not define supportsRefCursors method..." );
|
||||
}
|
||||
catch (Exception e) {
|
||||
log.debug( "Unexpected error trying to gauge level of JDBC REF_CURSOR support : " + e.getMessage() );
|
||||
return meta.supportsRefCursors();
|
||||
}
|
||||
catch (SQLException throwable) {
|
||||
log.debug( "Unexpected error trying to gauge level of JDBC REF_CURSOR support : " + throwable.getMessage() );
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private int refCursorTypeCode() {
|
||||
return Types.REF_CURSOR;
|
||||
}
|
||||
|
||||
|
||||
private static Method getResultSetByPositionMethod;
|
||||
|
||||
private Method getResultSetByPositionMethod() {
|
||||
if ( getResultSetByPositionMethod == null ) {
|
||||
try {
|
||||
getResultSetByPositionMethod = CallableStatement.class.getMethod( "getObject", int.class, Class.class );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new HibernateException( "CallableStatement class does not define getObject(int,Class) method" );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new HibernateException( "Unexpected error trying to access CallableStatement#getObject(int,Class)" );
|
||||
}
|
||||
}
|
||||
return getResultSetByPositionMethod;
|
||||
}
|
||||
|
||||
|
||||
private static Method getResultSetByNameMethod;
|
||||
|
||||
private Method getResultSetByNameMethod() {
|
||||
if ( getResultSetByNameMethod == null ) {
|
||||
try {
|
||||
getResultSetByNameMethod = CallableStatement.class.getMethod( "getObject", String.class, Class.class );
|
||||
}
|
||||
catch (NoSuchMethodException e) {
|
||||
throw new HibernateException( "CallableStatement class does not define getObject(String,Class) method" );
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new HibernateException( "Unexpected error trying to access CallableStatement#getObject(String,Class)" );
|
||||
}
|
||||
}
|
||||
return getResultSetByNameMethod;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue