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
This commit is contained in:
@@ -107,7 +107,8 @@ public class PartTreeJdbcQuery extends AbstractJdbcQuery {
|
||||
this.converter = converter;
|
||||
this.rowMapperFactory = rowMapperFactory;
|
||||
|
||||
this.tree = new PartTree(queryMethod.getName(), queryMethod.getEntityInformation().getJavaType());
|
||||
this.tree = new PartTree(queryMethod.getName(), queryMethod.getResultProcessor()
|
||||
.getReturnedType().getDomainType());
|
||||
JdbcQueryCreator.validate(this.tree, this.parameters, this.converter.getMappingContext());
|
||||
|
||||
}
|
||||
|
||||
@@ -67,7 +67,8 @@ public class PartTreeR2dbcQuery extends AbstractR2dbcQuery {
|
||||
this.parameters = method.getParameters();
|
||||
|
||||
try {
|
||||
this.tree = new PartTree(method.getName(), method.getEntityInformation().getJavaType());
|
||||
this.tree = new PartTree(method.getName(), processor.getReturnedType()
|
||||
.getDomainType());
|
||||
R2dbcQueryCreator.validate(this.tree, this.parameters);
|
||||
} catch (RuntimeException e) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -115,10 +116,9 @@ public class PartTreeR2dbcQuery extends AbstractR2dbcQuery {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(getClass().getSimpleName());
|
||||
sb.append(" [").append(getQueryMethod().getName());
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
String sb = getClass().getSimpleName()
|
||||
+ " [" + getQueryMethod().getName()
|
||||
+ ']';
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -692,12 +692,13 @@ class PartTreeR2dbcQueryUnitTests {
|
||||
.from(TABLE);
|
||||
}
|
||||
|
||||
@Test // GH-475
|
||||
@Test
|
||||
// GH-475, GH-1687
|
||||
void createsDtoProjectionQuery() throws Exception {
|
||||
|
||||
R2dbcQueryMethod queryMethod = getQueryMethod("findAsDtoProjectionBy");
|
||||
R2dbcQueryMethod queryMethod = getQueryMethod("findAsDtoProjectionByAge", Integer.TYPE);
|
||||
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, operations, r2dbcConverter, dataAccessStrategy);
|
||||
PreparedOperation<?> preparedOperation = createQuery(queryMethod, r2dbcQuery);
|
||||
PreparedOperation<?> preparedOperation = createQuery(queryMethod, r2dbcQuery, 42);
|
||||
|
||||
PreparedOperationAssert.assertThat(preparedOperation) //
|
||||
.selects("users.id", "users.first_name", "users.last_name", "users.date_of_birth", "users.age", "users.active") //
|
||||
@@ -756,7 +757,7 @@ class PartTreeR2dbcQueryUnitTests {
|
||||
|
||||
R2dbcQueryMethod queryMethod = getQueryMethod("findByFirstName", Mono.class);
|
||||
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, operations, r2dbcConverter, dataAccessStrategy);
|
||||
R2dbcParameterAccessor accessor = new R2dbcParameterAccessor(queryMethod, new Object[] { Mono.just("John") });
|
||||
R2dbcParameterAccessor accessor = new R2dbcParameterAccessor(queryMethod, Mono.just("John"));
|
||||
|
||||
PreparedOperation<?> preparedOperation = createQuery(r2dbcQuery, accessor.resolveParameters().block());
|
||||
BindTarget bindTarget = mock(BindTarget.class);
|
||||
@@ -986,7 +987,7 @@ class PartTreeR2dbcQueryUnitTests {
|
||||
|
||||
Mono<OpenUserProjection> findOpenProjectionBy();
|
||||
|
||||
Mono<UserDtoProjection> findAsDtoProjectionBy();
|
||||
Mono<UserDtoProjection> findAsDtoProjectionByAge(int age);
|
||||
|
||||
Mono<Integer> deleteByFirstName(String firstName);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user