Search in sources :

Example 1 with WriteOptions

use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.

the class ReactiveCassandraBatchTemplateIntegrationTests method shouldUpdateMonoCollectionOfEntitiesWithTtl.

// DATACASS-574
@Test
void shouldUpdateMonoCollectionOfEntitiesWithTtl() {
    walter.setEmail("walter@white.com");
    mike.setEmail("mike@sauls.com");
    int ttl = 30;
    WriteOptions options = WriteOptions.builder().ttl(ttl).build();
    ReactiveCassandraBatchOperations batchOperations = new ReactiveCassandraBatchTemplate(template, BatchType.LOGGED);
    Mono<ReactiveResultSet> resultSet = batchOperations.update(Collections.singletonList(walter), options).update(Mono.just(Collections.singletonList(mike)), options).execute().then(template.getReactiveCqlOperations().queryForResultSet("SELECT TTL(email) FROM group;"));
    // 
    resultSet.flatMapMany(ReactiveResultSet::availableRows).as(// 
    StepVerifier::create).assertNext(row -> assertThat(row.getInt(0)).isBetween(1, ttl)).assertNext(row -> assertThat(row.getInt(0)).isBetween(1, ttl)).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DefaultBridgedReactiveSession(org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ReactiveResultSet(org.springframework.data.cassandra.ReactiveResultSet) GroupKey(org.springframework.data.cassandra.domain.GroupKey) SchemaTestUtils(org.springframework.data.cassandra.repository.support.SchemaTestUtils) Mono(reactor.core.publisher.Mono) Random(java.util.Random) AbstractKeyspaceCreatingIntegrationTests(org.springframework.data.cassandra.test.util.AbstractKeyspaceCreatingIntegrationTests) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) FlatGroup(org.springframework.data.cassandra.domain.FlatGroup) Group(org.springframework.data.cassandra.domain.Group) BatchType(com.datastax.oss.driver.api.core.cql.BatchType) ReactiveCqlTemplate(org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate) Assertions(org.assertj.core.api.Assertions) Schedulers(reactor.core.scheduler.Schedulers) Collections(java.util.Collections) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Row(com.datastax.oss.driver.api.core.cql.Row) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) ReactiveResultSet(org.springframework.data.cassandra.ReactiveResultSet) Test(org.junit.jupiter.api.Test)

Example 2 with WriteOptions

use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.

the class ReactiveCassandraBatchTemplateIntegrationTests method shouldInsertMonoOfEntitiesWithTtl.

// DATACASS-574
@Test
void shouldInsertMonoOfEntitiesWithTtl() {
    walter.setEmail("walter@white.com");
    mike.setEmail("mike@sauls.com");
    int ttl = 30;
    WriteOptions options = WriteOptions.builder().ttl(30).build();
    ReactiveCassandraBatchOperations batchOperations = new ReactiveCassandraBatchTemplate(template, BatchType.LOGGED);
    Mono<ReactiveResultSet> resultSet = batchOperations.insert(Mono.just(Arrays.asList(walter, mike)), options).execute().then(template.getReactiveCqlOperations().queryForResultSet("SELECT TTL(email) FROM group;"));
    // 
    resultSet.flatMapMany(ReactiveResultSet::availableRows).as(// 
    StepVerifier::create).assertNext(row -> assertThat(row.getInt(0)).isBetween(1, ttl)).assertNext(row -> assertThat(row.getInt(0)).isBetween(1, ttl)).verifyComplete();
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) DefaultBridgedReactiveSession(org.springframework.data.cassandra.core.cql.session.DefaultBridgedReactiveSession) Arrays(java.util.Arrays) StepVerifier(reactor.test.StepVerifier) ReactiveResultSet(org.springframework.data.cassandra.ReactiveResultSet) GroupKey(org.springframework.data.cassandra.domain.GroupKey) SchemaTestUtils(org.springframework.data.cassandra.repository.support.SchemaTestUtils) Mono(reactor.core.publisher.Mono) Random(java.util.Random) AbstractKeyspaceCreatingIntegrationTests(org.springframework.data.cassandra.test.util.AbstractKeyspaceCreatingIntegrationTests) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) FlatGroup(org.springframework.data.cassandra.domain.FlatGroup) Group(org.springframework.data.cassandra.domain.Group) BatchType(com.datastax.oss.driver.api.core.cql.BatchType) ReactiveCqlTemplate(org.springframework.data.cassandra.core.cql.ReactiveCqlTemplate) Assertions(org.assertj.core.api.Assertions) Schedulers(reactor.core.scheduler.Schedulers) Collections(java.util.Collections) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Row(com.datastax.oss.driver.api.core.cql.Row) MappingCassandraConverter(org.springframework.data.cassandra.core.convert.MappingCassandraConverter) WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) ReactiveResultSet(org.springframework.data.cassandra.ReactiveResultSet) Test(org.junit.jupiter.api.Test)

Example 3 with WriteOptions

use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.

the class StatementFactoryUnitTests method updateObjectShouldApplyQueryOptions.

// DATACASS-708
@Test
void updateObjectShouldApplyQueryOptions() {
    WriteOptions queryOptions = // 
    WriteOptions.builder().executionProfile(// 
    "foo").serialConsistencyLevel(// 
    DefaultConsistencyLevel.QUORUM).build();
    Person person = new Person();
    person.id = "foo";
    person.set = Collections.emptySet();
    person.list = Collections.emptyList();
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(person, queryOptions);
    SimpleStatement statement = update.build();
    assertThat(statement.getExecutionProfileName()).isEqualTo("foo");
    assertThat(statement.getSerialConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.QUORUM);
}
Also used : WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 4 with WriteOptions

use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.

the class StatementFactoryUnitTests method shouldCreateSetUpdateWithTtl.

// DATACASS-656
@Test
void shouldCreateSetUpdateWithTtl() {
    WriteOptions options = WriteOptions.builder().ttl(Duration.ofMinutes(1)).build();
    Query query = Query.query(Criteria.where("foo").is("bar")).queryOptions(options);
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(query, Update.empty().set("firstName", "baz"), personEntity);
    assertThat(update.build(ParameterHandling.INLINE).getQuery()).isEqualTo("UPDATE person USING TTL 60 SET first_name='baz' WHERE foo='bar'");
}
Also used : WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Query(org.springframework.data.cassandra.core.query.Query) Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 5 with WriteOptions

use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.

the class StatementFactoryUnitTests method insertShouldApplyQueryOptions.

// DATACASS-708
@Test
void insertShouldApplyQueryOptions() {
    Person person = new Person();
    person.id = "foo";
    WriteOptions queryOptions = // 
    WriteOptions.builder().executionProfile(// 
    "foo").serialConsistencyLevel(// 
    DefaultConsistencyLevel.QUORUM).build();
    StatementBuilder<RegularInsert> insert = statementFactory.insert(person, queryOptions);
    SimpleStatement statement = insert.build();
    assertThat(statement.getExecutionProfileName()).isEqualTo("foo");
    assertThat(statement.getSerialConsistencyLevel()).isEqualTo(DefaultConsistencyLevel.QUORUM);
}
Also used : WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) RegularInsert(com.datastax.oss.driver.api.querybuilder.insert.RegularInsert) Test(org.junit.jupiter.api.Test)

Aggregations

WriteOptions (org.springframework.data.cassandra.core.cql.WriteOptions)18 Test (org.junit.jupiter.api.Test)14 Update (org.springframework.data.cassandra.core.query.Update)9 Collections (java.util.Collections)8 RegularInsert (com.datastax.oss.driver.api.querybuilder.insert.RegularInsert)7 Row (com.datastax.oss.driver.api.core.cql.Row)6 Query (org.springframework.data.cassandra.core.query.Query)6 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)4 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)4 BindMarker (com.datastax.oss.driver.api.querybuilder.BindMarker)4 QueryBuilder (com.datastax.oss.driver.api.querybuilder.QueryBuilder)4 Condition (com.datastax.oss.driver.api.querybuilder.condition.Condition)4 ConditionBuilder (com.datastax.oss.driver.api.querybuilder.condition.ConditionBuilder)4 Delete (com.datastax.oss.driver.api.querybuilder.delete.Delete)4 DeleteSelection (com.datastax.oss.driver.api.querybuilder.delete.DeleteSelection)4 Insert (com.datastax.oss.driver.api.querybuilder.insert.Insert)4 ColumnRelationBuilder (com.datastax.oss.driver.api.querybuilder.relation.ColumnRelationBuilder)4 Relation (com.datastax.oss.driver.api.querybuilder.relation.Relation)4 Select (com.datastax.oss.driver.api.querybuilder.select.Select)4 Term (com.datastax.oss.driver.api.querybuilder.term.Term)4