Search in sources :

Example 6 with Condition

use of org.springframework.data.relational.core.sql.Condition in project spring-data-jdbc by spring-projects.

the class QueryMapperUnitTests method shouldMapAndOrCriteria.

// DATAJDBC-318
@Test
public void shouldMapAndOrCriteria() {
    Criteria criteria = // 
    Criteria.where("name").is("foo").and("name").isNotNull().or("bar").is(// 
    "baz").and("anotherOne").is("alternative");
    Condition condition = map(criteria);
    assertThat(condition).hasToString("person.\"NAME\" = ?[:name] AND person.\"NAME\" IS NOT NULL OR person.bar = ?[:bar] AND person.anotherOne = ?[:anotherOne]");
}
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 7 with Condition

use of org.springframework.data.relational.core.sql.Condition in project spring-data-jdbc by spring-projects.

the class QueryMapperUnitTests method shouldMapIsNull.

// DATAJDBC-318
@Test
public void shouldMapIsNull() {
    Criteria criteria = Criteria.where("name").isNull();
    Condition condition = map(criteria);
    assertThat(condition).hasToString("person.\"NAME\" IS 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)

Example 8 with Condition

use of org.springframework.data.relational.core.sql.Condition in project spring-data-jdbc by spring-projects.

the class QueryMapperUnitTests method shouldMapIsLt.

// DATAJDBC-318
@Test
public void shouldMapIsLt() {
    Criteria criteria = Criteria.where("name").lessThan("a");
    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 9 with Condition

use of org.springframework.data.relational.core.sql.Condition in project spring-data-jdbc by spring-projects.

the class QueryMapperUnitTests method shouldMapAndCriteria.

// DATAJDBC-318
@Test
public void shouldMapAndCriteria() {
    Criteria criteria = Criteria.where("name").is("foo").and("bar").is("baz");
    Condition condition = map(criteria);
    assertThat(condition).hasToString("person.\"NAME\" = ?[:name] AND person.bar = ?[:bar]");
}
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 10 with Condition

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

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