Skip to content

Commit 8ba1204

Browse files
committed
Polishing.
Original pull request #1618 See #1554
1 parent 5344197 commit 8ba1204

File tree

11 files changed

+24
-46
lines changed

11 files changed

+24
-46
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,6 @@ public BasicJdbcConverter(RelationalMappingContext context, RelationResolver rel
7272
*/
7373
public BasicJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver,
7474
CustomConversions conversions, JdbcTypeFactory typeFactory, IdentifierProcessing identifierProcessing) {
75-
super(context, relationResolver, conversions, typeFactory, identifierProcessing);
75+
super(context, relationResolver, conversions, typeFactory);
7676
}
7777
}

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategy.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
312312
return getMapEntityRowMapper(path, identifier).mapRow(rs, rowNum);
313313
}
314314

315-
// Add row number as key for paths that do not defile an identifier and that are contained in a collection.
315+
// Add row number as key for paths that do not define an identifier and that are contained in a collection.
316316
Identifier identifierToUse = identifier;
317317
if (!path.hasIdProperty() && path.isQualified()) {
318318

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/JdbcConverter.java

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ default <T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet,
8282
@SuppressWarnings("unchecked")
8383
@Deprecated(since = "3.2", forRemoval = true)
8484
default <T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier, Object key) {
85+
8586
try {
8687
return (T) readAndResolve(path.getRequiredLeafEntity().getType(),
8788
RowDocumentResultSetExtractor.toRowDocument(resultSet), identifier);

spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java

+3-11
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
4545
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
4646
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
47-
import org.springframework.data.relational.core.sql.IdentifierProcessing;
4847
import org.springframework.data.relational.domain.RowDocument;
4948
import org.springframework.data.util.TypeInformation;
5049
import org.springframework.lang.Nullable;
@@ -77,7 +76,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
7776
/**
7877
* Creates a new {@link MappingJdbcConverter} given {@link MappingContext} and a {@link JdbcTypeFactory#unsupported()
7978
* no-op type factory} throwing {@link UnsupportedOperationException} on type creation. Use
80-
* {@link #MappingJdbcConverter(RelationalMappingContext, RelationResolver, CustomConversions, JdbcTypeFactory, IdentifierProcessing)}
79+
* {@link #MappingJdbcConverter(RelationalMappingContext, RelationResolver, CustomConversions, JdbcTypeFactory)}
8180
* (MappingContext, RelationResolver, JdbcTypeFactory)} to convert arrays and large objects into JDBC-specific types.
8281
*
8382
* @param context must not be {@literal null}.
@@ -112,13 +111,6 @@ public MappingJdbcConverter(RelationalMappingContext context, RelationResolver r
112111
this.relationResolver = relationResolver;
113112
}
114113

115-
MappingJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver,
116-
CustomConversions conversions, JdbcTypeFactory typeFactory, IdentifierProcessing identifierProcessing) {
117-
super(context, conversions);
118-
this.relationResolver = relationResolver;
119-
this.typeFactory = typeFactory;
120-
}
121-
122114
@Nullable
123115
private Class<?> getEntityColumnType(Class<?> type) {
124116

@@ -217,8 +209,8 @@ private boolean canWriteAsJdbcValue(@Nullable Object value) {
217209
return true;
218210
}
219211

220-
if (AggregateReference.class.isAssignableFrom(value.getClass())) {
221-
return canWriteAsJdbcValue(((AggregateReference) value).getId());
212+
if (value instanceof AggregateReference aggregateReference) {
213+
return canWriteAsJdbcValue(aggregateReference.getId());
222214
}
223215

224216
RelationalPersistentEntity<?> persistentEntity = getMappingContext().getPersistentEntity(value.getClass());

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/DefaultDataAccessStrategyUnitTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void before() {
6060
DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy();
6161
Dialect dialect = HsqlDbDialect.INSTANCE;
6262
converter = new MappingJdbcConverter(context, relationResolver, new JdbcCustomConversions(),
63-
new DefaultJdbcTypeFactory(jdbcOperations), dialect.getIdentifierProcessing());
63+
new DefaultJdbcTypeFactory(jdbcOperations));
6464
accessStrategy = new DataAccessStrategyFactory( //
6565
new SqlGeneratorSource(context, converter, dialect), //
6666
converter, //

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/EntityRowMapperUnitTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@
5454
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
5555
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
5656
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
57-
import org.springframework.data.relational.core.sql.IdentifierProcessing;
5857
import org.springframework.data.repository.query.Param;
5958
import org.springframework.util.Assert;
6059
import org.springframework.util.LinkedCaseInsensitiveMap;
@@ -1066,7 +1065,7 @@ private <T> EntityRowMapper<T> createRowMapper(Class<T> type, NamingStrategy nam
10661065
.findAllByPath(identifierOfValue(ID_FOR_ENTITY_REFERENCING_LIST), any(PersistentPropertyPath.class));
10671066

10681067
MappingJdbcConverter converter = new MappingJdbcConverter(context, accessStrategy, new JdbcCustomConversions(),
1069-
JdbcTypeFactory.unsupported(), IdentifierProcessing.ANSI);
1068+
JdbcTypeFactory.unsupported());
10701069

10711070
return new EntityRowMapper<>( //
10721071
(RelationalPersistentEntity<T>) context.getRequiredPersistentEntity(type), //

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverterUnitTests.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.springframework.data.jdbc.support.JdbcUtil;
4242
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
4343
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
44-
import org.springframework.data.relational.core.sql.IdentifierProcessing;
4544
import org.springframework.data.util.TypeInformation;
4645

4746
/**
@@ -59,7 +58,7 @@ public class MappingJdbcConverterUnitTests {
5958
throw new UnsupportedOperationException();
6059
}, //
6160
new JdbcCustomConversions(), //
62-
typeFactory, IdentifierProcessing.ANSI //
61+
typeFactory //
6362
);
6463

6564
@Test // DATAJDBC-104, DATAJDBC-1384

spring-data-jdbc/src/test/java/org/springframework/data/jdbc/core/convert/SqlParametersFactoryTest.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -300,8 +300,7 @@ public WithIllegalCharacters(Long id, String value) {
300300
private SqlParametersFactory createSqlParametersFactoryWithConverters(List<?> converters) {
301301

302302
MappingJdbcConverter converter = new MappingJdbcConverter(context, relationResolver,
303-
new JdbcCustomConversions(converters), new DefaultJdbcTypeFactory(mock(JdbcOperations.class)),
304-
dialect.getIdentifierProcessing());
303+
new JdbcCustomConversions(converters), new DefaultJdbcTypeFactory(mock(JdbcOperations.class)));
305304
return new SqlParametersFactory(context, converter);
306305
}
307306
}

spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/AbstractRelationalConverter.java

-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ public AbstractRelationalConverter(RelationalMappingContext context, CustomConve
6161
this(context, conversions, new DefaultConversionService(), new EntityInstantiators());
6262
}
6363

64-
@SuppressWarnings("unchecked")
6564
private AbstractRelationalConverter(RelationalMappingContext context, CustomConversions conversions,
6665
ConfigurableConversionService conversionService, EntityInstantiators entityInstantiators) {
6766

spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/MappingRelationalConverter.java

+14-23
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ public <R> R read(Class<R> type, RowDocument source) {
294294
return read(TypeInformation.of(type), source);
295295
}
296296

297-
protected <S extends Object> S read(TypeInformation<S> type, RowDocument source) {
297+
protected <S> S read(TypeInformation<S> type, RowDocument source) {
298298
return readAggregate(getConversionContext(ObjectPath.ROOT), source, type);
299299
}
300300

@@ -306,9 +306,8 @@ protected <S extends Object> S read(TypeInformation<S> type, RowDocument source)
306306
* @param typeHint the {@link TypeInformation} to be used to unmarshall this {@link RowDocument}.
307307
* @return the converted object, will never be {@literal null}.
308308
*/
309-
@SuppressWarnings("unchecked")
310-
protected <S extends Object> S readAggregate(ConversionContext context, RowDocument document,
311-
TypeInformation<? extends S> typeHint) {
309+
protected <S> S readAggregate(ConversionContext context, RowDocument document,
310+
TypeInformation<? extends S> typeHint) {
312311
return readAggregate(context, new RowDocumentAccessor(document), typeHint);
313312
}
314313

@@ -321,8 +320,8 @@ protected <S extends Object> S readAggregate(ConversionContext context, RowDocum
321320
* @return the converted object, will never be {@literal null}.
322321
*/
323322
@SuppressWarnings("unchecked")
324-
protected <S extends Object> S readAggregate(ConversionContext context, RowDocumentAccessor documentAccessor,
325-
TypeInformation<? extends S> typeHint) {
323+
protected <S> S readAggregate(ConversionContext context, RowDocumentAccessor documentAccessor,
324+
TypeInformation<? extends S> typeHint) {
326325

327326
Class<? extends S> rawType = typeHint.getType();
328327

@@ -426,13 +425,13 @@ protected Object readCollectionOrArray(ConversionContext context, Collection<?>
426425
return getPotentiallyConvertedSimpleRead(items, targetType);
427426
}
428427

429-
private <T extends Object> T doConvert(Object value, Class<? extends T> target) {
428+
private <T> T doConvert(Object value, Class<? extends T> target) {
430429
return doConvert(value, target, null);
431430
}
432431

433432
@SuppressWarnings("ConstantConditions")
434-
private <T extends Object> T doConvert(Object value, Class<? extends T> target,
435-
@Nullable Class<? extends T> fallback) {
433+
private <T> T doConvert(Object value, Class<? extends T> target,
434+
@Nullable Class<? extends T> fallback) {
436435

437436
if (getConversionService().canConvert(value.getClass(), target) || fallback == null) {
438437
return getConversionService().convert(value, target);
@@ -788,8 +787,8 @@ protected DefaultConversionContext(RelationalConverter sourceConverter,
788787

789788
@SuppressWarnings("unchecked")
790789
@Override
791-
public <S extends Object> S convert(Object source, TypeInformation<? extends S> typeHint,
792-
ConversionContext context) {
790+
public <S> S convert(Object source, TypeInformation<? extends S> typeHint,
791+
ConversionContext context) {
793792

794793
Assert.notNull(source, "Source must not be null");
795794
Assert.notNull(typeHint, "TypeInformation must not be null");
@@ -855,7 +854,7 @@ public RelationalConverter getSourceConverter() {
855854
*
856855
* @param <T>
857856
*/
858-
public interface ValueConverter<T> {
857+
interface ValueConverter<T> {
859858

860859
Object convert(T source, TypeInformation<?> typeHint);
861860

@@ -867,7 +866,7 @@ public interface ValueConverter<T> {
867866
*
868867
* @param <T>
869868
*/
870-
public interface ContainerValueConverter<T> {
869+
interface ContainerValueConverter<T> {
871870

872871
Object convert(ConversionContext context, T source, TypeInformation<?> typeHint);
873872

@@ -928,7 +927,7 @@ protected interface ConversionContext {
928927
* @param typeHint must not be {@literal null}.
929928
* @return the converted object.
930929
*/
931-
default <S extends Object> S convert(Object source, TypeInformation<? extends S> typeHint) {
930+
default <S> S convert(Object source, TypeInformation<? extends S> typeHint) {
932931
return convert(source, typeHint, this);
933932
}
934933

@@ -940,7 +939,7 @@ default <S extends Object> S convert(Object source, TypeInformation<? extends S>
940939
* @param context must not be {@literal null}.
941940
* @return the converted object.
942941
*/
943-
<S extends Object> S convert(Object source, TypeInformation<? extends S> typeHint, ConversionContext context);
942+
<S> S convert(Object source, TypeInformation<? extends S> typeHint, ConversionContext context);
944943

945944
/**
946945
* Obtain a {@link ConversionContext} for the given property {@code name}.
@@ -998,15 +997,13 @@ protected interface RelationalPropertyValueProvider extends PropertyValueProvide
998997
* Determine whether there is a value for the given {@link RelationalPersistentProperty}.
999998
*
1000999
* @param property the property to check for whether a value is present.
1001-
* @return
10021000
*/
10031001
boolean hasValue(RelationalPersistentProperty property);
10041002

10051003
/**
10061004
* Contextualize this property value provider.
10071005
*
10081006
* @param context the context to use.
1009-
* @return
10101007
*/
10111008
RelationalPropertyValueProvider withContext(ConversionContext context);
10121009

@@ -1021,32 +1018,26 @@ protected interface AggregatePathValueProvider extends RelationalPropertyValuePr
10211018
* Determine whether there is a value for the given {@link AggregatePath}.
10221019
*
10231020
* @param path the path to check for whether a value is present.
1024-
* @return
10251021
*/
10261022
boolean hasValue(AggregatePath path);
10271023

10281024
/**
10291025
* Determine whether there is a value for the given {@link SqlIdentifier}.
10301026
*
10311027
* @param identifier the path to check for whether a value is present.
1032-
* @return
10331028
*/
10341029
boolean hasValue(SqlIdentifier identifier);
10351030

10361031
/**
10371032
* Return a value for the given {@link AggregatePath}.
10381033
*
10391034
* @param path will never be {@literal null}.
1040-
* @return
10411035
*/
10421036
@Nullable
10431037
Object getValue(AggregatePath path);
10441038

10451039
/**
10461040
* Contextualize this property value provider.
1047-
*
1048-
* @param context
1049-
* @return
10501041
*/
10511042
@Override
10521043
AggregatePathValueProvider withContext(ConversionContext context);

spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/RelationalConverter.java

-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ public interface RelationalConverter {
5252
/**
5353
* Return the underlying {@link EntityInstantiators}.
5454
*
55-
* @return
5655
* @since 2.3
5756
*/
5857
EntityInstantiators getEntityInstantiators();
@@ -109,7 +108,6 @@ default <T> T createInstance(PersistentEntity<T, RelationalPersistentProperty> e
109108
*
110109
* @param descriptor the projection descriptor, must not be {@literal null}.
111110
* @param document must not be {@literal null}.
112-
* @param <R>
113111
* @return a new instance of the projection return type {@code R}.
114112
* @since 3.2
115113
*/

0 commit comments

Comments
 (0)