Skip to content

Commit 7d67f30

Browse files
committed
Polishing.
Tweak method names. Rebase onto main. Convert issue references to GH- from hash prefixed ones. Remove final keyword from variable and parameter declarations. Original pull request: #999. See #987
1 parent 11734c1 commit 7d67f30

File tree

5 files changed

+35
-42
lines changed

5 files changed

+35
-42
lines changed

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/BasicJdbcConverter.java

+2-17
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.sql.JDBCType;
2020
import java.sql.ResultSet;
2121
import java.sql.SQLException;
22-
import java.util.List;
2322
import java.util.Map;
2423
import java.util.Optional;
2524

@@ -28,7 +27,6 @@
2827

2928
import org.springframework.context.ApplicationContext;
3029
import org.springframework.context.ApplicationContextAware;
31-
import org.springframework.core.ResolvableType;
3230
import org.springframework.core.convert.ConverterNotFoundException;
3331
import org.springframework.core.convert.TypeDescriptor;
3432
import org.springframework.core.convert.converter.Converter;
@@ -228,12 +226,10 @@ public Object readValue(@Nullable Object value, TypeInformation<?> type) {
228226
TypeDescriptor sourceDescriptor = TypeDescriptor.valueOf(value.getClass());
229227
TypeDescriptor targetDescriptor = createTypeDescriptor(type);
230228

231-
return getConversionService().convert(value, sourceDescriptor,
232-
targetDescriptor);
229+
return getConversionService().convert(value, sourceDescriptor, targetDescriptor);
233230
}
234231

235-
if ( !getConversions().hasCustomReadTarget(value.getClass(), type.getType()) &&
236-
value instanceof Array) {
232+
if (value instanceof Array) {
237233
try {
238234
return readValue(((Array) value).getArray(), type);
239235
} catch (SQLException | ConverterNotFoundException e) {
@@ -244,17 +240,6 @@ public Object readValue(@Nullable Object value, TypeInformation<?> type) {
244240
return super.readValue(value, type);
245241
}
246242

247-
private static TypeDescriptor createTypeDescriptor(TypeInformation<?> type) {
248-
249-
List<TypeInformation<?>> typeArguments = type.getTypeArguments();
250-
Class<?>[] generics = new Class[typeArguments.size()];
251-
for (int i = 0; i < typeArguments.size(); i++) {
252-
generics[i] = typeArguments.get(i).getType();
253-
}
254-
255-
return new TypeDescriptor(ResolvableType.forClassWithGenerics(type.getType(), generics), type.getType(), null);
256-
}
257-
258243
/*
259244
* (non-Javadoc)
260245
* @see org.springframework.data.relational.core.conversion.RelationalConverter#writeValue(java.lang.Object, org.springframework.data.util.TypeInformation)

Diff for: spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/QueryMapper.java

+13-12
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@
5555
* conversion.
5656
*
5757
* @author Mark Paluch
58+
* @author Jens Schauder
5859
* @since 2.0
5960
*/
6061
class QueryMapper {
@@ -299,7 +300,7 @@ private Condition mapCondition(CriteriaDefinition criteria, MapSqlParameterSourc
299300
&& (criteria.getValue() == null || !criteria.getValue().getClass().isArray())) {
300301

301302
RelationalPersistentProperty property = ((MetadataBackedField) propertyField).property;
302-
JdbcValue jdbcValue = convertSpecial(property, criteria.getValue());
303+
JdbcValue jdbcValue = convertToJdbcValue(property, criteria.getValue());
303304
mappedValue = jdbcValue.getValue();
304305
sqlType = jdbcValue.getJdbcType() != null ? jdbcValue.getJdbcType().getVendorTypeNumber()
305306
: propertyField.getSqlType();
@@ -315,23 +316,23 @@ private Condition mapCondition(CriteriaDefinition criteria, MapSqlParameterSourc
315316
}
316317

317318
/**
318-
* Converts values while taking special value types like arrays, {@link Iterable}, or {@link Pair}.
319-
*
319+
* Converts values while taking specific value types like arrays, {@link Iterable}, or {@link Pair}.
320+
*
320321
* @param property the property to which the value relates. It determines the type to convert to. Must not be
321322
* {@literal null}.
322323
* @param value the value to be converted.
323324
* @return a non null {@link JdbcValue} holding the converted value and the appropriate JDBC type information.
324325
*/
325-
private JdbcValue convertSpecial(RelationalPersistentProperty property, @Nullable Object value) {
326+
private JdbcValue convertToJdbcValue(RelationalPersistentProperty property, @Nullable Object value) {
326327

327328
if (value == null) {
328329
return JdbcValue.of(null, JDBCType.NULL);
329330
}
330331

331332
if (value instanceof Pair) {
332333

333-
final JdbcValue first = convertSimple(property, ((Pair<?, ?>) value).getFirst());
334-
final JdbcValue second = convertSimple(property, ((Pair<?, ?>) value).getSecond());
334+
JdbcValue first = getWriteValue(property, ((Pair<?, ?>) value).getFirst());
335+
JdbcValue second = getWriteValue(property, ((Pair<?, ?>) value).getSecond());
335336
return JdbcValue.of(Pair.of(first.getValue(), second.getValue()), first.getJdbcType());
336337
}
337338

@@ -342,7 +343,7 @@ private JdbcValue convertSpecial(RelationalPersistentProperty property, @Nullabl
342343

343344
for (Object o : (Iterable<?>) value) {
344345

345-
final JdbcValue jdbcValue = convertSimple(property, o);
346+
JdbcValue jdbcValue = getWriteValue(property, o);
346347
if (jdbcType == null) {
347348
jdbcType = jdbcValue.getJdbcType();
348349
}
@@ -355,13 +356,13 @@ private JdbcValue convertSpecial(RelationalPersistentProperty property, @Nullabl
355356

356357
if (value.getClass().isArray()) {
357358

358-
final Object[] valueAsArray = (Object[]) value;
359-
final Object[] mappedValueArray = new Object[valueAsArray.length];
359+
Object[] valueAsArray = (Object[]) value;
360+
Object[] mappedValueArray = new Object[valueAsArray.length];
360361
JDBCType jdbcType = null;
361362

362363
for (int i = 0; i < valueAsArray.length; i++) {
363364

364-
final JdbcValue jdbcValue = convertSimple(property, valueAsArray[i]);
365+
JdbcValue jdbcValue = getWriteValue(property, valueAsArray[i]);
365366
if (jdbcType == null) {
366367
jdbcType = jdbcValue.getJdbcType();
367368
}
@@ -372,7 +373,7 @@ private JdbcValue convertSpecial(RelationalPersistentProperty property, @Nullabl
372373
return JdbcValue.of(mappedValueArray, jdbcType);
373374
}
374375

375-
return convertSimple(property, value);
376+
return getWriteValue(property, value);
376377
}
377378

378379
/**
@@ -383,7 +384,7 @@ private JdbcValue convertSpecial(RelationalPersistentProperty property, @Nullabl
383384
* @param value the value to be converted.
384385
* @return a non null {@link JdbcValue} holding the converted value and the appropriate JDBC type information.
385386
*/
386-
private JdbcValue convertSimple(RelationalPersistentProperty property, Object value) {
387+
private JdbcValue getWriteValue(RelationalPersistentProperty property, Object value) {
387388

388389
return converter.writeJdbcValue( //
389390
value, //

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
import java.time.ZoneOffset;
3333
import java.util.ArrayList;
3434
import java.util.Arrays;
35-
import java.util.Collections;
3635
import java.util.List;
3736

3837
import org.junit.jupiter.api.BeforeEach;
3938
import org.junit.jupiter.api.Test;
4039
import org.junit.jupiter.api.extension.ExtendWith;
40+
4141
import org.springframework.beans.factory.annotation.Autowired;
4242
import org.springframework.beans.factory.config.PropertiesFactoryBean;
4343
import org.springframework.context.ApplicationListener;
@@ -515,7 +515,7 @@ void derivedQueryWithBooleanLiteralFindsCorrectValues() {
515515
assertThat(result).extracting(e -> e.idProp).containsExactly(entity.idProp);
516516
}
517517

518-
@Test // #987
518+
@Test // GH-987
519519
void queryBySimpleReference() {
520520

521521
final DummyEntity one = repository.save(createDummyEntity());
@@ -528,7 +528,7 @@ void queryBySimpleReference() {
528528
assertThat(result).extracting(e -> e.idProp).containsExactly(two.idProp);
529529
}
530530

531-
@Test // #987
531+
@Test // GH-987
532532
void queryByAggregateReference() {
533533

534534
final DummyEntity one = repository.save(createDummyEntity());

Diff for: spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/PartTreeJdbcQueryUnitTests.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,12 @@ public void shouldFailForQueryByReference() throws Exception {
7878
assertThatIllegalArgumentException().isThrownBy(() -> createQuery(queryMethod));
7979
}
8080

81-
@Test // #922
81+
@Test // GH-922
8282
public void createQueryByAggregateReference() throws Exception {
8383

8484
JdbcQueryMethod queryMethod = getQueryMethod("findAllByHobbyReference", Hobby.class);
8585
PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
86-
final Hobby hobby = new Hobby();
86+
Hobby hobby = new Hobby();
8787
hobby.name = "twentythree";
8888
ParametrizedQuery query = jdbcQuery.createQuery(getAccessor(queryMethod, new Object[] {hobby}), returnedType);
8989

@@ -110,12 +110,12 @@ public void shouldFailForQueryByEmbeddedList() throws Exception {
110110
assertThatIllegalArgumentException().isThrownBy(() -> createQuery(queryMethod));
111111
}
112112

113-
@Test // #922
113+
@Test // GH-922
114114
public void createQueryForQueryByAggregateReference() throws Exception {
115115

116116
JdbcQueryMethod queryMethod = getQueryMethod("findViaReferenceByHobbyReference", AggregateReference.class);
117117
PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
118-
final AggregateReference<Object, String> hobby = AggregateReference.to("twentythree");
118+
AggregateReference<Object, String> hobby = AggregateReference.to("twentythree");
119119
ParametrizedQuery query = jdbcQuery.createQuery(getAccessor(queryMethod, new Object[] {hobby}), returnedType);
120120

121121
assertSoftly(softly -> {
@@ -127,12 +127,12 @@ public void createQueryForQueryByAggregateReference() throws Exception {
127127
});
128128
}
129129

130-
@Test // #922
130+
@Test // GH-922
131131
public void createQueryForQueryByAggregateReferenceId() throws Exception {
132132

133133
JdbcQueryMethod queryMethod = getQueryMethod("findViaIdByHobbyReference", String.class);
134134
PartTreeJdbcQuery jdbcQuery = createQuery(queryMethod);
135-
final String hobby = "twentythree";
135+
String hobby = "twentythree";
136136
ParametrizedQuery query = jdbcQuery.createQuery(getAccessor(queryMethod, new Object[] {hobby}), returnedType);
137137

138138
assertSoftly(softly -> {

Diff for: spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/BasicRelationalConverter.java

+11-4
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@
1616
package org.springframework.data.relational.core.conversion;
1717

1818
import java.util.Collections;
19+
import java.util.List;
1920
import java.util.Optional;
2021
import java.util.function.Function;
2122

23+
import org.springframework.core.ResolvableType;
2224
import org.springframework.core.convert.ConversionService;
25+
import org.springframework.core.convert.TypeDescriptor;
2326
import org.springframework.core.convert.support.ConfigurableConversionService;
2427
import org.springframework.core.convert.support.DefaultConversionService;
2528
import org.springframework.data.convert.CustomConversions;
@@ -160,7 +163,7 @@ public Object readValue(@Nullable Object value, TypeInformation<?> type) {
160163
if (getConversions().hasCustomReadTarget(value.getClass(), type.getType())) {
161164

162165
TypeDescriptor sourceDescriptor = TypeDescriptor.valueOf(value.getClass());
163-
TypeDescriptor targetDescriptor = typeInformationToTypeDescriptor(type);
166+
TypeDescriptor targetDescriptor = createTypeDescriptor(type);
164167

165168
return getConversionService().convert(value, sourceDescriptor, targetDescriptor);
166169
}
@@ -250,11 +253,15 @@ private Object getPotentiallyConvertedSimpleRead(@Nullable Object value, @Nullab
250253
return conversionService.convert(value, target);
251254
}
252255

253-
protected static TypeDescriptor typeInformationToTypeDescriptor(TypeInformation<?> type) {
256+
protected static TypeDescriptor createTypeDescriptor(TypeInformation<?> type) {
254257

255-
Class<?>[] generics = type.getTypeArguments().stream().map(TypeInformation::getType).toArray(Class[]::new);
258+
List<TypeInformation<?>> typeArguments = type.getTypeArguments();
259+
Class<?>[] generics = new Class[typeArguments.size()];
260+
for (int i = 0; i < typeArguments.size(); i++) {
261+
generics[i] = typeArguments.get(i).getType();
262+
}
256263

257-
return new TypeDescriptor(ResolvableType.forClassWithGenerics(type.getType(), generics), null, null);
264+
return new TypeDescriptor(ResolvableType.forClassWithGenerics(type.getType(), generics), type.getType(), null);
258265
}
259266

260267
/**

0 commit comments

Comments
 (0)