spring-projects-experimental / spring-fu

Configuration DSLs for Spring Boot
Apache License 2.0
1.67k stars 138 forks source link

Spring Kofu TransactionalOperator Support with R2DBC #259

Closed Kotlin-GDE closed 4 years ago

sdeleuze commented 4 years ago

Duplicates of #129 which is already fixed.

pull-vert commented 4 years ago

@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);