|
|
|
@ -15,17 +15,8 @@ |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
package org.springframework.data.jdbc.repository.query; |
|
|
|
package org.springframework.data.jdbc.repository.query; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.LIST; |
|
|
|
import static org.assertj.core.api.Assertions.*; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.mockito.Mockito.*; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThatThrownBy; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.RETURNS_DEEP_STUBS; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.any; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.anyString; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.eq; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.mock; |
|
|
|
|
|
|
|
import static org.mockito.Mockito.verify; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.sql.JDBCType; |
|
|
|
import java.sql.JDBCType; |
|
|
|
@ -40,8 +31,10 @@ import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Properties; |
|
|
|
import java.util.Properties; |
|
|
|
import java.util.Set; |
|
|
|
import java.util.Set; |
|
|
|
|
|
|
|
import java.util.stream.Collectors; |
|
|
|
import java.util.stream.Stream; |
|
|
|
import java.util.stream.Stream; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.assertj.core.groups.Tuple; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.BeforeEach; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.mockito.ArgumentCaptor; |
|
|
|
import org.mockito.ArgumentCaptor; |
|
|
|
@ -92,6 +85,7 @@ import org.springframework.util.ReflectionUtils; |
|
|
|
* @author Chirag Tailor |
|
|
|
* @author Chirag Tailor |
|
|
|
* @author Christopher Klein |
|
|
|
* @author Christopher Klein |
|
|
|
* @author Marcin Grzejszczak |
|
|
|
* @author Marcin Grzejszczak |
|
|
|
|
|
|
|
* @author Mikhail Polivakha |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class StringBasedJdbcQueryUnitTests { |
|
|
|
class StringBasedJdbcQueryUnitTests { |
|
|
|
|
|
|
|
|
|
|
|
@ -322,23 +316,17 @@ class StringBasedJdbcQueryUnitTests { |
|
|
|
SqlParameterSource sqlParameterSource = forMethod("spelContainingQuery", ComplexEntity.class) |
|
|
|
SqlParameterSource sqlParameterSource = forMethod("spelContainingQuery", ComplexEntity.class) |
|
|
|
.withArguments(expressionRootObject).extractParameterSource(); |
|
|
|
.withArguments(expressionRootObject).extractParameterSource(); |
|
|
|
|
|
|
|
|
|
|
|
var expectedSqlTypes = Map.<Object, Integer>of( |
|
|
|
Set<Tuple> valueTypePairs = Arrays.stream(sqlParameterSource.getParameterNames()) //
|
|
|
|
type, Types.VARCHAR, |
|
|
|
.filter(n -> !n.equalsIgnoreCase("complexEntity")) //
|
|
|
|
score, Types.INTEGER, |
|
|
|
.map(n -> tuple(sqlParameterSource.getValue(n), sqlParameterSource.getSqlType(n))) //
|
|
|
|
creationDate, Types.TIMESTAMP, |
|
|
|
.collect(Collectors.toSet()); |
|
|
|
dayOfWeek, Types.VARCHAR |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(sqlParameterSource.getParameterNames()).hasSize(5); // 1 root + 4 expressions
|
|
|
|
assertThat(valueTypePairs).containsExactlyInAnyOrder( |
|
|
|
assertThat(sqlParameterSource.getParameterNames()).satisfies(parameterNames -> { |
|
|
|
tuple(type, Types.VARCHAR), |
|
|
|
for (var paramName : parameterNames) { |
|
|
|
tuple(score, Types.INTEGER), |
|
|
|
if (paramName.equalsIgnoreCase("complexEntity")) { |
|
|
|
tuple(creationDate, Types.TIMESTAMP), |
|
|
|
continue; // do not check root for sqlType
|
|
|
|
tuple(dayOfWeek, Types.VARCHAR) |
|
|
|
} |
|
|
|
); |
|
|
|
Object value = sqlParameterSource.getValue(paramName); |
|
|
|
|
|
|
|
assertThat(sqlParameterSource.getSqlType(paramName)).isEqualTo(expectedSqlTypes.get(value)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // GH-1212
|
|
|
|
@Test // GH-1212
|
|
|
|
@ -549,12 +537,12 @@ class StringBasedJdbcQueryUnitTests { |
|
|
|
List<Object> findByEnumTypeIn(Set<Direction> directions); |
|
|
|
List<Object> findByEnumTypeIn(Set<Direction> directions); |
|
|
|
|
|
|
|
|
|
|
|
@Query(value = """ |
|
|
|
@Query(value = """ |
|
|
|
SELECT * FROM my_table |
|
|
|
SELECT * FROM my_table |
|
|
|
WHERE t = :#{#complexEntity.type} |
|
|
|
WHERE t = :#{#complexEntity.type} |
|
|
|
AND s = :#{#complexEntity.score} |
|
|
|
AND s = :#{#complexEntity.score} |
|
|
|
AND cd = :#{#complexEntity.creationDate} |
|
|
|
AND cd = :#{#complexEntity.creationDate} |
|
|
|
AND dow = :#{#complexEntity.dayOfWeek} |
|
|
|
AND dow = :#{#complexEntity.dayOfWeek} |
|
|
|
""") |
|
|
|
""") |
|
|
|
List<Object> spelContainingQuery(ComplexEntity complexEntity); |
|
|
|
List<Object> spelContainingQuery(ComplexEntity complexEntity); |
|
|
|
|
|
|
|
|
|
|
|
@Query(value = "some sql statement") |
|
|
|
@Query(value = "some sql statement") |
|
|
|
|