DefaultQueryDslPredicateExecutor extends PagingAndSortingSupport implements DataStoreAware { public Iterable findAll(Predicate predicate) { return ((CollQuery) CollQueryFactory.from(alias, dataStore.retrieveAll()).where(predicate)).fetch(); }  Object findOne(Predicate predicate); Iterable findAll(Predicate predicate); Iterable findAll(Predicate predicate, Sort sort); Page findAll(Predicate predicate, Pageable pageable); long count(Predicate predicate); boolean exists(Predicate predicate); Iterable findAll(OrderSpecifier... orders); Iterable findAll(Predicate predicate, OrderSpecifier... orders); @Override void setDataStore(DataStore dataStore);  }
@Test public void testFindAllUsingAPredicate() { dataStore.save("1", new Person().setId("1").setAge(10)); dataStore.save("2", new Person().setId("2").setAge(15)); dataStore.save("3", new Person().setId("3").setAge(20)); dataStore.save("4", new Person().setId("4").setAge(25)); dataStore.save("5", new Person().setId("5").setAge(30)); final Person person = alias(Person.class); final Iterable result = executor.findAll($(person.getAge()).gt(20).or($(person.getAge()).eq(20))); assertThat(result, is(notNullValue())); final List<?> list = TestUtils.iterableToList(result); assertThat(list, hasSize(3)); final List<String> ids = new ArrayList<>(Arrays.asList("3", "4", "5")); for (Object obj : list) { assertThat(obj, is(instanceOf(Person.class))); final Person loaded = (Person) obj; assertThat(loaded.getId(), isIn(ids)); ids.remove(loaded.getId()); } assertThat(ids, is(Matchers.empty())); }
@Test public void testFindAllWithSort() { dataStore.save("1", new Person().setId("1").setAge(30)); dataStore.save("2", new Person().setId("2").setAge(25)); dataStore.save("3", new Person().setId("3").setAge(20)); dataStore.save("4", new Person().setId("4").setAge(15)); dataStore.save("5", new Person().setId("5").setAge(10)); final Person person = alias(Person.class); final Iterable result = executor.findAll($(person.getAge()).gt(20).or($(person.getAge()).eq(20)), Sort.by(Sort.Direction.ASC, "age")); assertThat(result, is(notNullValue())); final List<?> list = TestUtils.iterableToList(result); assertThat(list, hasSize(3)); assertThat(list.get(0), Matchers.is(dataStore.retrieve("3"))); assertThat(list.get(1), Matchers.is(dataStore.retrieve("2"))); assertThat(list.get(2), Matchers.is(dataStore.retrieve("1"))); }
@Test public void testFindAllWithPagingAndSorting() { dataStore.save("1", new Person().setId("1").setAge(30)); dataStore.save("2", new Person().setId("2").setAge(25)); dataStore.save("3", new Person().setId("3").setAge(20)); dataStore.save("4", new Person().setId("4").setAge(15)); dataStore.save("5", new Person().setId("5").setAge(10)); final Person person = alias(Person.class); final Iterable result = executor.findAll($(person.getAge()).gt(20).or($(person.getAge()).eq(20)), PageRequest.of(0, 2, Sort.by(Sort.Direction.ASC, "age"))); assertThat(result, is(notNullValue())); final List<?> list = TestUtils.iterableToList(result); assertThat(list, hasSize(2)); assertThat(list.get(0), Matchers.is(dataStore.retrieve("3"))); assertThat(list.get(1), Matchers.is(dataStore.retrieve("2"))); }
@Test public void testFindAllWithPaging() { dataStore.save("1", new Person().setId("1").setAge(30)); dataStore.save("2", new Person().setId("2").setAge(25)); dataStore.save("3", new Person().setId("3").setAge(20)); dataStore.save("4", new Person().setId("4").setAge(15)); dataStore.save("5", new Person().setId("5").setAge(10)); final Person person = alias(Person.class); final Iterable result = executor.findAll($(person.getAge()).gt(20).or($(person.getAge()).eq(20)), PageRequest.of(0, 2)); assertThat(result, is(notNullValue())); final List<?> list = TestUtils.iterableToList(result); assertThat(list, hasSize(2)); for (Object obj : list) { assertThat(obj, is(instanceOf(Person.class))); final Person loaded = (Person) obj; assertThat(loaded, is(dataStore.retrieve(loaded.getId()))); } }
@Test public void testFindAllWithExplicitOrdering() { dataStore.save("1", new Person().setId("1").setAge(30)); dataStore.save("2", new Person().setId("2").setAge(25)); dataStore.save("3", new Person().setId("3").setAge(20)); dataStore.save("4", new Person().setId("4").setAge(15)); dataStore.save("5", new Person().setId("5").setAge(10)); final Person person = alias(Person.class); final Iterable all = executor.findAll($(person.getAge()).asc()); assertThat(all, is(notNullValue())); final List<?> list = TestUtils.iterableToList(all); assertThat(list, hasSize(5)); assertThat(list.get(0), Matchers.is(dataStore.retrieve("5"))); assertThat(list.get(1), Matchers.is(dataStore.retrieve("4"))); assertThat(list.get(2), Matchers.is(dataStore.retrieve("3"))); assertThat(list.get(3), Matchers.is(dataStore.retrieve("2"))); assertThat(list.get(4), Matchers.is(dataStore.retrieve("1"))); }
@Test public void testFindAllWithPredicateAndExplicitOrdering() { dataStore.save("1", new Person().setId("1").setAge(30)); dataStore.save("2", new Person().setId("2").setAge(25)); dataStore.save("3", new Person().setId("3").setAge(20)); dataStore.save("4", new Person().setId("4").setAge(15)); dataStore.save("5", new Person().setId("5").setAge(10)); final Person person = alias(Person.class); final Iterable all = executor.findAll($(person.getAge()).gt(20), $(person.getAge()).asc()); assertThat(all, is(notNullValue())); final List<?> list = TestUtils.iterableToList(all); assertThat(list, hasSize(2)); assertThat(list.get(0), Matchers.is(dataStore.retrieve("2"))); assertThat(list.get(1), Matchers.is(dataStore.retrieve("1"))); }