Add support for executing derived existsBy queries.

Closes: #385
Original pull request: #386.
This commit is contained in:
Christoph Strobl
2021-07-23 07:02:04 +02:00
committed by Mark Paluch
parent 8f1c0ece24
commit 8c32f0ae6d
2 changed files with 24 additions and 0 deletions

View File

@@ -137,10 +137,32 @@ class KeyValuePartTreeQueryUnitTests {
assertThat(query.getRows()).isEqualTo(3);
}
@Test // GH-385
void shouldUseCountForExists() throws NoSuchMethodException {
when(metadataMock.getDomainType()).thenReturn((Class) Person.class);
when(metadataMock.getReturnType(any(Method.class)))
.thenReturn((TypeInformation) ClassTypeInformation.from(Boolean.class));
when(metadataMock.getReturnedDomainClass(any(Method.class))).thenReturn((Class) Boolean.class);
QueryMethod qm = new QueryMethod(Repo.class.getMethod("existsByFirstname", String.class), metadataMock,
projectionFactoryMock);
KeyValuePartTreeQuery partTreeQuery = new KeyValuePartTreeQuery(qm, QueryMethodEvaluationContextProvider.DEFAULT,
kvOpsMock, SpelQueryCreator.class);
KeyValueQuery<?> query = partTreeQuery.prepareQuery(new Object[] { "firstname" });
partTreeQuery.doExecute(new Object[] { "firstname" }, query);
verify(kvOpsMock).count(eq(query), eq(Person.class));
}
interface Repo {
List<Person> findByFirstname(String firstname);
boolean existsByFirstname(String firstname);
List<Person> findBy(Pageable page);
List<Person> findTop3By();