I am trying to generate a code that performs 2 postgresql commands simultaneously, in one transaction. I have in my DB 2 rules with different rule order, and I want to switch the rule order between them. I am using r2dbc-postgresql (v0.8.4) and spring-data-r2dbc (v1.1.1).
I have defined DatabaseClient and TransactionalOperator and tried to use that piece of code:
public Mono<Void> insertRows() {
return databaseClient.execute("update rules set rule_order = 2 where rule_order = 1")
.fetch().rowsUpdated()
.then(databaseClient.execute("update rules set rule_order = 1 where rule_order = 2")
.fetch().rowsUpdated())
.then()
.as(transactionalOperator::transactional);
}
but the result was that the commands ran one after another, so I finished with having both rules with rule order = 1.
What am I doing wrong, and how can I fix this?