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

Add no-op TransactionOperations implementation #23198

Closed
wants to merge 1 commit into from

Conversation

vpavic
Copy link
Contributor

@vpavic vpavic commented Jun 26, 2019

A no-op implementation can be useful for:

  • having TransactionOperations consuming code switch to non-transactional behavior by injecting NoOpTransactionOperations instead of TransactionTemplate
  • testing purposes

For first point we have a use case in Spring Session's JdbcOperationsSessionRepository. I've used similar approach in a number of other projects so having Framework provide it OOTB would be nice. Also note that TransactionOperations isn't parameterized, but TransactionOperations#execute is which makes it impossible to have no-op implementation as lambda expression.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 26, 2019
@sbrannen sbrannen added in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement for: team-attention labels Jun 27, 2019
@sbrannen
Copy link
Member

Thanks for the PR, @vpavic.

We'll consider it.

Also note that TransactionOperations isn't parameterized, but TransactionOperations#execute is which makes it impossible to have no-op implementation as lambda expression.

Yes, that is a bit unfortunate.

@jhoeller jhoeller self-assigned this Jun 28, 2019
@jhoeller jhoeller removed for: team-attention status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 28, 2019
@jhoeller jhoeller added this to the 5.2 RC1 milestone Jun 28, 2019
@jhoeller
Copy link
Contributor

jhoeller commented Jul 3, 2019

Good idea in general! I've implemented this slightly differently as a static withoutTransaction() method on TransactionOperations, along the lines of the recently introduced withDefaults() method on TransactionDefinition.

@vpavic
Copy link
Contributor Author

vpavic commented Jul 4, 2019

I don't see anything pushed to the master yet so I'm not sure if I understood the described changes correctly, but if non-transactional behavior is implemented using a new operation on TransactionOperations I'm afraid that won't allow changing transactional behavior by injecting a different TransactionOperations implementation which was the motivation for this PR.

Ideally, TransactionOperations consuming code shouldn't be aware of the fact that there's no transaction involved. This is similar like to, for instance, changing propagation behavior by injecting a differently configured TransactionTemplate.

@jhoeller
Copy link
Contributor

jhoeller commented Jul 5, 2019

I'm about to commit this along with a number of other changes now, so it'll be in master in a moment. Thanks for your patience :-)

As for the implementation, withoutTransaction() is a new static factory method on TransactionOperations, returning a TransactionOperations instance with a regular execute method which executes the callback without an actual transaction. This should allow for substitution underneath any TransactionOperations caller as intended.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants