|
|
|
@ -17,7 +17,9 @@ package org.springframework.data.jdbc.repository.query; |
|
|
|
|
|
|
|
|
|
|
|
import static org.springframework.data.jdbc.repository.query.JdbcQueryExecution.*; |
|
|
|
import static org.springframework.data.jdbc.repository.query.JdbcQueryExecution.*; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Array; |
|
|
|
import java.lang.reflect.Constructor; |
|
|
|
import java.lang.reflect.Constructor; |
|
|
|
|
|
|
|
import java.sql.JDBCType; |
|
|
|
import java.sql.SQLType; |
|
|
|
import java.sql.SQLType; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collection; |
|
|
|
import java.util.Collection; |
|
|
|
@ -45,6 +47,7 @@ import org.springframework.data.repository.query.SpelEvaluator; |
|
|
|
import org.springframework.data.repository.query.SpelQueryContext; |
|
|
|
import org.springframework.data.repository.query.SpelQueryContext; |
|
|
|
import org.springframework.data.util.Lazy; |
|
|
|
import org.springframework.data.util.Lazy; |
|
|
|
import org.springframework.data.util.TypeInformation; |
|
|
|
import org.springframework.data.util.TypeInformation; |
|
|
|
|
|
|
|
import org.springframework.data.util.TypeUtils; |
|
|
|
import org.springframework.jdbc.core.ResultSetExtractor; |
|
|
|
import org.springframework.jdbc.core.ResultSetExtractor; |
|
|
|
import org.springframework.jdbc.core.RowMapper; |
|
|
|
import org.springframework.jdbc.core.RowMapper; |
|
|
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; |
|
|
|
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; |
|
|
|
@ -204,13 +207,35 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery { |
|
|
|
TypeInformation<?> typeInformation = parameter.getTypeInformation(); |
|
|
|
TypeInformation<?> typeInformation = parameter.getTypeInformation(); |
|
|
|
|
|
|
|
|
|
|
|
JdbcValue jdbcValue; |
|
|
|
JdbcValue jdbcValue; |
|
|
|
if (typeInformation.isCollectionLike() && value instanceof Collection<?>) { |
|
|
|
if (typeInformation.isCollectionLike() //
|
|
|
|
|
|
|
|
&& value instanceof Collection<?> collectionValue//
|
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
if ( typeInformation.getActualType().getType().isArray() ){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TypeInformation<?> arrayElementType = typeInformation.getActualType().getActualType(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<Object[]> mapped = new ArrayList<>(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (Object array : collectionValue) { |
|
|
|
|
|
|
|
int length = Array.getLength(array); |
|
|
|
|
|
|
|
Object[] mappedArray = new Object[length]; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++) { |
|
|
|
|
|
|
|
Object element = Array.get(array, i); |
|
|
|
|
|
|
|
JdbcValue elementJdbcValue = converter.writeJdbcValue(element, arrayElementType, parameter.getActualSqlType()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mappedArray[i] = elementJdbcValue.getValue(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mapped.add(mappedArray); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
jdbcValue = JdbcValue.of(mapped, JDBCType.OTHER); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} else { |
|
|
|
List<Object> mapped = new ArrayList<>(); |
|
|
|
List<Object> mapped = new ArrayList<>(); |
|
|
|
SQLType jdbcType = null; |
|
|
|
SQLType jdbcType = null; |
|
|
|
|
|
|
|
|
|
|
|
TypeInformation<?> actualType = typeInformation.getRequiredActualType(); |
|
|
|
TypeInformation<?> actualType = typeInformation.getRequiredActualType(); |
|
|
|
for (Object o : (Iterable<?>) value) { |
|
|
|
for (Object o : collectionValue) { |
|
|
|
JdbcValue elementJdbcValue = converter.writeJdbcValue(o, actualType, parameter.getActualSqlType()); |
|
|
|
JdbcValue elementJdbcValue = converter.writeJdbcValue(o, actualType, parameter.getActualSqlType()); |
|
|
|
if (jdbcType == null) { |
|
|
|
if (jdbcType == null) { |
|
|
|
jdbcType = elementJdbcValue.getJdbcType(); |
|
|
|
jdbcType = elementJdbcValue.getJdbcType(); |
|
|
|
@ -220,7 +245,9 @@ public class StringBasedJdbcQuery extends AbstractJdbcQuery { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
jdbcValue = JdbcValue.of(mapped, jdbcType); |
|
|
|
jdbcValue = JdbcValue.of(mapped, jdbcType); |
|
|
|
|
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
|
|
|
|
|
|
|
|
SQLType sqlType = parameter.getSqlType(); |
|
|
|
SQLType sqlType = parameter.getSqlType(); |
|
|
|
jdbcValue = converter.writeJdbcValue(value, typeInformation, sqlType); |
|
|
|
jdbcValue = converter.writeJdbcValue(value, typeInformation, sqlType); |
|
|
|
} |
|
|
|
} |
|
|
|
|