|
17 | 17 |
|
18 | 18 | import static org.springframework.data.jdbc.repository.query.JdbcQueryExecution.*;
|
19 | 19 |
|
| 20 | +import java.lang.reflect.Array; |
20 | 21 | import java.lang.reflect.Constructor;
|
| 22 | +import java.sql.JDBCType; |
21 | 23 | import java.sql.SQLType;
|
22 | 24 | import java.util.ArrayList;
|
23 | 25 | import java.util.Collection;
|
|
45 | 47 | import org.springframework.data.repository.query.SpelQueryContext;
|
46 | 48 | import org.springframework.data.util.Lazy;
|
47 | 49 | import org.springframework.data.util.TypeInformation;
|
| 50 | +import org.springframework.data.util.TypeUtils; |
48 | 51 | import org.springframework.jdbc.core.ResultSetExtractor;
|
49 | 52 | import org.springframework.jdbc.core.RowMapper;
|
50 | 53 | import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
@@ -205,24 +208,44 @@ private void convertAndAddParameter(MapSqlParameterSource parameters, Parameter
|
205 | 208 |
|
206 | 209 | JdbcValue jdbcValue;
|
207 | 210 | if (typeInformation.isCollectionLike() //
|
208 |
| - && value instanceof Collection<?> // |
209 |
| - && !typeInformation.getActualType().getType().isArray() |
| 211 | + && value instanceof Collection<?> collectionValue// |
210 | 212 | ) {
|
| 213 | + if ( typeInformation.getActualType().getType().isArray() ){ |
211 | 214 |
|
212 |
| - List<Object> mapped = new ArrayList<>(); |
213 |
| - SQLType jdbcType = null; |
| 215 | + TypeInformation<?> arrayElementType = typeInformation.getActualType().getActualType(); |
214 | 216 |
|
215 |
| - TypeInformation<?> actualType = typeInformation.getRequiredActualType(); |
216 |
| - for (Object o : (Iterable<?>) value) { |
217 |
| - JdbcValue elementJdbcValue = converter.writeJdbcValue(o, actualType, parameter.getActualSqlType()); |
218 |
| - if (jdbcType == null) { |
219 |
| - jdbcType = elementJdbcValue.getJdbcType(); |
| 217 | + List<Object[]> mapped = new ArrayList<>(); |
| 218 | + |
| 219 | + for (Object array : collectionValue) { |
| 220 | + int length = Array.getLength(array); |
| 221 | + Object[] mappedArray = new Object[length]; |
| 222 | + |
| 223 | + for (int i = 0; i < length; i++) { |
| 224 | + Object element = Array.get(array, i); |
| 225 | + JdbcValue elementJdbcValue = converter.writeJdbcValue(element, arrayElementType, parameter.getActualSqlType()); |
| 226 | + |
| 227 | + mappedArray[i] = elementJdbcValue.getValue(); |
| 228 | + } |
| 229 | + mapped.add(mappedArray); |
220 | 230 | }
|
| 231 | + jdbcValue = JdbcValue.of(mapped, JDBCType.OTHER); |
221 | 232 |
|
222 |
| - mapped.add(elementJdbcValue.getValue()); |
223 |
| - } |
| 233 | + } else { |
| 234 | + List<Object> mapped = new ArrayList<>(); |
| 235 | + SQLType jdbcType = null; |
224 | 236 |
|
225 |
| - jdbcValue = JdbcValue.of(mapped, jdbcType); |
| 237 | + TypeInformation<?> actualType = typeInformation.getRequiredActualType(); |
| 238 | + for (Object o : collectionValue) { |
| 239 | + JdbcValue elementJdbcValue = converter.writeJdbcValue(o, actualType, parameter.getActualSqlType()); |
| 240 | + if (jdbcType == null) { |
| 241 | + jdbcType = elementJdbcValue.getJdbcType(); |
| 242 | + } |
| 243 | + |
| 244 | + mapped.add(elementJdbcValue.getValue()); |
| 245 | + } |
| 246 | + |
| 247 | + jdbcValue = JdbcValue.of(mapped, jdbcType); |
| 248 | + } |
226 | 249 | } else {
|
227 | 250 |
|
228 | 251 | SQLType sqlType = parameter.getSqlType();
|
|
0 commit comments