Search in sources :

Example 1 with R2dbcTransactionManager

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);
}
Also used : AnnotationConfigApplicationContext(org.springframework.context.annotation.AnnotationConfigApplicationContext) R2dbcTransactionManager(org.springframework.r2dbc.connection.R2dbcTransactionManager) Result(io.r2dbc.spi.Result) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with R2dbcTransactionManager

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();
}
Also used : TransactionalOperator(org.springframework.transaction.reactive.TransactionalOperator) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) R2dbcTransactionManager(org.springframework.r2dbc.connection.R2dbcTransactionManager) StepVerifier(reactor.test.StepVerifier) Test(org.junit.jupiter.api.Test)

Aggregations

R2dbcTransactionManager (org.springframework.r2dbc.connection.R2dbcTransactionManager)2 Result (io.r2dbc.spi.Result)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 AnnotationConfigApplicationContext (org.springframework.context.annotation.AnnotationConfigApplicationContext)1 TransactionalOperator (org.springframework.transaction.reactive.TransactionalOperator)1 DefaultTransactionDefinition (org.springframework.transaction.support.DefaultTransactionDefinition)1 StepVerifier (reactor.test.StepVerifier)1