Search in sources :

Example 11 with Query

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

Example 12 with Query

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

Example 13 with Query

use of org.springframework.data.relational.core.query.Query in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameAndLastname.

// GH-929
@Test
void queryByExampleWithFirstnameAndLastname() {
    Person person = new Person();
    person.setFirstname("Frodo");
    person.setLastname("Baggins");
    Example<Person> example = Example.of(person);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria().map(Object::toString).get()).contains(// 
    "(firstname = 'Frodo')", // 
    " AND ", "(lastname = 'Baggins')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) Test(org.junit.jupiter.api.Test)

Example 14 with Query

use of org.springframework.data.relational.core.query.Query in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithFirstnameAndLastnameWithNullMatchingIgnoringFirstName.

// GH-929
@Test
void queryByExampleWithFirstnameAndLastnameWithNullMatchingIgnoringFirstName() {
    Person person = new Person();
    person.setFirstname("Frodo");
    person.setLastname("Baggins");
    ExampleMatcher matcher = matching().withIncludeNullValues().withIgnorePaths("firstname");
    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 15 with Query

use of org.springframework.data.relational.core.query.Query in project spring-data-jdbc by spring-projects.

the class RelationalExampleMapperTests method queryByExampleWithId.

// GH-929
@Test
void queryByExampleWithId() {
    Person person = new Person();
    person.setId("id1");
    Example<Person> example = Example.of(person);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Objects::toString).hasValue("(id = 'id1')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) 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