Search in sources :

Example 1 with CriteriaDefinition

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

the class QueryMapperUnitTests method shouldMapPropertyToColumnName.

// DATACASS-343
@Test
void shouldMapPropertyToColumnName() {
    Query query = Query.query(Criteria.where("firstName").is("bar"));
    Filter mappedObject = queryMapper.getMappedObject(query, persistentEntity);
    CriteriaDefinition mappedCriteriaDefinition = mappedObject.iterator().next();
    assertThat(mappedCriteriaDefinition.getColumnName()).isEqualTo(ColumnName.from(CqlIdentifier.fromCql("first_name")));
    assertThat(mappedCriteriaDefinition.getColumnName().toString()).isEqualTo("first_name");
}
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 2 with CriteriaDefinition

use of org.springframework.data.cassandra.core.query.CriteriaDefinition 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 3 with CriteriaDefinition

use of org.springframework.data.cassandra.core.query.CriteriaDefinition 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 4 with CriteriaDefinition

use of org.springframework.data.cassandra.core.query.CriteriaDefinition 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)

Example 5 with CriteriaDefinition

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

the class QueryMapperUnitTests method shouldMapSimpleQuery.

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