Skip to content

Commit 343569b

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 152fe93 commit 343569b

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
@@ -692,12 +692,13 @@ void createsQueryToFindByOpenProjection() throws Exception {
692692
.from(TABLE);
693693
}
694694

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

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

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

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

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

987988
Mono<OpenUserProjection> findOpenProjectionBy();
988989

989-
Mono<UserDtoProjection> findAsDtoProjectionBy();
990+
Mono<UserDtoProjection> findAsDtoProjectionByAge(int age);
990991

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

0 commit comments

Comments
 (0)