Search in sources :

Example 6 with Filter

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

the class QueryMapperUnitTests method shouldMapEmbeddedType.

// DATACASS-167
@Test
void shouldMapEmbeddedType() {
    Filter filter = Filter.from(Criteria.where("nested.firstname").is("spring"));
    Filter mappedObject = this.queryMapper.getMappedObject(filter, this.mappingContext.getRequiredPersistentEntity(WithNullableEmbeddedType.class));
    assertThat(mappedObject.iterator().next().getColumnName()).isEqualTo(ColumnName.from("firstname"));
}
Also used : Filter(org.springframework.data.cassandra.core.query.Filter) Test(org.junit.jupiter.api.Test)

Example 7 with Filter

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

the class QueryMapperUnitTests method shouldMapUdtMapContains.

// DATACASS-487
@Test
void shouldMapUdtMapContains() {
    Query query = Query.query(Criteria.where("relocations").contains(new Address("21 Jump-Street")));
    Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
    CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
    assertThat(mappedCriteriaDefinition.getPredicate().getOperator()).isEqualTo(Operators.CONTAINS);
    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 8 with Filter

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

the class QueryMapperUnitTests method shouldMapApplyingCustomConversion.

// DATACASS-343
@Test
void shouldMapApplyingCustomConversion() {
    Query query = Query.query(Criteria.where("foo_name").is(Currency.getInstance("EUR")));
    Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
    CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
    assertThat(mappedCriteriaDefinition.getPredicate().getOperator()).isEqualTo(Operators.EQ);
    assertThat(mappedCriteriaDefinition.getPredicate().getValue()).isEqualTo("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 9 with Filter

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

the class QueryMapperUnitTests method shouldMapQueryWithCompositePrimaryKeyClass.

// DATACASS-343
@Test
void shouldMapQueryWithCompositePrimaryKeyClass() {
    Filter filter = Filter.from(Criteria.where("key.firstname").is("foo"));
    Filter mappedObject = queryMapper.getMappedObject(filter, mappingContext.getRequiredPersistentEntity(TypeWithKeyClass.class));
    assertThat(mappedObject).contains(Criteria.where("first_name").is("foo"));
}
Also used : Filter(org.springframework.data.cassandra.core.query.Filter) TypeWithKeyClass(org.springframework.data.cassandra.domain.TypeWithKeyClass) Test(org.junit.jupiter.api.Test)

Example 10 with Filter

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

the class QueryMapperUnitTests method shouldMapEnumToString.

// DATACASS-343
@Test
void shouldMapEnumToString() {
    Query query = Query.query(Criteria.where("foo_name").is(State.Active));
    Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
    CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
    assertThat(mappedCriteriaDefinition.getPredicate().getValue()).isInstanceOf(String.class).isEqualTo("Active");
}
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

Filter (org.springframework.data.cassandra.core.query.Filter)31 CriteriaDefinition (org.springframework.data.cassandra.core.query.CriteriaDefinition)21 Query (org.springframework.data.cassandra.core.query.Query)21 Test (org.junit.jupiter.api.Test)20 ColumnSelector (org.springframework.data.cassandra.core.query.Columns.ColumnSelector)10 Selector (org.springframework.data.cassandra.core.query.Columns.Selector)10 Update (org.springframework.data.cassandra.core.query.Update)9 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)8 ArrayList (java.util.ArrayList)8 Collections (java.util.Collections)8 List (java.util.List)8 Optional (java.util.Optional)8 Set (java.util.Set)8 CassandraPersistentProperty (org.springframework.data.cassandra.core.mapping.CassandraPersistentProperty)8 Collection (java.util.Collection)7 CassandraPersistentEntity (org.springframework.data.cassandra.core.mapping.CassandraPersistentEntity)7 Columns (org.springframework.data.cassandra.core.query.Columns)7 FunctionCall (org.springframework.data.cassandra.core.query.Columns.FunctionCall)7 Predicate (org.springframework.data.cassandra.core.query.CriteriaDefinition.Predicate)7 Sort (org.springframework.data.domain.Sort)7