Search in sources :

Example 46 with Criteria

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

the class CriteriaUnitTests method shouldBuildIsFalseCriteria.

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

Example 47 with Criteria

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

the class CriteriaUnitTests method andChainedCriteria.

// DATAJDBC-513
@Test
void andChainedCriteria() {
    Criteria criteria = where("foo").is("bar").and("baz").isNotNull();
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("baz"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.IS_NOT_NULL);
    assertThat(criteria.getValue()).isNull();
    assertThat(criteria.getPrevious()).isNotNull();
    assertThat(criteria.getCombinator()).isEqualTo(Criteria.Combinator.AND);
    criteria = criteria.getPrevious();
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.EQ);
    assertThat(criteria.getValue()).isEqualTo("bar");
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 48 with Criteria

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

the class CriteriaUnitTests method shouldBuildEqualsCriteria.

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

Example 49 with Criteria

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

the class CriteriaUnitTests method orChainedCriteria.

// DATAJDBC-513
@Test
void orChainedCriteria() {
    Criteria criteria = where("foo").is("bar").or("baz").isNotNull();
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("baz"));
    assertThat(criteria.getCombinator()).isEqualTo(Criteria.Combinator.OR);
    criteria = criteria.getPrevious();
    assertThat(criteria).isNotNull();
    assertThat(criteria.getPrevious()).isNull();
    assertThat(criteria.getValue()).isEqualTo("bar");
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 50 with Criteria

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

the class CriteriaUnitTests method shouldBuildLikeCriteria.

// DATAJDBC-513
@Test
void shouldBuildLikeCriteria() {
    Criteria criteria = where("foo").like("hello%");
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.LIKE);
    assertThat(criteria.getValue()).isEqualTo("hello%");
}
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