Search in sources :

Example 6 with Query

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

the class ReactiveCassandraTemplateUnitTests method updateShouldApplyUpdateQueryWitLwt.

// DATACASS-575
@Test
void updateShouldApplyUpdateQueryWitLwt() {
    when(reactiveResultSet.rows()).thenReturn(Flux.just(row));
    Filter ifCondition = Filter.from(where("firstname").is("Walter"), where("lastname").is("White"));
    Query query = Query.query(where("id").is("heisenberg")).queryOptions(UpdateOptions.builder().ifCondition(ifCondition).build());
    Update update = Update.update("firstname", "Walter");
    // 
    template.update(query, update, User.class).as(// 
    StepVerifier::create).expectNextCount(// 
    1).verifyComplete();
    verify(session).execute(statementCaptor.capture());
    assertThat(render(statementCaptor.getValue())).isEqualTo("UPDATE users SET firstname='Walter' WHERE id='heisenberg' IF firstname='Walter' AND lastname='White'");
}
Also used : VersionedUser(org.springframework.data.cassandra.domain.VersionedUser) User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) Filter(org.springframework.data.cassandra.core.query.Filter) Update(org.springframework.data.cassandra.core.query.Update) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 7 with Query

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

the class ReactiveCassandraTemplateIntegrationTests method deleteByQueryShouldRemoveEntityWithLwt.

// DATACASS-606
@Test
void deleteByQueryShouldRemoveEntityWithLwt() {
    DeleteOptions lwtOptions = DeleteOptions.builder().withIfExists().build();
    User user = new User("heisenberg", "Walter", "White");
    template.insert(user).as(StepVerifier::create).expectNextCount(1).verifyComplete();
    Query query = Query.query(where("id").is("heisenberg")).queryOptions(lwtOptions);
    // 
    template.delete(query, User.class).as(// 
    StepVerifier::create).expectNext(// 
    true).verifyComplete();
    // 
    template.delete(query, User.class).as(// 
    StepVerifier::create).expectNext(// 
    false).verifyComplete();
}
Also used : User(org.springframework.data.cassandra.domain.User) Query(org.springframework.data.cassandra.core.query.Query) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Example 8 with Query

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

the class StatementFactoryUnitTests method shouldMapDeleteQueryWithColumns.

// DATACASS-343
@Test
void shouldMapDeleteQueryWithColumns() {
    Query query = Query.empty().columns(Columns.from("age"));
    StatementBuilder<Delete> delete = statementFactory.delete(query, converter.getMappingContext().getRequiredPersistentEntity(Group.class));
    assertThat(delete.build(ParameterHandling.INLINE).getQuery()).isEqualTo("DELETE age FROM group");
}
Also used : Delete(com.datastax.oss.driver.api.querybuilder.delete.Delete) Group(org.springframework.data.cassandra.domain.Group) Query(org.springframework.data.cassandra.core.query.Query) Test(org.junit.jupiter.api.Test)

Example 9 with Query

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

the class StatementFactoryUnitTests method shouldMapSelectQueryWithColumnsAndCriteria.

// DATACASS-343
@Test
void shouldMapSelectQueryWithColumnsAndCriteria() {
    Query query = Query.query(Criteria.where("foo").is("bar")).columns(Columns.from("age"));
    StatementBuilder<Select> select = statementFactory.select(query, groupEntity);
    assertThat(select.build(ParameterHandling.INLINE).getQuery()).isEqualTo("SELECT age FROM group WHERE foo='bar'");
}
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 10 with Query

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

the class StatementFactoryUnitTests method updateShouldApplyQueryOptions.

// DATACASS-708
@Test
void updateShouldApplyQueryOptions() {
    UpdateOptions queryOptions = // 
    UpdateOptions.builder().executionProfile(// 
    "foo").serialConsistencyLevel(// 
    DefaultConsistencyLevel.QUORUM).build();
    Query query = Query.query(Criteria.where("foo").is("bar")).queryOptions(queryOptions);
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(query, Update.empty().set("firstName", "baz"), personEntity);
    SimpleStatement statement = update.build();
    assertThat(statement.getExecutionProfileName()).isEqualTo("foo");
    assertThat(statement.getSerialConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.QUORUM);
}
Also used : Query(org.springframework.data.cassandra.core.query.Query) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Update(org.springframework.data.cassandra.core.query.Update) 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