Search in sources :

Example 11 with Condition

use of org.springframework.data.relational.core.sql.Condition 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 12 with Condition

use of org.springframework.data.relational.core.sql.Condition 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 13 with Condition

use of org.springframework.data.relational.core.sql.Condition 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 14 with Condition

use of org.springframework.data.relational.core.sql.Condition 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 15 with Condition

use of org.springframework.data.relational.core.sql.Condition 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)

Aggregations

Test (org.junit.jupiter.api.Test)22 Criteria (org.springframework.data.relational.core.query.Criteria)22 Condition (org.springframework.data.relational.core.sql.Condition)22 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)1