Tadaya Tsuyukubo opened SPR-17491 and commented
With TransactionTemplate, for example, setReadOnly(true) is called, all executions with this template becomes readOnly transactions. If I want to perform another transaction with non-readonly, I need to create another template and so for all variation of transactions.
Instead, It would be nice to perform various transaction configurations with single TransactionTemplate.
For example:
public <T> T execute(Consumer<DefaultTransactionDefinition> txConfig, TransactionCallback<T> action) throws TransactionException
template.execute( txConfig -> {
txConfig.setReadOnly(true);
txConfig.setIsolationLevel(...);
...
}, status -> {
// action to perform in transaction
});
No further details from SPR-17491
Comment From: spring-projects-issues
Tadaya Tsuyukubo commented
Thinking a bit more, TransactionTemplate may not be a good place to add since it is a stateful for transaction definitions.
So, maybe something like:
public class SimpleTransactionTemplate {
// with default
public <T> T execute(TransactionCallback<T> action) throws TransactionException {
...
}
public <T> T execute(TransactionDefinition definition, TransactionCallback<T> action) throws TransactionException {
...
}
}
If API looks ok, then I can write a PR for this.
Comment From: snicoll
With TransactionTemplate, for example, setReadOnly(true) is called, all executions with this template becomes readOnly transactions. If I want to perform another transaction with non-readonly, I need to create another template and so for all variation of transactions.
That's a common pattern with our template infrastructure. The same applies to JmsTemplate
that can set some QoS values that are common to all executions. Thanks for the suggestion, in any case.