Search in sources :

Example 31 with Criteria

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

the class QueryMapperUnitTests method shouldMapIsIn.

// DATAJDBC-318
@Test
public void shouldMapIsIn() {
    Criteria criteria = Criteria.where("name").in("a", "b", "c");
    Condition condition = map(criteria);
    assertThat(condition).hasToString("person.\"NAME\" IN (?[:name], ?[:name1], ?[:name2])");
}
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 32 with Criteria

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

the class QueryMapperUnitTests method shouldMapNestedGroup.

// DATAJDBC-318
@Test
public void shouldMapNestedGroup() {
    Criteria initial = Criteria.empty();
    Criteria criteria = // 
    initial.and(Criteria.where("name").is("Foo")).and(// 
    Criteria.where("name").is("Bar").or("age").lessThan(// 
    49).or(// 
    Criteria.where("name").not("Bar").and("age").greaterThan(// 
    49)));
    assertThat(criteria.isEmpty()).isFalse();
    Condition condition = map(criteria);
    assertThat(condition).hasToString("(person.\"NAME\" = ?[:name]) AND (person.\"NAME\" = ?[:name1] OR person.age < ?[:age] OR (person.\"NAME\" != ?[:name2] AND person.age > ?[:age1]))");
}
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 33 with Criteria

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

the class QueryMapperUnitTests method shouldMapBetween.

// DATAJDBC-318
@Test
public void shouldMapBetween() {
    Criteria criteria = Criteria.where("name").between("a", "b");
    Condition condition = map(criteria);
    assertThat(condition).hasToString("person.\"NAME\" BETWEEN ?[:name] AND ?[:name1]");
}
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 34 with Criteria

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

the class QueryMapperUnitTests method shouldMapSimpleCriteriaWithoutEntity.

// DATAJDBC-318
@Test
public void shouldMapSimpleCriteriaWithoutEntity() {
    Criteria criteria = Criteria.where("name").is("foo");
    Condition condition = mapper.getMappedObject(new MapSqlParameterSource(), criteria, Table.create("person"), null);
    assertThat(condition).hasToString("person.name = ?[:name]");
}
Also used : Condition(org.springframework.data.relational.core.sql.Condition) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 35 with Criteria

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

the class QueryMapperUnitTests method shouldMapIsNotNull.

// DATAJDBC-318
@Test
public void shouldMapIsNotNull() {
    Criteria criteria = Criteria.where("name").isNotNull();
    Condition condition = map(criteria);
    assertThat(condition).hasToString("person.\"NAME\" IS NOT NULL");
}
Also used : Condition(org.springframework.data.relational.core.sql.Condition) 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