org.springframework.transaction.reactive.GenericReactiveTransaction Java Examples

The following examples show how to use org.springframework.transaction.reactive.GenericReactiveTransaction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ReactiveFirestoreTransactionManager.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@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))
				.then();
	});
}
 
Example #2
Source File: ReactiveNeo4jTransactionManager.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Void> doCommit(TransactionSynchronizationManager transactionSynchronizationManager,
		GenericReactiveTransaction genericReactiveTransaction) throws TransactionException {

	ReactiveNeo4jTransactionHolder holder = extractNeo4jTransaction(genericReactiveTransaction)
		.getRequiredResourceHolder();
	return holder.commit()
		.doOnNext(bookmark -> bookmarkManager.updateBookmarks(holder.getBookmarks(), bookmark))
		.then();
}
 
Example #3
Source File: ReactiveNeo4jTransactionManager.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Void> doRollback(TransactionSynchronizationManager transactionSynchronizationManager,
		GenericReactiveTransaction genericReactiveTransaction) throws TransactionException {

	ReactiveNeo4jTransactionHolder holder = extractNeo4jTransaction(genericReactiveTransaction)
		.getRequiredResourceHolder();
	return holder.rollback();
}
 
Example #4
Source File: ReactiveNeo4jTransactionManager.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Void> doSetRollbackOnly(TransactionSynchronizationManager synchronizationManager,
	GenericReactiveTransaction genericReactiveTransaction) throws TransactionException {

	return Mono.fromRunnable(() -> {
		ReactiveNeo4jTransactionObject transactionObject = extractNeo4jTransaction(genericReactiveTransaction);
		transactionObject.getRequiredResourceHolder().setRollbackOnly();
	});
}
 
Example #5
Source File: ReactiveFirestoreTransactionManager.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Void> doRollback(TransactionSynchronizationManager transactionSynchronizationManager,
		GenericReactiveTransaction genericReactiveTransaction) throws TransactionException {

	return ObservableReactiveUtil
			.<Empty>unaryCall(
					obs -> this.firestore.rollback(RollbackRequest.newBuilder()
							.setTransaction(
									extractFirestoreTransaction(genericReactiveTransaction).getTransactionId())
							.setDatabase(this.databasePath)
							.build(), obs))
			.then();
}
 
Example #6
Source File: ReactiveFirestoreTransactionManager.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
private static ReactiveFirestoreTransactionObject extractFirestoreTransaction(
		GenericReactiveTransaction transaction) {

	Assert.isInstanceOf(ReactiveFirestoreTransactionObject.class, transaction.getTransaction(),
			() -> String.format("Expected to find a %s but it turned out to be %s.",
					ReactiveFirestoreTransactionObject.class,
					transaction.getTransaction().getClass()));

	return (ReactiveFirestoreTransactionObject) transaction.getTransaction();
}
 
Example #7
Source File: ReactiveRedissonTransactionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Void> doCommit(TransactionSynchronizationManager synchronizationManager, GenericReactiveTransaction status) throws TransactionException {
    ReactiveRedissonTransactionObject to = (ReactiveRedissonTransactionObject) status.getTransaction();
    return to.getResourceHolder().getTransaction().commit().onErrorMap(ex -> {
        return new TransactionSystemException("Unable to commit transaction " + to.getResourceHolder().getTransaction(), ex);
    });
}
 
Example #8
Source File: ReactiveRedissonTransactionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Void> doRollback(TransactionSynchronizationManager synchronizationManager, GenericReactiveTransaction status) throws TransactionException {
    ReactiveRedissonTransactionObject to = (ReactiveRedissonTransactionObject) status.getTransaction();
    return to.getResourceHolder().getTransaction().rollback().onErrorMap(ex -> {
        return new TransactionSystemException("Unable to rollback transaction", ex);
    });
}
 
Example #9
Source File: ReactiveRedissonTransactionManager.java    From redisson with Apache License 2.0 5 votes vote down vote up
@Override
protected Mono<Void> doSetRollbackOnly(TransactionSynchronizationManager synchronizationManager, GenericReactiveTransaction status) throws TransactionException {
    return Mono.fromRunnable(() -> {
        ReactiveRedissonTransactionObject to = (ReactiveRedissonTransactionObject) status.getTransaction();
        to.getResourceHolder().setRollbackOnly();
    });
}
 
Example #10
Source File: ReactiveNeo4jTransactionManager.java    From sdn-rx with Apache License 2.0 4 votes vote down vote up
private static ReactiveNeo4jTransactionObject extractNeo4jTransaction(GenericReactiveTransaction status) {
	return extractNeo4jTransaction(status.getTransaction());
}