prosgarz35 opened a new pull request, #3203:
URL: https://github.com/apache/james-project/pull/3203
### Rationale & Context
Currently, `PostgresExecutor` provides isolated query execution methods
(`executeRow`, `executeVoid`, `executeRows`, etc.), each acquiring and
returning a single R2DBC connection to the pool.
There was no mechanism to execute multiple queries atomically within a
single database transaction. This made it impossible for calling services (such
as mailbox message operations, ACL updates, or quota management) to ensure all-
or-nothing atomicity across multiple SQL statements, potentially leading
to inconsistent data states upon transient failures or server restarts.
### Changes
1. **Add `executeTransaction` to `PostgresExecutor`**:
- Signature: `<T> Mono<T> executeTransaction(Function<DSLContext,
Mono<T>> transactionFunction)`
- Starts an explicit transaction on an acquired connection via
`connection.beginTransaction()`.
- Executes the provided lambda block against the connection's
`DSLContext`.
- Automatically commits on completion
(`connection.commitTransaction()`) or rolls back on error
(`connection.rollbackTransaction()`).
- Ensures the connection is safely released back to the R2DBC pool
via `Mono.usingWhen`.
- Preserves configured jOOQ timeout, retry policy for prepared
statements, and records timing metrics under `postgres-transaction-execution`.
- Fully backward-compatible; existing query execution methods remain
unaffected.
2. **Integration Tests**:
- Added unit/integration test suite `PostgresExecutorTest` covering
both successful transaction commit and rollback on failure.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]