|
|
|
@ -352,9 +352,7 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
if (getConversions().hasCustomReadTarget(RowDocument.class, rawType)) { |
|
|
|
if (getConversions().hasCustomReadTarget(RowDocument.class, rawType)) { |
|
|
|
|
|
|
|
|
|
|
|
S converted = doConvert(documentAccessor.getDocument(), rawType, typeHint.getType()); |
|
|
|
S converted = doConvert(documentAccessor.getDocument(), rawType, typeHint.getType()); |
|
|
|
|
|
|
|
|
|
|
|
Assert.state(converted != null, "Converted must not be null"); |
|
|
|
Assert.state(converted != null, "Converted must not be null"); |
|
|
|
|
|
|
|
|
|
|
|
return converted; |
|
|
|
return converted; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -363,7 +361,10 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (typeHint.isMap()) { |
|
|
|
if (typeHint.isMap()) { |
|
|
|
return context.convert(documentAccessor, typeHint); |
|
|
|
|
|
|
|
|
|
|
|
S converted = context.convert(documentAccessor, typeHint); |
|
|
|
|
|
|
|
Assert.state(converted != null, "Converted must not be null"); |
|
|
|
|
|
|
|
return converted; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
RelationalPersistentEntity<?> entity = getMappingContext().getPersistentEntity(typeHint); |
|
|
|
RelationalPersistentEntity<?> entity = getMappingContext().getPersistentEntity(typeHint); |
|
|
|
@ -425,7 +426,7 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
* @param targetType the {@link Map} {@link TypeInformation} to be used to unmarshall this {@link RowDocument}. |
|
|
|
* @param targetType the {@link Map} {@link TypeInformation} to be used to unmarshall this {@link RowDocument}. |
|
|
|
* @return the converted {@link Collection} or array, will never be {@literal null}. |
|
|
|
* @return the converted {@link Collection} or array, will never be {@literal null}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
protected @Nullable Object readCollectionOrArray(ConversionContext context, Collection<?> source, |
|
|
|
protected Object readCollectionOrArray(ConversionContext context, Collection<?> source, |
|
|
|
TypeInformation<?> targetType) { |
|
|
|
TypeInformation<?> targetType) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(targetType, "Target type must not be null"); |
|
|
|
Assert.notNull(targetType, "Target type must not be null"); |
|
|
|
@ -444,14 +445,14 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
: CollectionFactory.createCollection(collectionType, rawComponentType, source.size()); |
|
|
|
: CollectionFactory.createCollection(collectionType, rawComponentType, source.size()); |
|
|
|
|
|
|
|
|
|
|
|
if (source.isEmpty()) { |
|
|
|
if (source.isEmpty()) { |
|
|
|
return getPotentiallyConvertedSimpleRead(items, targetType); |
|
|
|
return getRequiredPotentiallyConvertedSimpleRead(items, targetType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (Object element : source) { |
|
|
|
for (Object element : source) { |
|
|
|
items.add(element != null ? context.convert(element, componentType) : element); |
|
|
|
items.add(element != null ? context.convert(element, componentType) : element); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return getPotentiallyConvertedSimpleRead(items, targetType); |
|
|
|
return getRequiredPotentiallyConvertedSimpleRead(items, targetType); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private <T> @Nullable T doConvert(Object value, Class<? extends T> target) { |
|
|
|
private <T> @Nullable T doConvert(Object value, Class<? extends T> target) { |
|
|
|
@ -637,17 +638,17 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
* |
|
|
|
* |
|
|
|
* @param value a value as it is returned by the driver accessing the persistence store. May be {@literal null}. |
|
|
|
* @param value a value as it is returned by the driver accessing the persistence store. May be {@literal null}. |
|
|
|
* @param targetType {@link TypeInformation} into which the value is to be converted. Must not be {@literal null}. |
|
|
|
* @param targetType {@link TypeInformation} into which the value is to be converted. Must not be {@literal null}. |
|
|
|
* @return The converted value. May be {@literal null}. |
|
|
|
* @return the converted value, can be {@literal null}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Nullable |
|
|
|
public @Nullable Object readValue(@Nullable Object value, TypeInformation<?> targetType) { |
|
|
|
public Object readValue(@Nullable Object value, TypeInformation<?> targetType) { |
|
|
|
return null == value ? null : getPotentiallyConvertedSimpleRead(value, targetType); |
|
|
|
|
|
|
|
} |
|
|
|
if (null == value) { |
|
|
|
|
|
|
|
return null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return getPotentiallyConvertedSimpleRead(value, targetType); |
|
|
|
private Object getRequiredPotentiallyConvertedSimpleRead(Object value, TypeInformation<?> type) { |
|
|
|
|
|
|
|
Object result = getPotentiallyConvertedSimpleRead(value, type); |
|
|
|
|
|
|
|
Assert.state(result != null, "Converted must not be null"); |
|
|
|
|
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
@ -865,7 +866,7 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public <S> S convert(Object source, TypeInformation<? extends S> typeHint, ConversionContext context) { |
|
|
|
public <S> @Nullable S convert(Object source, TypeInformation<? extends S> typeHint, ConversionContext context) { |
|
|
|
|
|
|
|
|
|
|
|
Assert.notNull(source, "Source must not be null"); |
|
|
|
Assert.notNull(source, "Source must not be null"); |
|
|
|
Assert.notNull(typeHint, "TypeInformation must not be null"); |
|
|
|
Assert.notNull(typeHint, "TypeInformation must not be null"); |
|
|
|
@ -875,7 +876,6 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (source instanceof Collection<?> collection) { |
|
|
|
if (source instanceof Collection<?> collection) { |
|
|
|
|
|
|
|
|
|
|
|
if (typeHint.isCollectionLike() || typeHint.getType().isAssignableFrom(Collection.class)) { |
|
|
|
if (typeHint.isCollectionLike() || typeHint.getType().isAssignableFrom(Collection.class)) { |
|
|
|
return (S) collectionConverter.convert(context, collection, typeHint); |
|
|
|
return (S) collectionConverter.convert(context, collection, typeHint); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1011,9 +1011,9 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
* |
|
|
|
* |
|
|
|
* @param source must not be {@literal null}. |
|
|
|
* @param source must not be {@literal null}. |
|
|
|
* @param typeHint must not be {@literal null}. |
|
|
|
* @param typeHint must not be {@literal null}. |
|
|
|
* @return the converted object. |
|
|
|
* @return the converted object, can be {@literal null}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
default <S> S convert(Object source, TypeInformation<? extends S> typeHint) { |
|
|
|
default <S> @Nullable S convert(Object source, TypeInformation<? extends S> typeHint) { |
|
|
|
return convert(source, typeHint, this); |
|
|
|
return convert(source, typeHint, this); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -1023,9 +1023,9 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
* @param source must not be {@literal null}. |
|
|
|
* @param source must not be {@literal null}. |
|
|
|
* @param typeHint must not be {@literal null}. |
|
|
|
* @param typeHint must not be {@literal null}. |
|
|
|
* @param context must not be {@literal null}. |
|
|
|
* @param context must not be {@literal null}. |
|
|
|
* @return the converted object. |
|
|
|
* @return the converted object, can be {@literal null}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
<S> S convert(Object source, TypeInformation<? extends S> typeHint, ConversionContext context); |
|
|
|
<S> @Nullable S convert(Object source, TypeInformation<? extends S> typeHint, ConversionContext context); |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Obtain a {@link ConversionContext} for the given property {@code name}. |
|
|
|
* Obtain a {@link ConversionContext} for the given property {@code name}. |
|
|
|
@ -1186,9 +1186,8 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
@Nullable |
|
|
|
|
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public <T> T getPropertyValue(RelationalPersistentProperty property) { |
|
|
|
public <T> @Nullable T getPropertyValue(RelationalPersistentProperty property) { |
|
|
|
|
|
|
|
|
|
|
|
String expression = property.getSpelExpression(); |
|
|
|
String expression = property.getSpelExpression(); |
|
|
|
Object value = expression != null ? evaluator.evaluate(expression) : accessor.get(property); |
|
|
|
Object value = expression != null ? evaluator.evaluate(expression) : accessor.get(property); |
|
|
|
@ -1353,7 +1352,7 @@ public class MappingRelationalConverter extends AbstractRelationalConverter |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected <T> T potentiallyConvertExpressionValue(Object object, |
|
|
|
protected <T> @Nullable T potentiallyConvertExpressionValue(Object object, |
|
|
|
Parameter<T, RelationalPersistentProperty> parameter) { |
|
|
|
Parameter<T, RelationalPersistentProperty> parameter) { |
|
|
|
return context.convert(object, parameter.getType()); |
|
|
|
return context.convert(object, parameter.getType()); |
|
|
|
} |
|
|
|
} |
|
|
|
|