From 2c7efbb9d09f46691c905467e5a192f79acfa55b Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Mon, 19 Mar 2018 12:04:51 +0100 Subject: [PATCH] Deprecate TableMetaDataContext.getSimulationQueryForGetGeneratedKey --- .../core/metadata/TableMetaDataContext.java | 46 +++++++++++-------- .../jdbc/core/simple/AbstractJdbcInsert.java | 21 +++++---- 2 files changed, 38 insertions(+), 29 deletions(-) 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 f5743e06bf..10823a73b1 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 @@ -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 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 matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource) { List 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 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 parameters = obtainMetaDataProvider().getTableParameterMetaData(); - Map parameterMap = - new LinkedHashMap<>(parameters.size()); + Map 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() { diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java index b772898c0b..70b8055b0a 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcInsert.java @@ -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. + * + *

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 */