DATAREDIS-771 - Add support for IsTrue and IsFalse keywords in repository query methods.
We now support IsTrue and IsFalse keywords usage in repository query methods to create queries with predicates for boolean fields values without requiring to pass a boolean argument.
class Person {
@Id String id;
@Indexed Boolean alive;
}
interface PersonRepository extends Repository<Person, String> {
Person findByAliveIsTrue();
Person findByAliveIsFalse();
}
Original Pull Request: #342
This commit is contained in:
committed by
Christoph Strobl
parent
127aa26f68
commit
d73a0e1677
@@ -224,6 +224,24 @@ public abstract class RedisRepositoryIntegrationTestBase {
|
||||
assertThat(repo.findBy(firstPage.nextPageable()).getContent(), hasSize(1));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-771
|
||||
public void shouldFindByBooleanIsTrue() {
|
||||
|
||||
Person eddard = new Person("eddard", "stark");
|
||||
eddard.setAlive(true);
|
||||
|
||||
Person robb = new Person("robb", "stark");
|
||||
robb.setAlive(false);
|
||||
Person jon = new Person("jon", "snow");
|
||||
|
||||
repo.saveAll(Arrays.asList(eddard, robb, jon));
|
||||
|
||||
List<Person> result = repo.findPersonByAliveIsTrue();
|
||||
|
||||
assertThat(result, hasSize(1));
|
||||
assertThat(result, contains(eddard));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-547
|
||||
public void shouldReturnEmptyListWhenPageableOutOfBoundsUsingFindAll() {
|
||||
|
||||
@@ -374,6 +392,8 @@ public abstract class RedisRepositoryIntegrationTestBase {
|
||||
|
||||
Page<Person> findPersonByLastname(String lastname, Pageable page);
|
||||
|
||||
List<Person> findPersonByAliveIsTrue();
|
||||
|
||||
List<Person> findByFirstnameAndLastname(String firstname, String lastname);
|
||||
|
||||
List<Person> findByFirstnameOrLastname(String firstname, String lastname);
|
||||
@@ -429,6 +449,7 @@ public abstract class RedisRepositoryIntegrationTestBase {
|
||||
|
||||
@Id String id;
|
||||
@Indexed String firstname;
|
||||
@Indexed Boolean alive;
|
||||
String lastname;
|
||||
@Reference City city;
|
||||
City hometown;
|
||||
|
||||
@@ -173,6 +173,30 @@ public class RedisQueryCreatorUnitTests {
|
||||
creator.createQuery();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-771
|
||||
public void findByBooleanIsTrue() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
RedisQueryCreator creator = createQueryCreatorForMethodWithArgs(
|
||||
SampleRepository.class.getMethod("findByAliveIsTrue"), new Object[0]);
|
||||
|
||||
KeyValueQuery<RedisOperationChain> query = creator.createQuery();
|
||||
|
||||
assertThat(query.getCriteria().getSismember(), hasSize(1));
|
||||
assertThat(query.getCriteria().getSismember(), hasItem(new PathAndValue("alive", true)));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-771
|
||||
public void findByBooleanIsFalse() throws SecurityException, NoSuchMethodException {
|
||||
|
||||
RedisQueryCreator creator = createQueryCreatorForMethodWithArgs(
|
||||
SampleRepository.class.getMethod("findByAliveIsFalse"), new Object[0]);
|
||||
|
||||
KeyValueQuery<RedisOperationChain> query = creator.createQuery();
|
||||
|
||||
assertThat(query.getCriteria().getSismember(), hasSize(1));
|
||||
assertThat(query.getCriteria().getSismember(), hasItem(new PathAndValue("alive", false)));
|
||||
}
|
||||
|
||||
private RedisQueryCreator createQueryCreatorForMethodWithArgs(Method method, Object[] args) {
|
||||
|
||||
PartTree partTree = new PartTree(method.getName(), method.getReturnType());
|
||||
@@ -190,6 +214,10 @@ public class RedisQueryCreatorUnitTests {
|
||||
|
||||
Person findByAgeOrFirstname(Integer age, String firstname);
|
||||
|
||||
Person findByAliveIsTrue();
|
||||
|
||||
Person findByAliveIsFalse();
|
||||
|
||||
Person findByLocationWithin(Circle circle);
|
||||
|
||||
Person findByLocationNear(Point point, Distance distance);
|
||||
|
||||
Reference in New Issue
Block a user