use of org.springframework.data.cassandra.ReactiveResultSet in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraTemplate method truncate.
/* (non-Javadoc)
* @see org.springframework.data.cassandra.core.ReactiveCassandraOperations#truncate(java.lang.Class)
*/
@Override
public Mono<Void> truncate(Class<?> entityClass) {
Assert.notNull(entityClass, "Entity type must not be null");
CqlIdentifier tableName = getTableName(entityClass);
Truncate truncate = QueryBuilder.truncate(tableName);
SimpleStatement statement = truncate.build();
Mono<Boolean> result = doExecute(statement, ReactiveResultSet::wasApplied).doOnSubscribe(it -> maybeEmitEvent(new BeforeDeleteEvent<>(statement, entityClass, tableName)));
return result.doOnNext(it -> maybeEmitEvent(new AfterDeleteEvent<>(statement, entityClass, tableName))).then();
}
use of org.springframework.data.cassandra.ReactiveResultSet 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();
}
use of org.springframework.data.cassandra.ReactiveResultSet 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();
}
use of org.springframework.data.cassandra.ReactiveResultSet in project spring-data-cassandra by spring-projects.
the class DefaultBridgedReactiveSessionUnitTests method shouldReadAvailableResults.
// DATACASS-529
@Test
void shouldReadAvailableResults() {
AsyncResultSet resultSet = mock(AsyncResultSet.class);
when(resultSet.remaining()).thenReturn(10);
when(resultSet.currentPage()).thenReturn(IntStream.range(0, 10).mapToObj(value -> mock(Row.class)).collect(Collectors.toList()));
future.complete(resultSet);
Flux<Row> flux = reactiveSession.execute(SimpleStatement.newInstance("")).flatMapMany(ReactiveResultSet::availableRows);
flux.as(StepVerifier::create).expectNextCount(10).verifyComplete();
verify(resultSet, never()).fetchNextPage();
}
use of org.springframework.data.cassandra.ReactiveResultSet in project spring-data-cassandra by spring-projects.
the class ReactiveCassandraTemplateUnitTests method setUp.
@BeforeEach
void setUp() {
when(driverContext.getCodecRegistry()).thenReturn(codecRegistry);
when(session.getContext()).thenReturn(driverContext);
when(session.execute(any(Statement.class))).thenReturn(Mono.just(reactiveResultSet));
when(row.getColumnDefinitions()).thenReturn(columnDefinitions);
ReactiveEntityCallbacks callbacks = ReactiveEntityCallbacks.create();
callbacks.addEntityCallback((ReactiveBeforeSaveCallback<Object>) (entity, tableName, statement) -> {
assertThat(tableName).isNotNull();
assertThat(statement).isNotNull();
beforeSave = entity;
return Mono.just(entity);
});
callbacks.addEntityCallback((ReactiveBeforeConvertCallback<Object>) (entity, tableName) -> {
assertThat(tableName).isNotNull();
beforeConvert = entity;
return Mono.just(entity);
});
template = new ReactiveCassandraTemplate(session);
template.setUsePreparedStatements(false);
template.setEntityCallbacks(callbacks);
}
Aggregations