Search in sources :

Example 16 with Query

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

the class RelationalExampleMapperTests method queryByExampleEvenHandlesInvisibleFields.

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

Example 17 with Query

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

the class RelationalExampleMapperTests method queryByExampleWithFirstname.

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

Example 18 with Query

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

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithStringMatchingAtTheBeginning.

// GH-929
@Test
void queryByExampleWithFirstnameWithStringMatchingAtTheBeginning() {
    Person person = new Person();
    person.setFirstname("Fro");
    ExampleMatcher matcher = matching().withStringMatcher(STARTING);
    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 19 with Query

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

the class RelationalExampleMapperTests method queryByExampleWithFirstnameWithFieldSpecificStringMatcherEndsWith.

// GH-929
@Test
void queryByExampleWithFirstnameWithFieldSpecificStringMatcherEndsWith() {
    Person person = new Person();
    person.setFirstname("do");
    ExampleMatcher matcher = matching().withMatcher("firstname", endsWith());
    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 20 with Query

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

the class RelationalExampleMapperTests method queryByExampleWithFirstnameIgnoreCase.

// GH-929
@Test
void queryByExampleWithFirstnameIgnoreCase() {
    Person person = new Person();
    person.setFirstname("Frodo");
    ExampleMatcher matcher = matching().withIgnoreCase(true);
    Example<Person> example = Example.of(person, matcher);
    Query query = exampleMapper.getMappedExample(example);
    // 
    assertThat(query.getCriteria()).map(// 
    Object::toString).hasValue("(firstname = 'Frodo')");
    assertThat(example.getMatcher().isIgnoreCaseEnabled()).isTrue();
}
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