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 4e62e98eff..5d33b7fad7 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 @@ -35,7 +35,7 @@ import org.springframework.jdbc.support.JdbcUtils; import org.springframework.jdbc.support.nativejdbc.NativeJdbcExtractor; /** - * 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 @@ -59,13 +59,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 private TableMetaDataProvider metaDataProvider; // Are we using generated key columns @@ -118,14 +118,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; @@ -162,7 +162,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 @@ -174,7 +174,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 */ @@ -205,7 +205,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) { @@ -255,7 +255,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) { @@ -303,7 +303,7 @@ 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() { @@ -335,7 +335,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() { @@ -344,7 +344,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() { @@ -352,11 +352,19 @@ 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 + 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()}? */ - public String getSimulationQueryForGetGeneratedKey(String tableName, String keyColumnName) { + public String getSimpleQueryForGetGeneratedKey(String tableName, String keyColumnName) { return this.metaDataProvider.getSimpleQueryForGetGeneratedKey(tableName, keyColumnName); } diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java index b55dbaa8f7..eade972f55 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/AbstractJdbcCall.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2015 the original author or authors. + * Copyright 2002-2018 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,8 +39,9 @@ import org.springframework.util.StringUtils; /** * Abstract class to provide base functionality for easy stored procedure calls - * based on configuration options and database metadata. - * This class provides the base SPI for {@link SimpleJdbcCall}. + * based on configuration options and database meta-data. + * + *

This class provides the base SPI for {@link SimpleJdbcCall}. * * @author Thomas Risberg * @author Juergen Hoeller @@ -54,7 +55,7 @@ public abstract class AbstractJdbcCall { /** 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 CallMetaDataContext callMetaDataContext = new CallMetaDataContext(); /** List of SqlParameter objects */ @@ -208,7 +209,7 @@ public abstract class AbstractJdbcCall { } /** - * 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 setAccessCallParameterMetaData(boolean accessCallParameterMetaData) { @@ -216,7 +217,7 @@ public abstract class AbstractJdbcCall { } /** - * Get the call string that should be used based on parameters and meta data. + * Get the call string that should be used based on parameters and meta-data. */ public String getCallString() { return this.callString; @@ -268,13 +269,13 @@ public abstract class AbstractJdbcCall { //------------------------------------------------------------------------- /** - * Compile this JdbcCall using provided parameters and meta data plus other settings. + * Compile this JdbcCall 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 call is executed. * @throws org.springframework.dao.InvalidDataAccessApiUsageException if the object hasn't * been correctly initialized, for example if no DataSource has been provided */ - public synchronized final void compile() throws InvalidDataAccessApiUsageException { + public final synchronized void compile() throws InvalidDataAccessApiUsageException { if (!isCompiled()) { if (getProcedureName() == null) { throw new InvalidDataAccessApiUsageException("Procedure or Function name is required"); @@ -416,7 +417,7 @@ public abstract class AbstractJdbcCall { /** * Get a List of all the call parameters to be used for call. - * This includes any parameters added based on meta data processing. + * This includes any parameters added based on meta-data processing. */ protected List getCallParameters() { return this.callMetaDataContext.getCallParameters(); @@ -424,7 +425,7 @@ public abstract class AbstractJdbcCall { /** * Match the provided in parameter values with registered parameters and - * parameters defined via metadata processing. + * parameters defined via meta-data processing. * @param parameterSource the parameter vakues provided as a {@link SqlParameterSource} * @return Map with parameter names and values */ @@ -434,7 +435,7 @@ public abstract class AbstractJdbcCall { /** * Match the provided in parameter values with registered parameters and - * parameters defined via metadata processing. + * parameters defined via meta-data processing. * @param args the parameter values provided as an array * @return Map with parameter names and values */ @@ -444,7 +445,7 @@ public abstract class AbstractJdbcCall { /** * Match the provided in parameter values with registered parameters and - * parameters defined via metadata processing. + * parameters defined via meta-data processing. * @param args the parameter values provided in a Map * @return Map with parameter names and values */ 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 43c6acaf05..ee9acf6588 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 @@ -52,8 +52,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 @@ -67,7 +68,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) { @@ -246,13 +247,13 @@ 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, * for example if no DataSource has been provided */ - public synchronized final void compile() throws InvalidDataAccessApiUsageException { + public final synchronized void compile() throws InvalidDataAccessApiUsageException { if (!isCompiled()) { if (getTableName() == null) { throw new InvalidDataAccessApiUsageException("Table name is required"); @@ -321,7 +322,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"); } } @@ -432,6 +433,7 @@ public abstract class AbstractJdbcInsert { logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values); } final KeyHolder keyHolder = new GeneratedKeyHolder(); + if (this.tableMetaDataContext.isGetGeneratedKeysSupported()) { getJdbcTemplate().update( new PreparedStatementCreator() { @@ -444,6 +446,7 @@ public abstract class AbstractJdbcInsert { }, keyHolder); } + else { if (!this.tableMetaDataContext.isGetGeneratedKeysSimulated()) { throw new InvalidDataAccessResourceUsageException( @@ -459,7 +462,7 @@ public abstract class AbstractJdbcInsert { getGeneratedKeyNames().length + " columns specified: " + Arrays.asList(getGeneratedKeyNames())); } - final String keyQuery = this.tableMetaDataContext.getSimulationQueryForGetGeneratedKey( + final String keyQuery = this.tableMetaDataContext.getSimpleQueryForGetGeneratedKey( this.tableMetaDataContext.getTableName(), getGeneratedKeyNames()[0]); Assert.notNull(keyQuery, "Query for simulating get generated keys can't be null"); @@ -611,7 +614,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 */ @@ -621,7 +624,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 */