Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single TransactionTemplate to perform variations of transaction configurations [SPR-17491] #22023

Open
spring-projects-issues opened this issue Nov 13, 2018 · 1 comment

Comments

@spring-projects-issues
Copy link
Collaborator

@spring-projects-issues spring-projects-issues commented Nov 13, 2018

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

@spring-projects-issues
Copy link
Collaborator Author

@spring-projects-issues spring-projects-issues commented Nov 14, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant
You can’t perform that action at this time.