|
19 | 19 |
|
20 | 20 | import java.lang.reflect.Array;
|
21 | 21 | import java.lang.reflect.Constructor;
|
22 |
| -import java.sql.JDBCType; |
23 | 22 | import java.sql.SQLType;
|
24 | 23 | import java.util.ArrayList;
|
25 | 24 | import java.util.Collection;
|
|
31 | 30 | import org.springframework.beans.BeanInstantiationException;
|
32 | 31 | import org.springframework.beans.BeanUtils;
|
33 | 32 | import org.springframework.beans.factory.BeanFactory;
|
| 33 | +import org.springframework.data.jdbc.core.convert.JdbcColumnTypes; |
34 | 34 | import org.springframework.data.jdbc.core.convert.JdbcConverter;
|
35 | 35 | import org.springframework.data.jdbc.core.mapping.JdbcValue;
|
| 36 | +import org.springframework.data.jdbc.support.JdbcUtil; |
36 | 37 | import org.springframework.data.relational.core.mapping.RelationalMappingContext;
|
37 | 38 | import org.springframework.data.relational.repository.query.RelationalParameterAccessor;
|
38 | 39 | import org.springframework.data.relational.repository.query.RelationalParametersParameterAccessor;
|
@@ -223,7 +224,7 @@ private JdbcValue writeValue(@Nullable Object value, TypeInformation<?> typeInfo
|
223 | 224 | if (actualType != null && actualType.getType().isArray()) {
|
224 | 225 |
|
225 | 226 | TypeInformation<?> nestedElementType = actualType.getRequiredActualType();
|
226 |
| - return writeCollection(collection, JDBCType.OTHER, |
| 227 | + return writeCollection(collection, parameter.getActualSqlType(), |
227 | 228 | array -> writeArrayValue(parameter, array, nestedElementType));
|
228 | 229 | }
|
229 | 230 |
|
@@ -265,21 +266,29 @@ private JdbcValue writeCollection(Collection<?> value, SQLType defaultType, Func
|
265 | 266 | return jdbcValue;
|
266 | 267 | }
|
267 | 268 |
|
268 |
| - private Object[] writeArrayValue(JdbcParameters.JdbcParameter parameter, Object array, |
| 269 | + private JdbcValue writeArrayValue(JdbcParameters.JdbcParameter parameter, Object array, |
269 | 270 | TypeInformation<?> nestedElementType) {
|
270 | 271 |
|
271 | 272 | int length = Array.getLength(array);
|
272 | 273 | Object[] mappedArray = new Object[length];
|
| 274 | + SQLType sqlType = null; |
273 | 275 |
|
274 | 276 | for (int i = 0; i < length; i++) {
|
275 | 277 |
|
276 | 278 | Object element = Array.get(array, i);
|
277 |
| - JdbcValue elementJdbcValue = converter.writeJdbcValue(element, nestedElementType, parameter.getActualSqlType()); |
| 279 | + JdbcValue converted = converter.writeJdbcValue(element, nestedElementType, parameter.getActualSqlType()); |
278 | 280 |
|
279 |
| - mappedArray[i] = elementJdbcValue.getValue(); |
| 281 | + if (sqlType == null && converted.getJdbcType() != null) { |
| 282 | + sqlType = converted.getJdbcType(); |
| 283 | + } |
| 284 | + mappedArray[i] = converted.getValue(); |
| 285 | + } |
| 286 | + |
| 287 | + if (sqlType == null) { |
| 288 | + sqlType = JdbcUtil.targetSqlTypeFor(JdbcColumnTypes.INSTANCE.resolvePrimitiveType(nestedElementType.getType())); |
280 | 289 | }
|
281 | 290 |
|
282 |
| - return mappedArray; |
| 291 | + return JdbcValue.of(mappedArray, sqlType); |
283 | 292 | }
|
284 | 293 |
|
285 | 294 | RowMapper<Object> determineRowMapper(ResultProcessor resultProcessor, boolean hasDynamicProjection) {
|
|
0 commit comments