use of com.google.cloud.spring.data.firestore.util.ObservableReactiveUtil in project spring-cloud-gcp by GoogleCloudPlatform.
the class ReactiveFirestoreTransactionManager method doCommit.
@Override
protected Mono<Void> doCommit(TransactionSynchronizationManager transactionSynchronizationManager, GenericReactiveTransaction genericReactiveTransaction) throws TransactionException {
return Mono.defer(() -> {
ReactiveFirestoreResourceHolder resourceHolder = extractFirestoreTransaction(genericReactiveTransaction).getResourceHolder();
CommitRequest.Builder builder = CommitRequest.newBuilder().setDatabase(this.databasePath).setTransaction(resourceHolder.getTransactionId());
resourceHolder.getWrites().forEach(builder::addWrites);
return ObservableReactiveUtil.<CommitResponse>unaryCall(obs -> this.firestore.commit(builder.build(), obs)).flatMap(response -> {
for (Object entity : resourceHolder.getEntities()) {
this.classMapper.setUpdateTime(entity, Timestamp.fromProto(response.getCommitTime()));
}
return Mono.empty();
});
});
}
use of com.google.cloud.spring.data.firestore.util.ObservableReactiveUtil in project spring-cloud-gcp by GoogleCloudPlatform.
the class ReactiveFirestoreTransactionManager method startTransaction.
private Mono<ReactiveFirestoreResourceHolder> startTransaction(TransactionDefinition definition) {
TransactionOptions.Builder txOptions = definition.isReadOnly() ? TransactionOptions.newBuilder().setReadOnly(TransactionOptions.ReadOnly.newBuilder().build()) : TransactionOptions.newBuilder().setReadWrite(TransactionOptions.ReadWrite.newBuilder().build());
BeginTransactionRequest beginTransactionRequest = BeginTransactionRequest.newBuilder().setOptions(txOptions).setDatabase(this.databasePath).build();
return ObservableReactiveUtil.<BeginTransactionResponse>unaryCall(obs -> this.firestore.beginTransaction(beginTransactionRequest, obs)).map(beginTransactionResponse -> new ReactiveFirestoreResourceHolder(beginTransactionResponse.getTransaction()));
}
Aggregations