#139 - Consider value type in Dialect-specific array type conversion.

We now inspect the value type of a SettableValue before attempting to convert a value into an array type. This check allows applying custom conversions to map objects to a simple type and bypassing the array conversion afterwards.

Previously, we just relied on the property type without checking whether the value qualifies for array type conversion.
This commit is contained in:
Mark Paluch
2019-12-06 10:36:04 +01:00
parent 96706cf7ed
commit f2a76fa74f
3 changed files with 111 additions and 3 deletions

View File

@@ -101,7 +101,7 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
storeConverters.addAll(R2dbcCustomConversions.STORE_CONVERTERS);
R2dbcCustomConversions customConversions = new R2dbcCustomConversions(
StoreConversions.of(dialect.getSimpleTypeHolder(), storeConverters), storeConverters);
StoreConversions.of(dialect.getSimpleTypeHolder(), storeConverters), converters);
R2dbcMappingContext context = new R2dbcMappingContext();
context.setSimpleTypeHolder(customConversions.getSimpleTypeHolder());
@@ -215,7 +215,20 @@ public class DefaultReactiveDataAccessStrategy implements ReactiveDataAccessStra
}
private boolean shouldConvertArrayValue(RelationalPersistentProperty property, SettableValue value) {
return property.isCollectionLike();
if (!property.isCollectionLike()) {
return false;
}
if (value.hasValue() && (value.getValue() instanceof Collection || value.getValue().getClass().isArray())) {
return true;
}
if (Collection.class.isAssignableFrom(value.getType()) || value.getType().isArray()) {
return true;
}
return false;
}
private SettableValue getArrayValue(SettableValue value, RelationalPersistentProperty property) {

View File

@@ -56,7 +56,13 @@ public interface ReactiveDataAccessStrategy {
*/
OutboundRow getOutboundRow(Object object);
// TODO: Broaden T to Mono<T>/Flux<T> for reactive relational data access?
/**
* Returns a {@link BiFunction row mapping function} to map {@link Row rows} to {@code T}.
*
* @param typeToRead
* @param <T>
* @return
*/
<T> BiFunction<Row, RowMetadata, T> getRowMapper(Class<T> typeToRead);
/**