Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d98ef18

Browse files
committed
Polishing.
Fix Oracle test setup. Formatting. Restructure some code Author tags. Original pull request #2079 See #2007
1 parent 01f10dd commit d98ef18

File tree

11 files changed

+58
-71
lines changed

11 files changed

+58
-71
lines changed

‎spring-data-jdbc/src/main/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQuery.java

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package org.springframework.data.jdbc.repository.query;
1717

18-
import static org.springframework.data.jdbc.repository.query.JdbcQueryExecution.ResultProcessingConverter;
18+
import static org.springframework.data.jdbc.repository.query.JdbcQueryExecution.*;
1919

2020
import java.lang.reflect.Array;
2121
import java.lang.reflect.Constructor;
@@ -186,11 +186,8 @@ private String evaluateExpressions(Object[] objects, Parameters<?, ?> bindablePa
186186
return this.query;
187187
}
188188

189-
private static void addEvaluatedParameterToParameterSource(
190-
MapSqlParameterSource parameterMap,
191-
String paramName,
192-
ValueExpression valueExpression,
193-
ValueEvaluationContext evaluationContext) {
189+
private static void addEvaluatedParameterToParameterSource(MapSqlParameterSource parameterMap, String paramName,
190+
ValueExpression valueExpression, ValueEvaluationContext evaluationContext) {
194191

195192
Object evaluatedValue = valueExpression.evaluate(evaluationContext);
196193
Class<?> valueType = valueExpression.getValueType(evaluationContext);
@@ -215,8 +212,7 @@ private static void addEvaluatedParameterToParameterSource(
215212
}
216213

217214
private static SQLType getSqlType(Class<?> valueType) {
218-
Class<?> resolvedPrimitiveType = JdbcColumnTypes.INSTANCE.resolvePrimitiveType(valueType);
219-
return JdbcUtil.targetSqlTypeFor(resolvedPrimitiveType);
215+
return JdbcUtil.targetSqlTypeFor(JdbcColumnTypes.INSTANCE.resolvePrimitiveType(valueType));
220216
}
221217

222218
private JdbcQueryExecution<?> createJdbcQueryExecution(RelationalParameterAccessor accessor,

‎spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/JdbcRepositoryIntegrationTests.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
import org.junit.jupiter.params.provider.EnumSource;
4545
import org.junit.jupiter.params.provider.MethodSource;
4646
import org.junit.jupiter.params.provider.NullSource;
47-
import org.junit.jupiter.params.provider.ValueSource;
4847
import org.springframework.beans.factory.annotation.Autowired;
4948
import org.springframework.beans.factory.config.PropertiesFactoryBean;
5049
import org.springframework.context.ApplicationListener;
@@ -352,16 +351,15 @@ public void update() {
352351

353352
@ParameterizedTest
354353
@NullSource
355-
@EnumSource(value = EnumClass.class)
354+
@EnumSource(value = EnumClass.class)// GH-2007
356355
void shouldSaveWithCustomSpellExpressions(EnumClass value) {
356+
357357
expressionSqlTypePropagationRepository.saveWithSpel(new ExpressionSqlTypePropagation(1L, value));
358358

359-
varfound = expressionSqlTypePropagationRepository.findById(1L);
359+
ExpressionSqlTypePropagationreloaded = expressionSqlTypePropagationRepository.findById(1L).orElseThrow();
360360

361-
assertThat(found).isPresent().hasValueSatisfying(entity -> {
362-
assertThat(entity.getIdentifier()).isEqualTo(1L);
363-
assertThat(entity.getEnumClass()).isEqualTo(value);
364-
});
361+
assertThat(reloaded.getIdentifier()).isEqualTo(1L);
362+
assertThat(reloaded.getEnumClass()).isEqualTo(value);
365363
}
366364

367365
@Test // DATAJDBC-98
@@ -1596,13 +1594,12 @@ interface ExpressionSqlTypePropagationRepository extends CrudRepository<Expressi
15961594
// language=sql
15971595
@Modifying
15981596
@Query(value = """
1599-
INSERT INTO EXPRESSION_SQL_TYPE_PROPAGATION(identifier, enum_class)
1597+
INSERT INTO EXPRESSION_SQL_TYPE_PROPAGATION(identifier, enum_class)
16001598
VALUES(:#{#expressionSqlTypePropagation.identifier}, :#{#expressionSqlTypePropagation.enumClass})
1601-
""")
1599+
""")
16021600
void saveWithSpel(@Param("expressionSqlTypePropagation") ExpressionSqlTypePropagation expressionSqlTypePropagation);
16031601
}
16041602

1605-
16061603
interface DummyProjection {
16071604
String getName();
16081605
}
@@ -1930,8 +1927,7 @@ public Long getId() {
19301927

19311928
static class ExpressionSqlTypePropagation {
19321929

1933-
@Id
1934-
Long identifier;
1930+
@Id Long identifier;
19351931

19361932
EnumClass enumClass;
19371933

@@ -1950,8 +1946,7 @@ public Long getIdentifier() {
19501946
}
19511947

19521948
enum EnumClass {
1953-
ACTIVE,
1954-
DELETE
1949+
ACTIVE, DELETE
19551950
}
19561951

19571952
static class EntityWithSequence {

‎spring-data-jdbc/src/test/java/org/springframework/data/jdbc/repository/query/StringBasedJdbcQueryUnitTests.java

Lines changed: 21 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,8 @@
1515
*/
1616
package org.springframework.data.jdbc.repository.query;
1717

18-
import static org.assertj.core.api.Assertions.LIST;
19-
import static org.assertj.core.api.Assertions.assertThat;
20-
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
21-
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
22-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
23-
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
24-
import static org.mockito.Mockito.any;
25-
import static org.mockito.Mockito.anyString;
26-
import static org.mockito.Mockito.eq;
27-
import static org.mockito.Mockito.mock;
28-
import static org.mockito.Mockito.verify;
18+
import static org.assertj.core.api.Assertions.*;
19+
import static org.mockito.Mockito.*;
2920

3021
import java.lang.reflect.Method;
3122
import java.sql.JDBCType;
@@ -40,8 +31,10 @@
4031
import java.util.Map;
4132
import java.util.Properties;
4233
import java.util.Set;
34+
import java.util.stream.Collectors;
4335
import java.util.stream.Stream;
4436

37+
import org.assertj.core.groups.Tuple;
4538
import org.junit.jupiter.api.BeforeEach;
4639
import org.junit.jupiter.api.Test;
4740
import org.mockito.ArgumentCaptor;
@@ -92,6 +85,7 @@
9285
* @author Chirag Tailor
9386
* @author Christopher Klein
9487
* @author Marcin Grzejszczak
88+
* @author Mikhail Polivakha
9589
*/
9690
class StringBasedJdbcQueryUnitTests {
9791

@@ -322,23 +316,17 @@ void spelParametersSqlTypesArePropagatedCorrectly() {
322316
SqlParameterSource sqlParameterSource = forMethod("spelContainingQuery", ComplexEntity.class)
323317
.withArguments(expressionRootObject).extractParameterSource();
324318

325-
var expectedSqlTypes = Map.<Object, Integer>of(
326-
type, Types.VARCHAR,
327-
score, Types.INTEGER,
328-
creationDate, Types.TIMESTAMP,
329-
dayOfWeek, Types.VARCHAR
330-
);
319+
Set<Tuple> valueTypePairs = Arrays.stream(sqlParameterSource.getParameterNames()) //
320+
.filter(n -> !n.equalsIgnoreCase("complexEntity")) //
321+
.map(n -> tuple(sqlParameterSource.getValue(n), sqlParameterSource.getSqlType(n))) //
322+
.collect(Collectors.toSet());
331323

332-
assertThat(sqlParameterSource.getParameterNames()).hasSize(5); // 1 root + 4 expressions
333-
assertThat(sqlParameterSource.getParameterNames()).satisfies(parameterNames -> {
334-
for (var paramName : parameterNames) {
335-
if (paramName.equalsIgnoreCase("complexEntity")) {
336-
continue; // do not check root for sqlType
337-
}
338-
Object value = sqlParameterSource.getValue(paramName);
339-
assertThat(sqlParameterSource.getSqlType(paramName)).isEqualTo(expectedSqlTypes.get(value));
340-
}
341-
});
324+
assertThat(valueTypePairs).containsExactlyInAnyOrder(
325+
tuple(type, Types.VARCHAR),
326+
tuple(score, Types.INTEGER),
327+
tuple(creationDate, Types.TIMESTAMP),
328+
tuple(dayOfWeek, Types.VARCHAR)
329+
);
342330
}
343331

344332
@Test // GH-1212
@@ -549,12 +537,12 @@ interface MyRepository extends Repository<Object, Long> {
549537
List<Object> findByEnumTypeIn(Set<Direction> directions);
550538

551539
@Query(value = """
552-
SELECT * FROM my_table
553-
WHERE t = :#{#complexEntity.type}
554-
AND s = :#{#complexEntity.score}
555-
AND cd = :#{#complexEntity.creationDate}
556-
AND dow = :#{#complexEntity.dayOfWeek}
557-
""")
540+
SELECT * FROM my_table
541+
WHERE t = :#{#complexEntity.type}
542+
AND s = :#{#complexEntity.score}
543+
AND cd = :#{#complexEntity.creationDate}
544+
AND dow = :#{#complexEntity.dayOfWeek}
545+
""")
558546
List<Object> spelContainingQuery(ComplexEntity complexEntity);
559547

560548
@Query(value = "some sql statement")

‎spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-db2.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ CREATE TABLE PROVIDED_ID_ENTITY
6565
NAME VARCHAR(30)
6666
);
6767

68-
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION(
69-
IDENTIFIER BIGINT NOT NULL PRIMARY KEY,
68+
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION
69+
(
70+
IDENTIFIER BIGINT NOT NULL PRIMARY KEY,
7071
ENUM_CLASS VARCHAR(30)
7172
);

‎spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-h2.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ CREATE TABLE PROVIDED_ID_ENTITY
5555
NAME VARCHAR(30)
5656
);
5757

58-
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION(
59-
IDENTIFIER BIGINT PRIMARY KEY,
58+
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION
59+
(
60+
IDENTIFIER BIGINT PRIMARY KEY,
6061
ENUM_CLASS VARCHAR(30)
6162
);

‎spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-hsql.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ CREATE TABLE PROVIDED_ID_ENTITY
5555
NAME VARCHAR(30)
5656
);
5757

58-
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION(
59-
IDENTIFIER BIGINT PRIMARY KEY,
58+
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION
59+
(
60+
IDENTIFIER BIGINT PRIMARY KEY,
6061
ENUM_CLASS VARCHAR(30)
6162
);

‎spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mariadb.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ CREATE TABLE PROVIDED_ID_ENTITY
5555
NAME VARCHAR(30)
5656
);
5757

58-
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION(
59-
IDENTIFIER BIGINT PRIMARY KEY,
58+
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION
59+
(
60+
IDENTIFIER BIGINT PRIMARY KEY,
6061
ENUM_CLASS VARCHAR(30)
6162
);

‎spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mssql.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ CREATE TABLE PROVIDED_ID_ENTITY
6565
NAME VARCHAR(30)
6666
);
6767

68-
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION(
69-
IDENTIFIER BIGINT PRIMARY KEY,
68+
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION
69+
(
70+
IDENTIFIER BIGINT PRIMARY KEY,
7071
ENUM_CLASS VARCHAR(30)
7172
);

‎spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-mysql.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
SET
2-
SQL_MODE = 'ALLOW_INVALID_DATES';
2+
SQL_MODE = 'ALLOW_INVALID_DATES';
33

44
CREATE TABLE DUMMY_ENTITY
55
(
@@ -50,7 +50,8 @@ CREATE TABLE PROVIDED_ID_ENTITY
5050
NAME VARCHAR(30)
5151
);
5252

53-
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION(
54-
IDENTIFIER BIGINT PRIMARY KEY,
53+
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION
54+
(
55+
IDENTIFIER BIGINT PRIMARY KEY,
5556
ENUM_CLASS VARCHAR(30)
5657
);

‎spring-data-jdbc/src/test/resources/org.springframework.data.jdbc.repository/JdbcRepositoryIntegrationTests-oracle.sql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ CREATE TABLE PROVIDED_ID_ENTITY
6565
NAME VARCHAR2(30)
6666
);
6767

68-
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION(
69-
IDENTIFIER BIGINT PRIMARY KEY,
68+
CREATE TABLE EXPRESSION_SQL_TYPE_PROPAGATION
69+
(
70+
IDENTIFIER NUMBER PRIMARY KEY,
7071
ENUM_CLASS VARCHAR2(30)
7172
);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /