Search in sources :

Example 1 with Query

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

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingAtTheBeginningIncludingNull.

// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingAtTheBeginningIncludingNull() {
    Person person = new Person();
    person.setFirstname("Fro");
    ExampleMatcher matcher = matching().withStringMatcher(STARTING).withIncludeNullValues();
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(firstname IS NULL OR 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 2 with Query

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

the class RelationalExampleMapperTests method queryByExampleWithFirstnameAndLastnameIgnoringFirstname.

// GH-929
@Test
void queryByExampleWithFirstnameAndLastnameIgnoringFirstname() {
    Person person = new Person();
    person.setFirstname("Frodo");
    person.setLastname("Baggins");
    ExampleMatcher matcher = matching().withIgnorePaths("firstname");
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(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 3 with Query

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

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingContaining.

// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingContaining() {
    Person person = new Person();
    person.setFirstname("do");
    ExampleMatcher matcher = matching().withStringMatcher(CONTAINING);
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(firstname LIKE '%do%')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 4 with Query

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

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingContainingIncludingNull.

// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingContainingIncludingNull() {
    Person person = new Person();
    person.setFirstname("do");
    ExampleMatcher matcher = matching().withStringMatcher(CONTAINING).withIncludeNullValues();
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(firstname IS NULL OR firstname LIKE '%do%')");
}
Also used : Query(org.springframework.data.relational.core.query.Query) ExampleMatcher(org.springframework.data.domain.ExampleMatcher) Test(org.junit.jupiter.api.Test)

Example 5 with Query

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

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithFieldSpecificStringMatcherContains.

// GH-929
@Test
void queryByExampleWithFirstnameWithFieldSpecificStringMatcherContains() {
    Person person = new Person();
    person.setFirstname("do");
    ExampleMatcher matcher = matching().withMatcher("firstname", contains());
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(firstname LIKE '%do%')");
}
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