Search in sources :

Example 16 with Query

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

the class StatementFactoryUnitTests method shouldCreateSetUpdate.

// DATACASS-343
@Test
void shouldCreateSetUpdate() {
    Query query = Query.query(Criteria.where("foo").is("bar"));
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(query, Update.empty().set("firstName", "baz").set("boo", "baa"), personEntity);
    assertThat(update.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person SET first_name='baz', boo='baa' WHERE foo='bar'");
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 17 with Query

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

the class StatementFactoryUnitTests method shouldMapSelectQueryIsNotNull.

// DATACASS-549
@Test
void shouldMapSelectQueryIsNotNull() {
    Query query = Query.query(Criteria.where("foo").isNotNull()).columns(Columns.from("age"));
    StatementBuilder<Select> select = statementFactory.select(query, groupEntity);
    assertThat(select.build(ParameterHandling.INLINE).getQuery()).isEqualTo("SELECT age FROM group WHERE foo IS NOT NULL");
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) Select(com.datastax.oss.driver.api.querybuilder.select.Select) Test(org.junit.jupiter.api.Test)

Example 18 with Query

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

the class StatementFactoryUnitTests method shouldMapSelectQueryWithSortLimitAndAllowFiltering.

// #1008
@Test
void shouldMapSelectQueryWithSortLimitAndAllowFiltering() {
    Query query = Query.empty().sort(Sort.by(DESC, "email", "age"));
    StatementBuilder<Select> select = statementFactory.select(query, converter.getMappingContext().getRequiredPersistentEntity(Group.class));
    assertThat(select.build(ParameterHandling.INLINE).getQuery()).isEqualTo("SELECT * FROM group ORDER BY email DESC,age DESC");
}
Also used : Group(org.springframework.data.cassandra.domain.Group) Query(org.springframework.data.cassandra.core.query.Query) Select(com.datastax.oss.driver.api.querybuilder.select.Select) Test(org.junit.jupiter.api.Test)

Example 19 with Query

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

the class CassandraTemplateIntegrationTests method deleteByQueryShouldRemoveEntity.

// DATACASS-343
@Test
void deleteByQueryShouldRemoveEntity() {
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user);
    Query query = Query.query(where("id").is("heisenberg"));
    assertThat(template.delete(query, User.class)).isTrue();
    assertThat(template.selectOneById(user.getId(), User.class)).isNull();
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) Test(org.junit.jupiter.api.Test)

Example 20 with Query

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

the class CassandraTemplateIntegrationTests method selectByQueryWithKeyspaceShouldRetrieveData.

// DATACASS-767
@Test
void selectByQueryWithKeyspaceShouldRetrieveData() {
    assumeThat(cassandraVersion.isGreaterThanOrEqualTo(CASSANDRA_4)).isTrue();
    QueryOptions queryOptions = QueryOptions.builder().keyspace(CqlIdentifier.fromCql(keyspace)).build();
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user);
    Query query = Query.query(where("id").is("heisenberg")).queryOptions(queryOptions);
    assertThat(template.select(query, User.class)).isNotEmpty();
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) QueryOptions(org.springframework.data.cassandra.core.cql.QueryOptions) Test(org.junit.jupiter.api.Test)

Aggregations

Query (org.springframework.data.cassandra.core.query.Query)72 Test (org.junit.jupiter.api.Test)65 User (org.springframework.data.cassandra.domain.User)22 Filter (org.springframework.data.cassandra.core.query.Filter)18 Update (org.springframework.data.cassandra.core.query.Update)17 CriteriaDefinition (org.springframework.data.cassandra.core.query.CriteriaDefinition)15 Select (com.datastax.oss.driver.api.querybuilder.select.Select)13 UserToken (org.springframework.data.cassandra.domain.UserToken)8 Group (org.springframework.data.cassandra.domain.Group)7 QueryOptions (org.springframework.data.cassandra.core.cql.QueryOptions)6 Columns (org.springframework.data.cassandra.core.query.Columns)6 Delete (com.datastax.oss.driver.api.querybuilder.delete.Delete)5 WriteOptions (org.springframework.data.cassandra.core.cql.WriteOptions)5 UdtValue (com.datastax.oss.driver.api.core.data.UdtValue)4 Collection (java.util.Collection)4 LinkedHashMap (java.util.LinkedHashMap)4 StepVerifier (reactor.test.StepVerifier)4 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)3 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)3 Uuids (com.datastax.oss.driver.api.core.uuid.Uuids)3