Search in sources :

Example 21 with Query

use of org.springframework.data.relational.core.query.Query 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')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 22 with Query

use of org.springframework.data.relational.core.query.Query 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')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Aggregations

Query (org.springframework.data.relational.core.query.Query)22 Test (org.junit.jupiter.api.Test)21 ExampleMatcher (org.springframework.data.domain.ExampleMatcher)18 Example (org.springframework.data.domain.Example)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Data (lombok.Data)1 NoArgsConstructor (lombok.NoArgsConstructor)1 Assertions (org.assertj.core.api.Assertions)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Id (org.springframework.data.annotation.Id)1 GenericPropertyMatchers (org.springframework.data.domain.ExampleMatcher.GenericPropertyMatchers)1 StringMatcher (org.springframework.data.domain.ExampleMatcher.StringMatcher)1 PersistentPropertyAccessor (org.springframework.data.mapping.PersistentPropertyAccessor)1 PropertyHandler (org.springframework.data.mapping.PropertyHandler)1 MappingContext (org.springframework.data.mapping.context.MappingContext)1 RelationalMappingContext (org.springframework.data.relational.core.mapping.RelationalMappingContext)1