diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java index 642894871af..ffe32040d3b 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2017 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. @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import org.springframework.dao.InvalidDataAccessApiUsageException; -import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor; /** * Helper class that efficiently creates multiple {@link CallableStatementCreator} @@ -49,8 +48,6 @@ public class CallableStatementCreatorFactory { private boolean updatableResults = false; - private NativeJdbcExtractor nativeJdbcExtractor; - /** * Create a new factory. Will need to add parameters via the @@ -100,13 +97,6 @@ public class CallableStatementCreatorFactory { this.updatableResults = updatableResults; } - /** - * Specify the NativeJdbcExtractor to use for unwrapping CallableStatements, if any. - */ - public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor) { - this.nativeJdbcExtractor = nativeJdbcExtractor; - } - /** * Return a new CallableStatementCreator instance given this parameters. @@ -172,12 +162,6 @@ public class CallableStatementCreatorFactory { updatableResults ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY); } - // Determine CallabeStatement to pass to custom types. - CallableStatement csToUse = cs; - if (nativeJdbcExtractor != null) { - csToUse = nativeJdbcExtractor.getNativeCallableStatement(cs); - } - int sqlColIndx = 1; for (SqlParameter declaredParam : declaredParameters) { if (!declaredParam.isResultsParameter()) { @@ -200,7 +184,7 @@ public class CallableStatementCreatorFactory { } } if (declaredParam.isInputValueProvided()) { - StatementCreatorUtils.setParameterValue(csToUse, sqlColIndx, declaredParam, inValue); + StatementCreatorUtils.setParameterValue(cs, sqlColIndx, declaredParam, inValue); } } } @@ -210,7 +194,7 @@ public class CallableStatementCreatorFactory { throw new InvalidDataAccessApiUsageException( "Required input parameter '" + declaredParam.getName() + "' is missing"); } - StatementCreatorUtils.setParameterValue(csToUse, sqlColIndx, declaredParam, inValue); + StatementCreatorUtils.setParameterValue(cs, sqlColIndx, declaredParam, inValue); } sqlColIndx++; } @@ -233,10 +217,7 @@ public class CallableStatementCreatorFactory { @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append("CallableStatementCreatorFactory.CallableStatementCreatorImpl: sql=["); - sb.append(callString).append("]; parameters=").append(this.inParameters); - return sb.toString(); + return "CallableStatementCreator: sql=[" + callString + "]; parameters=" + this.inParameters; } } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java index ee663b101d6..73739eaf35e 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java @@ -46,7 +46,6 @@ import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.jdbc.support.JdbcAccessor; import org.springframework.jdbc.support.JdbcUtils; import org.springframework.jdbc.support.KeyHolder; -import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor; import org.springframework.jdbc.support.rowset.SqlRowSet; import org.springframework.util.Assert; import org.springframework.util.LinkedCaseInsensitiveMap; @@ -104,9 +103,6 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { private static final String RETURN_UPDATE_COUNT_PREFIX = "#update-count-"; - /** Custom NativeJdbcExtractor */ - private NativeJdbcExtractor nativeJdbcExtractor; - /** If this variable is false, we will throw exceptions on SQL warnings */ private boolean ignoreWarnings = true; @@ -182,23 +178,6 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations { } - /** - * Set a NativeJdbcExtractor to extract native JDBC objects from wrapped handles. - * Useful if native Statement and/or ResultSet handles are expected for casting - * to database-specific implementation classes, but a connection pool that wraps - * JDBC objects is used (note: any pool will return wrapped Connections). - */ - public void setNativeJdbcExtractor(NativeJdbcExtractor extractor) { - this.nativeJdbcExtractor = extractor; - } - - /** - * Return the current NativeJdbcExtractor implementation. - */ - public NativeJdbcExtractor getNativeJdbcExtractor() { - return this.nativeJdbcExtractor; - } - /** * Set whether or not we want to ignore SQLWarnings. *
Default is "true", swallowing and logging all warnings. Switch this flag
@@ -341,15 +320,8 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
Connection con = DataSourceUtils.getConnection(getDataSource());
try {
- Connection conToUse = con;
- if (this.nativeJdbcExtractor != null) {
- // Extract native JDBC Connection, castable to OracleConnection or the like.
- conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
- }
- else {
- // Create close-suppressing Connection proxy, also preparing returned Statements.
- conToUse = createConnectionProxy(con);
- }
+ // Create close-suppressing Connection proxy, also preparing returned Statements.
+ Connection conToUse = createConnectionProxy(con);
return action.doInConnection(conToUse);
}
catch (SQLException ex) {
@@ -394,18 +366,9 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
Connection con = DataSourceUtils.getConnection(getDataSource());
Statement stmt = null;
try {
- Connection conToUse = con;
- if (this.nativeJdbcExtractor != null &&
- this.nativeJdbcExtractor.isNativeConnectionNecessaryForNativeStatements()) {
- conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
- }
- stmt = conToUse.createStatement();
+ stmt = con.createStatement();
applyStatementSettings(stmt);
- Statement stmtToUse = stmt;
- if (this.nativeJdbcExtractor != null) {
- stmtToUse = this.nativeJdbcExtractor.getNativeStatement(stmt);
- }
- T result = action.doInStatement(stmtToUse);
+ T result = action.doInStatement(stmt);
handleWarnings(stmt);
return result;
}
@@ -456,11 +419,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
ResultSet rs = null;
try {
rs = stmt.executeQuery(sql);
- ResultSet rsToUse = rs;
- if (nativeJdbcExtractor != null) {
- rsToUse = nativeJdbcExtractor.getNativeResultSet(rs);
- }
- return rse.extractData(rsToUse);
+ return rse.extractData(rs);
}
finally {
JdbcUtils.closeResultSet(rs);
@@ -619,18 +578,9 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
Connection con = DataSourceUtils.getConnection(getDataSource());
PreparedStatement ps = null;
try {
- Connection conToUse = con;
- if (this.nativeJdbcExtractor != null &&
- this.nativeJdbcExtractor.isNativeConnectionNecessaryForNativePreparedStatements()) {
- conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
- }
- ps = psc.createPreparedStatement(conToUse);
+ ps = psc.createPreparedStatement(con);
applyStatementSettings(ps);
- PreparedStatement psToUse = ps;
- if (this.nativeJdbcExtractor != null) {
- psToUse = this.nativeJdbcExtractor.getNativePreparedStatement(ps);
- }
- T result = action.doInPreparedStatement(psToUse);
+ T result = action.doInPreparedStatement(ps);
handleWarnings(ps);
return result;
}
@@ -690,11 +640,7 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
pss.setValues(ps);
}
rs = ps.executeQuery();
- ResultSet rsToUse = rs;
- if (nativeJdbcExtractor != null) {
- rsToUse = nativeJdbcExtractor.getNativeResultSet(rs);
- }
- return rse.extractData(rsToUse);
+ return rse.extractData(rs);
}
finally {
JdbcUtils.closeResultSet(rs);
@@ -1070,17 +1016,9 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
Connection con = DataSourceUtils.getConnection(getDataSource());
CallableStatement cs = null;
try {
- Connection conToUse = con;
- if (this.nativeJdbcExtractor != null) {
- conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
- }
- cs = csc.createCallableStatement(conToUse);
+ cs = csc.createCallableStatement(con);
applyStatementSettings(cs);
- CallableStatement csToUse = cs;
- if (this.nativeJdbcExtractor != null) {
- csToUse = this.nativeJdbcExtractor.getNativeCallableStatement(cs);
- }
- T result = action.doInCallableStatement(csToUse);
+ T result = action.doInCallableStatement(cs);
handleWarnings(cs);
return result;
}
@@ -1274,22 +1212,18 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
}
Map Thanks to Mike Youngstrom and Bruce Campbell for submitting the original suggestion for the Oracle
* current schema lookup implementation.
@@ -46,17 +45,53 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
private String defaultSchema;
+ /**
+ * Constructor used to initialize with provided database metadata.
+ * @param databaseMetaData metadata to be used
+ */
public OracleTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException {
this(databaseMetaData, false);
}
- public OracleTableMetaDataProvider(DatabaseMetaData databaseMetaData, boolean includeSynonyms) throws SQLException {
+ /**
+ * Constructor used to initialize with provided database metadata.
+ * @param databaseMetaData metadata to be used
+ * @param includeSynonyms whether to include synonyms
+ */
+ public OracleTableMetaDataProvider(DatabaseMetaData databaseMetaData, boolean includeSynonyms)
+ throws SQLException {
+
super(databaseMetaData);
this.includeSynonyms = includeSynonyms;
+
lookupDefaultSchema(databaseMetaData);
}
+ /*
+ * Oracle-based implementation for detecting the current schema.
+ */
+ private void lookupDefaultSchema(DatabaseMetaData databaseMetaData) {
+ try {
+ CallableStatement cstmt = null;
+ try {
+ cstmt = databaseMetaData.getConnection().prepareCall(
+ "{? = call sys_context('USERENV', 'CURRENT_SCHEMA')}");
+ cstmt.registerOutParameter(1, Types.VARCHAR);
+ cstmt.execute();
+ this.defaultSchema = cstmt.getString(1);
+ }
+ finally {
+ if (cstmt != null) {
+ cstmt.close();
+ }
+ }
+ }
+ catch (SQLException ex) {
+ logger.debug("Encountered exception during default schema lookup", ex);
+ }
+ }
+
@Override
protected String getDefaultSchema() {
if (this.defaultSchema != null) {
@@ -65,6 +100,7 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
return super.getDefaultSchema();
}
+
@Override
public void initializeWithTableColumnMetaData(DatabaseMetaData databaseMetaData,
String catalogName, String schemaName, String tableName) throws SQLException {
@@ -76,25 +112,12 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
}
Connection con = databaseMetaData.getConnection();
- NativeJdbcExtractor nativeJdbcExtractor = getNativeJdbcExtractor();
- if (nativeJdbcExtractor != null) {
- con = nativeJdbcExtractor.getNativeConnection(con);
- }
- boolean isOracleCon;
try {
Class> oracleConClass = con.getClass().getClassLoader().loadClass("oracle.jdbc.OracleConnection");
- isOracleCon = oracleConClass.isInstance(con);
- }
- catch (ClassNotFoundException ex) {
- if (logger.isInfoEnabled()) {
- logger.info("Couldn't find Oracle JDBC API: " + ex);
- }
- isOracleCon = false;
+ con = (Connection) con.unwrap(oracleConClass);
}
-
- if (!isOracleCon) {
- logger.warn("Unable to include synonyms in table metadata lookup. Connection used for " +
- "DatabaseMetaData is not recognized as an Oracle connection: " + con);
+ catch (ClassNotFoundException | SQLException ex) {
+ logger.warn("Unable to include synonyms in table metadata lookup - no Oracle Connection: " + ex);
super.initializeWithTableColumnMetaData(databaseMetaData, catalogName, schemaName, tableName);
return;
}
@@ -112,8 +135,8 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
ReflectionUtils.makeAccessible(setIncludeSynonyms);
setIncludeSynonyms.invoke(con, Boolean.TRUE);
}
- catch (Exception ex) {
- throw new InvalidDataAccessApiUsageException("Couldn't prepare Oracle Connection", ex);
+ catch (Throwable ex) {
+ throw new InvalidDataAccessApiUsageException("Could not prepare Oracle Connection", ex);
}
super.initializeWithTableColumnMetaData(databaseMetaData, catalogName, schemaName, tableName);
@@ -121,30 +144,8 @@ public class OracleTableMetaDataProvider extends GenericTableMetaDataProvider {
try {
setIncludeSynonyms.invoke(con, originalValueForIncludeSynonyms);
}
- catch (Exception ex) {
- throw new InvalidDataAccessApiUsageException("Couldn't reset Oracle Connection", ex);
- }
- }
-
- /*
- * Oracle-based implementation for detecting the current schema.
- */
- private void lookupDefaultSchema(DatabaseMetaData databaseMetaData) {
- try {
- CallableStatement cstmt = null;
- try {
- cstmt = databaseMetaData.getConnection().prepareCall("{? = call sys_context('USERENV', 'CURRENT_SCHEMA')}");
- cstmt.registerOutParameter(1, Types.VARCHAR);
- cstmt.execute();
- this.defaultSchema = cstmt.getString(1);
- }
- finally {
- if (cstmt != null) {
- cstmt.close();
- }
- }
- }
- catch (Exception ignore) {
+ catch (Throwable ex) {
+ throw new InvalidDataAccessApiUsageException("Could not reset Oracle Connection", ex);
}
}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java
index 9c4c8335deb..e1fbb77f495 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/TableMetaDataContext.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -32,7 +32,6 @@ import org.springframework.jdbc.core.SqlTypeValue;
import org.springframework.jdbc.core.namedparam.SqlParameterSource;
import org.springframework.jdbc.core.namedparam.SqlParameterSourceUtils;
import org.springframework.jdbc.support.JdbcUtils;
-import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
/**
* Class to manage context metadata used for the configuration
@@ -71,9 +70,6 @@ public class TableMetaDataContext {
/** are we using generated key columns */
private boolean generatedKeyColumnsUsed = false;
- /** NativeJdbcExtractor to be used to retrieve the native connection */
- NativeJdbcExtractor nativeJdbcExtractor;
-
/**
* Set the name of the table for this context.
@@ -187,13 +183,6 @@ public class TableMetaDataContext {
return this.metaDataProvider.isGeneratedKeysColumnNameArraySupported();
}
- /**
- * Set {@link NativeJdbcExtractor} to be used to retrieve the native connection.
- */
- public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor) {
- this.nativeJdbcExtractor = nativeJdbcExtractor;
- }
-
/**
* Process the current meta data with the provided configuration options.
@@ -202,8 +191,7 @@ public class TableMetaDataContext {
* @param generatedKeyNames name of generated keys
*/
public void processMetaData(DataSource dataSource, List This interface can be checked when there is a need to cast to a
- * native JDBC Connection such as Oracle's OracleConnection. Spring's
- * {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter}
- * automatically detects such proxies before delegating to the actual
- * unwrapping for a specific connection pool.
+ * native JDBC Connection such as Oracle's OracleConnection. Alternatively,
+ * all such connections also support JDBC 4.0's {@link Connection#unwrap}.
*
* @author Juergen Hoeller
* @since 1.1
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java
index 743122e7429..8396d1be5bb 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/LazyConnectionDataSourceProxy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -68,11 +68,8 @@ import org.springframework.core.Constants;
*
* NOTE: This DataSource proxy needs to return wrapped Connections
* (which implement the {@link ConnectionProxy} interface) in order to handle
- * lazy fetching of an actual JDBC Connection. Therefore, the returned Connections
- * cannot be cast to a native JDBC Connection type such as OracleConnection or
- * to a connection pool implementation type. Use a corresponding
- * {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor}
- * or JDBC 4's {@link Connection#unwrap} to retrieve the native JDBC Connection.
+ * lazy fetching of an actual JDBC Connection. Use {@link Connection#unwrap}
+ * to retrieve the native JDBC Connection.
*
* @author Juergen Hoeller
* @since 1.1.4
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java
index 9d1411e906a..b7bd8df0df2 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/SingleConnectionDataSource.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2013 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -39,9 +39,6 @@ import org.springframework.util.ObjectUtils;
* If client code will call {@code close()} in the assumption of a pooled
* Connection, like when using persistence tools, set "suppressClose" to "true".
* This will return a close-suppressing proxy instead of the physical Connection.
- * Be aware that you will not be able to cast this to a native
- * {@code OracleConnection} or the like anymore; you need to use a
- * {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor} then.
*
* This is primarily intended for testing. For example, it enables easy testing
* outside an application server, for code that expects to work on a DataSource.
@@ -53,10 +50,8 @@ import org.springframework.util.ObjectUtils;
* @see #getConnection()
* @see java.sql.Connection#close()
* @see DataSourceUtils#releaseConnection
- * @see org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor
*/
-public class SingleConnectionDataSource extends DriverManagerDataSource
- implements SmartDataSource, DisposableBean {
+public class SingleConnectionDataSource extends DriverManagerDataSource implements SmartDataSource, DisposableBean {
/** Create a close-suppressing proxy? */
private boolean suppressClose;
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java
index 4898699a9da..f90b9bdb42f 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/datasource/TransactionAwareDataSourceProxy.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -61,13 +61,9 @@ import org.springframework.util.Assert;
* that all operations performed through standard JDBC will automatically participate
* in Spring-managed transaction timeouts.
*
- * NOTE: This DataSource proxy needs to return wrapped Connections
- * (which implement the {@link ConnectionProxy} interface) in order to handle
- * close calls properly. Therefore, the returned Connections cannot be cast
- * to a native JDBC Connection type such as OracleConnection or to a connection
- * pool implementation type. Use a corresponding
- * {@link org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor}
- * or JDBC 4's {@link Connection#unwrap} to retrieve the native JDBC Connection.
+ * NOTE: This DataSource proxy needs to return wrapped Connections (which
+ * implement the {@link ConnectionProxy} interface) in order to handle close calls
+ * properly. Use {@link Connection#unwrap} to retrieve the native JDBC Connection.
*
* @author Juergen Hoeller
* @since 1.1
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java
index ee70d608d34..6420802d3ff 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlCall.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -157,7 +157,6 @@ public abstract class SqlCall extends RdbmsOperation {
this.callableStatementFactory = new CallableStatementCreatorFactory(getCallString(), getDeclaredParameters());
this.callableStatementFactory.setResultSetType(getResultSetType());
this.callableStatementFactory.setUpdatableResults(isUpdatableResults());
- this.callableStatementFactory.setNativeJdbcExtractor(getJdbcTemplate().getNativeJdbcExtractor());
onCompileInternal();
}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlOperation.java b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlOperation.java
index 2f9cc053ce1..bc85ae180b8 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlOperation.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/object/SqlOperation.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2012 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -60,7 +60,6 @@ public abstract class SqlOperation extends RdbmsOperation {
if (getGeneratedKeysColumnNames() != null) {
this.preparedStatementFactory.setGeneratedKeysColumnNames(getGeneratedKeysColumnNames());
}
- this.preparedStatementFactory.setNativeJdbcExtractor(getJdbcTemplate().getNativeJdbcExtractor());
onCompileInternal();
}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java
index ef7c972ed82..890013176fd 100644
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java
+++ b/spring-jdbc/src/main/java/org/springframework/jdbc/support/JdbcUtils.java
@@ -412,7 +412,7 @@ public abstract class JdbcUtils {
/**
* Extract a common name for the database in use even if various drivers/platforms provide varying names.
- * @param source the name as provided in database metedata
+ * @param source the name as provided in database metadata
* @return the common name to be used
*/
public static String commonDatabaseName(String source) {
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/C3P0NativeJdbcExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/C3P0NativeJdbcExtractor.java
deleted file mode 100644
index d109506b4ee..00000000000
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/C3P0NativeJdbcExtractor.java
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.jdbc.support.nativejdbc;
-
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import com.mchange.v2.c3p0.C3P0ProxyConnection;
-
-import org.springframework.util.ReflectionUtils;
-
-/**
- * Implementation of the {@link NativeJdbcExtractor} interface for the
- * C3P0 connection pool.
- *
- * Returns underlying native Connections to application code instead of C3P0's
- * wrapper implementations; unwraps the Connection for native Statements.
- * The returned JDBC classes can then safely be cast, e.g. to
- * {@code oracle.jdbc.OracleConnection}.
- *
- * This NativeJdbcExtractor can be set just to allow working with
- * a C3P0 DataSource: If a given object is not a C3P0 wrapper, it will be
- * returned as-is.
- *
- * Note that this class requires C3P0 0.8.5 or later; for earlier C3P0 versions,
- * use SimpleNativeJdbcExtractor (which won't work for C3P0 0.8.5 or later).
- *
- * @author Juergen Hoeller
- * @since 1.1.5
- * @see com.mchange.v2.c3p0.C3P0ProxyConnection#rawConnectionOperation
- * @see SimpleNativeJdbcExtractor
- */
-public class C3P0NativeJdbcExtractor extends NativeJdbcExtractorAdapter {
-
- private final Method getRawConnectionMethod;
-
-
- /**
- * This method is not meant to be used directly; it rather serves
- * as callback method for C3P0's "rawConnectionOperation" API.
- * @param con a native Connection handle
- * @return the native Connection handle, as-is
- */
- public static Connection getRawConnection(Connection con) {
- return con;
- }
-
-
- public C3P0NativeJdbcExtractor() {
- try {
- this.getRawConnectionMethod = getClass().getMethod("getRawConnection", new Class>[] {Connection.class});
- }
- catch (NoSuchMethodException ex) {
- throw new IllegalStateException("Internal error in C3P0NativeJdbcExtractor: " + ex.getMessage());
- }
- }
-
-
- @Override
- public boolean isNativeConnectionNecessaryForNativeStatements() {
- return true;
- }
-
- @Override
- public boolean isNativeConnectionNecessaryForNativePreparedStatements() {
- return true;
- }
-
- @Override
- public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
- return true;
- }
-
- /**
- * Retrieve the Connection via C3P0's {@code rawConnectionOperation} API,
- * using the {@code getRawConnection} as callback to get access to the
- * raw Connection (which is otherwise not directly supported by C3P0).
- * @see #getRawConnection
- */
- @Override
- protected Connection doGetNativeConnection(Connection con) throws SQLException {
- if (con instanceof C3P0ProxyConnection) {
- C3P0ProxyConnection cpCon = (C3P0ProxyConnection) con;
- try {
- return (Connection) cpCon.rawConnectionOperation(
- this.getRawConnectionMethod, null, new Object[] {C3P0ProxyConnection.RAW_CONNECTION});
- }
- catch (SQLException ex) {
- throw ex;
- }
- catch (Exception ex) {
- ReflectionUtils.handleReflectionException(ex);
- }
- }
- return con;
- }
-
-}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/JBossNativeJdbcExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/JBossNativeJdbcExtractor.java
deleted file mode 100644
index e85a1efedfc..00000000000
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/JBossNativeJdbcExtractor.java
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.jdbc.support.nativejdbc;
-
-import java.lang.reflect.Method;
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.springframework.util.ReflectionUtils;
-
-/**
- * Implementation of the {@link NativeJdbcExtractor} interface for JBoss,
- * supporting JBoss Application Server 3.2.4+. As of Spring 3.1.1, it also
- * supports JBoss 7.
- *
- * Returns the underlying native Connection, Statement, etc to
- * application code instead of JBoss' wrapper implementations.
- * The returned JDBC classes can then safely be cast, e.g. to
- * {@code oracle.jdbc.OracleConnection}.
- *
- * This NativeJdbcExtractor can be set just to allow working with
- * a JBoss connection pool: If a given object is not a JBoss wrapper,
- * it will be returned as-is.
- *
- * @author Juergen Hoeller
- * @since 03.01.2004
- * @see org.jboss.resource.adapter.jdbc.WrappedConnection#getUnderlyingConnection
- * @see org.jboss.resource.adapter.jdbc.WrappedStatement#getUnderlyingStatement
- * @see org.jboss.resource.adapter.jdbc.WrappedResultSet#getUnderlyingResultSet
- */
-public class JBossNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
-
- // JBoss 7
- private static final String JBOSS_JCA_PREFIX = "org.jboss.jca.adapters.jdbc.";
-
- // JBoss <= 6
- private static final String JBOSS_RESOURCE_PREFIX = "org.jboss.resource.adapter.jdbc.";
-
-
- private Class> wrappedConnectionClass;
-
- private Class> wrappedStatementClass;
-
- private Class> wrappedResultSetClass;
-
- private Method getUnderlyingConnectionMethod;
-
- private Method getUnderlyingStatementMethod;
-
- private Method getUnderlyingResultSetMethod;
-
-
- /**
- * This constructor retrieves JBoss JDBC wrapper classes,
- * so we can get the underlying vendor connection using reflection.
- */
- public JBossNativeJdbcExtractor() {
- String prefix = JBOSS_JCA_PREFIX;
- try {
- // trying JBoss 7 jca package first...
- this.wrappedConnectionClass = getClass().getClassLoader().loadClass(prefix + "WrappedConnection");
- }
- catch (ClassNotFoundException ex) {
- // JBoss 7 jca package not found -> try traditional resource package.
- prefix = JBOSS_RESOURCE_PREFIX;
- try {
- this.wrappedConnectionClass = getClass().getClassLoader().loadClass(prefix + "WrappedConnection");
- }
- catch (ClassNotFoundException ex2) {
- throw new IllegalStateException("Could not initialize JBossNativeJdbcExtractor: neither JBoss 7's [" +
- JBOSS_JCA_PREFIX + ".WrappedConnection] nor traditional JBoss [" + JBOSS_RESOURCE_PREFIX +
- ".WrappedConnection] found");
- }
- }
- try {
- this.wrappedStatementClass = getClass().getClassLoader().loadClass(prefix + "WrappedStatement");
- this.wrappedResultSetClass = getClass().getClassLoader().loadClass(prefix + "WrappedResultSet");
- this.getUnderlyingConnectionMethod =
- this.wrappedConnectionClass.getMethod("getUnderlyingConnection", (Class[]) null);
- this.getUnderlyingStatementMethod =
- this.wrappedStatementClass.getMethod("getUnderlyingStatement", (Class[]) null);
- this.getUnderlyingResultSetMethod =
- this.wrappedResultSetClass.getMethod("getUnderlyingResultSet", (Class[]) null);
- }
- catch (Exception ex) {
- throw new IllegalStateException(
- "Could not initialize JBossNativeJdbcExtractor because of missing JBoss API methods/classes: " + ex);
- }
- }
-
-
- /**
- * Retrieve the Connection via JBoss' {@code getUnderlyingConnection} method.
- */
- @Override
- protected Connection doGetNativeConnection(Connection con) throws SQLException {
- if (this.wrappedConnectionClass.isAssignableFrom(con.getClass())) {
- return (Connection) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingConnectionMethod, con);
- }
- return con;
- }
-
- /**
- * Retrieve the Connection via JBoss' {@code getUnderlyingStatement} method.
- */
- @Override
- public Statement getNativeStatement(Statement stmt) throws SQLException {
- if (this.wrappedStatementClass.isAssignableFrom(stmt.getClass())) {
- return (Statement) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingStatementMethod, stmt);
- }
- return stmt;
- }
-
- /**
- * Retrieve the Connection via JBoss' {@code getUnderlyingStatement} method.
- */
- @Override
- public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException {
- return (PreparedStatement) getNativeStatement(ps);
- }
-
- /**
- * Retrieve the Connection via JBoss' {@code getUnderlyingStatement} method.
- */
- @Override
- public CallableStatement getNativeCallableStatement(CallableStatement cs) throws SQLException {
- return (CallableStatement) getNativeStatement(cs);
- }
-
- /**
- * Retrieve the Connection via JBoss' {@code getUnderlyingResultSet} method.
- */
- @Override
- public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
- if (this.wrappedResultSetClass.isAssignableFrom(rs.getClass())) {
- return (ResultSet) ReflectionUtils.invokeJdbcMethod(this.getUnderlyingResultSetMethod, rs);
- }
- return rs;
- }
-
-}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/Jdbc4NativeJdbcExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/Jdbc4NativeJdbcExtractor.java
deleted file mode 100644
index b4d34a93640..00000000000
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/Jdbc4NativeJdbcExtractor.java
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.jdbc.support.nativejdbc;
-
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-/**
- * {@link NativeJdbcExtractor} implementation that delegates to JDBC 4.0's
- * {@code unwrap} method, as defined by {@link java.sql.Wrapper}.
- * You will typically need to specify a vendor {@link #setConnectionType Connection type}
- * / {@link #setStatementType Statement type} / {@link #setResultSetType ResultSet type}
- * to extract, since JDBC 4.0 only actually unwraps to a given target type.
- *
- * Note: Only use this when actually running against a JDBC 4.0 driver, with a
- * connection pool that supports the JDBC 4.0 API (i.e. at least accepts JDBC 4.0
- * API calls and passes them through to the underlying driver)! Other than that,
- * there is no need for connection pool specific setup. As of JDBC 4.0,
- * NativeJdbcExtractors will typically be implemented for specific drivers
- * instead of for specific pools (e.g. {@link OracleJdbc4NativeJdbcExtractor}).
- *
- * @author Juergen Hoeller
- * @since 2.5
- * @see java.sql.Wrapper#unwrap
- * @see SimpleNativeJdbcExtractor
- * @see org.springframework.jdbc.core.JdbcTemplate#setNativeJdbcExtractor
- */
-public class Jdbc4NativeJdbcExtractor extends NativeJdbcExtractorAdapter {
-
- private Class extends Connection> connectionType = Connection.class;
-
- private Class extends Statement> statementType = Statement.class;
-
- private Class extends PreparedStatement> preparedStatementType = PreparedStatement.class;
-
- private Class extends CallableStatement> callableStatementType = CallableStatement.class;
-
- private Class extends ResultSet> resultSetType = ResultSet.class;
-
-
- /**
- * Set the vendor's Connection type, e.g. {@code oracle.jdbc.OracleConnection}.
- */
- public void setConnectionType(Class extends Connection> connectionType) {
- this.connectionType = connectionType;
- }
-
- /**
- * Set the vendor's Statement type, e.g. {@code oracle.jdbc.OracleStatement}.
- */
- public void setStatementType(Class extends Statement> statementType) {
- this.statementType = statementType;
- }
-
- /**
- * Set the vendor's PreparedStatement type, e.g. {@code oracle.jdbc.OraclePreparedStatement}.
- */
- public void setPreparedStatementType(Class extends PreparedStatement> preparedStatementType) {
- this.preparedStatementType = preparedStatementType;
- }
-
- /**
- * Set the vendor's CallableStatement type, e.g. {@code oracle.jdbc.OracleCallableStatement}.
- */
- public void setCallableStatementType(Class extends CallableStatement> callableStatementType) {
- this.callableStatementType = callableStatementType;
- }
-
- /**
- * Set the vendor's ResultSet type, e.g. {@code oracle.jdbc.OracleResultSet}.
- */
- public void setResultSetType(Class extends ResultSet> resultSetType) {
- this.resultSetType = resultSetType;
- }
-
-
- @Override
- protected Connection doGetNativeConnection(Connection con) throws SQLException {
- return con.unwrap(this.connectionType);
- }
-
- @Override
- public Statement getNativeStatement(Statement stmt) throws SQLException {
- return stmt.unwrap(this.statementType);
- }
-
- @Override
- public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException {
- return ps.unwrap(this.preparedStatementType);
- }
-
- @Override
- public CallableStatement getNativeCallableStatement(CallableStatement cs) throws SQLException {
- return cs.unwrap(this.callableStatementType);
- }
-
- @Override
- public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
- return rs.unwrap(this.resultSetType);
- }
-
-}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractor.java
deleted file mode 100644
index fef6c7bb9c6..00000000000
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractor.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.jdbc.support.nativejdbc;
-
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-/**
- * Interface for extracting native JDBC objects from wrapped objects coming from
- * connection pools. This is necessary to allow for casting to native implementations
- * like {@code OracleConnection} or {@code OracleResultSet} in application
- * code, for example to create Blobs or to access vendor-specific features.
- *
- * Note: Setting a custom {@code NativeJdbcExtractor} is just necessary
- * if you intend to cast to database-specific implementations like
- * {@code OracleConnection} or {@code OracleResultSet}.
- * Otherwise, any wrapped JDBC object will be fine, with no need for unwrapping.
- *
- * Note: To be able to support any pool's strategy of native ResultSet wrapping,
- * it is advisable to get both the native Statement and the native ResultSet
- * via this extractor. Some pools just allow to unwrap the Statement, some just to
- * unwrap the ResultSet - the above strategy will cover both. It is typically
- * not necessary to unwrap the Connection to retrieve a native ResultSet.
- *
- * When working with a simple connection pool that wraps Connections but not
- * Statements, a {@link SimpleNativeJdbcExtractor} is often sufficient.
- *
- * {@link org.springframework.jdbc.core.JdbcTemplate} can properly apply a
- * {@code NativeJdbcExtractor} if specified, unwrapping all JDBC objects
- * that it creates. Note that this is just necessary if you intend to cast to
- * native implementations in your data access code.
- *
- * @author Juergen Hoeller
- * @since 25.08.2003
- * @see SimpleNativeJdbcExtractor
- * @see org.springframework.jdbc.core.JdbcTemplate#setNativeJdbcExtractor
- */
-public interface NativeJdbcExtractor {
-
- /**
- * Return whether it is necessary to work on the native Connection to
- * receive native Statements.
- * This should be true if the connection pool does not allow to extract
- * the native JDBC objects from its Statement wrapper but supports a way
- * to retrieve the native JDBC Connection. This way, applications can
- * still receive native Statements and ResultSet via working on the
- * native JDBC Connection.
- */
- boolean isNativeConnectionNecessaryForNativeStatements();
-
- /**
- * Return whether it is necessary to work on the native Connection to
- * receive native PreparedStatements.
- * This should be true if the connection pool does not allow to extract
- * the native JDBC objects from its PreparedStatement wrappers but
- * supports a way to retrieve the native JDBC Connection. This way,
- * applications can still receive native Statements and ResultSet via
- * working on the native JDBC Connection.
- */
- boolean isNativeConnectionNecessaryForNativePreparedStatements();
-
- /**
- * Return whether it is necessary to work on the native Connection to
- * receive native CallableStatements.
- * This should be true if the connection pool does not allow to extract
- * the native JDBC objects from its CallableStatement wrappers but
- * supports a way to retrieve the native JDBC Connection. This way,
- * applications can still receive native Statements and ResultSet via
- * working on the native JDBC Connection.
- */
- boolean isNativeConnectionNecessaryForNativeCallableStatements();
-
- /**
- * Retrieve the underlying native JDBC Connection for the given Connection.
- * Supposed to return the given Connection if not capable of unwrapping.
- * @param con the Connection handle, potentially wrapped by a connection pool
- * @return the underlying native JDBC Connection, if possible;
- * else, the original Connection
- * @throws SQLException if thrown by JDBC methods
- */
- Connection getNativeConnection(Connection con) throws SQLException;
-
- /**
- * Retrieve the underlying native JDBC Connection for the given Statement.
- * Supposed to return the {@code Statement.getConnection()} if not
- * capable of unwrapping.
- * Having this extra method allows for more efficient unwrapping if data
- * access code already has a Statement. {@code Statement.getConnection()}
- * often returns the native JDBC Connection even if the Statement itself
- * is wrapped by a pool.
- * @param stmt the Statement handle, potentially wrapped by a connection pool
- * @return the underlying native JDBC Connection, if possible;
- * else, the original Connection
- * @throws SQLException if thrown by JDBC methods
- * @see java.sql.Statement#getConnection()
- */
- Connection getNativeConnectionFromStatement(Statement stmt) throws SQLException;
-
- /**
- * Retrieve the underlying native JDBC Statement for the given Statement.
- * Supposed to return the given Statement if not capable of unwrapping.
- * @param stmt the Statement handle, potentially wrapped by a connection pool
- * @return the underlying native JDBC Statement, if possible;
- * else, the original Statement
- * @throws SQLException if thrown by JDBC methods
- */
- Statement getNativeStatement(Statement stmt) throws SQLException;
-
- /**
- * Retrieve the underlying native JDBC PreparedStatement for the given statement.
- * Supposed to return the given PreparedStatement if not capable of unwrapping.
- * @param ps the PreparedStatement handle, potentially wrapped by a connection pool
- * @return the underlying native JDBC PreparedStatement, if possible;
- * else, the original PreparedStatement
- * @throws SQLException if thrown by JDBC methods
- */
- PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException;
-
- /**
- * Retrieve the underlying native JDBC CallableStatement for the given statement.
- * Supposed to return the given CallableStatement if not capable of unwrapping.
- * @param cs the CallableStatement handle, potentially wrapped by a connection pool
- * @return the underlying native JDBC CallableStatement, if possible;
- * else, the original CallableStatement
- * @throws SQLException if thrown by JDBC methods
- */
- CallableStatement getNativeCallableStatement(CallableStatement cs) throws SQLException;
-
- /**
- * Retrieve the underlying native JDBC ResultSet for the given statement.
- * Supposed to return the given ResultSet if not capable of unwrapping.
- * @param rs the ResultSet handle, potentially wrapped by a connection pool
- * @return the underlying native JDBC ResultSet, if possible;
- * else, the original ResultSet
- * @throws SQLException if thrown by JDBC methods
- */
- ResultSet getNativeResultSet(ResultSet rs) throws SQLException;
-
-}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractorAdapter.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractorAdapter.java
deleted file mode 100644
index 60d859b7153..00000000000
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/NativeJdbcExtractorAdapter.java
+++ /dev/null
@@ -1,175 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.jdbc.support.nativejdbc;
-
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.DatabaseMetaData;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-
-import org.springframework.jdbc.datasource.DataSourceUtils;
-
-/**
- * Abstract adapter class for the {@link NativeJdbcExtractor} interface,
- * for simplified implementation of basic extractors.
- * Basically returns the passed-in JDBC objects on all methods.
- *
- * {@code getNativeConnection} checks for a ConnectionProxy chain,
- * for example from a TransactionAwareDataSourceProxy, before delegating to
- * {@code doGetNativeConnection} for actual unwrapping. You can override
- * either of the two for a specific connection pool, but the latter is
- * recommended to participate in ConnectionProxy unwrapping.
- *
- * {@code getNativeConnection} also applies a fallback if the first
- * native extraction process failed, that is, returned the same Connection as
- * passed in. It assumes that some additional proxying is going in this case:
- * Hence, it retrieves the underlying native Connection from the DatabaseMetaData
- * via {@code conHandle.getMetaData().getConnection()} and retries the native
- * extraction process based on that Connection handle. This works, for example,
- * for the Connection proxies exposed by Hibernate 3.1's {@code Session.connection()}.
- *
- * The {@code getNativeConnectionFromStatement} method is implemented
- * to simply delegate to {@code getNativeConnection} with the Statement's
- * Connection. This is what most extractor implementations will stick to,
- * unless there's a more efficient version for a specific pool.
- *
- * @author Juergen Hoeller
- * @since 1.1
- * @see #getNativeConnection
- * @see #getNativeConnectionFromStatement
- * @see org.springframework.jdbc.datasource.ConnectionProxy
- */
-public abstract class NativeJdbcExtractorAdapter implements NativeJdbcExtractor {
-
- /**
- * Return {@code false} by default.
- */
- @Override
- public boolean isNativeConnectionNecessaryForNativeStatements() {
- return false;
- }
-
- /**
- * Return {@code false} by default.
- */
- @Override
- public boolean isNativeConnectionNecessaryForNativePreparedStatements() {
- return false;
- }
-
- /**
- * Return {@code false} by default.
- */
- @Override
- public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
- return false;
- }
-
- /**
- * Check for a ConnectionProxy chain, then delegate to doGetNativeConnection.
- * ConnectionProxy is used by Spring's TransactionAwareDataSourceProxy
- * and LazyConnectionDataSourceProxy. The target connection behind it is
- * typically one from a local connection pool, to be unwrapped by the
- * doGetNativeConnection implementation of a concrete subclass.
- * @see #doGetNativeConnection
- * @see org.springframework.jdbc.datasource.ConnectionProxy
- * @see org.springframework.jdbc.datasource.DataSourceUtils#getTargetConnection
- * @see org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy
- * @see org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy
- */
- @Override
- public Connection getNativeConnection(Connection con) throws SQLException {
- if (con == null) {
- return null;
- }
- Connection targetCon = DataSourceUtils.getTargetConnection(con);
- Connection nativeCon = doGetNativeConnection(targetCon);
- if (nativeCon == targetCon) {
- // We haven't received a different Connection, so we'll assume that there's
- // some additional proxying going on. Let's check whether we get something
- // different back from the DatabaseMetaData.getConnection() call.
- DatabaseMetaData metaData = targetCon.getMetaData();
- // The following check is only really there for mock Connections
- // which might not carry a DatabaseMetaData instance.
- if (metaData != null) {
- Connection metaCon = metaData.getConnection();
- if (metaCon != null && metaCon != targetCon) {
- // We've received a different Connection there:
- // Let's retry the native extraction process with it.
- nativeCon = doGetNativeConnection(metaCon);
- }
- }
- }
- return nativeCon;
- }
-
- /**
- * Not able to unwrap: return passed-in Connection.
- */
- protected Connection doGetNativeConnection(Connection con) throws SQLException {
- return con;
- }
-
- /**
- * Retrieve the Connection via the Statement's Connection.
- * @see #getNativeConnection
- * @see Statement#getConnection
- */
- @Override
- public Connection getNativeConnectionFromStatement(Statement stmt) throws SQLException {
- if (stmt == null) {
- return null;
- }
- return getNativeConnection(stmt.getConnection());
- }
-
- /**
- * Not able to unwrap: return passed-in Statement.
- */
- @Override
- public Statement getNativeStatement(Statement stmt) throws SQLException {
- return stmt;
- }
-
- /**
- * Not able to unwrap: return passed-in PreparedStatement.
- */
- @Override
- public PreparedStatement getNativePreparedStatement(PreparedStatement ps) throws SQLException {
- return ps;
- }
-
- /**
- * Not able to unwrap: return passed-in CallableStatement.
- */
- @Override
- public CallableStatement getNativeCallableStatement(CallableStatement cs) throws SQLException {
- return cs;
- }
-
- /**
- * Not able to unwrap: return passed-in ResultSet.
- */
- @Override
- public ResultSet getNativeResultSet(ResultSet rs) throws SQLException {
- return rs;
- }
-
-}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/OracleJdbc4NativeJdbcExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/OracleJdbc4NativeJdbcExtractor.java
deleted file mode 100644
index 1446c894360..00000000000
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/OracleJdbc4NativeJdbcExtractor.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2002-2012 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.jdbc.support.nativejdbc;
-
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Statement;
-
-/**
- * A {@link Jdbc4NativeJdbcExtractor} which comes pre-configured for Oracle's JDBC driver,
- * specifying the following vendor-specific API types for unwrapping:
- * Note: This will work with any JDBC 4.0 compliant connection pool, without a need for
- * connection pool specific setup. In other words, as of JDBC 4.0, NativeJdbcExtractors
- * will typically be implemented for specific drivers instead of for specific pools.
- *
- * @author Juergen Hoeller
- * @since 3.0.5
- */
-public class OracleJdbc4NativeJdbcExtractor extends Jdbc4NativeJdbcExtractor {
-
- @SuppressWarnings("unchecked")
- public OracleJdbc4NativeJdbcExtractor() {
- try {
- setConnectionType((Class This extractor should work with any pool that does not wrap DatabaseMetaData,
- * and will also work with any plain JDBC driver. Note that a pool can still wrap
- * Statements, PreparedStatements, etc: The only requirement of this extractor is
- * that {@code java.sql.DatabaseMetaData} does not get wrapped, returning the
- * native Connection of the JDBC driver on {@code metaData.getConnection()}.
- *
- * Customize this extractor by setting the "nativeConnectionNecessaryForXxx"
- * flags accordingly: If Statements, PreparedStatements, and/or CallableStatements
- * are wrapped by your pool, set the corresponding "nativeConnectionNecessaryForXxx"
- * flags to "true". If none of the statement types is wrapped - or you solely need
- * Connection unwrapping in the first place -, the defaults are fine.
- *
- * For full usage with JdbcTemplate, i.e. to also provide Statement unwrapping:
- * This makes sense if you need to work with native Statements from
- * a pool that does not allow to extract the native JDBC objects from its
- * wrappers but returns the native Connection on DatabaseMetaData.getConnection.
- * The standard SimpleNativeJdbcExtractor is unable to unwrap statements,
- * so set this to true if your connection pool wraps Statements.
- * @see java.sql.Connection#createStatement
- * @see java.sql.DatabaseMetaData#getConnection
- */
- public void setNativeConnectionNecessaryForNativeStatements(boolean nativeConnectionNecessaryForNativeStatements) {
- this.nativeConnectionNecessaryForNativeStatements = nativeConnectionNecessaryForNativeStatements;
- }
-
- @Override
- public boolean isNativeConnectionNecessaryForNativeStatements() {
- return this.nativeConnectionNecessaryForNativeStatements;
- }
-
- /**
- * Set whether it is necessary to work on the native Connection to
- * receive native PreparedStatements. Default is "false". If true,
- * the Connection will be unwrapped first to create a PreparedStatement.
- * This makes sense if you need to work with native PreparedStatements from
- * a pool that does not allow to extract the native JDBC objects from its
- * wrappers but returns the native Connection on Statement.getConnection.
- * The standard SimpleNativeJdbcExtractor is unable to unwrap statements,
- * so set this to true if your connection pool wraps PreparedStatements.
- * @see java.sql.Connection#prepareStatement
- * @see java.sql.DatabaseMetaData#getConnection
- */
- public void setNativeConnectionNecessaryForNativePreparedStatements(boolean nativeConnectionNecessary) {
- this.nativeConnectionNecessaryForNativePreparedStatements = nativeConnectionNecessary;
- }
-
- @Override
- public boolean isNativeConnectionNecessaryForNativePreparedStatements() {
- return this.nativeConnectionNecessaryForNativePreparedStatements;
- }
-
- /**
- * Set whether it is necessary to work on the native Connection to
- * receive native CallableStatements. Default is "false". If true,
- * the Connection will be unwrapped first to create a CallableStatement.
- * This makes sense if you need to work with native CallableStatements from
- * a pool that does not allow to extract the native JDBC objects from its
- * wrappers but returns the native Connection on Statement.getConnection.
- * The standard SimpleNativeJdbcExtractor is unable to unwrap statements,
- * so set this to true if your connection pool wraps CallableStatements.
- * @see java.sql.Connection#prepareCall
- * @see java.sql.DatabaseMetaData#getConnection
- */
- public void setNativeConnectionNecessaryForNativeCallableStatements(boolean nativeConnectionNecessary) {
- this.nativeConnectionNecessaryForNativeCallableStatements = nativeConnectionNecessary;
- }
-
- @Override
- public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
- return this.nativeConnectionNecessaryForNativeCallableStatements;
- }
-
-}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/WebLogicNativeJdbcExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/WebLogicNativeJdbcExtractor.java
deleted file mode 100644
index aa77ddca68a..00000000000
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/WebLogicNativeJdbcExtractor.java
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Copyright 2002-2013 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.jdbc.support.nativejdbc;
-
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import org.springframework.util.ReflectionUtils;
-
-/**
- * Implementation of the {@link NativeJdbcExtractor} interface for WebLogic,
- * supporting WebLogic Server 9.0 and higher.
- *
- * Returns the underlying native Connection to application code instead
- * of WebLogic's wrapper implementation; unwraps the Connection for native
- * statements. The returned JDBC classes can then safely be cast, e.g. to
- * {@code oracle.jdbc.OracleConnection}.
- *
- * This NativeJdbcExtractor can be set just to allow working
- * with a WebLogic DataSource: If a given object is not a WebLogic
- * Connection wrapper, it will be returned as-is.
- *
- * @author Thomas Risberg
- * @author Juergen Hoeller
- * @since 1.0.2
- * @see #getNativeConnection
- * @see weblogic.jdbc.extensions.WLConnection#getVendorConnection
- */
-public class WebLogicNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
-
- private static final String JDBC_EXTENSION_NAME = "weblogic.jdbc.extensions.WLConnection";
-
-
- private final Class> jdbcExtensionClass;
-
- private final Method getVendorConnectionMethod;
-
-
- /**
- * This constructor retrieves the WebLogic JDBC extension interface,
- * so we can get the underlying vendor connection using reflection.
- */
- public WebLogicNativeJdbcExtractor() {
- try {
- this.jdbcExtensionClass = getClass().getClassLoader().loadClass(JDBC_EXTENSION_NAME);
- this.getVendorConnectionMethod = this.jdbcExtensionClass.getMethod("getVendorConnection", (Class[]) null);
- }
- catch (Exception ex) {
- throw new IllegalStateException(
- "Could not initialize WebLogicNativeJdbcExtractor because WebLogic API classes are not available: " + ex);
- }
- }
-
-
- /**
- * Return {@code true}, as WebLogic returns wrapped Statements.
- */
- @Override
- public boolean isNativeConnectionNecessaryForNativeStatements() {
- return true;
- }
-
- /**
- * Return {@code true}, as WebLogic returns wrapped PreparedStatements.
- */
- @Override
- public boolean isNativeConnectionNecessaryForNativePreparedStatements() {
- return true;
- }
-
- /**
- * Return {@code true}, as WebLogic returns wrapped CallableStatements.
- */
- @Override
- public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
- return true;
- }
-
- /**
- * Retrieve the Connection via WebLogic's {@code getVendorConnection} method.
- */
- @Override
- protected Connection doGetNativeConnection(Connection con) throws SQLException {
- if (this.jdbcExtensionClass.isAssignableFrom(con.getClass())) {
- return (Connection) ReflectionUtils.invokeJdbcMethod(this.getVendorConnectionMethod, con);
- }
- return con;
- }
-
-}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/WebSphereNativeJdbcExtractor.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/WebSphereNativeJdbcExtractor.java
deleted file mode 100644
index 55e818d3818..00000000000
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/WebSphereNativeJdbcExtractor.java
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * Copyright 2002-2013 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.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.springframework.jdbc.support.nativejdbc;
-
-import java.lang.reflect.Method;
-import java.sql.Connection;
-import java.sql.SQLException;
-
-import org.springframework.util.ReflectionUtils;
-
-/**
- * Implementation of the {@link NativeJdbcExtractor} interface for WebSphere,
- * supporting WebSphere Application Server 6.1 and higher.
- *
- * Returns the underlying native Connection to application code instead
- * of WebSphere's wrapper implementation; unwraps the Connection for
- * native statements. The returned JDBC classes can then safely be cast,
- * e.g. to {@code oracle.jdbc.OracleConnection}.
- *
- * This NativeJdbcExtractor can be set just to allow working
- * with a WebSphere DataSource: If a given object is not a WebSphere
- * Connection wrapper, it will be returned as-is.
- *
- * @author Juergen Hoeller
- * @since 1.1
- */
-public class WebSphereNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
-
- private static final String JDBC_ADAPTER_CONNECTION_NAME = "com.ibm.ws.rsadapter.jdbc.WSJdbcConnection";
-
- private static final String JDBC_ADAPTER_UTIL_NAME = "com.ibm.ws.rsadapter.jdbc.WSJdbcUtil";
-
-
- private Class> webSphereConnectionClass;
-
- private Method webSphereNativeConnectionMethod;
-
-
- /**
- * This constructor retrieves WebSphere JDBC adapter classes,
- * so we can get the underlying vendor connection using reflection.
- */
- public WebSphereNativeJdbcExtractor() {
- try {
- this.webSphereConnectionClass = getClass().getClassLoader().loadClass(JDBC_ADAPTER_CONNECTION_NAME);
- Class> jdbcAdapterUtilClass = getClass().getClassLoader().loadClass(JDBC_ADAPTER_UTIL_NAME);
- this.webSphereNativeConnectionMethod =
- jdbcAdapterUtilClass.getMethod("getNativeConnection", new Class>[] {this.webSphereConnectionClass});
- }
- catch (Exception ex) {
- throw new IllegalStateException(
- "Could not initialize WebSphereNativeJdbcExtractor because WebSphere API classes are not available: " + ex);
- }
- }
-
-
- /**
- * Return {@code true}, as WebSphere returns wrapped Statements.
- */
- @Override
- public boolean isNativeConnectionNecessaryForNativeStatements() {
- return true;
- }
-
- /**
- * Return {@code true}, as WebSphere returns wrapped PreparedStatements.
- */
- @Override
- public boolean isNativeConnectionNecessaryForNativePreparedStatements() {
- return true;
- }
-
- /**
- * Return {@code true}, as WebSphere returns wrapped CallableStatements.
- */
- @Override
- public boolean isNativeConnectionNecessaryForNativeCallableStatements() {
- return true;
- }
-
- /**
- * Retrieve the Connection via WebSphere's {@code getNativeConnection} method.
- */
- @Override
- protected Connection doGetNativeConnection(Connection con) throws SQLException {
- if (this.webSphereConnectionClass.isAssignableFrom(con.getClass())) {
- return (Connection) ReflectionUtils.invokeJdbcMethod(this.webSphereNativeConnectionMethod, null, con);
- }
- return con;
- }
-
-}
diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/package-info.java b/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/package-info.java
deleted file mode 100644
index 172467cb85a..00000000000
--- a/spring-jdbc/src/main/java/org/springframework/jdbc/support/nativejdbc/package-info.java
+++ /dev/null
@@ -1,7 +0,0 @@
-/**
- * Provides a mechanism for extracting native implementations of JDBC
- * interfaces from wrapper objects that got returned from connection pools.
- *
- * Can be used independently, for example in custom JDBC access code.
- */
-package org.springframework.jdbc.support.nativejdbc;
diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java
index b7c38059707..3d1220fcabb 100644
--- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java
+++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/JdbcTemplateTests.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2016 the original author or authors.
+ * Copyright 2002-2017 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.
@@ -48,8 +48,6 @@ import org.springframework.jdbc.core.support.AbstractInterruptibleBatchPreparedS
import org.springframework.jdbc.datasource.SingleConnectionDataSource;
import org.springframework.jdbc.support.SQLErrorCodeSQLExceptionTranslator;
import org.springframework.jdbc.support.SQLStateSQLExceptionTranslator;
-import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
-import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractorAdapter;
import org.springframework.util.LinkedCaseInsensitiveMap;
import static org.hamcrest.Matchers.*;
@@ -295,19 +293,6 @@ public class JdbcTemplateTests {
verify(this.preparedStatement).close();
}
- @Test
- public void testConnectionCallback() throws Exception {
- this.template.setNativeJdbcExtractor(new PlainNativeJdbcExtractor());
- String result = this.template.execute(new ConnectionCallback
- *
- *
- *
- *
- *
- * @author Juergen Hoeller
- * @since 05.12.2003
- * @see #setNativeConnectionNecessaryForNativeStatements
- * @see #setNativeConnectionNecessaryForNativePreparedStatements
- * @see #setNativeConnectionNecessaryForNativeCallableStatements
- * @see Jdbc4NativeJdbcExtractor
- * @see org.springframework.jdbc.core.JdbcTemplate#setNativeJdbcExtractor
- */
-public class SimpleNativeJdbcExtractor extends NativeJdbcExtractorAdapter {
-
- private boolean nativeConnectionNecessaryForNativeStatements = false;
-
- private boolean nativeConnectionNecessaryForNativePreparedStatements = false;
-
- private boolean nativeConnectionNecessaryForNativeCallableStatements = false;
-
-
- /**
- * Set whether it is necessary to work on the native Connection to
- * receive native Statements. Default is "false". If true, the Connection
- * will be unwrapped first to create a Statement.
- *