#363 - Count projection support for derived queries.

Original pull request: #360.
This commit is contained in:
mhyeon-lee
2020-05-05 22:50:31 +09:00
committed by Jens Schauder
parent 919d8c663f
commit d004bc0dd9
2 changed files with 36 additions and 8 deletions

View File

@@ -56,6 +56,7 @@ import org.springframework.data.repository.core.support.DefaultRepositoryMetadat
* @author Roman Chigvintsev
* @author Mark Paluch
* @author Mingyuan Wu
* @author Myeonghyeon Lee
*/
@RunWith(MockitoJUnitRunner.class)
public class PartTreeR2dbcQueryUnitTests {
@@ -618,6 +619,18 @@ public class PartTreeR2dbcQueryUnitTests {
+ ".foo FROM " + TABLE + " WHERE " + TABLE + ".first_name = $1");
}
@Test // DATAJDBC-534
public void createsQueryForCountProjection() throws Exception {
R2dbcQueryMethod queryMethod = getQueryMethod("countByFirstName", String.class);
PartTreeR2dbcQuery r2dbcQuery = new PartTreeR2dbcQuery(queryMethod, databaseClient, r2dbcConverter,
dataAccessStrategy);
BindableQuery query = r2dbcQuery.createQuery((getAccessor(queryMethod, new Object[] { "John" })));
assertThat(query.get())
.isEqualTo("SELECT COUNT(users.id) FROM " + TABLE + " WHERE " + TABLE + ".first_name = $1");
}
private R2dbcQueryMethod getQueryMethod(String methodName, Class<?>... parameterTypes) throws Exception {
Method method = UserRepository.class.getMethod(methodName, parameterTypes);
return new R2dbcQueryMethod(method, new DefaultRepositoryMetadata(UserRepository.class),
@@ -699,6 +712,8 @@ public class PartTreeR2dbcQueryUnitTests {
Mono<UserProjection> findDistinctByFirstName(String firstName);
Mono<Integer> deleteByFirstName(String firstName);
Mono<Long> countByFirstName(String firstName);
}
@Table("users")