org.springframework.data.r2dbc.connectionfactory.R2dbcTransactionManager Java Examples

The following examples show how to use org.springframework.data.r2dbc.connectionfactory.R2dbcTransactionManager. 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: ReactiveNeo4jTransactionManagerTest.java    From sdn-rx with Apache License 2.0 6 votes vote down vote up
@Test
void shouldSynchronizeWithExternalWithCommit() {

	R2dbcTransactionManager t = new R2dbcTransactionManager(new H2ConnectionFactory(
		H2ConnectionConfiguration.builder().inMemory("test").build()));

	TransactionalOperator transactionalOperator = TransactionalOperator.create(t);

	transactionalOperator
		.execute(transactionStatus -> TransactionSynchronizationManager
			.forCurrentTransaction().doOnNext(tsm -> assertThat(tsm.hasResource(driver)).isFalse())
			.then(retrieveReactiveTransaction(driver, databaseName))
			.flatMap(ignoredNativeTx -> TransactionSynchronizationManager.forCurrentTransaction()
				.doOnNext(tsm -> assertThat(tsm.hasResource(driver)).isTrue()))
		)
		.as(StepVerifier::create)
		.expectNextCount(1L)
		.verifyComplete();

	verify(driver).rxSession(any(SessionConfig.class));

	verify(session).beginTransaction(any(TransactionConfig.class));
	verify(session).close();
	verify(transaction).commit();
	verify(transaction, never()).rollback();
}
 
Example #2
Source File: ReactiveNeo4jTransactionManagerTest.java    From sdn-rx with Apache License 2.0 5 votes vote down vote up
@Test
void shouldSynchronizeWithExternalWithRollback() {

	R2dbcTransactionManager t = new R2dbcTransactionManager(new H2ConnectionFactory(
		H2ConnectionConfiguration.builder().inMemory("test").build()));

	TransactionalOperator transactionalOperator = TransactionalOperator.create(t);

	transactionalOperator
		.execute(transactionStatus -> TransactionSynchronizationManager
			.forCurrentTransaction()
			.doOnNext(tsm -> {
				assertThat(tsm.hasResource(driver)).isFalse();
				transactionStatus.setRollbackOnly();
			})
			.then(retrieveReactiveTransaction(driver, databaseName))
			.flatMap(ignoredNativeTx -> TransactionSynchronizationManager.forCurrentTransaction()
				.doOnNext(tsm -> assertThat(tsm.hasResource(driver)).isTrue()))
		)
		.as(StepVerifier::create)
		.expectNextCount(1L)
		.verifyComplete();

	verify(driver).rxSession(any(SessionConfig.class));

	verify(session).beginTransaction(any(TransactionConfig.class));
	verify(session).close();
	verify(transaction).rollback();
	verify(transaction, never()).commit();
}
 
Example #3
Source File: DatabaseConfig.java    From spring-reactive-sample with GNU General Public License v3.0 4 votes vote down vote up
@Bean
ReactiveTransactionManager transactionManager(ConnectionFactory connectionFactory) {
    return new R2dbcTransactionManager(connectionFactory);
}
 
Example #4
Source File: DatabaseConfig.java    From spring-reactive-sample with GNU General Public License v3.0 4 votes vote down vote up
@Bean
ReactiveTransactionManager transactionManager(ConnectionFactory connectionFactory) {
    return new R2dbcTransactionManager(connectionFactory);
}
 
Example #5
Source File: ConnectionFactoryConfig.java    From spring-data-examples with Apache License 2.0 4 votes vote down vote up
@Bean
public ReactiveTransactionManager transactionManager(ConnectionFactory connectionFactory) {
  return new R2dbcTransactionManager(connectionFactory);
}