Skip to content

Commit 52fbdb0

Browse files
committed
Create PartTree against the domain type.
We now derive queries against the domain type and no longer using the result type to ensure query mapping and query creation against the domain type. Closes #1688
1 parent 7b6a239 commit 52fbdb0

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,8 @@ public PartTreeJdbcQuery(RelationalMappingContext context, JdbcQueryMethod query
107107
this.converter = converter;
108108
this.rowMapperFactory = rowMapperFactory;
109109

110-
this.tree = new PartTree(queryMethod.getName(), queryMethod.getEntityInformation().getJavaType());
110+
this.tree = new PartTree(queryMethod.getName(), queryMethod.getResultProcessor()
111+
.getReturnedType().getDomainType());
111112
JdbcQueryCreator.validate(this.tree, this.parameters, this.converter.getMappingContext());
112113

113114
}

spring-data-r2dbc/src/main/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQuery.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ public PartTreeR2dbcQuery(R2dbcQueryMethod method, R2dbcEntityOperations entityO
6767
this.parameters = method.getParameters();
6868

6969
try {
70-
this.tree = new PartTree(method.getName(), method.getEntityInformation().getJavaType());
70+
this.tree = new PartTree(method.getName(), processor.getReturnedType()
71+
.getDomainType());
7172
R2dbcQueryCreator.validate(this.tree, this.parameters);
7273
} catch (RuntimeException e) {
7374
throw new IllegalArgumentException(
@@ -115,10 +116,9 @@ private Sort getDynamicSort(RelationalParameterAccessor accessor) {
115116

116117
@Override
117118
public String toString() {
118-
StringBuffer sb = new StringBuffer();
119-
sb.append(getClass().getSimpleName());
120-
sb.append(" [").append(getQueryMethod().getName());
121-
sb.append(']');
122-
return sb.toString();
119+
String sb = getClass().getSimpleName()
120+
+ " [" + getQueryMethod().getName()
121+
+ ']';
122+
return sb;
123123
}
124124
}

spring-data-r2dbc/src/test/java/org/springframework/data/r2dbc/repository/query/PartTreeR2dbcQueryUnitTests.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -693,12 +693,13 @@ void createsQueryToFindByOpenProjection() throws Exception {
693693
.from(TABLE);
694694
}
695695

696-
@Test // GH-475
696+
@Test
697+
// GH-475, GH-1687
697698
void createsDtoProjectionQuery() throws Exception {
698699

699-
R2dbcQueryMethod queryMethod = getQueryMethod("findAsDtoProjectionBy");
700+
R2dbcQueryMethod queryMethod = getQueryMethod("findAsDtoProjectionByAge", Integer.TYPE);
700701
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, operations, r2dbcConverter, dataAccessStrategy);
701-
PreparedOperation<?> preparedOperation = createQuery(queryMethod, r2dbcQuery);
702+
PreparedOperation<?> preparedOperation = createQuery(queryMethod, r2dbcQuery, 42);
702703

703704
PreparedOperationAssert.assertThat(preparedOperation) //
704705
.selects("users.id", "users.first_name", "users.last_name", "users.date_of_birth", "users.age", "users.active") //
@@ -757,7 +758,7 @@ void bindsParametersFromPublisher() throws Exception {
757758

758759
R2dbcQueryMethod queryMethod = getQueryMethod("findByFirstName", Mono.class);
759760
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, operations, r2dbcConverter, dataAccessStrategy);
760-
R2dbcParameterAccessor accessor = new R2dbcParameterAccessor(queryMethod, new Object[] { Mono.just("John") });
761+
R2dbcParameterAccessor accessor = new R2dbcParameterAccessor(queryMethod, Mono.just("John"));
761762

762763
PreparedOperation<?> preparedOperation = createQuery(r2dbcQuery, accessor.resolveParameters().block());
763764
BindTarget bindTarget = mock(BindTarget.class);
@@ -987,7 +988,7 @@ interface UserRepository extends Repository<User, Long> {
987988

988989
Mono<OpenUserProjection> findOpenProjectionBy();
989990

990-
Mono<UserDtoProjection> findAsDtoProjectionBy();
991+
Mono<UserDtoProjection> findAsDtoProjectionByAge(int age);
991992

992993
Mono<Integer> deleteByFirstName(String firstName);
993994

0 commit comments

Comments
 (0)