Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid double-conversion of values considered simple. #1830

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,14 @@ private boolean canWriteAsJdbcValue(@Nullable Object value) {
@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);

Object convertedValue = writeValue(value, columnType);
if (convertedValue instanceof JdbcValue result) {
return result;
}

if (convertedValue == null || !convertedValue.getClass().isArray()) {

return JdbcValue.of(convertedValue, sqlType);
}

Expand All @@ -269,20 +268,6 @@ public JdbcValue writeJdbcValue(@Nullable Object value, TypeInformation<?> colum
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) {
Expand Down
Loading