Skip to content

Commit bbde68c

Browse files
committed
Polishing
1 parent fdf1418 commit bbde68c

File tree

22 files changed

+75
-64
lines changed

22 files changed

+75
-64
lines changed

spring-beans/src/main/java/org/springframework/beans/AbstractNestablePropertyAccessor.java

Lines changed: 3 additions & 3 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.
@@ -280,7 +280,7 @@ protected void setPropertyValue(PropertyTokenHolder tokens, PropertyValue pv) th
280280
}
281281
}
282282

283-
@SuppressWarnings({"unchecked", "rawtypes"})
283+
@SuppressWarnings({"rawtypes", "unchecked"})
284284
private void processKeyedProperty(PropertyTokenHolder tokens, PropertyValue pv) {
285285
Object propValue = getPropertyHoldingValue(tokens);
286286
PropertyHandler ph = getLocalPropertyHandler(tokens.actualName);
@@ -616,7 +616,7 @@ public Object getPropertyValue(String propertyName) throws BeansException {
616616
return nestedPa.getPropertyValue(tokens);
617617
}
618618

619-
@SuppressWarnings({"unchecked", "rawtypes"})
619+
@SuppressWarnings({"rawtypes", "unchecked"})
620620
@Nullable
621621
protected Object getPropertyValue(PropertyTokenHolder tokens) throws BeansException {
622622
String propertyName = tokens.canonicalName;

spring-beans/src/main/java/org/springframework/beans/factory/config/YamlProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ private void handleProcessError(Resource resource, IOException ex) {
226226
}
227227
}
228228

229-
@SuppressWarnings({ "unchecked", "rawtypes" })
229+
@SuppressWarnings({"rawtypes", "unchecked"})
230230
private Map<String, Object> asMap(Object object) {
231231
// YAML can have numbers as keys
232232
Map<String, Object> result = new LinkedHashMap<>();
@@ -305,7 +305,7 @@ protected final Map<String, Object> getFlattenedMap(Map<String, Object> source)
305305
return result;
306306
}
307307

308-
@SuppressWarnings({ "rawtypes", "unchecked" })
308+
@SuppressWarnings({"rawtypes", "unchecked"})
309309
private void buildFlattenedMap(Map<String, Object> result, Map<String, Object> source, @Nullable String path) {
310310
source.forEach((key, value) -> {
311311
if (StringUtils.hasText(path)) {

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2137,7 +2137,7 @@ public Stream<Object> orderedStream() {
21372137
return resolveStream(true);
21382138
}
21392139

2140-
@SuppressWarnings({ "unchecked", "rawtypes" })
2140+
@SuppressWarnings({"rawtypes", "unchecked"})
21412141
private Stream<Object> resolveStream(boolean ordered) {
21422142
DependencyDescriptor descriptorToUse = new StreamDependencyDescriptor(this.descriptor, ordered);
21432143
Object result = doResolveDependency(descriptorToUse, this.beanName, null, null);

spring-context/src/main/java/org/springframework/validation/beanvalidation/SpringValidatorAdapter.java

Lines changed: 2 additions & 2 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.
@@ -113,7 +113,7 @@ public void validate(Object target, Errors errors, Object... validationHints) {
113113
}
114114
}
115115

116-
@SuppressWarnings({ "unchecked", "rawtypes" })
116+
@SuppressWarnings({"rawtypes", "unchecked"})
117117
@Override
118118
public void validateValue(
119119
Class<?> targetType, String fieldName, @Nullable Object value, Errors errors, Object... validationHints) {

spring-core/src/main/java/org/springframework/core/io/buffer/DataBufferUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ public static Mono<DataBuffer> join(Publisher<? extends DataBuffer> dataBuffers)
588588
* @throws DataBufferLimitException if maxByteCount is exceeded
589589
* @since 5.1.11
590590
*/
591-
@SuppressWarnings({ "unchecked", "rawtypes" })
591+
@SuppressWarnings({"rawtypes", "unchecked"})
592592
public static Mono<DataBuffer> join(Publisher<? extends DataBuffer> buffers, int maxByteCount) {
593593
Assert.notNull(buffers, "'buffers' must not be null");
594594

spring-expression/src/main/java/org/springframework/expression/spel/support/StandardTypeComparator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public boolean canCompare(@Nullable Object left, @Nullable Object right) {
5353
}
5454

5555
@Override
56-
@SuppressWarnings({ "unchecked", "rawtypes" })
56+
@SuppressWarnings({"rawtypes", "unchecked"})
5757
public int compare(@Nullable Object left, @Nullable Object right) throws SpelEvaluationException {
5858
// If one is null, check if the other is
5959
if (left == null) {

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcOperations.java

Lines changed: 4 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.
@@ -35,12 +35,13 @@
3535
* <p>Alternatively, the standard JDBC infrastructure can be mocked.
3636
* However, mocking this interface constitutes significantly less work.
3737
* As an alternative to a mock objects approach to testing data access code,
38-
* consider the powerful integration testing support provided via the <em>Spring
39-
* TestContext Framework</em>, in the {@code spring-test} artifact.
38+
* consider the powerful integration testing support provided via the
39+
* <em>Spring TestContext Framework</em>, in the {@code spring-test} artifact.
4040
*
4141
* @author Rod Johnson
4242
* @author Juergen Hoeller
4343
* @see JdbcTemplate
44+
* @see org.springframework.jdbc.core.namedparam.NamedParameterJdbcOperations
4445
*/
4546
public interface JdbcOperations {
4647

spring-jdbc/src/main/java/org/springframework/jdbc/core/JdbcTemplate.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
* It executes core JDBC workflow, leaving application code to provide SQL
6666
* and extract results. This class executes SQL queries or updates, initiating
6767
* iteration over ResultSets and catching JDBC exceptions and translating
68-
* them to the generic, more informative exception hierarchy defined in the
69-
* {@code org.springframework.dao} package.
68+
* them to the common {@code org.springframework.dao} exception hierarchy.
7069
*
7170
* <p>Code using this class need only implement callback interfaces, giving
7271
* them a clearly defined contract. The {@link PreparedStatementCreator} callback
@@ -75,7 +74,8 @@
7574
* values from a ResultSet. See also {@link PreparedStatementSetter} and
7675
* {@link RowMapper} for two popular alternative callback interfaces.
7776
*
78-
* <p>Can be used within a service implementation via direct instantiation
77+
* <p>An instance of this template class is thread-safe once configured.
78+
* Can be used within a service implementation via direct instantiation
7979
* with a DataSource reference, or get prepared in an application context
8080
* and given to services as bean reference. Note: The DataSource should
8181
* always be configured as a bean in the application context, in the first case
@@ -88,12 +88,11 @@
8888
* <p>All SQL operations performed by this class are logged at debug level,
8989
* using "org.springframework.jdbc.core.JdbcTemplate" as log category.
9090
*
91-
* <p><b>NOTE: An instance of this class is thread-safe once configured.</b>
92-
*
9391
* @author Rod Johnson
9492
* @author Juergen Hoeller
9593
* @author Thomas Risberg
9694
* @since May 3, 2001
95+
* @see JdbcOperations
9796
* @see PreparedStatementCreator
9897
* @see PreparedStatementSetter
9998
* @see CallableStatementCreator
@@ -103,6 +102,7 @@
103102
* @see RowCallbackHandler
104103
* @see RowMapper
105104
* @see org.springframework.jdbc.support.SQLExceptionTranslator
105+
* @see org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate
106106
*/
107107
public class JdbcTemplate extends JdbcAccessor implements JdbcOperations {
108108

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/BeanPropertySqlParameterSource.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 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.
@@ -32,9 +32,10 @@
3232
/**
3333
* {@link SqlParameterSource} implementation that obtains parameter values
3434
* from bean properties of a given JavaBean object. The names of the bean
35-
* properties have to match the parameter names.
35+
* properties have to match the parameter names. Supports components of
36+
* record classes as well, with accessor methods matching parameter names.
3637
*
37-
* <p>Uses a Spring BeanWrapper for bean property access underneath.
38+
* <p>Uses a Spring {@link BeanWrapper} for bean property access underneath.
3839
*
3940
* @author Thomas Risberg
4041
* @author Juergen Hoeller

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/NamedParameterJdbcTemplate.java

Lines changed: 7 additions & 4 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.
@@ -55,16 +55,19 @@
5555
* done at execution time. It also allows for expanding a {@link java.util.List}
5656
* of values to the appropriate number of placeholders.
5757
*
58-
* <p>The underlying {@link org.springframework.jdbc.core.JdbcTemplate} is
58+
* <p>An instance of this template class is thread-safe once configured.
59+
* The underlying {@link org.springframework.jdbc.core.JdbcTemplate} is
5960
* exposed to allow for convenient access to the traditional
6061
* {@link org.springframework.jdbc.core.JdbcTemplate} methods.
6162
*
62-
* <p><b>NOTE: An instance of this class is thread-safe once configured.</b>
63-
*
6463
* @author Thomas Risberg
6564
* @author Juergen Hoeller
6665
* @since 2.0
6766
* @see NamedParameterJdbcOperations
67+
* @see SqlParameterSource
68+
* @see ResultSetExtractor
69+
* @see RowCallbackHandler
70+
* @see RowMapper
6871
* @see org.springframework.jdbc.core.JdbcTemplate
6972
*/
7073
public class NamedParameterJdbcTemplate implements NamedParameterJdbcOperations {

spring-jdbc/src/main/java/org/springframework/jdbc/core/namedparam/SqlParameterSourceUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static SqlParameterSource[] createBatch(Object... candidates) {
5959
* @see BeanPropertySqlParameterSource
6060
* @see NamedParameterJdbcTemplate#batchUpdate(String, SqlParameterSource[])
6161
*/
62-
@SuppressWarnings({ "unchecked", "rawtypes" })
62+
@SuppressWarnings({"rawtypes", "unchecked"})
6363
public static SqlParameterSource[] createBatch(Collection<?> candidates) {
6464
SqlParameterSource[] batch = new SqlParameterSource[candidates.size()];
6565
int i = 0;

spring-jdbc/src/test/java/org/springframework/jdbc/core/namedparam/NamedParameterQueryTests.java

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@
3434
import org.junit.jupiter.api.BeforeEach;
3535
import org.junit.jupiter.api.Test;
3636

37-
import org.springframework.jdbc.core.RowMapper;
38-
3937
import static org.assertj.core.api.Assertions.assertThat;
4038
import static org.mockito.ArgumentMatchers.anyString;
4139
import static org.mockito.BDDMockito.given;
@@ -129,8 +127,7 @@ public void testQueryForListWithParamMapAndSingleRowAndColumn() throws Exception
129127
}
130128

131129
@Test
132-
public void testQueryForListWithParamMapAndIntegerElementAndSingleRowAndColumn()
133-
throws Exception {
130+
public void testQueryForListWithParamMapAndIntegerElementAndSingleRowAndColumn() throws Exception {
134131
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
135132
given(resultSet.next()).willReturn(true, false);
136133
given(resultSet.getInt(1)).willReturn(11);
@@ -168,11 +165,10 @@ public void testQueryForObjectWithParamMapAndRowMapper() throws Exception {
168165

169166
MapSqlParameterSource params = new MapSqlParameterSource();
170167
params.addValue("id", 3);
171-
Object o = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
172-
params, (RowMapper<Object>) (rs, rowNum) -> rs.getInt(1));
168+
Integer value = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
169+
params, (rs, rowNum) -> rs.getInt(1));
173170

174-
boolean condition = o instanceof Integer;
175-
assertThat(condition).as("Correct result type").isTrue();
171+
assertThat(value).isEqualTo(22);
176172
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
177173
verify(preparedStatement).setObject(1, 3);
178174
}
@@ -185,11 +181,10 @@ public void testQueryForObjectWithMapAndInteger() throws Exception {
185181

186182
Map<String, Object> params = new HashMap<>();
187183
params.put("id", 3);
188-
Object o = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
184+
Integer value = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
189185
params, Integer.class);
190186

191-
boolean condition = o instanceof Integer;
192-
assertThat(condition).as("Correct result type").isTrue();
187+
assertThat(value).isEqualTo(22);
193188
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
194189
verify(preparedStatement).setObject(1, 3);
195190
}
@@ -202,30 +197,26 @@ public void testQueryForObjectWithParamMapAndInteger() throws Exception {
202197

203198
MapSqlParameterSource params = new MapSqlParameterSource();
204199
params.addValue("id", 3);
205-
Object o = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
200+
Integer value = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id",
206201
params, Integer.class);
207202

208-
boolean condition = o instanceof Integer;
209-
assertThat(condition).as("Correct result type").isTrue();
203+
assertThat(value).isEqualTo(22);
210204
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
211205
verify(preparedStatement).setObject(1, 3);
212206
}
213207

214208
@Test
215209
public void testQueryForObjectWithParamMapAndList() throws Exception {
216-
String sql = "SELECT AGE FROM CUSTMR WHERE ID IN (:ids)";
217-
String sqlToUse = "SELECT AGE FROM CUSTMR WHERE ID IN (?, ?)";
218210
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
219211
given(resultSet.next()).willReturn(true, false);
220212
given(resultSet.getInt(1)).willReturn(22);
221213

222214
MapSqlParameterSource params = new MapSqlParameterSource();
223215
params.addValue("ids", Arrays.asList(3, 4));
224-
Object o = template.queryForObject(sql, params, Integer.class);
216+
Integer value = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID IN (:ids)", params, Integer.class);
225217

226-
boolean condition = o instanceof Integer;
227-
assertThat(condition).as("Correct result type").isTrue();
228-
verify(connection).prepareStatement(sqlToUse);
218+
assertThat(value).isEqualTo(22);
219+
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID IN (?, ?)");
229220
verify(preparedStatement).setObject(1, 3);
230221
}
231222

@@ -240,14 +231,11 @@ public void testQueryForObjectWithParamMapAndListOfExpressionLists() throws Exce
240231
l1.add(new Object[] {3, "Rod"});
241232
l1.add(new Object[] {4, "Juergen"});
242233
params.addValue("multiExpressionList", l1);
243-
Object o = template.queryForObject(
244-
"SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN (:multiExpressionList)",
234+
Integer value = template.queryForObject("SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN (:multiExpressionList)",
245235
params, Integer.class);
246236

247-
boolean condition = o instanceof Integer;
248-
assertThat(condition).as("Correct result type").isTrue();
249-
verify(connection).prepareStatement(
250-
"SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN ((?, ?), (?, ?))");
237+
assertThat(value).isEqualTo(22);
238+
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE (ID, NAME) IN ((?, ?), (?, ?))");
251239
verify(preparedStatement).setObject(1, 3);
252240
}
253241

@@ -295,6 +283,20 @@ public void testQueryForLongWithParamBeanWithCollection() throws Exception {
295283
verify(preparedStatement).setObject(2, 5);
296284
}
297285

286+
@Test
287+
public void testQueryForLongWithParamRecord() throws Exception {
288+
given(resultSet.getMetaData()).willReturn(resultSetMetaData);
289+
given(resultSet.next()).willReturn(true, false);
290+
given(resultSet.getLong(1)).willReturn(87L);
291+
292+
BeanPropertySqlParameterSource params = new BeanPropertySqlParameterSource(new ParameterRecord(3));
293+
long l = template.queryForObject("SELECT AGE FROM CUSTMR WHERE ID = :id", params, Long.class);
294+
295+
assertThat(l).as("Return of a long").isEqualTo(87);
296+
verify(connection).prepareStatement("SELECT AGE FROM CUSTMR WHERE ID = ?");
297+
verify(preparedStatement).setObject(1, 3, Types.INTEGER);
298+
}
299+
298300

299301
static class ParameterBean {
300302

@@ -323,4 +325,8 @@ public Collection<Integer> getIds() {
323325
}
324326
}
325327

328+
329+
record ParameterRecord(int id) {
330+
}
331+
326332
}

spring-jms/src/main/java/org/springframework/jms/listener/adapter/MessageListenerAdapter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ protected String getDefaultListenerMethod() {
197197
* @throws JMSException if thrown by JMS API methods
198198
*/
199199
@Override
200-
@SuppressWarnings({ "unchecked", "rawtypes" })
200+
@SuppressWarnings({"rawtypes", "unchecked"})
201201
public void onMessage(Message message, @Nullable Session session) throws JMSException {
202202
// Check whether the delegate is a MessageListener impl itself.
203203
// In that case, the adapter will simply act as a pass-through.

spring-jms/src/main/java/org/springframework/jms/support/converter/MessagingMessageConverter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public jakarta.jms.Message toMessage(Object object, Session session) throws JMSE
113113
}
114114

115115
@Override
116-
@SuppressWarnings({ "unchecked", "rawtypes" })
116+
@SuppressWarnings({"rawtypes", "unchecked"})
117117
public Object fromMessage(jakarta.jms.Message message) throws JMSException, MessageConversionException {
118118
Map<String, Object> mappedHeaders = extractHeaders(message);
119119
Object convertedObject = extractPayload(message);

spring-r2dbc/src/main/java/org/springframework/r2dbc/connection/ConnectionFactoryUtils.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ private static boolean connectionEquals(ConnectionHolder conHolder, Connection p
301301
* @return the innermost target Connection, or the passed-in one if not wrapped
302302
* @see Wrapped#unwrap()
303303
*/
304-
@SuppressWarnings({ "unchecked", "rawtypes" })
304+
@SuppressWarnings({"rawtypes", "unchecked"})
305305
public static Connection getTargetConnection(Connection con) {
306306
Object conToUse = con;
307307
while (conToUse instanceof Wrapped wrapped) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ private static class ExpandedQuery implements PreparedOperation<String> {
513513
this.parameterSource = parameterSource;
514514
}
515515

516-
@SuppressWarnings({ "unchecked", "rawtypes" })
516+
@SuppressWarnings({"rawtypes", "unchecked"})
517517
public void bind(BindTarget target, String identifier, Parameter parameter) {
518518
List<BindMarker> bindMarkers = getBindMarkers(identifier);
519519
if (bindMarkers == null) {

spring-web/src/main/java/org/springframework/http/codec/multipart/MultipartHttpMessageWriter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ private Flux<DataBuffer> encodePartValues(
241241
.concatMap(value -> encodePart(boundary, name, value, bufferFactory));
242242
}
243243

244-
@SuppressWarnings({ "unchecked", "rawtypes" })
244+
@SuppressWarnings({"rawtypes", "unchecked"})
245245
private <T> Flux<DataBuffer> encodePart(byte[] boundary, String name, T value, DataBufferFactory factory) {
246246
MultipartHttpOutputMessage message = new MultipartHttpOutputMessage(factory);
247247
HttpHeaders headers = message.getHeaders();

0 commit comments

Comments
 (0)