use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.
the class RelationalExampleMapperTests method queryByExampleSupportsPropertyTransforms.
// GH-929
@Test
void queryByExampleSupportsPropertyTransforms() {
Person person = new Person();
person.setFirstname("Frodo");
person.setLastname("Baggins");
person.setSecret("I have the ring!");
ExampleMatcher matcher = //
matching().withTransformer("firstname", o -> {
if (o.isPresent()) {
return o.map(o1 -> ((String) o1).toUpperCase());
}
return o;
}).withTransformer("lastname", o -> {
if (o.isPresent()) {
return o.map(o1 -> ((String) o1).toLowerCase());
}
return o;
});
Example<Person> example = Example.of(person, matcher);
Query query = exampleMapper.getMappedExample(example);
//
assertThat(query.getCriteria().map(Object::toString).get()).contains(//
"(firstname = 'FRODO')", //
" AND ", //
"(lastname = 'baggins')", "(secret = 'I have the ring!')");
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.
the class RelationalExampleMapperTests method queryByExampleWithNullMatchingFirstnameAndLastname.
// GH-929
@Test
void queryByExampleWithNullMatchingFirstnameAndLastname() {
Person person = new Person();
person.setFirstname("Bilbo");
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).get()).contains(//
"(firstname IS NULL OR firstname = 'Bilbo')", //
" AND ", "(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 queryByExampleWithFirstnameWithStringMatchingOnTheEnding.
// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingOnTheEnding() {
Person person = new Person();
person.setFirstname("do");
ExampleMatcher matcher = matching().withStringMatcher(ENDING);
Example<Person> example = Example.of(person, matcher);
Query query = exampleMapper.getMappedExample(example);
//
assertThat(query.getCriteria()).map(//
Object::toString).hasValue("(firstname LIKE '%do')");
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.
the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithFieldSpecificStringMatcherStartsWith.
// GH-929
@Test
void queryByExampleWithFirstnameWithFieldSpecificStringMatcherStartsWith() {
Person person = new Person();
person.setFirstname("Fro");
ExampleMatcher matcher = matching().withMatcher("firstname", startsWith());
Example<Person> example = Example.of(person, matcher);
Query query = exampleMapper.getMappedExample(example);
//
assertThat(query.getCriteria()).map(//
Object::toString).hasValue("(firstname LIKE 'Fro%')");
}
use of org.springframework.data.domain.ExampleMatcher in project spring-data-jdbc by spring-projects.
the class RelationalExampleMapperTests method queryByExampleWithFirstnameIgnoreCaseFieldLevel.
// GH-929
@Test
void queryByExampleWithFirstnameIgnoreCaseFieldLevel() {
Person person = new Person();
person.setFirstname("fro");
ExampleMatcher matcher = matching().withMatcher("firstname", startsWith().ignoreCase());
Example<Person> example = Example.of(person, matcher);
Query query = exampleMapper.getMappedExample(example);
//
assertThat(query.getCriteria()).map(//
Object::toString).hasValue("(firstname LIKE 'fro%')");
assertThat(example.getMatcher().getPropertySpecifiers().getForPath("firstname").getIgnoreCase()).isTrue();
}
Aggregations