use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.
the class RelationalExampleMapperTests method queryByExampleWithNullMatchingLastName.
// GH-929
@Test
void queryByExampleWithNullMatchingLastName() {
Person person = new Person();
person.setLastname("Baggins");
ExampleMatcher matcher = matching().withIncludeNullValues();
Example<Person> example = Example.of(person, matcher);
Query query = exampleMapper.getMappedExample(example);
//
assertThat(query.getCriteria()).map(//
Object::toString).hasValue("(lastname IS NULL OR lastname = 'Baggins')");
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.
the class RelationalExampleMapperTests method queryByExampleWithFirstnameOrLastname.
// GH-929
@Test
void queryByExampleWithFirstnameOrLastname() {
Person person = new Person();
person.setFirstname("Frodo");
person.setLastname("Baggins");
ExampleMatcher matcher = matchingAny();
Example<Person> example = Example.of(person, matcher);
Query query = exampleMapper.getMappedExample(example);
//
assertThat(query.getCriteria().map(Object::toString).get()).contains(//
"(firstname = 'Frodo')", //
" OR ", "(lastname = 'Baggins')");
}
use of org.springframework.data.domain.ExampleMatcher in project spring-cloud-gcp by spring-cloud.
the class DatastoreTemplate method validateExample.
private <T> void validateExample(Example<T> example) {
Assert.notNull(example, "A non-null example is expected");
ExampleMatcher matcher = example.getMatcher();
if (!matcher.isAllMatching()) {
throw new DatastoreDataException("Unsupported MatchMode. Only MatchMode.ALL is supported");
}
if (matcher.isIgnoreCaseEnabled()) {
throw new DatastoreDataException("Ignore case matching is not supported");
}
if (!(matcher.getDefaultStringMatcher() == ExampleMatcher.StringMatcher.EXACT || matcher.getDefaultStringMatcher() == ExampleMatcher.StringMatcher.DEFAULT)) {
throw new DatastoreDataException("Unsupported StringMatcher. Only EXACT and DEFAULT are supported");
}
Optional<String> path = example.getMatcher().getIgnoredPaths().stream().filter((s) -> s.contains(".")).findFirst();
if (path.isPresent()) {
throw new DatastoreDataException("Ignored paths deeper than 1 are not supported");
}
if (matcher.getPropertySpecifiers().hasValues()) {
throw new DatastoreDataException("Property matchers are not supported");
}
}
Aggregations