Avoid double-conversion of values considered simple.

MappingJdbcConverter previously tried to create a JdbcValue for simple values via the ConversionService, only to drop the conversion result if the conversino did not result in a JdbcValue eventually. In that case it triggered an additional (same) conversion to then handle the wrapping of the conversion result into a JdbcValue manually.

This commit alters the flow so that it only triggers the conversion once and manually applies the JdbcValue wrapping only if the result of the original conversion is not a JdbcValue, yet.

Original pull request #1830
This commit is contained in:
Oliver Drotbohm
2024-07-08 14:27:58 +02:00
committed by Jens Schauder
parent 7bd907c5e6
commit 112c084b29

View File

@@ -243,15 +243,14 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
@Override
public JdbcValue writeJdbcValue(@Nullable Object value, TypeInformation<?> columnType, SQLType sqlType) {
JdbcValue jdbcValue = tryToConvertToJdbcValue(value);
if (jdbcValue != null) {
return jdbcValue;
TypeInformation<?> targetType = canWriteAsJdbcValue(value) ? TypeInformation.of(JdbcValue.class) : columnType;
Object convertedValue = writeValue(value, targetType);
if (convertedValue instanceof JdbcValue result) {
return result;
}
Object convertedValue = writeValue(value, columnType);
if (convertedValue == null || !convertedValue.getClass().isArray()) {
return JdbcValue.of(convertedValue, sqlType);
}
@@ -269,20 +268,6 @@ public class MappingJdbcConverter extends MappingRelationalConverter implements
return JdbcValue.of(convertedValue, JDBCType.BINARY);
}
@Nullable
private JdbcValue tryToConvertToJdbcValue(@Nullable Object value) {
if (canWriteAsJdbcValue(value)) {
Object converted = writeValue(value, TypeInformation.of(JdbcValue.class));
if (converted instanceof JdbcValue) {
return (JdbcValue) converted;
}
}
return null;
}
@SuppressWarnings("unchecked")
@Override
public <R> R readAndResolve(TypeInformation<R> type, RowDocument source, Identifier identifier) {