use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraBatchTemplateIntegrationTests method shouldUpdateCollectionOfEntitiesWithTtl.
// DATACASS-574
@Test
void shouldUpdateCollectionOfEntitiesWithTtl() {
walter.setEmail("walter@white.com");
int ttl = 30;
WriteOptions options = WriteOptions.builder().ttl(ttl).build();
ReactiveCassandraBatchOperations batchOperations = new ReactiveCassandraBatchTemplate(template, BatchType.LOGGED);
Mono<ReactiveResultSet> resultSet = batchOperations.update(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();
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldCreateSetInsertWithTimestamp.
// DATACASS-656
@Test
void shouldCreateSetInsertWithTimestamp() {
WriteOptions options = WriteOptions.builder().timestamp(1234).build();
Person person = new Person();
person.id = "foo";
StatementBuilder<RegularInsert> insert = statementFactory.insert(person, options);
assertThat(insert.build(ParameterHandling.INLINE).getQuery()).isEqualTo("INSERT INTO person (id) VALUES ('foo') USING TIMESTAMP 1234");
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldCreateSetInsertWithTtl.
// DATACASS-656
@Test
void shouldCreateSetInsertWithTtl() {
WriteOptions options = WriteOptions.builder().ttl(Duration.ofMinutes(1)).build();
Person person = new Person();
person.id = "foo";
StatementBuilder<RegularInsert> insert = statementFactory.insert(person, options);
assertThat(insert.build(ParameterHandling.INLINE).getQuery()).isEqualTo("INSERT INTO person (id) VALUES ('foo') USING TTL 60");
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class StatementFactoryUnitTests method shouldCreateSetUpdateWithTimestamp.
// DATACASS-656
@Test
void shouldCreateSetUpdateWithTimestamp() {
WriteOptions options = WriteOptions.builder().timestamp(1234).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 TIMESTAMP 1234 SET first_name='baz' WHERE foo='bar'");
}
use of org.springframework.data.cassandra.core.cql.WriteOptions in project spring-data-cassandra by spring-projects.
the class StatementFactory method delete.
/**
* Create a {@literal DELETE} statement by mapping {@link Query} to {@link Delete}.
*
* @param query must not be {@literal null}.
* @param persistentEntity must not be {@literal null}.
* @param tableName must not be {@literal null}.
* @return the delete builder.
* @see 2.1
*/
public StatementBuilder<Delete> delete(Query query, CassandraPersistentEntity<?> persistentEntity, CqlIdentifier tableName) {
Assert.notNull(query, "Query must not be null");
Assert.notNull(persistentEntity, "CassandraPersistentEntity must not be null");
Assert.notNull(tableName, "Table name must not be null");
Filter filter = getQueryMapper().getMappedObject(query, persistentEntity);
List<CqlIdentifier> columnNames = getQueryMapper().getMappedColumnNames(query.getColumns(), persistentEntity);
StatementBuilder<Delete> builder = delete(columnNames, tableName, filter);
query.getQueryOptions().filter(DeleteOptions.class::isInstance).map(DeleteOptions.class::cast).map(DeleteOptions::getIfCondition).ifPresent(criteriaDefinitions -> applyDeleteIfCondition(builder, criteriaDefinitions));
query.getQueryOptions().filter(WriteOptions.class::isInstance).map(WriteOptions.class::cast).ifPresent(writeOptions -> builder.apply(statement -> addWriteOptions(statement, writeOptions)));
query.getQueryOptions().ifPresent(options -> builder.transform(statement -> QueryOptionsUtil.addQueryOptions(statement, options)));
return builder;
}
Aggregations