Skip to content

Commit 14c8c91

Browse files
committed
Polishing
1 parent 23eb0e3 commit 14c8c91

File tree

8 files changed

+54
-64
lines changed

8 files changed

+54
-64
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -43,7 +43,7 @@
4343
* Abstract class to provide base functionality for easy stored procedure calls
4444
* based on configuration options and database meta-data.
4545
*
46-
* <p>This class provides the base SPI for {@link SimpleJdbcCall}.
46+
* <p>This class provides the processing arrangement for {@link SimpleJdbcCall}.
4747
*
4848
* @author Thomas Risberg
4949
* @author Juergen Hoeller
@@ -453,7 +453,7 @@ protected Map<String, Object> matchInParameterValuesWithCallParameters(SqlParame
453453
/**
454454
* Match the provided in parameter values with registered parameters and
455455
* parameters defined via meta-data processing.
456-
* @param args the parameter values provided in a Map
456+
* @param args the parameter values provided as a Map
457457
* @return a Map with parameter names and values
458458
*/
459459
protected Map<String, ?> matchInParameterValuesWithCallParameters(Map<String, ?> args) {

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -50,10 +50,10 @@
5050
import org.springframework.util.Assert;
5151

5252
/**
53-
* Abstract class to provide base functionality for easy inserts
53+
* Abstract class to provide base functionality for easy (batch) inserts
5454
* based on configuration options and database meta-data.
5555
*
56-
* <p>This class provides the base SPI for {@link SimpleJdbcInsert}.
56+
* <p>This class provides the processing arrangement for {@link SimpleJdbcInsert}.
5757
*
5858
* @author Thomas Risberg
5959
* @author Juergen Hoeller
@@ -409,7 +409,7 @@ protected KeyHolder doExecuteAndReturnKeyHolder(SqlParameterSource parameterSour
409409
/**
410410
* Delegate method to execute the insert, generating a single key.
411411
*/
412-
private Number executeInsertAndReturnKeyInternal(final List<?> values) {
412+
private Number executeInsertAndReturnKeyInternal(List<?> values) {
413413
KeyHolder kh = executeInsertAndReturnKeyHolderInternal(values);
414414
if (kh.getKey() != null) {
415415
return kh.getKey();
@@ -423,11 +423,11 @@ private Number executeInsertAndReturnKeyInternal(final List<?> values) {
423423
/**
424424
* Delegate method to execute the insert, generating any number of keys.
425425
*/
426-
private KeyHolder executeInsertAndReturnKeyHolderInternal(final List<?> values) {
426+
private KeyHolder executeInsertAndReturnKeyHolderInternal(List<?> values) {
427427
if (logger.isDebugEnabled()) {
428428
logger.debug("The following parameters are used for call " + getInsertString() + " with: " + values);
429429
}
430-
final KeyHolder keyHolder = new GeneratedKeyHolder();
430+
KeyHolder keyHolder = new GeneratedKeyHolder();
431431

432432
if (this.tableMetaDataContext.isGetGeneratedKeysSupported()) {
433433
getJdbcTemplate().update(
@@ -455,7 +455,7 @@ private KeyHolder executeInsertAndReturnKeyHolderInternal(final List<?> values)
455455
}
456456

457457
Assert.state(getTableName() != null, "No table name set");
458-
final String keyQuery = this.tableMetaDataContext.getSimpleQueryForGetGeneratedKey(
458+
String keyQuery = this.tableMetaDataContext.getSimpleQueryForGetGeneratedKey(
459459
getTableName(), getGeneratedKeyNames()[0]);
460460
Assert.state(keyQuery != null, "Query for simulating get generated keys must not be null");
461461

@@ -535,8 +535,8 @@ private PreparedStatement prepareStatementForGeneratedKeys(Connection con) throw
535535

536536
/**
537537
* Delegate method that executes a batch insert using the passed-in Maps of parameters.
538-
* @param batch array of Maps with parameter names and values to be used in batch insert
539-
* @return array of number of rows affected
538+
* @param batch maps with parameter names and values to be used in the batch insert
539+
* @return an array of number of rows affected
540540
*/
541541
@SuppressWarnings("unchecked")
542542
protected int[] doExecuteBatch(Map<String, ?>... batch) {
@@ -549,9 +549,10 @@ protected int[] doExecuteBatch(Map<String, ?>... batch) {
549549
}
550550

551551
/**
552-
* Delegate method that executes a batch insert using the passed-in {@link SqlParameterSource SqlParameterSources}.
553-
* @param batch array of SqlParameterSource with parameter names and values to be used in insert
554-
* @return array of number of rows affected
552+
* Delegate method that executes a batch insert using the passed-in
553+
* {@link SqlParameterSource SqlParameterSources}.
554+
* @param batch parameter sources with names and values to be used in the batch insert
555+
* @return an array of number of rows affected
555556
*/
556557
protected int[] doExecuteBatch(SqlParameterSource... batch) {
557558
checkCompiled();
@@ -606,7 +607,7 @@ private void setParameterValues(PreparedStatement preparedStatement, List<?> val
606607
* Match the provided in parameter values with registered parameters and parameters
607608
* defined via meta-data processing.
608609
* @param parameterSource the parameter values provided as a {@link SqlParameterSource}
609-
* @return a Map with parameter names and values
610+
* @return a List of values
610611
*/
611612
protected List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSource parameterSource) {
612613
return this.tableMetaDataContext.matchInParameterValuesWithInsertColumns(parameterSource);
@@ -615,8 +616,8 @@ protected List<Object> matchInParameterValuesWithInsertColumns(SqlParameterSourc
615616
/**
616617
* Match the provided in parameter values with registered parameters and parameters
617618
* defined via meta-data processing.
618-
* @param args the parameter values provided in a Map
619-
* @return a Map with parameter names and values
619+
* @param args the parameter values provided as a Map
620+
* @return a List of values
620621
*/
621622
protected List<Object> matchInParameterValuesWithInsertColumns(Map<String, ?> args) {
622623
return this.tableMetaDataContext.matchInParameterValuesWithInsertColumns(args);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -47,7 +47,7 @@
4747
* any meta-data processing if you want to use parameter names that do not
4848
* match what is declared during the stored procedure compilation.
4949
*
50-
* <p>The actual insert is being handled using Spring's {@link JdbcTemplate}.
50+
* <p>The actual call is being handled using Spring's {@link JdbcTemplate}.
5151
*
5252
* <p>Many of the configuration methods return the current instance of the
5353
* SimpleJdbcCall in order to provide the ability to chain multiple ones

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -26,17 +26,17 @@
2626
import org.springframework.jdbc.support.KeyHolder;
2727

2828
/**
29-
* A SimpleJdbcInsert is a multithreaded, reusable object providing easy insert
29+
* A SimpleJdbcInsert is a multithreaded, reusable object providing easy (batch) insert
3030
* capabilities for a table. It provides meta-data processing to simplify the code
31-
* needed to construct a basic insert statement. All you need to provide is the
32-
* name of the table and a Map containing the column names and the column values.
31+
* needed to construct a basic insert statement. All you need to provide is the name
32+
* of the table and a Map containing the column names and the column values.
3333
*
3434
* <p>The meta-data processing is based on the DatabaseMetaData provided by the
3535
* JDBC driver. As long as the JDBC driver can provide the names of the columns
3636
* for a specified table then we can rely on this auto-detection feature. If that
3737
* is not the case, then the column names must be specified explicitly.
3838
*
39-
* <p>The actual insert is handled using Spring's {@link JdbcTemplate}.
39+
* <p>The actual (batch) insert is handled using Spring's {@link JdbcTemplate}.
4040
*
4141
* <p>Many of the configuration methods return the current instance of the
4242
* SimpleJdbcInsert to provide the ability to chain multiple ones together
@@ -142,8 +142,8 @@ public KeyHolder executeAndReturnKeyHolder(SqlParameterSource parameterSource) {
142142
return doExecuteAndReturnKeyHolder(parameterSource);
143143
}
144144

145-
@Override
146145
@SuppressWarnings("unchecked")
146+
@Override
147147
public int[] executeBatch(Map<String, ?>... batch) {
148148
return doExecuteBatch(batch);
149149
}

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/NamedParameterUtils.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -22,7 +22,6 @@
2222
import java.util.Iterator;
2323
import java.util.List;
2424
import java.util.Map;
25-
import java.util.Objects;
2625
import java.util.Set;
2726
import java.util.TreeMap;
2827

@@ -373,6 +372,7 @@ private static class ParameterHolder {
373372
private final int endIndex;
374373

375374
ParameterHolder(String parameterName, int startIndex, int endIndex) {
375+
Assert.notNull(parameterName, "Parameter name must not be null");
376376
this.parameterName = parameterName;
377377
this.startIndex = startIndex;
378378
this.endIndex = endIndex;
@@ -391,21 +391,21 @@ int getEndIndex() {
391391
}
392392

393393
@Override
394-
public boolean equals(Object o) {
395-
if (this == o) {
394+
public boolean equals(Object other) {
395+
if (this == other) {
396396
return true;
397397
}
398-
if (!(o instanceof ParameterHolder)) {
398+
if (!(other instanceof ParameterHolder)) {
399399
return false;
400400
}
401-
ParameterHolder that = (ParameterHolder) o;
402-
return this.startIndex == that.startIndex && this.endIndex == that.endIndex
403-
&& Objects.equals(this.parameterName, that.parameterName);
401+
ParameterHolder that = (ParameterHolder) other;
402+
return (this.startIndex == that.startIndex && this.endIndex == that.endIndex &&
403+
this.parameterName.equals(that.parameterName));
404404
}
405405

406406
@Override
407407
public int hashCode() {
408-
return Objects.hash(this.parameterName, this.startIndex, this.endIndex);
408+
return this.parameterName.hashCode();
409409
}
410410
}
411411

spring-r2dbc/src/main/java/org/springframework/r2dbc/core/Parameter.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 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.
@@ -16,8 +16,6 @@
1616

1717
package org.springframework.r2dbc.core;
1818

19-
import java.util.Objects;
20-
2119
import org.springframework.lang.Nullable;
2220
import org.springframework.util.Assert;
2321
import org.springframework.util.ClassUtils;
@@ -109,21 +107,21 @@ public boolean isEmpty() {
109107

110108

111109
@Override
112-
public boolean equals(Object obj) {
113-
if (this == obj) {
110+
public boolean equals(Object other) {
111+
if (this == other) {
114112
return true;
115113
}
116-
if (!(obj instanceof Parameter)) {
114+
if (!(other instanceof Parameter)) {
117115
return false;
118116
}
119-
Parameter other = (Parameter) obj;
120-
return (ObjectUtils.nullSafeEquals(this.value, other.value) &&
121-
ObjectUtils.nullSafeEquals(this.type, other.type));
117+
Parameter that = (Parameter) other;
118+
return (ObjectUtils.nullSafeEquals(this.value, that.value) &&
119+
ObjectUtils.nullSafeEquals(this.type, that.type));
122120
}
123121

124122
@Override
125123
public int hashCode() {
126-
return Objects.hash(this.value, this.type);
124+
return ObjectUtils.nullSafeHashCode(this.value) + ObjectUtils.nullSafeHashCode(this.type);
127125
}
128126

129127
@Override

src/docs/asciidoc/data-access.adoc

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3636,11 +3636,8 @@ parameters. The following example shows how to use `NamedParameterJdbcTemplate`:
36363636
}
36373637
36383638
public int countOfActorsByFirstName(String firstName) {
3639-
3640-
String sql = "select count(*) from T_ACTOR where first_name = :first_name";
3641-
3639+
String sql = "select count(*) from t_actor where first_name = :first_name";
36423640
SqlParameterSource namedParameters = new MapSqlParameterSource("first_name", firstName);
3643-
36443641
return this.namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Integer.class);
36453642
}
36463643
----
@@ -3651,7 +3648,7 @@ parameters. The following example shows how to use `NamedParameterJdbcTemplate`:
36513648
private val namedParameterJdbcTemplate = NamedParameterJdbcTemplate(dataSource)
36523649
36533650
fun countOfActorsByFirstName(firstName: String): Int {
3654-
val sql = "select count(*) from T_ACTOR where first_name = :first_name"
3651+
val sql = "select count(*) from t_actor where first_name = :first_name"
36553652
val namedParameters = MapSqlParameterSource("first_name", firstName)
36563653
return namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Int::class.java)!!
36573654
}
@@ -3679,11 +3676,8 @@ The following example shows the use of the `Map`-based style:
36793676
}
36803677
36813678
public int countOfActorsByFirstName(String firstName) {
3682-
3683-
String sql = "select count(*) from T_ACTOR where first_name = :first_name";
3684-
3679+
String sql = "select count(*) from t_actor where first_name = :first_name";
36853680
Map<String, String> namedParameters = Collections.singletonMap("first_name", firstName);
3686-
36873681
return this.namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Integer.class);
36883682
}
36893683
----
@@ -3694,7 +3688,7 @@ The following example shows the use of the `Map`-based style:
36943688
private val namedParameterJdbcTemplate = NamedParameterJdbcTemplate(dataSource)
36953689
36963690
fun countOfActorsByFirstName(firstName: String): Int {
3697-
val sql = "select count(*) from T_ACTOR where first_name = :first_name"
3691+
val sql = "select count(*) from t_actor where first_name = :first_name"
36983692
val namedParameters = mapOf("first_name" to firstName)
36993693
return namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Int::class.java)!!
37003694
}
@@ -3761,12 +3755,9 @@ members of the class shown in the preceding example:
37613755
}
37623756
37633757
public int countOfActors(Actor exampleActor) {
3764-
37653758
// notice how the named parameters match the properties of the above 'Actor' class
3766-
String sql = "select count(*) from T_ACTOR where first_name = :firstName and last_name = :lastName";
3767-
3759+
String sql = "select count(*) from t_actor where first_name = :firstName and last_name = :lastName";
37683760
SqlParameterSource namedParameters = new BeanPropertySqlParameterSource(exampleActor);
3769-
37703761
return this.namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Integer.class);
37713762
}
37723763
----
@@ -3780,7 +3771,7 @@ members of the class shown in the preceding example:
37803771
37813772
fun countOfActors(exampleActor: Actor): Int {
37823773
// notice how the named parameters match the properties of the above 'Actor' class
3783-
val sql = "select count(*) from T_ACTOR where first_name = :firstName and last_name = :lastName"
3774+
val sql = "select count(*) from t_actor where first_name = :firstName and last_name = :lastName"
37843775
val namedParameters = BeanPropertySqlParameterSource(exampleActor)
37853776
return namedParameterJdbcTemplate.queryForObject(sql, namedParameters, Int::class.java)!!
37863777
}
@@ -6089,7 +6080,7 @@ The following example shows how to do so:
60896080
==== Passing in Lists of Values for IN Clause
60906081

60916082
The SQL standard allows for selecting rows based on an expression that includes a
6092-
variable list of values. A typical example would be `select * from T_ACTOR where id in
6083+
variable list of values. A typical example would be `select * from t_actor where id in
60936084
(1, 2, 3)`. This variable list is not directly supported for prepared statements by the
60946085
JDBC standard. You cannot declare a variable number of placeholders. You need a number
60956086
of variations with the desired number of placeholders prepared, or you need to generate
@@ -6106,7 +6097,7 @@ limit is 1000.
61066097

61076098
In addition to the primitive values in the value list, you can create a `java.util.List`
61086099
of object arrays. This list can support multiple expressions being defined for the `in`
6109-
clause, such as `+++select * from T_ACTOR where (id, last_name) in ((1, 'Johnson'), (2,
6100+
clause, such as `+++select * from t_actor where (id, last_name) in ((1, 'Johnson'), (2,
61106101
'Harrop'))+++`. This, of course, requires that your database supports this syntax.
61116102

61126103

src/docs/asciidoc/integration.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6033,7 +6033,7 @@ confirm the exclusion.
60336033

60346034

60356035
[[cache-annotations-evict]]
6036-
==== The `@CacheEvict` annotation
6036+
==== The `@CacheEvict` Annotation
60376037

60386038
The cache abstraction allows not just population of a cache store but also eviction.
60396039
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:
60916091

60926092

60936093
[[cache-annotations-config]]
6094-
==== The `@CacheConfig` annotation
6094+
==== The `@CacheConfig` Annotation
60956095

60966096
So far, we have seen that caching operations offer many customization options and that
60976097
you can set these options for each operation. However, some of the customization options

0 commit comments

Comments
 (0)