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 82a2ad19c1..0121db51c0 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-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -43,7 +43,7 @@ import org.springframework.util.StringUtils; * Abstract class to provide base functionality for easy stored procedure calls * based on configuration options and database meta-data. * - *

This class provides the base SPI for {@link SimpleJdbcCall}. + *

This class provides the processing arrangement for {@link SimpleJdbcCall}. * * @author Thomas Risberg * @author Juergen Hoeller @@ -453,7 +453,7 @@ public abstract class AbstractJdbcCall { /** * Match the provided in parameter values with registered parameters and * parameters defined via meta-data processing. - * @param args the parameter values provided in a Map + * @param args the parameter values provided as a Map * @return a Map with parameter names and values */ protected Map matchInParameterValuesWithCallParameters(Map args) { 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 5d6d83c142..504ee7013b 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -50,10 +50,10 @@ import org.springframework.lang.Nullable; import org.springframework.util.Assert; /** - * Abstract class to provide base functionality for easy inserts + * Abstract class to provide base functionality for easy (batch) inserts * based on configuration options and database meta-data. * - *

This class provides the base SPI for {@link SimpleJdbcInsert}. + *

This class provides the processing arrangement for {@link SimpleJdbcInsert}. * * @author Thomas Risberg * @author Juergen Hoeller @@ -409,7 +409,7 @@ public abstract class AbstractJdbcInsert { /** * Delegate method to execute the insert, generating a single key. */ - private Number executeInsertAndReturnKeyInternal(final List values) { + private Number executeInsertAndReturnKeyInternal(List values) { KeyHolder kh = executeInsertAndReturnKeyHolderInternal(values); if (kh.getKey() != null) { return kh.getKey(); @@ -423,11 +423,11 @@ public abstract class AbstractJdbcInsert { /** * Delegate method to execute the insert, generating any number of keys. */ - private KeyHolder executeInsertAndReturnKeyHolderInternal(final List values) { + private KeyHolder executeInsertAndReturnKeyHolderInternal(List values) { if (logger.isDebugEnabled()) { logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values); } - final KeyHolder keyHolder = new GeneratedKeyHolder(); + KeyHolder keyHolder = new GeneratedKeyHolder(); if (this.tableMetaDataContext.isGetGeneratedKeysSupported()) { getJdbcTemplate().update( @@ -455,7 +455,7 @@ public abstract class AbstractJdbcInsert { } Assert.state(getTableName() != null, "No table name set"); - final String keyQuery = this.tableMetaDataContext.getSimpleQueryForGetGeneratedKey( + String keyQuery = this.tableMetaDataContext.getSimpleQueryForGetGeneratedKey( getTableName(), getGeneratedKeyNames()[0]); Assert.state(keyQuery != null, "Query for simulating get generated keys must not be null"); @@ -535,8 +535,8 @@ public abstract class AbstractJdbcInsert { /** * Delegate method that executes a batch insert using the passed-in Maps of parameters. - * @param batch array of Maps with parameter names and values to be used in batch insert - * @return array of number of rows affected + * @param batch maps with parameter names and values to be used in the batch insert + * @return an array of number of rows affected */ @SuppressWarnings("unchecked") protected int[] doExecuteBatch(Map... batch) { @@ -549,9 +549,10 @@ public abstract class AbstractJdbcInsert { } /** - * Delegate method that executes a batch insert using the passed-in {@link SqlParameterSource SqlParameterSources}. - * @param batch array of SqlParameterSource with parameter names and values to be used in insert - * @return array of number of rows affected + * Delegate method that executes a batch insert using the passed-in + * {@link SqlParameterSource SqlParameterSources}. + * @param batch parameter sources with names and values to be used in the batch insert + * @return an array of number of rows affected */ protected int[] doExecuteBatch(SqlParameterSource... batch) { checkCompiled(); @@ -606,7 +607,7 @@ public abstract class AbstractJdbcInsert { * Match the provided in parameter values with registered parameters and parameters * defined via meta-data processing. * @param parameterSource the parameter values provided as a {@link SqlParameterSource} - * @return a Map with parameter names and values + * @return a List of values */ protected List matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource) { return this.tableMetaDataContext.matchInParameterValuesWithInsertColumns(parameterSource); @@ -615,8 +616,8 @@ public abstract class AbstractJdbcInsert { /** * Match the provided in parameter values with registered parameters and parameters * defined via meta-data processing. - * @param args the parameter values provided in a Map - * @return a Map with parameter names and values + * @param args the parameter values provided as a Map + * @return a List of values */ protected List matchInParameterValuesWithInsertColumns(Map args) { return this.tableMetaDataContext.matchInParameterValuesWithInsertColumns(args); diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java index f26ea8aee3..c5d946fad4 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcCall.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2023 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. @@ -47,7 +47,7 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource; * any meta-data processing if you want to use parameter names that do not * match what is declared during the stored procedure compilation. * - *

The actual insert is being handled using Spring's {@link JdbcTemplate}. + *

The actual call is being handled using Spring's {@link JdbcTemplate}. * *

Many of the configuration methods return the current instance of the * SimpleJdbcCall in order to provide the ability to chain multiple ones diff --git a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsert.java b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsert.java index ce210b39b4..f48fb62d14 100644 --- a/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsert.java +++ b/spring-jdbc/src/main/java/org/springframework/jdbc/core/simple/SimpleJdbcInsert.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2023 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. @@ -26,17 +26,17 @@ import org.springframework.jdbc.core.namedparam.SqlParameterSource; import org.springframework.jdbc.support.KeyHolder; /** - * A SimpleJdbcInsert is a multithreaded, reusable object providing easy insert + * A SimpleJdbcInsert is a multithreaded, reusable object providing easy (batch) insert * capabilities for a table. It provides meta-data processing to simplify the code - * needed to construct a basic insert statement. All you need to provide is the - * name of the table and a Map containing the column names and the column values. + * needed to construct a basic insert statement. All you need to provide is the name + * of the table and a Map containing the column names and the column values. * *

The meta-data processing is based on the DatabaseMetaData provided by the * JDBC driver. As long as the JDBC driver can provide the names of the columns * for a specified table then we can rely on this auto-detection feature. If that * is not the case, then the column names must be specified explicitly. * - *

The actual insert is handled using Spring's {@link JdbcTemplate}. + *

The actual (batch) insert is handled using Spring's {@link JdbcTemplate}. * *

Many of the configuration methods return the current instance of the * SimpleJdbcInsert to provide the ability to chain multiple ones together @@ -142,8 +142,8 @@ public class SimpleJdbcInsert extends AbstractJdbcInsert implements SimpleJdbcIn return doExecuteAndReturnKeyHolder(parameterSource); } - @Override @SuppressWarnings("unchecked") + @Override public int[] executeBatch(Map... batch) { return doExecuteBatch(batch); } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java index a9c3231eaf..ce9d1bc5a1 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2022 the original author or authors. + * Copyright 2002-2023 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. @@ -22,7 +22,6 @@ import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.Set; import java.util.TreeMap; @@ -373,6 +372,7 @@ abstract class NamedParameterUtils { private final int endIndex; ParameterHolder(String parameterName, int startIndex, int endIndex) { + Assert.notNull(parameterName, "Parameter name must not be null"); this.parameterName = parameterName; this.startIndex = startIndex; this.endIndex = endIndex; @@ -391,21 +391,21 @@ abstract class NamedParameterUtils { } @Override - public boolean equals(Object o) { - if (this == o) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(o instanceof ParameterHolder)) { + if (!(other instanceof ParameterHolder)) { return false; } - ParameterHolder that = (ParameterHolder) o; - return this.startIndex == that.startIndex && this.endIndex == that.endIndex - && Objects.equals(this.parameterName, that.parameterName); + ParameterHolder that = (ParameterHolder) other; + return (this.startIndex == that.startIndex && this.endIndex == that.endIndex && + this.parameterName.equals(that.parameterName)); } @Override public int hashCode() { - return Objects.hash(this.parameterName, this.startIndex, this.endIndex); + return this.parameterName.hashCode(); } } diff --git a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java index 7615477fce..bea746611a 100644 --- a/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java +++ b/spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2023 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. @@ -16,8 +16,6 @@ package org.springframework.r2dbc.core; -import java.util.Objects; - import org.springframework.lang.Nullable; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; @@ -109,21 +107,21 @@ public final class Parameter { @Override - public boolean equals(Object obj) { - if (this == obj) { + public boolean equals(Object other) { + if (this == other) { return true; } - if (!(obj instanceof Parameter)) { + if (!(other instanceof Parameter)) { return false; } - Parameter other = (Parameter) obj; - return (ObjectUtils.nullSafeEquals(this.value, other.value) && - ObjectUtils.nullSafeEquals(this.type, other.type)); + Parameter that = (Parameter) other; + return (ObjectUtils.nullSafeEquals(this.value, that.value) && + ObjectUtils.nullSafeEquals(this.type, that.type)); } @Override public int hashCode() { - return Objects.hash(this.value, this.type); + return ObjectUtils.nullSafeHashCode(this.value) + ObjectUtils.nullSafeHashCode(this.type); } @Override diff --git a/src/docs/asciidoc/data-access.adoc b/src/docs/asciidoc/data-access.adoc index 88ddf5c2fe..46d97b22e9 100644 --- a/src/docs/asciidoc/data-access.adoc +++ b/src/docs/asciidoc/data-access.adoc @@ -3636,11 +3636,8 @@ parameters. The following example shows how to use `NamedParameterJdbcTemplate`: } public int countOfActorsByFirstName(String firstName) { - - String sql = "select count(*) from T_ACTOR where first_name = :first_name"; - + String sql = "select count(*) from t_actor where first_name = :first_name"; SqlParameterSource namedParameters = new MapSqlParameterSource("first_name", firstName); - return this.namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Integer.class); } ---- @@ -3651,7 +3648,7 @@ parameters. The following example shows how to use `NamedParameterJdbcTemplate`: private val namedParameterJdbcTemplate = NamedParameterJdbcTemplate(dataSource) fun countOfActorsByFirstName(firstName: String): Int { - val sql = "select count(*) from T_ACTOR where first_name = :first_name" + val sql = "select count(*) from t_actor where first_name = :first_name" val namedParameters = MapSqlParameterSource("first_name", firstName) return namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Int::class.java)!! } @@ -3679,11 +3676,8 @@ The following example shows the use of the `Map`-based style: } public int countOfActorsByFirstName(String firstName) { - - String sql = "select count(*) from T_ACTOR where first_name = :first_name"; - + String sql = "select count(*) from t_actor where first_name = :first_name"; Map namedParameters = Collections.singletonMap("first_name", firstName); - return this.namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Integer.class); } ---- @@ -3694,7 +3688,7 @@ The following example shows the use of the `Map`-based style: private val namedParameterJdbcTemplate = NamedParameterJdbcTemplate(dataSource) fun countOfActorsByFirstName(firstName: String): Int { - val sql = "select count(*) from T_ACTOR where first_name = :first_name" + val sql = "select count(*) from t_actor where first_name = :first_name" val namedParameters = mapOf("first_name" to firstName) return namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Int::class.java)!! } @@ -3761,12 +3755,9 @@ members of the class shown in the preceding example: } public int countOfActors(Actor exampleActor) { - // notice how the named parameters match the properties of the above 'Actor' class - String sql = "select count(*) from T_ACTOR where first_name = :firstName and last_name = :lastName"; - + String sql = "select count(*) from t_actor where first_name = :firstName and last_name = :lastName"; SqlParameterSource namedParameters = new BeanPropertySqlParameterSource(exampleActor); - return this.namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Integer.class); } ---- @@ -3780,7 +3771,7 @@ members of the class shown in the preceding example: fun countOfActors(exampleActor: Actor): Int { // notice how the named parameters match the properties of the above 'Actor' class - val sql = "select count(*) from T_ACTOR where first_name = :firstName and last_name = :lastName" + val sql = "select count(*) from t_actor where first_name = :firstName and last_name = :lastName" val namedParameters = BeanPropertySqlParameterSource(exampleActor) return namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Int::class.java)!! } @@ -6089,7 +6080,7 @@ The following example shows how to do so: ==== Passing in Lists of Values for IN Clause The SQL standard allows for selecting rows based on an expression that includes a -variable list of values. A typical example would be `select * from T_ACTOR where id in +variable list of values. A typical example would be `select * from t_actor where id in (1, 2, 3)`. This variable list is not directly supported for prepared statements by the JDBC standard. You cannot declare a variable number of placeholders. You need a number of variations with the desired number of placeholders prepared, or you need to generate @@ -6106,7 +6097,7 @@ limit is 1000. In addition to the primitive values in the value list, you can create a `java.util.List` of object arrays. This list can support multiple expressions being defined for the `in` -clause, such as `+++select * from T_ACTOR where (id, last_name) in ((1, 'Johnson'), (2, +clause, such as `+++select * from t_actor where (id, last_name) in ((1, 'Johnson'), (2, 'Harrop'))+++`. This, of course, requires that your database supports this syntax. diff --git a/src/docs/asciidoc/integration.adoc b/src/docs/asciidoc/integration.adoc index a05ea6e559..ba1fc2e14d 100644 --- a/src/docs/asciidoc/integration.adoc +++ b/src/docs/asciidoc/integration.adoc @@ -6033,7 +6033,7 @@ confirm the exclusion. [[cache-annotations-evict]] -==== The `@CacheEvict` annotation +==== The `@CacheEvict` Annotation The cache abstraction allows not just population of a cache store but also eviction. This process is useful for removing stale or unused data from the cache. As opposed to @@ -6091,7 +6091,7 @@ The following example uses two `@CacheEvict` annotations: [[cache-annotations-config]] -==== The `@CacheConfig` annotation +==== The `@CacheConfig` Annotation So far, we have seen that caching operations offer many customization options and that you can set these options for each operation. However, some of the customization options