Search in sources :

Example 26 with Criteria

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

the class QueryMapperUnitTests method shouldMapSomeNestedCriteria.

// DATAJDBC-318
@Test
public void shouldMapSomeNestedCriteria() {
    Criteria criteria = Criteria.empty().and(Collections.emptyList()).and(Criteria.empty().and(Criteria.where("name").is("Hank")));
    assertThat(criteria.isEmpty()).isFalse();
    Condition condition = map(criteria);
    assertThat(condition).hasToString("((person.\"NAME\" = ?[:name]))");
}
Also used : Condition(org.springframework.data.relational.core.sql.Condition) Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 27 with Criteria

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

the class QueryMapperUnitTests method shouldMapNeq.

// DATAJDBC-318
@Test
public void shouldMapNeq() {
    Criteria criteria = Criteria.where("name").not("foo");
    Condition condition = map(criteria);
    assertThat(condition).hasToString("person.\"NAME\" != ?[:name]");
}
Also used : Condition(org.springframework.data.relational.core.sql.Condition) Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 28 with Criteria

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

the class QueryMapperUnitTests method shouldMapFrom.

// DATAJDBC-318
@Test
public void shouldMapFrom() {
    Criteria criteria = // 
    Criteria.from(Criteria.where("name").is("Foo")).and(// 
    Criteria.where("name").is("Bar").or("age").lessThan(// 
    49));
    assertThat(criteria.isEmpty()).isFalse();
    Condition condition = map(criteria);
    assertThat(condition).hasToString("person.\"NAME\" = ?[:name] AND (person.\"NAME\" = ?[:name1] OR person.age < ?[:age])");
}
Also used : Condition(org.springframework.data.relational.core.sql.Condition) Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 29 with Criteria

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

the class QueryMapperUnitTests method shouldNotMapEmptyNestedCriteria.

// DATAJDBC-318
@Test
public void shouldNotMapEmptyNestedCriteria() {
    Criteria criteria = Criteria.empty().and(Collections.emptyList()).and(Criteria.empty().and(Criteria.empty()));
    assertThat(criteria.isEmpty()).isTrue();
    assertThatIllegalArgumentException().isThrownBy(() -> map(criteria));
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 30 with Criteria

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

the class QueryMapperUnitTests method shouldNotMapEmptyAndCriteria.

// DATAJDBC-318
@Test
public void shouldNotMapEmptyAndCriteria() {
    Criteria criteria = Criteria.empty().and(Collections.emptyList());
    assertThatIllegalArgumentException().isThrownBy(() -> map(criteria));
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Aggregations

Criteria (org.springframework.data.relational.core.query.Criteria)50 Test (org.junit.jupiter.api.Test)49 Condition (org.springframework.data.relational.core.sql.Condition)22 QueryMethod (org.springframework.data.repository.query.QueryMethod)2 Part (org.springframework.data.repository.query.parser.Part)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 Example (org.springframework.data.domain.Example)1 ExampleMatcher (org.springframework.data.domain.ExampleMatcher)1 PersistentPropertyAccessor (org.springframework.data.mapping.PersistentPropertyAccessor)1 PropertyHandler (org.springframework.data.mapping.PropertyHandler)1 MappingContext (org.springframework.data.mapping.context.MappingContext)1 RelationalPersistentEntity (org.springframework.data.relational.core.mapping.RelationalPersistentEntity)1 RelationalPersistentProperty (org.springframework.data.relational.core.mapping.RelationalPersistentProperty)1 Query (org.springframework.data.relational.core.query.Query)1 ExampleMatcherAccessor (org.springframework.data.support.ExampleMatcherAccessor)1 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1 Assert (org.springframework.util.Assert)1