spring-projects-experimental/spring-fu

Spring Kofu TransactionalOperator Support with R2DBC

Closed this issue · 2 comments

Spring Kofu TransactionalOperator Support with R2DBC

Duplicates of #129 which is already fixed.

@sdeleuze can you explain how to write R2DBC transaction managed queries with kofu please ?

Considering this article reactive transactions with Spring we should use a TransactionalOperator to manage transactional queries.
Kofu R2DBC for now only registers a DatabaseClient Bean in Spring Context.

For example this is the H2 initializer code, Postgres and other R2DBC initializers are built on the same model.

Shouldn't these Initializers register TransactionalOperator as Bean in Spring context, or maybe just expose the ConnectionFactory so we can create a TransactionalOperator from it ?

ConnectionFactory factory = …
ReactiveTransactionManager tm = new R2dbcTransactionManager(factory);
TransactionalOperator to = TransactionalOperator.create(tm);

NB : according to reactive transactions with Spring MongoDB supports TransactionalOperator too. In MongoDB initializer code the SimpleReactiveMongoDatabaseFactory is registered in Spring context so we can already use it to create a TransactionalOperator :

ReactiveTransactionManager tm  = new ReactiveMongoTransactionManager(databaseFactory);
TransactionalOperator rxtx = TransactionalOperator.create(tm);
template.setSessionSynchronization(ALWAYS);