Skip to content

Commit

Permalink
Polishing.
Browse files Browse the repository at this point in the history
Original pull request #1618
See #1554
  • Loading branch information
schauder committed Oct 13, 2023
1 parent 5344197 commit 8ba1204
Show file tree
Hide file tree
Showing 11 changed files with 24 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public BasicJdbcConverter(RelationalMappingContext context, RelationResolver rel
*/
public BasicJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver,
CustomConversions conversions, JdbcTypeFactory typeFactory, IdentifierProcessing identifierProcessing) {
super(context, relationResolver, conversions, typeFactory, identifierProcessing);
super(context, relationResolver, conversions, typeFactory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ public Object mapRow(ResultSet rs, int rowNum) throws SQLException {
return getMapEntityRowMapper(path, identifier).mapRow(rs, rowNum);
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ default <T> T mapRow(RelationalPersistentEntity<T> entity, ResultSet resultSet,
@SuppressWarnings("unchecked")
@Deprecated(since = "3.2", forRemoval = true)
default <T> T mapRow(PersistentPropertyPathExtension path, ResultSet resultSet, Identifier identifier, Object key) {

try {
return (T) readAndResolve(path.getRequiredLeafEntity().getType(),
RowDocumentResultSetExtractor.toRowDocument(resultSet), identifier);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.relational.domain.RowDocument;
import org.springframework.data.util.TypeInformation;
import org.springframework.lang.Nullable;
Expand Down Expand Up @@ -77,7 +76,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
/**
* Creates a new {@link MappingJdbcConverter} given {@link MappingContext} and a {@link JdbcTypeFactory#unsupported()
* no-op type factory} throwing {@link UnsupportedOperationException} on type creation. Use
* {@link #MappingJdbcConverter(RelationalMappingContext, RelationResolver, CustomConversions, JdbcTypeFactory, IdentifierProcessing)}
* {@link #MappingJdbcConverter(RelationalMappingContext, RelationResolver, CustomConversions, JdbcTypeFactory)}
* (MappingContext, RelationResolver, JdbcTypeFactory)} to convert arrays and large objects into JDBC-specific types.
*
* @param context must not be {@literal null}.
Expand Down Expand Up @@ -112,13 +111,6 @@ public MappingJdbcConverter(RelationalMappingContext context, RelationResolver r
this.relationResolver = relationResolver;
}

MappingJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver,
CustomConversions conversions, JdbcTypeFactory typeFactory, IdentifierProcessing identifierProcessing) {
super(context, conversions);
this.relationResolver = relationResolver;
this.typeFactory = typeFactory;
}

@Nullable
private Class<?> getEntityColumnType(Class<?> type) {

Expand Down Expand Up @@ -217,8 +209,8 @@ private boolean canWriteAsJdbcValue(@Nullable Object value) {
return true;
}

if (AggregateReference.class.isAssignableFrom(value.getClass())) {
return canWriteAsJdbcValue(((AggregateReference) value).getId());
if (value instanceof AggregateReference aggregateReference) {
return canWriteAsJdbcValue(aggregateReference.getId());
}

RelationalPersistentEntity<?> persistentEntity = getMappingContext().getPersistentEntity(value.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void before() {
DelegatingDataAccessStrategy relationResolver = new DelegatingDataAccessStrategy();
Dialect dialect = HsqlDbDialect.INSTANCE;
converter = new MappingJdbcConverter(context, relationResolver, new JdbcCustomConversions(),
new DefaultJdbcTypeFactory(jdbcOperations), dialect.getIdentifierProcessing());
new DefaultJdbcTypeFactory(jdbcOperations));
accessStrategy = new DataAccessStrategyFactory( //
new SqlGeneratorSource(context, converter, dialect), //
converter, //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import org.springframework.data.relational.core.mapping.RelationalMappingContext;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.repository.query.Param;
import org.springframework.util.Assert;
import org.springframework.util.LinkedCaseInsensitiveMap;
Expand Down Expand Up @@ -1066,7 +1065,7 @@ private <T> EntityRowMapper<T> createRowMapper(Class<T> type, NamingStrategy nam
.findAllByPath(identifierOfValue(ID_FOR_ENTITY_REFERENCING_LIST), any(PersistentPropertyPath.class));

MappingJdbcConverter converter = new MappingJdbcConverter(context, accessStrategy, new JdbcCustomConversions(),
JdbcTypeFactory.unsupported(), IdentifierProcessing.ANSI);
JdbcTypeFactory.unsupported());

return new EntityRowMapper<>( //
(RelationalPersistentEntity<T>) context.getRequiredPersistentEntity(type), //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import org.springframework.data.jdbc.support.JdbcUtil;
import org.springframework.data.relational.core.mapping.RelationalPersistentEntity;
import org.springframework.data.relational.core.mapping.RelationalPersistentProperty;
import org.springframework.data.relational.core.sql.IdentifierProcessing;
import org.springframework.data.util.TypeInformation;

/**
Expand All @@ -59,7 +58,7 @@ public class MappingJdbcConverterUnitTests {
throw new UnsupportedOperationException();
}, //
new JdbcCustomConversions(), //
typeFactory, IdentifierProcessing.ANSI //
typeFactory //
);

@Test // DATAJDBC-104, DATAJDBC-1384
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ public WithIllegalCharacters(Long id, String value) {
private SqlParametersFactory createSqlParametersFactoryWithConverters(List<?> converters) {

MappingJdbcConverter converter = new MappingJdbcConverter(context, relationResolver,
new JdbcCustomConversions(converters), new DefaultJdbcTypeFactory(mock(JdbcOperations.class)),
dialect.getIdentifierProcessing());
new JdbcCustomConversions(converters), new DefaultJdbcTypeFactory(mock(JdbcOperations.class)));
return new SqlParametersFactory(context, converter);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ public AbstractRelationalConverter(RelationalMappingContext context, CustomConve
this(context, conversions, new DefaultConversionService(), new EntityInstantiators());
}

@SuppressWarnings("unchecked")
private AbstractRelationalConverter(RelationalMappingContext context, CustomConversions conversions,
ConfigurableConversionService conversionService, EntityInstantiators entityInstantiators) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ public <R> R read(Class<R> type, RowDocument source) {
return read(TypeInformation.of(type), source);
}

protected <S extends Object> S read(TypeInformation<S> type, RowDocument source) {
protected <S> S read(TypeInformation<S> type, RowDocument source) {
return readAggregate(getConversionContext(ObjectPath.ROOT), source, type);
}

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

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

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

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

private <T extends Object> T doConvert(Object value, Class<? extends T> target) {
private <T> T doConvert(Object value, Class<? extends T> target) {
return doConvert(value, target, null);
}

@SuppressWarnings("ConstantConditions")
private <T extends Object> T doConvert(Object value, Class<? extends T> target,
@Nullable Class<? extends T> fallback) {
private <T> T doConvert(Object value, Class<? extends T> target,
@Nullable Class<? extends T> fallback) {

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

@SuppressWarnings("unchecked")
@Override
public <S extends Object> S convert(Object source, TypeInformation<? extends S> typeHint,
ConversionContext context) {
public <S> S convert(Object source, TypeInformation<? extends S> typeHint,
ConversionContext context) {

Assert.notNull(source, "Source must not be null");
Assert.notNull(typeHint, "TypeInformation must not be null");
Expand Down Expand Up @@ -855,7 +854,7 @@ public RelationalConverter getSourceConverter() {
*
* @param <T>
*/
public interface ValueConverter<T> {
interface ValueConverter<T> {

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

Expand All @@ -867,7 +866,7 @@ public interface ValueConverter<T> {
*
* @param <T>
*/
public interface ContainerValueConverter<T> {
interface ContainerValueConverter<T> {

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

Expand Down Expand Up @@ -928,7 +927,7 @@ protected interface ConversionContext {
* @param typeHint must not be {@literal null}.
* @return the converted object.
*/
default <S extends Object> S convert(Object source, TypeInformation<? extends S> typeHint) {
default <S> S convert(Object source, TypeInformation<? extends S> typeHint) {
return convert(source, typeHint, this);
}

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

/**
* Obtain a {@link ConversionContext} for the given property {@code name}.
Expand Down Expand Up @@ -998,15 +997,13 @@ protected interface RelationalPropertyValueProvider extends PropertyValueProvide
* Determine whether there is a value for the given {@link RelationalPersistentProperty}.
*
* @param property the property to check for whether a value is present.
* @return
*/
boolean hasValue(RelationalPersistentProperty property);

/**
* Contextualize this property value provider.
*
* @param context the context to use.
* @return
*/
RelationalPropertyValueProvider withContext(ConversionContext context);

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

/**
* Determine whether there is a value for the given {@link SqlIdentifier}.
*
* @param identifier the path to check for whether a value is present.
* @return
*/
boolean hasValue(SqlIdentifier identifier);

/**
* Return a value for the given {@link AggregatePath}.
*
* @param path will never be {@literal null}.
* @return
*/
@Nullable
Object getValue(AggregatePath path);

/**
* Contextualize this property value provider.
*
* @param context
* @return
*/
@Override
AggregatePathValueProvider withContext(ConversionContext context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public interface RelationalConverter {
/**
* Return the underlying {@link EntityInstantiators}.
*
* @return
* @since 2.3
*/
EntityInstantiators getEntityInstantiators();
Expand Down Expand Up @@ -109,7 +108,6 @@ default <T> T createInstance(PersistentEntity<T, RelationalPersistentProperty> e
*
* @param descriptor the projection descriptor, must not be {@literal null}.
* @param document must not be {@literal null}.
* @param <R>
* @return a new instance of the projection return type {@code R}.
* @since 3.2
*/
Expand Down

0 comments on commit 8ba1204

Please sign in to comment.