Skip to content

Commit 0e7e49b

Browse files
committed
Deprecate TableMetaDataContext.getSimulationQueryForGetGeneratedKey
(cherry picked from commit 2c7efbb)
1 parent 301ba01 commit 0e7e49b

File tree

3 files changed

+50
-38
lines changed

3 files changed

+50
-38
lines changed

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

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor;
3636

3737
/**
38-
* Class to manage context metadata used for the configuration
38+
* Class to manage context meta-data used for the configuration
3939
* and execution of operations on a database table.
4040
*
4141
* @author Thomas Risberg
@@ -59,13 +59,13 @@ public class TableMetaDataContext {
5959
// List of columns objects to be used in this context
6060
private List<String> tableColumns = new ArrayList<String>();
6161

62-
// Should we access insert parameter meta data info or not
62+
// Should we access insert parameter meta-data info or not
6363
private boolean accessTableColumnMetaData = true;
6464

65-
// Should we override default for including synonyms for meta data lookups
65+
// Should we override default for including synonyms for meta-data lookups
6666
private boolean overrideIncludeSynonymsDefault = false;
6767

68-
// The provider of table meta data
68+
// The provider of table meta-data
6969
private TableMetaDataProvider metaDataProvider;
7070

7171
// Are we using generated key columns
@@ -118,14 +118,14 @@ public String getSchemaName() {
118118
}
119119

120120
/**
121-
* Specify whether we should access table column meta data.
121+
* Specify whether we should access table column meta-data.
122122
*/
123123
public void setAccessTableColumnMetaData(boolean accessTableColumnMetaData) {
124124
this.accessTableColumnMetaData = accessTableColumnMetaData;
125125
}
126126

127127
/**
128-
* Are we accessing table meta data?
128+
* Are we accessing table meta-data?
129129
*/
130130
public boolean isAccessTableColumnMetaData() {
131131
return this.accessTableColumnMetaData;
@@ -162,7 +162,7 @@ public void setNativeJdbcExtractor(NativeJdbcExtractor nativeJdbcExtractor) {
162162

163163

164164
/**
165-
* Process the current meta data with the provided configuration options.
165+
* Process the current meta-data with the provided configuration options.
166166
* @param dataSource the DataSource being used
167167
* @param declaredColumns any columns that are declared
168168
* @param generatedKeyNames name of generated keys
@@ -174,7 +174,7 @@ public void processMetaData(DataSource dataSource, List<String> declaredColumns,
174174
}
175175

176176
/**
177-
* Compare columns created from metadata with declared columns and return a reconciled list.
177+
* Compare columns created from meta-data with declared columns and return a reconciled list.
178178
* @param declaredColumns declared column names
179179
* @param generatedKeyNames names of generated key columns
180180
*/
@@ -205,7 +205,7 @@ protected List<String> reconcileColumnsToUse(List<String> declaredColumns, Strin
205205
public List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource) {
206206
List<Object> values = new ArrayList<Object>();
207207
// For parameter source lookups we need to provide case-insensitive lookup support since the
208-
// database metadata is not necessarily providing case-sensitive column names
208+
// database meta-data is not necessarily providing case-sensitive column names
209209
Map<String, String> caseInsensitiveParameterNames =
210210
SqlParameterSourceUtils.extractCaseInsensitiveParameterNames(parameterSource);
211211
for (String column : this.tableColumns) {
@@ -255,7 +255,7 @@ public List<Object> matchInParameterValuesWithInsertColumns(Map<String, ?> inPar
255255

256256

257257
/**
258-
* Build the insert string based on configuration and metadata information
258+
* Build the insert string based on configuration and meta-data information
259259
* @return the insert string to be used
260260
*/
261261
public String createInsertString(String... generatedKeyNames) {
@@ -303,7 +303,7 @@ public String createInsertString(String... generatedKeyNames) {
303303
}
304304

305305
/**
306-
* Build the array of {@link java.sql.Types} based on configuration and metadata information
306+
* Build the array of {@link java.sql.Types} based on configuration and meta-data information.
307307
* @return the array of types to be used
308308
*/
309309
public int[] createInsertTypes() {
@@ -335,7 +335,7 @@ public int[] createInsertTypes() {
335335

336336

337337
/**
338-
* Does this database support the JDBC 3.0 feature of retrieving generated keys
338+
* Does this database support the JDBC 3.0 feature of retrieving generated keys:
339339
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
340340
*/
341341
public boolean isGetGeneratedKeysSupported() {
@@ -344,19 +344,27 @@ public boolean isGetGeneratedKeysSupported() {
344344

345345
/**
346346
* Does this database support simple query to retrieve generated keys
347-
* when the JDBC 3.0 feature is not supported.
347+
* when the JDBC 3.0 feature is not supported:
348348
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
349349
*/
350350
public boolean isGetGeneratedKeysSimulated() {
351351
return this.metaDataProvider.isGetGeneratedKeysSimulated();
352352
}
353353

354354
/**
355-
* Does this database support simple query to retrieve generated keys
356-
* when the JDBC 3.0 feature is not supported.
357-
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
355+
* @deprecated as of 4.3.15, in favor of {@link #getSimpleQueryForGetGeneratedKey}
358356
*/
357+
@Deprecated
359358
public String getSimulationQueryForGetGeneratedKey(String tableName, String keyColumnName) {
359+
return getSimpleQueryForGetGeneratedKey(tableName, keyColumnName);
360+
}
361+
362+
/**
363+
* Does this database support a simple query to retrieve generated keys
364+
* when the JDBC 3.0 feature is not supported:
365+
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
366+
*/
367+
public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
360368
return this.metaDataProvider.getSimpleQueryForGetGeneratedKey(tableName, keyColumnName);
361369
}
362370

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -39,8 +39,9 @@
3939

4040
/**
4141
* Abstract class to provide base functionality for easy stored procedure calls
42-
* based on configuration options and database metadata.
43-
* This class provides the base SPI for {@link SimpleJdbcCall}.
42+
* based on configuration options and database meta-data.
43+
*
44+
* <p>This class provides the base SPI for {@link SimpleJdbcCall}.
4445
*
4546
* @author Thomas Risberg
4647
* @author Juergen Hoeller
@@ -54,7 +55,7 @@ public abstract class AbstractJdbcCall {
5455
/** Lower-level class used to execute SQL */
5556
private final JdbcTemplate jdbcTemplate;
5657

57-
/** Context used to retrieve and manage database metadata */
58+
/** Context used to retrieve and manage database meta-data */
5859
private final CallMetaDataContext callMetaDataContext = new CallMetaDataContext();
5960

6061
/** List of SqlParameter objects */
@@ -208,15 +209,15 @@ public boolean isNamedBinding() {
208209
}
209210

210211
/**
211-
* Specify whether the parameter metadata for the call should be used.
212+
* Specify whether the parameter meta-data for the call should be used.
212213
* The default is {@code true}.
213214
*/
214215
public void setAccessCallParameterMetaData(boolean accessCallParameterMetaData) {
215216
this.callMetaDataContext.setAccessCallParameterMetaData(accessCallParameterMetaData);
216217
}
217218

218219
/**
219-
* Get the call string that should be used based on parameters and meta data.
220+
* Get the call string that should be used based on parameters and meta-data.
220221
*/
221222
public String getCallString() {
222223
return this.callString;
@@ -268,13 +269,13 @@ public void addDeclaredRowMapper(String parameterName, RowMapper<?> rowMapper) {
268269
//-------------------------------------------------------------------------
269270

270271
/**
271-
* Compile this JdbcCall using provided parameters and meta data plus other settings.
272+
* Compile this JdbcCall using provided parameters and meta-data plus other settings.
272273
* <p>This finalizes the configuration for this object and subsequent attempts to compile are
273274
* ignored. This will be implicitly called the first time an un-compiled call is executed.
274275
* @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't
275276
* been correctly initialized, for example if no DataSource has been provided
276277
*/
277-
public synchronized final void compile() throws InvalidDataAccessApiUsageException {
278+
public final synchronized void compile() throws InvalidDataAccessApiUsageException {
278279
if (!isCompiled()) {
279280
if (getProcedureName() == null) {
280281
throw new InvalidDataAccessApiUsageException("Procedure or Function name is required");
@@ -416,15 +417,15 @@ protected String getScalarOutParameterName() {
416417

417418
/**
418419
* Get a List of all the call parameters to be used for call.
419-
* This includes any parameters added based on meta data processing.
420+
* This includes any parameters added based on meta-data processing.
420421
*/
421422
protected List<SqlParameter> getCallParameters() {
422423
return this.callMetaDataContext.getCallParameters();
423424
}
424425

425426
/**
426427
* Match the provided in parameter values with registered parameters and
427-
* parameters defined via metadata processing.
428+
* parameters defined via meta-data processing.
428429
* @param parameterSource the parameter vakues provided as a {@link SqlParameterSource}
429430
* @return Map with parameter names and values
430431
*/
@@ -434,7 +435,7 @@ protected Map<String, Object> matchInParameterValuesWithCallParameters(SqlParame
434435

435436
/**
436437
* Match the provided in parameter values with registered parameters and
437-
* parameters defined via metadata processing.
438+
* parameters defined via meta-data processing.
438439
* @param args the parameter values provided as an array
439440
* @return Map with parameter names and values
440441
*/
@@ -444,7 +445,7 @@ protected Map<String, Object> matchInParameterValuesWithCallParameters(SqlParame
444445

445446
/**
446447
* Match the provided in parameter values with registered parameters and
447-
* parameters defined via metadata processing.
448+
* parameters defined via meta-data processing.
448449
* @param args the parameter values provided in a Map
449450
* @return Map with parameter names and values
450451
*/

spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@
5252

5353
/**
5454
* Abstract class to provide base functionality for easy inserts
55-
* based on configuration options and database metadata.
56-
* This class provides the base SPI for {@link SimpleJdbcInsert}.
55+
* based on configuration options and database meta-data.
56+
*
57+
* <p>This class provides the base SPI for {@link SimpleJdbcInsert}.
5758
*
5859
* @author Thomas Risberg
5960
* @author Juergen Hoeller
@@ -67,7 +68,7 @@ public abstract class AbstractJdbcInsert {
6768
/** Lower-level class used to execute SQL */
6869
private final JdbcTemplate jdbcTemplate;
6970

70-
/** Context used to retrieve and manage database metadata */
71+
/** Context used to retrieve and manage database meta-data */
7172
private final TableMetaDataContext tableMetaDataContext = new TableMetaDataContext();
7273

7374
/** List of columns objects to be used in insert statement */
@@ -204,7 +205,7 @@ public String[] getGeneratedKeyNames() {
204205
}
205206

206207
/**
207-
* Specify whether the parameter metadata for the call should be used.
208+
* Specify whether the parameter meta-data for the call should be used.
208209
* The default is {@code true}.
209210
*/
210211
public void setAccessTableColumnMetaData(boolean accessTableColumnMetaData) {
@@ -246,13 +247,13 @@ public int[] getInsertTypes() {
246247
//-------------------------------------------------------------------------
247248

248249
/**
249-
* Compile this JdbcInsert using provided parameters and meta data plus other settings.
250+
* Compile this JdbcInsert using provided parameters and meta-data plus other settings.
250251
* This finalizes the configuration for this object and subsequent attempts to compile are
251252
* ignored. This will be implicitly called the first time an un-compiled insert is executed.
252253
* @throws InvalidDataAccessApiUsageException if the object hasn't been correctly initialized,
253254
* for example if no DataSource has been provided
254255
*/
255-
public synchronized final void compile() throws InvalidDataAccessApiUsageException {
256+
public final synchronized void compile() throws InvalidDataAccessApiUsageException {
256257
if (!isCompiled()) {
257258
if (getTableName() == null) {
258259
throw new InvalidDataAccessApiUsageException("Table name is required");
@@ -321,7 +322,7 @@ protected void checkCompiled() {
321322
protected void checkIfConfigurationModificationIsAllowed() {
322323
if (isCompiled()) {
323324
throw new InvalidDataAccessApiUsageException(
324-
"Configuration can't be altered once the class has been compiled or used");
325+
"Configuration cannot be altered once the class has been compiled or used");
325326
}
326327
}
327328

@@ -432,6 +433,7 @@ private KeyHolder executeInsertAndReturnKeyHolderInternal(final List<?> values)
432433
logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values);
433434
}
434435
final KeyHolder keyHolder = new GeneratedKeyHolder();
436+
435437
if (this.tableMetaDataContext.isGetGeneratedKeysSupported()) {
436438
getJdbcTemplate().update(
437439
new PreparedStatementCreator() {
@@ -444,6 +446,7 @@ public PreparedStatement createPreparedStatement(Connection con) throws SQLExcep
444446
},
445447
keyHolder);
446448
}
449+
447450
else {
448451
if (!this.tableMetaDataContext.isGetGeneratedKeysSimulated()) {
449452
throw new InvalidDataAccessResourceUsageException(
@@ -459,7 +462,7 @@ public PreparedStatement createPreparedStatement(Connection con) throws SQLExcep
459462
getGeneratedKeyNames().length + " columns specified: " + Arrays.asList(getGeneratedKeyNames()));
460463
}
461464

462-
final String keyQuery = this.tableMetaDataContext.getSimulationQueryForGetGeneratedKey(
465+
final String keyQuery = this.tableMetaDataContext.getSimpleQueryForGetGeneratedKey(
463466
this.tableMetaDataContext.getTableName(), getGeneratedKeyNames()[0]);
464467
Assert.notNull(keyQuery, "Query for simulating get generated keys can't be null");
465468

@@ -611,7 +614,7 @@ private void setParameterValues(PreparedStatement preparedStatement, List<?> val
611614

612615
/**
613616
* Match the provided in parameter values with registered parameters and parameters
614-
* defined via metadata processing.
617+
* defined via meta-data processing.
615618
* @param parameterSource the parameter values provided as a {@link SqlParameterSource}
616619
* @return Map with parameter names and values
617620
*/
@@ -621,7 +624,7 @@ protected List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSourc
621624

622625
/**
623626
* Match the provided in parameter values with registered parameters and parameters
624-
* defined via metadata processing.
627+
* defined via meta-data processing.
625628
* @param args the parameter values provided in a Map
626629
* @return Map with parameter names and values
627630
*/

0 commit comments

Comments
 (0)