Search in sources :

Example 6 with CriteriaDefinition

use of org.springframework.data.cassandra.core.query.CriteriaDefinition in project spring-data-cassandra by spring-projects.

the class QueryMapperUnitTests method shouldMapUdtMapContainsKey.

// DATACASS-487
@Test
void shouldMapUdtMapContainsKey() {
    Query query = Query.query(Criteria.where("relocations").containsKey(new Address("21 Jump-Street")));
    Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
    CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
    assertThat(mappedCriteriaDefinition.getPredicate().getOperator()).isEqualTo(Operators.CONTAINS_KEY);
    assertThat(mappedCriteriaDefinition.getPredicate().getValue()).isInstanceOf(UdtValue.class);
    assertThat(((UdtValue) mappedCriteriaDefinition.getPredicate().getValue()).getFormattedContents()).isEqualTo("{street:'21 Jump-Street'}");
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) Query(org.springframework.data.cassandra.core.query.Query) Filter(org.springframework.data.cassandra.core.query.Filter) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition) Test(org.junit.jupiter.api.Test)

Example 7 with CriteriaDefinition

use of org.springframework.data.cassandra.core.query.CriteriaDefinition in project spring-data-cassandra by spring-projects.

the class QueryMapperUnitTests method shouldMapApplyingCustomConversionInCollection.

// DATACASS-343
@Test
void shouldMapApplyingCustomConversionInCollection() {
    Query query = Query.query(Criteria.where("foo_name").in(Currency.getInstance("EUR")));
    Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
    CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
    assertThat(mappedCriteriaDefinition.getPredicate().getOperator()).isEqualTo(Operators.IN);
    assertThat(mappedCriteriaDefinition.getPredicate().getValue()).isEqualTo(Collections.singletonList("Euro"));
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) Filter(org.springframework.data.cassandra.core.query.Filter) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition) Test(org.junit.jupiter.api.Test)

Example 8 with CriteriaDefinition

use of org.springframework.data.cassandra.core.query.CriteriaDefinition in project spring-data-cassandra by spring-projects.

the class QueryMapperUnitTests method shouldMapApplyingUdtValueConversion.

// DATACASS-343
@Test
void shouldMapApplyingUdtValueConversion() {
    Query query = Query.query(Criteria.where("address").is(new Address("21 Jump-Street")));
    Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
    CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
    CriteriaDefinition.Predicate predicate = mappedCriteriaDefinition.getPredicate();
    assertThat(predicate.getOperator()).isEqualTo(Operators.EQ);
    assertThat(predicate.getValue()).isInstanceOf(UdtValue.class);
    assertThat(predicate.as(UdtValue.class::cast).getFormattedContents()).isEqualTo("{street:'21 Jump-Street'}");
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) Filter(org.springframework.data.cassandra.core.query.Filter) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition) Test(org.junit.jupiter.api.Test)

Example 9 with CriteriaDefinition

use of org.springframework.data.cassandra.core.query.CriteriaDefinition in project spring-data-cassandra by spring-projects.

the class QueryMapperUnitTests method shouldMapApplyingUdtValueCollectionConversion.

// DATACASS-343
@Test
void shouldMapApplyingUdtValueCollectionConversion() {
    Query query = Query.query(Criteria.where("address").in(new Address("21 Jump-Street")));
    Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
    CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
    CriteriaDefinition.Predicate predicate = mappedCriteriaDefinition.getPredicate();
    assertThat(predicate.getOperator()).isEqualTo(Operators.IN);
    assertThat(predicate.getValue()).isInstanceOf(Collection.class);
    assertThat((List<UdtValue>) predicate.getValue()).extracting(UdtValue::getFormattedContents).contains("{street:'21 Jump-Street'}");
}
Also used : UdtValue(com.datastax.oss.driver.api.core.data.UdtValue) Query(org.springframework.data.cassandra.core.query.Query) Filter(org.springframework.data.cassandra.core.query.Filter) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition) Test(org.junit.jupiter.api.Test)

Example 10 with CriteriaDefinition

use of org.springframework.data.cassandra.core.query.CriteriaDefinition in project spring-data-cassandra by spring-projects.

the class QueryMapperUnitTests method shouldMapEnumToNumber.

// DATACASS-343
@Test
void shouldMapEnumToNumber() {
    Query query = Query.query(Criteria.where("number").is(State.Inactive));
    Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
    CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
    assertThat(mappedCriteriaDefinition.getPredicate().getValue()).isInstanceOf(Integer.class).isEqualTo(1);
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) Filter(org.springframework.data.cassandra.core.query.Filter) CriteriaDefinition(org.springframework.data.cassandra.core.query.CriteriaDefinition) Test(org.junit.jupiter.api.Test)

Aggregations

CriteriaDefinition (org.springframework.data.cassandra.core.query.CriteriaDefinition)16 Filter (org.springframework.data.cassandra.core.query.Filter)14 Test (org.junit.jupiter.api.Test)12 Query (org.springframework.data.cassandra.core.query.Query)12 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)4 Predicate (org.springframework.data.cassandra.core.query.CriteriaDefinition.Predicate)3 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)2 BindMarker (com.datastax.oss.driver.api.querybuilder.BindMarker)2 Term (com.datastax.oss.driver.api.querybuilder.term.Term)2 CassandraPersistentProperty (org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty)2 Condition (com.datastax.oss.driver.api.querybuilder.condition.Condition)1 Relation (com.datastax.oss.driver.api.querybuilder.relation.Relation)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 BasicCassandraPersistentEntity (org.springframework.data.cassandra.core.mapping.BasicCassandraPersistentEntity)1