DefaultQueryByExampleExecutor implements DataStoreAware, RepositoryConfigurationAware, RepositoryMetadataAware,
                   RepositoryFactoryConfigurationAware { public Iterable findAll(Example example) { return retrieveAll(example); } DefaultQueryByExampleExecutor(); Object findOne(Example example); Iterable findAll(Example example); Iterable findAll(Example example, Sort sort); Page findAll(Example example, Pageable pageable); long count(Example example); boolean exists(Example example); @Override void setDataStore(DataStore dataStore); @Override void setRepositoryConfiguration(RepositoryConfiguration repositoryConfiguration); @Override void setRepositoryMetadata(RepositoryMetadata repositoryMetadata); @Override void setRepositoryFactoryConfiguration(RepositoryFactoryConfiguration configuration);  }
@Test public void testFindByExampleUsingEndingWithMatcher() { final Person probe = new Person().setAddress(new Address().setState(new State().setName("ran"))); final ExampleMatcher matching = ExampleMatcher.matching().withMatcher("address.state.name", ExampleMatcher.GenericPropertyMatchers .endsWith()).withIgnoreCase(); final Example<Person> example = Example.of(probe, matching); final Iterable found = executor.findAll(example); assertThat(found, is(notNullValue())); final List<?> list = TestUtils.iterableToList(found); assertThat(list, hasSize(2)); }
@Test public void testFindByExampleUsingStartingWithMatcher() { final Person probe = new Person().setAddress(new Address().setState(new State().setName("Teh"))); final ExampleMatcher matching = ExampleMatcher.matching().withMatcher("address.state.name", ExampleMatcher.GenericPropertyMatchers .startsWith()).withIgnoreCase(); final Example<Person> example = Example.of(probe, matching); final Iterable found = executor.findAll(example); assertThat(found, is(notNullValue())); final List<?> list = TestUtils.iterableToList(found); assertThat(list, hasSize(2)); }
@Test public void testFindByExampleUsingContainingMatcher() { final Person probe = new Person().setAddress(new Address().setState(new State().setName("ehe"))); final ExampleMatcher matching = ExampleMatcher.matching().withMatcher("address.state.name", ExampleMatcher.GenericPropertyMatchers .contains()).withIgnoreCase(); final Example<Person> example = Example.of(probe, matching); final Iterable found = executor.findAll(example); assertThat(found, is(notNullValue())); final List<?> list = TestUtils.iterableToList(found); assertThat(list, hasSize(2)); }
@Test public void testFindByExampleUsingRegexMatcher() { final Person probe = new Person().setAddress(new Address().setState(new State().setName("(WA|Teheran)"))); final ExampleMatcher matching = ExampleMatcher.matching().withMatcher("address.state.name", ExampleMatcher.GenericPropertyMatchers .regex()).withIgnoreCase(); final Example<Person> example = Example.of(probe, matching); final Iterable found = executor.findAll(example); assertThat(found, is(notNullValue())); final List<?> list = TestUtils.iterableToList(found); assertThat(list, hasSize(4)); }
@Test public void testFindByExampleWithSorting() { final Person probe = new Person().setAddress(new Address().setState(new State().setName("(WA|Teheran)"))); final ExampleMatcher matching = ExampleMatcher.matching().withMatcher("address.state.name", ExampleMatcher.GenericPropertyMatchers .regex()).withIgnoreCase(); final Example<Person> example = Example.of(probe, matching); final Iterable found = executor.findAll(example, Sort.by(Sort.Direction.ASC, "firstName", "lastName", "address.state.name")); assertThat(found, is(notNullValue())); final List<?> list = TestUtils.iterableToList(found); assertThat(list, hasSize(4)); assertThat(list.get(0), is(dataStore.retrieve("1"))); assertThat(list.get(1), is(dataStore.retrieve("4"))); assertThat(list.get(2), is(dataStore.retrieve("3"))); assertThat(list.get(3), is(dataStore.retrieve("2"))); }
@Test public void testFindByExampleWithSortingAndPaging() { final Person probe = new Person().setAddress(new Address().setState(new State().setName("Teheran"))); final ExampleMatcher matching = ExampleMatcher.matching().withMatcher("address.state.name", ExampleMatcher.GenericPropertyMatchers .regex()).withIgnoreCase() .withIgnorePaths("address.state.name"); final Example<Person> example = Example.of(probe, matching); final Iterable found = executor.findAll(example, PageRequest .of(2, 1, Sort.by(Sort.Direction.ASC, "firstName", "lastName", "address.state.name"))); assertThat(found, is(notNullValue())); final List<?> list = TestUtils.iterableToList(found); assertThat(list, hasSize(1)); assertThat(list.get(0), is(dataStore.retrieve("3"))); }