Deprecate TableMetaDataContext.getSimulationQueryForGetGeneratedKey

This commit is contained in:
Juergen Hoeller 2018-03-19 12:04:51 +01:00
parent b7c423813d
commit 2c7efbb9d0
2 changed files with 38 additions and 29 deletions

View File

@ -36,7 +36,7 @@ import org.springframework.lang.Nullable;
import org.springframework.util.Assert;
/**
* Class to manage context metadata used for the configuration
* Class to manage context meta-data used for the configuration
* and execution of operations on a database table.
*
* @author Thomas Risberg
@ -63,13 +63,13 @@ public class TableMetaDataContext {
// List of columns objects to be used in this context
private List<String> tableColumns = new ArrayList<>();
// Should we access insert parameter meta data info or not
// Should we access insert parameter meta-data info or not
private boolean accessTableColumnMetaData = true;
// Should we override default for including synonyms for meta data lookups
// Should we override default for including synonyms for meta-data lookups
private boolean overrideIncludeSynonymsDefault = false;
// The provider of table meta data
// The provider of table meta-data
@Nullable
private TableMetaDataProvider metaDataProvider;
@ -123,14 +123,14 @@ public class TableMetaDataContext {
}
/**
* Specify whether we should access table column meta data.
* Specify whether we should access table column meta-data.
*/
public void setAccessTableColumnMetaData(boolean accessTableColumnMetaData) {
this.accessTableColumnMetaData = accessTableColumnMetaData;
}
/**
* Are we accessing table meta data?
* Are we accessing table meta-data?
*/
public boolean isAccessTableColumnMetaData() {
return this.accessTableColumnMetaData;
@ -160,7 +160,7 @@ public class TableMetaDataContext {
/**
* Process the current meta data with the provided configuration options.
* Process the current meta-data with the provided configuration options.
* @param dataSource the DataSource being used
* @param declaredColumns any columns that are declared
* @param generatedKeyNames name of generated keys
@ -176,7 +176,7 @@ public class TableMetaDataContext {
}
/**
* Compare columns created from metadata with declared columns and return a reconciled list.
* Compare columns created from meta-data with declared columns and return a reconciled list.
* @param declaredColumns declared column names
* @param generatedKeyNames names of generated key columns
*/
@ -207,7 +207,7 @@ public class TableMetaDataContext {
public List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource) {
List<Object> values = new ArrayList<>();
// For parameter source lookups we need to provide case-insensitive lookup support since the
// database metadata is not necessarily providing case-sensitive column names
// database meta-data is not necessarily providing case-sensitive column names
Map<String, String> caseInsensitiveParameterNames =
SqlParameterSourceUtils.extractCaseInsensitiveParameterNames(parameterSource);
for (String column : this.tableColumns) {
@ -257,7 +257,7 @@ public class TableMetaDataContext {
/**
* Build the insert string based on configuration and metadata information
* Build the insert string based on configuration and meta-data information
* @return the insert string to be used
*/
public String createInsertString(String... generatedKeyNames) {
@ -305,14 +305,13 @@ public class TableMetaDataContext {
}
/**
* Build the array of {@link java.sql.Types} based on configuration and metadata information
* Build the array of {@link java.sql.Types} based on configuration and meta-data information.
* @return the array of types to be used
*/
public int[] createInsertTypes() {
int[] types = new int[getTableColumns().size()];
List<TableParameterMetaData> parameters = obtainMetaDataProvider().getTableParameterMetaData();
Map<String, TableParameterMetaData> parameterMap =
new LinkedHashMap<>(parameters.size());
Map<String, TableParameterMetaData> parameterMap = new LinkedHashMap<>(parameters.size());
for (TableParameterMetaData tpmd : parameters) {
parameterMap.put(tpmd.getParameterName().toUpperCase(), tpmd);
}
@ -337,7 +336,7 @@ public class TableMetaDataContext {
/**
* Does this database support the JDBC 3.0 feature of retrieving generated keys
* Does this database support the JDBC 3.0 feature of retrieving generated keys:
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
*/
public boolean isGetGeneratedKeysSupported() {
@ -346,7 +345,7 @@ public class TableMetaDataContext {
/**
* Does this database support simple query to retrieve generated keys
* when the JDBC 3.0 feature is not supported.
* when the JDBC 3.0 feature is not supported:
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
*/
public boolean isGetGeneratedKeysSimulated() {
@ -354,17 +353,26 @@ public class TableMetaDataContext {
}
/**
* Does this database support simple query to retrieve generated keys
* when the JDBC 3.0 feature is not supported.
* @deprecated as of 4.3.15, in favor of {@link #getSimpleQueryForGetGeneratedKey}
*/
@Deprecated
@Nullable
public String getSimulationQueryForGetGeneratedKey(String tableName, String keyColumnName) {
return getSimpleQueryForGetGeneratedKey(tableName, keyColumnName);
}
/**
* Does this database support a simple query to retrieve generated keys
* when the JDBC 3.0 feature is not supported:
* {@link java.sql.DatabaseMetaData#supportsGetGeneratedKeys()}?
*/
@Nullable
public String getSimulationQueryForGetGeneratedKey(String tableName, String keyColumnName) {
public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) {
return obtainMetaDataProvider().getSimpleQueryForGetGeneratedKey(tableName, keyColumnName);
}
/**
* Is a column name String array for retrieving generated keys supported?
* Is a column name String array for retrieving generated keys supported:
* {@link java.sql.Connection#createStruct(String, Object[])}?
*/
public boolean isGeneratedKeysColumnNameArraySupported() {

View File

@ -50,8 +50,9 @@ import org.springframework.util.Assert;
/**
* Abstract class to provide base functionality for easy inserts
* based on configuration options and database metadata.
* This class provides the base SPI for {@link SimpleJdbcInsert}.
* based on configuration options and database meta-data.
*
* <p>This class provides the base SPI for {@link SimpleJdbcInsert}.
*
* @author Thomas Risberg
* @author Juergen Hoeller
@ -65,7 +66,7 @@ public abstract class AbstractJdbcInsert {
/** Lower-level class used to execute SQL */
private final JdbcTemplate jdbcTemplate;
/** Context used to retrieve and manage database metadata */
/** Context used to retrieve and manage database meta-data */
private final TableMetaDataContext tableMetaDataContext = new TableMetaDataContext();
/** List of columns objects to be used in insert statement */
@ -204,7 +205,7 @@ public abstract class AbstractJdbcInsert {
}
/**
* Specify whether the parameter metadata for the call should be used.
* Specify whether the parameter meta-data for the call should be used.
* The default is {@code true}.
*/
public void setAccessTableColumnMetaData(boolean accessTableColumnMetaData) {
@ -239,7 +240,7 @@ public abstract class AbstractJdbcInsert {
//-------------------------------------------------------------------------
/**
* Compile this JdbcInsert using provided parameters and meta data plus other settings.
* Compile this JdbcInsert using provided parameters and meta-data plus other settings.
* This finalizes the configuration for this object and subsequent attempts to compile are
* ignored. This will be implicitly called the first time an un-compiled insert is executed.
* @throws InvalidDataAccessApiUsageException if the object hasn't been correctly initialized,
@ -315,7 +316,7 @@ public abstract class AbstractJdbcInsert {
protected void checkIfConfigurationModificationIsAllowed() {
if (isCompiled()) {
throw new InvalidDataAccessApiUsageException(
"Configuration can't be altered once the class has been compiled or used");
"Configuration cannot be altered once the class has been compiled or used");
}
}
@ -453,9 +454,9 @@ public abstract class AbstractJdbcInsert {
}
Assert.state(getTableName() != null, "No table name set");
final String keyQuery = this.tableMetaDataContext.getSimulationQueryForGetGeneratedKey(
final String keyQuery = this.tableMetaDataContext.getSimpleQueryForGetGeneratedKey(
getTableName(), getGeneratedKeyNames()[0]);
Assert.state(keyQuery != null, "Query for simulating get generated keys can't be null");
Assert.state(keyQuery != null, "Query for simulating get generated keys must not be null");
// This is a hack to be able to get the generated key from a database that doesn't support
// get generated keys feature. HSQL is one, PostgreSQL is another. Postgres uses a RETURNING
@ -602,7 +603,7 @@ public abstract class AbstractJdbcInsert {
/**
* Match the provided in parameter values with registered parameters and parameters
* defined via metadata processing.
* defined via meta-data processing.
* @param parameterSource the parameter values provided as a {@link SqlParameterSource}
* @return Map with parameter names and values
*/
@ -612,7 +613,7 @@ public abstract class AbstractJdbcInsert {
/**
* Match the provided in parameter values with registered parameters and parameters
* defined via metadata processing.
* defined via meta-data processing.
* @param args the parameter values provided in a Map
* @return Map with parameter names and values
*/