Avoid defensive checks against Java 8 API (java.util.Optional etc)
This commit also fixes broken javadoc links and code references. Issue: SPR-13188
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,17 +24,12 @@ import javax.sql.rowset.RowSetProvider;
|
||||
|
||||
import org.springframework.jdbc.support.rowset.ResultSetWrappingSqlRowSet;
|
||||
import org.springframework.jdbc.support.rowset.SqlRowSet;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* {@link ResultSetExtractor} implementation that returns a Spring {@link SqlRowSet}
|
||||
* representation for each given {@link ResultSet}.
|
||||
*
|
||||
* <p>The default implementation uses a standard JDBC CachedRowSet underneath.
|
||||
* This means that JDBC RowSet support needs to be available at runtime:
|
||||
* by default, Sun's {@code com.sun.rowset.CachedRowSetImpl} class on Java 6,
|
||||
* or the {@code javax.sql.rowset.RowSetProvider} mechanism on Java 7+ / JDBC 4.1+.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @since 1.2
|
||||
@@ -45,17 +40,14 @@ import org.springframework.util.ClassUtils;
|
||||
*/
|
||||
public class SqlRowSetResultSetExtractor implements ResultSetExtractor<SqlRowSet> {
|
||||
|
||||
private static final CachedRowSetFactory cachedRowSetFactory;
|
||||
private static final RowSetFactory rowSetFactory;
|
||||
|
||||
static {
|
||||
if (ClassUtils.isPresent("javax.sql.rowset.RowSetProvider",
|
||||
SqlRowSetResultSetExtractor.class.getClassLoader())) {
|
||||
// using JDBC 4.1 RowSetProvider, available on JDK 7+
|
||||
cachedRowSetFactory = new StandardCachedRowSetFactory();
|
||||
try {
|
||||
rowSetFactory = RowSetProvider.newFactory();
|
||||
}
|
||||
else {
|
||||
// JDBC 4.1 API not available - fall back to Sun CachedRowSetImpl on JDK 6
|
||||
cachedRowSetFactory = new SunCachedRowSetFactory();
|
||||
catch (SQLException ex) {
|
||||
throw new IllegalStateException("Cannot create RowSetFactory through RowSetProvider", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,69 +86,7 @@ public class SqlRowSetResultSetExtractor implements ResultSetExtractor<SqlRowSet
|
||||
* @see #createSqlRowSet
|
||||
*/
|
||||
protected CachedRowSet newCachedRowSet() throws SQLException {
|
||||
return cachedRowSetFactory.createCachedRowSet();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Internal strategy interface for the creation of CachedRowSet instances.
|
||||
*/
|
||||
private interface CachedRowSetFactory {
|
||||
|
||||
CachedRowSet createCachedRowSet() throws SQLException;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on JDBC 4.1 RowSetProvider class.
|
||||
*/
|
||||
@UsesJava7
|
||||
private static class StandardCachedRowSetFactory implements CachedRowSetFactory {
|
||||
|
||||
private final RowSetFactory rowSetFactory;
|
||||
|
||||
public StandardCachedRowSetFactory() {
|
||||
try {
|
||||
this.rowSetFactory = RowSetProvider.newFactory();
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
throw new IllegalStateException("Cannot create RowSetFactory through RowSetProvider", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedRowSet createCachedRowSet() throws SQLException {
|
||||
return this.rowSetFactory.createCachedRowSet();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Inner class to avoid a hard dependency on Sun's CachedRowSetImpl class.
|
||||
*/
|
||||
private static class SunCachedRowSetFactory implements CachedRowSetFactory {
|
||||
|
||||
private static final Class<?> implementationClass;
|
||||
|
||||
static {
|
||||
try {
|
||||
implementationClass = ClassUtils.forName("com.sun.rowset.CachedRowSetImpl",
|
||||
SqlRowSetResultSetExtractor.class.getClassLoader());
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CachedRowSet createCachedRowSet() throws SQLException {
|
||||
try {
|
||||
return (CachedRowSet) implementationClass.newInstance();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
}
|
||||
return rowSetFactory.createCachedRowSet();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,8 +36,6 @@ import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.jdbc.CannotGetJdbcConnectionException;
|
||||
import org.springframework.jdbc.datasource.DataSourceUtils;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Generic utility methods for working with JDBC. Mainly for internal use
|
||||
@@ -54,11 +52,6 @@ public abstract class JdbcUtils {
|
||||
*/
|
||||
public static final int TYPE_UNKNOWN = Integer.MIN_VALUE;
|
||||
|
||||
|
||||
// Check for JDBC 4.1 getObject(int, Class) method - available on JDK 7 and higher
|
||||
private static final boolean getObjectWithTypeAvailable =
|
||||
ClassUtils.hasMethod(ResultSet.class, "getObject", int.class, Class.class);
|
||||
|
||||
private static final Log logger = LogFactory.getLog(JdbcUtils.class);
|
||||
|
||||
|
||||
@@ -135,7 +128,6 @@ public abstract class JdbcUtils {
|
||||
* @return the value object
|
||||
* @throws SQLException if thrown by the JDBC API
|
||||
*/
|
||||
@UsesJava7 // guard optional use of JDBC 4.1 (safe with 1.6 due to getObjectWithTypeAvailable check)
|
||||
public static Object getResultSetValue(ResultSet rs, int index, Class<?> requiredType) throws SQLException {
|
||||
if (requiredType == null) {
|
||||
return getResultSetValue(rs, index);
|
||||
@@ -192,19 +184,17 @@ public abstract class JdbcUtils {
|
||||
}
|
||||
else {
|
||||
// Some unknown type desired -> rely on getObject.
|
||||
if (getObjectWithTypeAvailable) {
|
||||
try {
|
||||
return rs.getObject(index, requiredType);
|
||||
}
|
||||
catch (AbstractMethodError err) {
|
||||
logger.debug("JDBC driver does not implement JDBC 4.1 'getObject(int, Class)' method", err);
|
||||
}
|
||||
catch (SQLFeatureNotSupportedException ex) {
|
||||
logger.debug("JDBC driver does not support JDBC 4.1 'getObject(int, Class)' method", ex);
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
logger.debug("JDBC driver has limited support for JDBC 4.1 'getObject(int, Class)' method", ex);
|
||||
}
|
||||
try {
|
||||
return rs.getObject(index, requiredType);
|
||||
}
|
||||
catch (AbstractMethodError err) {
|
||||
logger.debug("JDBC driver does not implement JDBC 4.1 'getObject(int, Class)' method", err);
|
||||
}
|
||||
catch (SQLFeatureNotSupportedException ex) {
|
||||
logger.debug("JDBC driver does not support JDBC 4.1 'getObject(int, Class)' method", ex);
|
||||
}
|
||||
catch (SQLException ex) {
|
||||
logger.debug("JDBC driver has limited support for JDBC 4.1 'getObject(int, Class)' method", ex);
|
||||
}
|
||||
// Fall back to getObject without type specification...
|
||||
return getResultSetValue(rs, index);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,6 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.jdbc.InvalidResultSetAccessException;
|
||||
import org.springframework.lang.UsesJava7;
|
||||
|
||||
/**
|
||||
* The default implementation of Spring's {@link SqlRowSet} interface, wrapping a
|
||||
@@ -412,7 +411,6 @@ public class ResultSetWrappingSqlRowSet implements SqlRowSet {
|
||||
/**
|
||||
* @see java.sql.ResultSet#getObject(int, Class)
|
||||
*/
|
||||
@UsesJava7
|
||||
@Override
|
||||
public <T> T getObject(int columnIndex, Class<T> type) throws InvalidResultSetAccessException {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user