use of org.springframework.r2dbc.connection.R2dbcTransactionManager in project spring-framework by spring-projects.
the class AbstractTransactionalDatabaseClientIntegrationTests method before.
@BeforeEach
public void before() {
connectionFactory = createConnectionFactory();
context = new AnnotationConfigApplicationContext();
context.getBeanFactory().registerResolvableDependency(ConnectionFactory.class, connectionFactory);
context.register(Config.class);
context.refresh();
Mono.from(connectionFactory.create()).flatMapMany(connection -> Flux.from(connection.createStatement("DROP TABLE legoset").execute()).flatMap(Result::getRowsUpdated).onErrorResume(e -> Mono.empty()).thenMany(connection.createStatement(getCreateTableStatement()).execute()).flatMap(Result::getRowsUpdated).thenMany(connection.close())).as(StepVerifier::create).verifyComplete();
databaseClient = DatabaseClient.create(connectionFactory);
transactionManager = new R2dbcTransactionManager(connectionFactory);
rxtx = TransactionalOperator.create(transactionManager);
}
use of org.springframework.r2dbc.connection.R2dbcTransactionManager in project spring-framework by spring-projects.
the class AbstractTransactionalDatabaseClientIntegrationTests method shouldRollbackTransactionUsingTransactionalOperator.
@Test
public void shouldRollbackTransactionUsingTransactionalOperator() {
DatabaseClient databaseClient = DatabaseClient.create(connectionFactory);
TransactionalOperator transactionalOperator = TransactionalOperator.create(new R2dbcTransactionManager(connectionFactory), new DefaultTransactionDefinition());
Flux<Integer> integerFlux = databaseClient.sql(getInsertIntoLegosetStatement()).bind(0, 42055).bind(1, "SCHAUFELRADBAGGER").bindNull(2, Integer.class).fetch().rowsUpdated().thenMany(Mono.fromSupplier(() -> {
throw new IllegalStateException("failed");
}));
integerFlux.as(transactionalOperator::transactional).as(StepVerifier::create).expectError(IllegalStateException.class).verify();
databaseClient.sql("SELECT id FROM legoset").fetch().first().as(StepVerifier::create).verifyComplete();
}
Aggregations