Browse Source

Polishing.

Fix typos. Add since tag.

See #2078
Original pull request: #2081
pull/2110/head
Mark Paluch 5 months ago
parent
commit
b42809eff0
No known key found for this signature in database
GPG Key ID: 55BC6374BAA9D973
  1. 38
      spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java
  2. 21
      spring-data-relational/src/main/java/org/springframework/data/relational/core/conversion/MappingRelationalConverter.java

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

@ -80,7 +80,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -80,7 +80,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
* {@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}.
* @param context must not be {@literal null}.
* @param relationResolver used to fetch additional relations from the database. Must not be {@literal null}.
*/
public MappingJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver) {
@ -98,12 +98,12 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -98,12 +98,12 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
/**
* Creates a new {@link MappingJdbcConverter} given {@link MappingContext}.
*
* @param context must not be {@literal null}.
* @param context must not be {@literal null}.
* @param relationResolver used to fetch additional relations from the database. Must not be {@literal null}.
* @param typeFactory must not be {@literal null}
* @param typeFactory must not be {@literal null}
*/
public MappingJdbcConverter(RelationalMappingContext context, RelationResolver relationResolver,
CustomConversions conversions, JdbcTypeFactory typeFactory) {
CustomConversions conversions, JdbcTypeFactory typeFactory) {
super(context, conversions);
@ -258,18 +258,18 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -258,18 +258,18 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
if (convertedValue.getClass().isArray()) {
if (componentType != byte.class && componentType != Byte.class) {
if (componentType != byte.class && componentType != Byte.class) {
Object[] objectArray = requireObjectArray(convertedValue);
return JdbcValue.of(typeFactory.createArray(objectArray), JDBCType.ARRAY);
}
Object[] objectArray = requireObjectArray(convertedValue);
return JdbcValue.of(typeFactory.createArray(objectArray), JDBCType.ARRAY);
}
if (componentType == Byte.class) {
convertedValue = ArrayUtils.toPrimitive((Byte[]) convertedValue);
}
if (componentType == Byte.class) {
convertedValue = ArrayUtils.toPrimitive((Byte[]) convertedValue);
}
return JdbcValue.of(convertedValue, JDBCType.BINARY);
}
return JdbcValue.of(convertedValue, JDBCType.BINARY);
}
return JdbcValue.of(convertedValue, sqlType);
}
@ -306,7 +306,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -306,7 +306,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
@Override
protected RelationalPropertyValueProvider newValueProvider(RowDocumentAccessor documentAccessor,
ValueExpressionEvaluator evaluator, ConversionContext context) {
ValueExpressionEvaluator evaluator, ConversionContext context) {
if (context instanceof ResolvingConversionContext rcc) {
@ -335,7 +335,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -335,7 +335,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
private final Identifier identifier;
private ResolvingRelationalPropertyValueProvider(AggregatePathValueProvider delegate, RowDocumentAccessor accessor,
ResolvingConversionContext context, Identifier identifier) {
ResolvingConversionContext context, Identifier identifier) {
AggregatePath path = context.aggregatePath();
@ -344,7 +344,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -344,7 +344,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
this.context = context;
this.identifier = path.isEntity()
? potentiallyAppendIdentifier(identifier, path.getRequiredLeafEntity(),
property -> delegate.getValue(path.append(property)))
property -> delegate.getValue(path.append(property)))
: identifier;
}
@ -352,7 +352,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -352,7 +352,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
* Conditionally append the identifier if the entity has an identifier property.
*/
static Identifier potentiallyAppendIdentifier(Identifier base, RelationalPersistentEntity<?> entity,
Function<RelationalPersistentProperty, Object> getter) {
Function<RelationalPersistentProperty, Object> getter) {
if (entity.hasIdProperty()) {
@ -481,7 +481,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -481,7 +481,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
return context == this.context ? this
: new ResolvingRelationalPropertyValueProvider(delegate.withContext(context), accessor,
(ResolvingConversionContext) context, identifier);
(ResolvingConversionContext) context, identifier);
}
}
@ -493,7 +493,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements @@ -493,7 +493,7 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
* @param identifier
*/
private record ResolvingConversionContext(ConversionContext delegate, AggregatePath aggregatePath,
Identifier identifier) implements ConversionContext {
Identifier identifier) implements ConversionContext {
@Override
public <S> S convert(Object source, TypeInformation<? extends S> typeHint) {

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

@ -44,7 +44,16 @@ import org.springframework.data.mapping.PersistentProperty; @@ -44,7 +44,16 @@ import org.springframework.data.mapping.PersistentProperty;
import org.springframework.data.mapping.PersistentPropertyAccessor;
import org.springframework.data.mapping.PersistentPropertyPathAccessor;
import org.springframework.data.mapping.context.MappingContext;
import org.springframework.data.mapping.model.*;
import org.springframework.data.mapping.model.CachingValueExpressionEvaluatorFactory;
import org.springframework.data.mapping.model.ConvertingPropertyAccessor;
import org.springframework.data.mapping.model.EntityInstantiator;
import org.springframework.data.mapping.model.ParameterValueProvider;
import org.springframework.data.mapping.model.PersistentEntityParameterValueProvider;
import org.springframework.data.mapping.model.PropertyValueProvider;
import org.springframework.data.mapping.model.SimpleTypeHolder;
import org.springframework.data.mapping.model.SpELContext;
import org.springframework.data.mapping.model.ValueExpressionEvaluator;
import org.springframework.data.mapping.model.ValueExpressionParameterValueProvider;
import org.springframework.data.projection.EntityProjection;
import org.springframework.data.projection.EntityProjectionIntrospector;
import org.springframework.data.projection.EntityProjectionIntrospector.ProjectionPredicate;
@ -792,16 +801,18 @@ public class MappingRelationalConverter extends AbstractRelationalConverter @@ -792,16 +801,18 @@ public class MappingRelationalConverter extends AbstractRelationalConverter
Class<?> targetComponentType = mapped.get(0).getClass();
targetType = Array.newInstance(targetComponentType, 0).getClass();
}
return getConversionService().convert(mapped, targetType);
}
/**
* Unwraps technology specific wrappers. Custom conversions may choose to return a wrapper class that contains additional information for the technology driver.
* These wrappers can't be used as members of a collection, therefore we may have to unwrap the values.
*
* This method allows technology specific implemenations to provide such an unwrapping mechanism.
* Unwraps technology-specific wrappers. Custom conversions may choose to return a wrapper class that contains
* additional information for the driver. These wrappers can't be used as members of a collection, therefore we may
* have to unwrap the values. This method allows technology-specific implementations to provide such an unwrapping
* mechanism.
*
* @param convertedValue a value that might need unwrapping.
* @since 3.5.2
*/
@Nullable
protected Object unwrap(@Nullable Object convertedValue) {

Loading…
Cancel
Save