Search in sources :

Example 6 with WriteOptions

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

the class StatementFactoryUnitTests method shouldCreateSetUpdateFromObjectWithTimestamp.

// DATACASS-656
@Test
void shouldCreateSetUpdateFromObjectWithTimestamp() {
    WriteOptions options = WriteOptions.builder().timestamp(1234).build();
    Person person = new Person();
    person.id = "foo";
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(person, options);
    assertThat(update.build(ParameterHandling.INLINE).getQuery()).startsWith("UPDATE person USING TIMESTAMP 1234 SET");
}
Also used : WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 7 with WriteOptions

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

the class StatementFactoryUnitTests method shouldCreateSetUpdateFromObjectWithTtl.

// DATACASS-656
@Test
void shouldCreateSetUpdateFromObjectWithTtl() {
    WriteOptions options = WriteOptions.builder().ttl(Duration.ofMinutes(1)).build();
    Person person = new Person();
    person.id = "foo";
    StatementBuilder<com.datastax.oss.driver.api.querybuilder.update.Update> update = statementFactory.update(person, options);
    assertThat(update.build(ParameterHandling.INLINE).getQuery()).startsWith("UPDATE person USING TTL 60 SET");
}
Also used : WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) Update(org.springframework.data.cassandra.core.query.Update) Test(org.junit.jupiter.api.Test)

Example 8 with WriteOptions

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

the class CassandraBatchTemplateIntegrationTests method shouldInsertCollectionOfEntitiesWithTtl.

// DATACASS-443
@Test
void shouldInsertCollectionOfEntitiesWithTtl() {
    walter.setEmail("walter@white.com");
    mike.setEmail("mike@sauls.com");
    int ttl = 30;
    WriteOptions options = WriteOptions.builder().ttl(30).build();
    CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
    batchOperations.insert(Arrays.asList(walter, mike), options).execute();
    ResultSet resultSet = template.getCqlOperations().queryForResultSet("SELECT TTL(email) FROM group;");
    assertThat(resultSet.getAvailableWithoutFetching()).isEqualTo(2);
    for (Row row : resultSet) {
        assertThat(row.getInt(0)).isBetween(1, ttl);
    }
}
Also used : WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.jupiter.api.Test)

Example 9 with WriteOptions

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

the class CassandraBatchTemplateIntegrationTests method shouldUpdateCollectionOfEntitiesWithTtl.

// DATACASS-443
@Test
void shouldUpdateCollectionOfEntitiesWithTtl() {
    walter.setEmail("walter@white.com");
    mike.setEmail("mike@sauls.com");
    int ttl = 30;
    WriteOptions options = WriteOptions.builder().ttl(ttl).build();
    CassandraBatchOperations batchOperations = new CassandraBatchTemplate(template, BatchType.LOGGED);
    batchOperations.update(walter, options).execute();
    ResultSet resultSet = template.getCqlOperations().queryForResultSet("SELECT TTL(email), email FROM group");
    assertThat(resultSet.getAvailableWithoutFetching()).isEqualTo(2);
    for (Row row : resultSet) {
        if (walter.getEmail().equals(row.getString("email"))) {
            assertThat(row.getInt(0)).isBetween(1, ttl);
        } else {
            assertThat(row.getInt(0)).isZero();
        }
    }
}
Also used : WriteOptions(org.springframework.data.cassandra.core.cql.WriteOptions) ResultSet(com.datastax.oss.driver.api.core.cql.ResultSet) Row(com.datastax.oss.driver.api.core.cql.Row) Test(org.junit.jupiter.api.Test)

Example 10 with WriteOptions

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

the class ReactiveCassandraBatchTemplateIntegrationTests method shouldInsertCollectionOfEntitiesWithTtl.

// DATACASS-574
@Test
void shouldInsertCollectionOfEntitiesWithTtl() {
    walter.setEmail("walter@white.com");
    int ttl = 30;
    WriteOptions options = WriteOptions.builder().ttl(30).build();
    ReactiveCassandraBatchOperations batchOperations = new ReactiveCassandraBatchTemplate(template, BatchType.LOGGED);
    Mono<ReactiveResultSet> resultSet = batchOperations.insert(walter, options).execute().then(template.getReactiveCqlOperations().queryForResultSet("SELECT TTL(email), email FROM group;"));
    // 
    resultSet.flatMapMany(ReactiveResultSet::availableRows).collectList().as(// 
    StepVerifier::create).assertNext(rows -> {
        for (Row row : rows) {
            if (walter.getEmail().equals(row.getString(1))) {
                assertThat(row.getInt(0)).isBetween(1, ttl);
            } else {
                assertThat(row.getInt(0)).isZero();
            }
        }
    }).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) Row(com.datastax.oss.driver.api.core.cql.Row) StepVerifier(reactor.test.StepVerifier) 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