Skip to content

Commit 07dd61e

Browse files
committed
Drop NativeJdbcExtractor mechanism in favor of JDBC 4 unwrap
Issue: SPR-14670
1 parent 54f01cf commit 07dd61e

36 files changed

+124
-1693
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/core/CallableStatementCreatorFactory.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@
2626
import java.util.Map;
2727

2828
import org.springframework.dao.InvalidDataAccessApiUsageException;
29-
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
3029

3130
/**
3231
* Helper class that efficiently creates multiple {@link CallableStatementCreator}
@@ -49,8 +48,6 @@ public class CallableStatementCreatorFactory {
4948

5049
private boolean updatableResults = false;
5150

52-
private NativeJdbcExtractor nativeJdbcExtractor;
53-
5451

5552
/**
5653
* Create a new factory. Will need to add parameters via the
@@ -100,13 +97,6 @@ public void setUpdatableResults(boolean updatableResults) {
10097
this.updatableResults = updatableResults;
10198
}
10299

103-
/**
104-
* Specify the NativeJdbcExtractor to use for unwrapping CallableStatements, if any.
105-
*/
106-
public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor) {
107-
this.nativeJdbcExtractor = nativeJdbcExtractor;
108-
}
109-
110100

111101
/**
112102
* Return a new CallableStatementCreator instance given this parameters.
@@ -172,12 +162,6 @@ public CallableStatement createCallableStatement(Connection con) throws SQLExcep
172162
updatableResults ? ResultSet.CONCUR_UPDATABLE : ResultSet.CONCUR_READ_ONLY);
173163
}
174164

175-
// Determine CallabeStatement to pass to custom types.
176-
CallableStatement csToUse = cs;
177-
if (nativeJdbcExtractor != null) {
178-
csToUse = nativeJdbcExtractor.getNativeCallableStatement(cs);
179-
}
180-
181165
int sqlColIndx = 1;
182166
for (SqlParameter declaredParam : declaredParameters) {
183167
if (!declaredParam.isResultsParameter()) {
@@ -200,7 +184,7 @@ public CallableStatement createCallableStatement(Connection con) throws SQLExcep
200184
}
201185
}
202186
if (declaredParam.isInputValueProvided()) {
203-
StatementCreatorUtils.setParameterValue(csToUse, sqlColIndx, declaredParam, inValue);
187+
StatementCreatorUtils.setParameterValue(cs, sqlColIndx, declaredParam, inValue);
204188
}
205189
}
206190
}
@@ -210,7 +194,7 @@ public CallableStatement createCallableStatement(Connection con) throws SQLExcep
210194
throw new InvalidDataAccessApiUsageException(
211195
"Required input parameter '" + declaredParam.getName() + "' is missing");
212196
}
213-
StatementCreatorUtils.setParameterValue(csToUse, sqlColIndx, declaredParam, inValue);
197+
StatementCreatorUtils.setParameterValue(cs, sqlColIndx, declaredParam, inValue);
214198
}
215199
sqlColIndx++;
216200
}
@@ -233,10 +217,7 @@ public void cleanupParameters() {
233217

234218
@Override
235219
public String toString() {
236-
StringBuilder sb = new StringBuilder();
237-
sb.append("CallableStatementCreatorFactory.CallableStatementCreatorImpl: sql=[");
238-
sb.append(callString).append("]; parameters=").append(this.inParameters);
239-
return sb.toString();
220+
return "CallableStatementCreator: sql=[" + callString + "]; parameters=" + this.inParameters;
240221
}
241222
}
242223

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 13 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.springframework.jdbc.support.JdbcAccessor;
4747
import org.springframework.jdbc.support.JdbcUtils;
4848
import org.springframework.jdbc.support.KeyHolder;
49-
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
5049
import org.springframework.jdbc.support.rowset.SqlRowSet;
5150
import org.springframework.util.Assert;
5251
import org.springframework.util.LinkedCaseInsensitiveMap;
@@ -104,9 +103,6 @@ public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
104103
private static final String RETURN_UPDATE_COUNT_PREFIX = "#update-count-";
105104

106105

107-
/** Custom NativeJdbcExtractor */
108-
private NativeJdbcExtractor nativeJdbcExtractor;
109-
110106
/** If this variable is false, we will throw exceptions on SQL warnings */
111107
private boolean ignoreWarnings = true;
112108

@@ -182,23 +178,6 @@ public JdbcTemplate(DataSource dataSource, boolean lazyInit) {
182178
}
183179

184180

185-
/**
186-
* Set a NativeJdbcExtractor to extract native JDBC objects from wrapped handles.
187-
* Useful if native Statement and/or ResultSet handles are expected for casting
188-
* to database-specific implementation classes, but a connection pool that wraps
189-
* JDBC objects is used (note: <i>any</i> pool will return wrapped Connections).
190-
*/
191-
public void setNativeJdbcExtractor(NativeJdbcExtractor extractor) {
192-
this.nativeJdbcExtractor = extractor;
193-
}
194-
195-
/**
196-
* Return the current NativeJdbcExtractor implementation.
197-
*/
198-
public NativeJdbcExtractor getNativeJdbcExtractor() {
199-
return this.nativeJdbcExtractor;
200-
}
201-
202181
/**
203182
* Set whether or not we want to ignore SQLWarnings.
204183
* <p>Default is "true", swallowing and logging all warnings. Switch this flag
@@ -341,15 +320,8 @@ public <T> T execute(ConnectionCallback<T> action) throws DataAccessException {
341320

342321
Connection con = DataSourceUtils.getConnection(getDataSource());
343322
try {
344-
Connection conToUse = con;
345-
if (this.nativeJdbcExtractor != null) {
346-
// Extract native JDBC Connection, castable to OracleConnection or the like.
347-
conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
348-
}
349-
else {
350-
// Create close-suppressing Connection proxy, also preparing returned Statements.
351-
conToUse = createConnectionProxy(con);
352-
}
323+
// Create close-suppressing Connection proxy, also preparing returned Statements.
324+
Connection conToUse = createConnectionProxy(con);
353325
return action.doInConnection(conToUse);
354326
}
355327
catch (SQLException ex) {
@@ -394,18 +366,9 @@ public <T> T execute(StatementCallback<T> action) throws DataAccessException {
394366
Connection con = DataSourceUtils.getConnection(getDataSource());
395367
Statement stmt = null;
396368
try {
397-
Connection conToUse = con;
398-
if (this.nativeJdbcExtractor != null &&
399-
this.nativeJdbcExtractor.isNativeConnectionNecessaryForNativeStatements()) {
400-
conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
401-
}
402-
stmt = conToUse.createStatement();
369+
stmt = con.createStatement();
403370
applyStatementSettings(stmt);
404-
Statement stmtToUse = stmt;
405-
if (this.nativeJdbcExtractor != null) {
406-
stmtToUse = this.nativeJdbcExtractor.getNativeStatement(stmt);
407-
}
408-
T result = action.doInStatement(stmtToUse);
371+
T result = action.doInStatement(stmt);
409372
handleWarnings(stmt);
410373
return result;
411374
}
@@ -456,11 +419,7 @@ public T doInStatement(Statement stmt) throws SQLException {
456419
ResultSet rs = null;
457420
try {
458421
rs = stmt.executeQuery(sql);
459-
ResultSet rsToUse = rs;
460-
if (nativeJdbcExtractor != null) {
461-
rsToUse = nativeJdbcExtractor.getNativeResultSet(rs);
462-
}
463-
return rse.extractData(rsToUse);
422+
return rse.extractData(rs);
464423
}
465424
finally {
466425
JdbcUtils.closeResultSet(rs);
@@ -619,18 +578,9 @@ public <T> T execute(PreparedStatementCreator psc, PreparedStatementCallback<T>
619578
Connection con = DataSourceUtils.getConnection(getDataSource());
620579
PreparedStatement ps = null;
621580
try {
622-
Connection conToUse = con;
623-
if (this.nativeJdbcExtractor != null &&
624-
this.nativeJdbcExtractor.isNativeConnectionNecessaryForNativePreparedStatements()) {
625-
conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
626-
}
627-
ps = psc.createPreparedStatement(conToUse);
581+
ps = psc.createPreparedStatement(con);
628582
applyStatementSettings(ps);
629-
PreparedStatement psToUse = ps;
630-
if (this.nativeJdbcExtractor != null) {
631-
psToUse = this.nativeJdbcExtractor.getNativePreparedStatement(ps);
632-
}
633-
T result = action.doInPreparedStatement(psToUse);
583+
T result = action.doInPreparedStatement(ps);
634584
handleWarnings(ps);
635585
return result;
636586
}
@@ -690,11 +640,7 @@ public T doInPreparedStatement(PreparedStatement ps) throws SQLException {
690640
pss.setValues(ps);
691641
}
692642
rs = ps.executeQuery();
693-
ResultSet rsToUse = rs;
694-
if (nativeJdbcExtractor != null) {
695-
rsToUse = nativeJdbcExtractor.getNativeResultSet(rs);
696-
}
697-
return rse.extractData(rsToUse);
643+
return rse.extractData(rs);
698644
}
699645
finally {
700646
JdbcUtils.closeResultSet(rs);
@@ -1070,17 +1016,9 @@ public <T> T execute(CallableStatementCreator csc, CallableStatementCallback<T>
10701016
Connection con = DataSourceUtils.getConnection(getDataSource());
10711017
CallableStatement cs = null;
10721018
try {
1073-
Connection conToUse = con;
1074-
if (this.nativeJdbcExtractor != null) {
1075-
conToUse = this.nativeJdbcExtractor.getNativeConnection(con);
1076-
}
1077-
cs = csc.createCallableStatement(conToUse);
1019+
cs = csc.createCallableStatement(con);
10781020
applyStatementSettings(cs);
1079-
CallableStatement csToUse = cs;
1080-
if (this.nativeJdbcExtractor != null) {
1081-
csToUse = this.nativeJdbcExtractor.getNativeCallableStatement(cs);
1082-
}
1083-
T result = action.doInCallableStatement(csToUse);
1021+
T result = action.doInCallableStatement(cs);
10841022
handleWarnings(cs);
10851023
return result;
10861024
}
@@ -1274,22 +1212,18 @@ protected Map<String, Object> processResultSet(ResultSet rs, ResultSetSupporting
12741212
}
12751213
Map<String, Object> returnedResults = new HashMap<>();
12761214
try {
1277-
ResultSet rsToUse = rs;
1278-
if (this.nativeJdbcExtractor != null) {
1279-
rsToUse = this.nativeJdbcExtractor.getNativeResultSet(rs);
1280-
}
12811215
if (param.getRowMapper() != null) {
12821216
RowMapper rowMapper = param.getRowMapper();
1283-
Object result = (new RowMapperResultSetExtractor(rowMapper)).extractData(rsToUse);
1217+
Object result = (new RowMapperResultSetExtractor(rowMapper)).extractData(rs);
12841218
returnedResults.put(param.getName(), result);
12851219
}
12861220
else if (param.getRowCallbackHandler() != null) {
12871221
RowCallbackHandler rch = param.getRowCallbackHandler();
1288-
(new RowCallbackHandlerResultSetExtractor(rch)).extractData(rsToUse);
1222+
(new RowCallbackHandlerResultSetExtractor(rch)).extractData(rs);
12891223
returnedResults.put(param.getName(), "ResultSet returned from stored procedure was processed");
12901224
}
12911225
else if (param.getResultSetExtractor() != null) {
1292-
Object result = param.getResultSetExtractor().extractData(rsToUse);
1226+
Object result = param.getResultSetExtractor().extractData(rs);
12931227
returnedResults.put(param.getName(), result);
12941228
}
12951229
}

spring-jdbc/src/main/java/org/springframework/jdbc/core/PreparedStatementCreatorFactory.java

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,7 +30,6 @@
3030
import java.util.Set;
3131

3232
import org.springframework.dao.InvalidDataAccessApiUsageException;
33-
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
3433
import org.springframework.util.Assert;
3534

3635
/**
@@ -58,8 +57,6 @@ public class PreparedStatementCreatorFactory {
5857

5958
private String[] generatedKeysColumnNames = null;
6059

61-
private NativeJdbcExtractor nativeJdbcExtractor;
62-
6360

6461
/**
6562
* Create a new factory. Will need to add parameters via the
@@ -133,13 +130,6 @@ public void setGeneratedKeysColumnNames(String... names) {
133130
this.generatedKeysColumnNames = names;
134131
}
135132

136-
/**
137-
* Specify the NativeJdbcExtractor to use for unwrapping PreparedStatements, if any.
138-
*/
139-
public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor) {
140-
this.nativeJdbcExtractor = nativeJdbcExtractor;
141-
}
142-
143133

144134
/**
145135
* Return a new PreparedStatementSetter for the given parameters.
@@ -247,12 +237,6 @@ else if (resultSetType == ResultSet.TYPE_FORWARD_ONLY && !updatableResults) {
247237

248238
@Override
249239
public void setValues(PreparedStatement ps) throws SQLException {
250-
// Determine PreparedStatement to pass to custom types.
251-
PreparedStatement psToUse = ps;
252-
if (nativeJdbcExtractor != null) {
253-
psToUse = nativeJdbcExtractor.getNativePreparedStatement(ps);
254-
}
255-
256240
// Set arguments: Does nothing if there are no parameters.
257241
int sqlColIndx = 1;
258242
for (int i = 0; i < this.parameters.size(); i++) {
@@ -280,16 +264,16 @@ public void setValues(PreparedStatement ps) throws SQLException {
280264
if (entry instanceof Object[]) {
281265
Object[] valueArray = ((Object[])entry);
282266
for (Object argValue : valueArray) {
283-
StatementCreatorUtils.setParameterValue(psToUse, sqlColIndx++, declaredParameter, argValue);
267+
StatementCreatorUtils.setParameterValue(ps, sqlColIndx++, declaredParameter, argValue);
284268
}
285269
}
286270
else {
287-
StatementCreatorUtils.setParameterValue(psToUse, sqlColIndx++, declaredParameter, entry);
271+
StatementCreatorUtils.setParameterValue(ps, sqlColIndx++, declaredParameter, entry);
288272
}
289273
}
290274
}
291275
else {
292-
StatementCreatorUtils.setParameterValue(psToUse, sqlColIndx++, declaredParameter, in);
276+
StatementCreatorUtils.setParameterValue(ps, sqlColIndx++, declaredParameter, in);
293277
}
294278
}
295279
}
@@ -306,10 +290,7 @@ public void cleanupParameters() {
306290

307291
@Override
308292
public String toString() {
309-
StringBuilder sb = new StringBuilder();
310-
sb.append("PreparedStatementCreatorFactory.PreparedStatementCreatorImpl: sql=[");
311-
sb.append(sql).append("]; parameters=").append(this.parameters);
312-
return sb.toString();
293+
return "PreparedStatementCreator: sql=[" + sql + "]; parameters=" + this.parameters;
313294
}
314295
}
315296

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/CallMetaDataProvider.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public interface CallMetaDataProvider {
4545
* This is only called for databases that are supported. This initialization
4646
* can be turned off by specifying that column meta data should not be used.
4747
* @param databaseMetaData used to retrieve database specific information
48-
* @param catalogName name of catalog to use or null
49-
* @param schemaName name of schema name to use or null
48+
* @param catalogName name of catalog to use (or {@code null} if none)
49+
* @param schemaName name of schema name to use (or {@code null} if none)
5050
* @param procedureName name of the stored procedure
5151
* @throws SQLException in case of initialization failure
5252
* @see org.springframework.jdbc.core.simple.SimpleJdbcCall#withoutProcedureColumnMetaDataAccess()

spring-jdbc/src/main/java/org/springframework/jdbc/core/metadata/GenericTableMetaDataProvider.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131

3232
import org.springframework.dao.DataAccessResourceFailureException;
3333
import org.springframework.jdbc.support.JdbcUtils;
34-
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
3534

3635
/**
3736
* A generic implementation of the {@link TableMetaDataProvider} that should provide
@@ -74,13 +73,10 @@ public class GenericTableMetaDataProvider implements TableMetaDataProvider {
7473
/** Collection of TableParameterMetaData objects */
7574
private List<TableParameterMetaData> tableParameterMetaData = new ArrayList<>();
7675

77-
/** NativeJdbcExtractor that can be used to retrieve the native connection */
78-
private NativeJdbcExtractor nativeJdbcExtractor;
79-
8076

8177
/**
82-
* Constructor used to initialize with provided database meta data.
83-
* @param databaseMetaData meta data to be used
78+
* Constructor used to initialize with provided database metadata.
79+
* @param databaseMetaData metadata to be used
8480
*/
8581
protected GenericTableMetaDataProvider(DatabaseMetaData databaseMetaData) throws SQLException {
8682
this.userName = databaseMetaData.getUserName();
@@ -142,15 +138,6 @@ public boolean isGeneratedKeysColumnNameArraySupported() {
142138
return this.generatedKeysColumnNameArraySupported;
143139
}
144140

145-
@Override
146-
public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor) {
147-
this.nativeJdbcExtractor = nativeJdbcExtractor;
148-
}
149-
150-
protected NativeJdbcExtractor getNativeJdbcExtractor() {
151-
return this.nativeJdbcExtractor;
152-
}
153-
154141

155142
@Override
156143
public void initializeWithMetaData(DatabaseMetaData databaseMetaData) throws SQLException {
@@ -308,7 +295,7 @@ protected String getDatabaseVersion() {
308295
}
309296

310297
/**
311-
* Method supporting the metedata processing for a table.
298+
* Method supporting the metadata processing for a table.
312299
*/
313300
private void locateTableAndProcessMetaData(
314301
DatabaseMetaData databaseMetaData, String catalogName, String schemaName, String tableName) {

0 commit comments

Comments
 (0)