use of org.springframework.data.jdbc.core.mapping.JdbcValue in project spring-data-jdbc by spring-projects.
the class DefaultDataAccessStrategy method addConvertedPropertyValuesAsList.
private void addConvertedPropertyValuesAsList(SqlIdentifierParameterSource parameterSource, RelationalPersistentProperty property, Iterable<?> values, SqlIdentifier paramName) {
List<Object> convertedIds = new ArrayList<>();
JdbcValue jdbcValue = null;
for (Object id : values) {
Class<?> columnType = converter.getColumnType(property);
SQLType sqlType = converter.getTargetSqlType(property);
jdbcValue = converter.writeJdbcValue(id, columnType, sqlType);
convertedIds.add(jdbcValue.getValue());
}
Assert.state(jdbcValue != null, "JdbcValue must be not null at this point. Please report this as a bug.");
SQLType jdbcType = jdbcValue.getJdbcType();
int typeNumber = jdbcType == null ? JdbcUtils.TYPE_UNKNOWN : jdbcType.getVendorTypeNumber();
parameterSource.addValue(paramName, convertedIds, typeNumber);
}
use of org.springframework.data.jdbc.core.mapping.JdbcValue in project spring-data-jdbc by spring-projects.
the class StringBasedJdbcQuery method convertAndAddParameter.
private void convertAndAddParameter(MapSqlParameterSource parameters, Parameter p, Object value) {
String parameterName = p.getName().orElseThrow(() -> new IllegalStateException(PARAMETER_NEEDS_TO_BE_NAMED));
Class<?> parameterType = queryMethod.getParameters().getParameter(p.getIndex()).getType();
Class<?> conversionTargetType = JdbcColumnTypes.INSTANCE.resolvePrimitiveType(parameterType);
JdbcValue jdbcValue = converter.writeJdbcValue(value, conversionTargetType, JdbcUtil.targetSqlTypeFor(conversionTargetType));
SQLType jdbcType = jdbcValue.getJdbcType();
if (jdbcType == null) {
parameters.addValue(parameterName, jdbcValue.getValue());
} else {
parameters.addValue(parameterName, jdbcValue.getValue(), jdbcType.getVendorTypeNumber());
}
}
Aggregations