Search in sources :

Example 11 with Criteria

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

the class CriteriaUnitTests method shouldBuildGtCriteria.

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

Example 12 with Criteria

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

the class CriteriaUnitTests method fromCriteria.

// DATAJDBC-513
@Test
void fromCriteria() {
    Criteria nested1 = where("foo").isNotNull();
    Criteria nested2 = where("foo").isNull();
    CriteriaDefinition criteria = Criteria.from(nested1, nested2);
    assertThat(criteria.isGroup()).isTrue();
    assertThat(criteria.getGroup()).containsExactly(nested1, nested2);
    assertThat(criteria.getPrevious()).isEqualTo(Criteria.empty());
    assertThat(criteria).hasToString("(foo IS NOT NULL AND foo IS NULL)");
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 13 with Criteria

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

the class CriteriaUnitTests method shouldBuildNotInCriteria.

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

Example 14 with Criteria

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

the class CriteriaUnitTests method andGroupedCriteria.

// DATAJDBC-513
@Test
void andGroupedCriteria() {
    Criteria grouped = where("foo").is("bar").and(where("foo").is("baz").or("bar").isNotNull());
    Criteria criteria = grouped;
    assertThat(criteria.isGroup()).isTrue();
    assertThat(criteria.getGroup()).hasSize(1);
    assertThat(criteria.getGroup().get(0).getColumn()).isEqualTo(SqlIdentifier.unquoted("bar"));
    assertThat(criteria.getCombinator()).isEqualTo(Criteria.Combinator.AND);
    criteria = criteria.getPrevious();
    assertThat(criteria).isNotNull();
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.EQ);
    assertThat(criteria.getValue()).isEqualTo("bar");
    assertThat(grouped).hasToString("foo = 'bar' AND (foo = 'baz' OR bar IS NOT NULL)");
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 15 with Criteria

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

the class CriteriaUnitTests method isEmpty.

// DATAJDBC-513
@Test
void isEmpty() {
    assertSoftly(softly -> {
        Criteria empty = empty();
        Criteria notEmpty = where("foo").is("bar");
        assertThat(empty.isEmpty()).isTrue();
        assertThat(notEmpty.isEmpty()).isFalse();
        assertThat(Criteria.from(notEmpty).isEmpty()).isFalse();
        assertThat(Criteria.from(notEmpty, notEmpty).isEmpty()).isFalse();
        assertThat(Criteria.from(empty).isEmpty()).isTrue();
        assertThat(Criteria.from(empty, empty).isEmpty()).isTrue();
        assertThat(Criteria.from(empty, notEmpty).isEmpty()).isFalse();
        assertThat(Criteria.from(notEmpty, empty).isEmpty()).isFalse();
    });
}
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