Search in sources :

Example 41 with Criteria

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

the class QueryMapperUnitTests method shouldMapIsLike.

// DATAJDBC-318
@Test
public void shouldMapIsLike() {
    Criteria criteria = Criteria.where("name").like("a");
    Condition condition = map(criteria);
    assertThat(condition).hasToString("person.\"NAME\" LIKE ?[: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 42 with Criteria

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

the class CriteriaFactoryUnitTests method shouldConsiderIterableValuesInInOperator.

// DATAJDBC-539
@Test
void shouldConsiderIterableValuesInInOperator() {
    QueryMethod queryMethod = getQueryMethod("findAllByNameIn", List.class);
    RelationalParametersParameterAccessor accessor = getAccessor(queryMethod, Arrays.asList("foo", "bar"));
    ParameterMetadataProvider parameterMetadata = new ParameterMetadataProvider(accessor);
    CriteriaFactory criteriaFactory = new CriteriaFactory(parameterMetadata);
    Part part = new Part("NameIn", User.class);
    Criteria criteria = criteriaFactory.createCriteria(part);
    assertThat(criteria.getValue()).isEqualTo(Arrays.asList("foo", "bar"));
}
Also used : QueryMethod(org.springframework.data.repository.query.QueryMethod) Part(org.springframework.data.repository.query.parser.Part) Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 43 with Criteria

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

the class CriteriaUnitTests method shouldBuildIsNotNullCriteria.

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

Example 44 with Criteria

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

the class CriteriaUnitTests method shouldBuildNotLikeCriteria.

@Test
void shouldBuildNotLikeCriteria() {
    Criteria criteria = where("foo").notLike("hello%");
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.NOT_LIKE);
    assertThat(criteria.getValue()).isEqualTo("hello%");
}
Also used : Criteria(org.springframework.data.relational.core.query.Criteria) Test(org.junit.jupiter.api.Test)

Example 45 with Criteria

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

the class CriteriaUnitTests method shouldBuildIsNullCriteria.

// DATAJDBC-513
@Test
void shouldBuildIsNullCriteria() {
    Criteria criteria = where("foo").isNull();
    assertThat(criteria.getColumn()).isEqualTo(SqlIdentifier.unquoted("foo"));
    assertThat(criteria.getComparator()).isEqualTo(CriteriaDefinition.Comparator.IS_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