Search in sources :

Example 6 with Criteria

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

the class CriteriaUnitTests method shouldBuildLtCriteria.

// DATAJDBC-513
@Test
void shouldBuildLtCriteria() {
    Criteria criteria = where("foo").lessThan(1);
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.LT);
    assertThat(criteria.getValue()).isEqualTo(1);
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 7 with Criteria

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

the class CriteriaUnitTests method shouldBuildLteCriteria.

// DATAJDBC-513
@Test
void shouldBuildLteCriteria() {
    Criteria criteria = where("foo").lessThanOrEquals(1);
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.LTE);
    assertThat(criteria.getValue()).isEqualTo(1);
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 8 with Criteria

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

the class CriteriaUnitTests method shouldBuildGteCriteria.

// DATAJDBC-513
@Test
void shouldBuildGteCriteria() {
    Criteria criteria = where("foo").greaterThanOrEquals(1);
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.GTE);
    assertThat(criteria.getValue()).isEqualTo(1);
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 9 with Criteria

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

the class CriteriaUnitTests method shouldBuildInCriteria.

// DATAJDBC-513
@Test
void shouldBuildInCriteria() {
    Criteria criteria = where("foo").in("bar", "baz");
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.IN);
    assertThat(criteria.getValue()).isEqualTo(Arrays.asList("bar", "baz"));
    assertThat(criteria).hasToString("foo IN ('bar', 'baz')");
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 10 with Criteria

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

the class CriteriaUnitTests method fromCriteriaOptimized.

// DATAJDBC-513
@Test
void fromCriteriaOptimized() {
    Criteria nested = where("foo").is("bar").and("baz").isNotNull();
    CriteriaDefinition criteria = Criteria.from(nested);
    assertThat(criteria).isSameAs(nested).hasToString("foo = 'bar' AND baz IS NOT NULL");
}
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