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

Question - Best practices for extending R2dbcTransactionManager? #547

Closed
dzou opened this issue Mar 1, 2021 · 3 comments
Closed

Question - Best practices for extending R2dbcTransactionManager? #547

dzou opened this issue Mar 1, 2021 · 3 comments
Labels
for: stackoverflow A question that's better suited to stackoverflow.com

Comments

@dzou
Copy link
Contributor

dzou commented Mar 1, 2021

Hey there,

I'm interested in extending the R2dbcTransactionManager for Cloud Spanner with our Spring Data R2DBC integration. For example, like overriding the prepareTransactionalConnection(..) to allow it to create custom transactions for Spanner.

I was wondering if you could share some best practices for how to best do this for users:

  • Should we put this in our project with the Spring Data R2DBC dialect, and then do we ask users to create a @Bean of it in their autoconfiguration so it hooks into Spring data?
  • Or should we consider providing our own autoconfiguration and a starter dependency so it's injected automatically?

Many thanks for your guidance.

@mp911de
Copy link
Member

mp911de commented Mar 2, 2021

Subclassing the transaction manager is the way to go. With Spring Framework, @Transactional(label =…) was introduced to allow labeling transactional methods with further details. Labels can be obtained through TransactionAttribute.getLabels(), accessible from R2dbcTransactionManager.prepareTransactionalConnection(…).

Once R2DBC 0.9 is fully available, we should reconsider the prepareTransactionalConnection and Connection.begin() arrangement in terms of extensible transaction definitions.

Right now, prepareTransactionalConnection implements what the extended Connection.begin(TransactionDefinition) does in terms of setting read only, transaction isolation, and auto-commit flags.

I would assume that we introduce another method that assembles the R2DBC TransactionDefinition so that we can shift functionality from prepareTransactionalConnection into extensible transaction definitions's begin.

@mp911de mp911de added for: stackoverflow A question that's better suited to stackoverflow.com and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 2, 2021
@mp911de mp911de closed this as completed Mar 2, 2021
@dzou
Copy link
Contributor Author

dzou commented Mar 2, 2021

@mp911de -- Thanks for the great help!

Sorry, one more followup -- So would you recommend we put our subclass of the Transaction Manager in the same module as our R2DBC dialect? Or is there another pattern R2DBC libraries use? (i.e. creating a starter dependency with autoconfigurations, etc.)

@mp911de
Copy link
Member

mp911de commented Mar 3, 2021

I think so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: stackoverflow A question that's better suited to stackoverflow.com
Projects
None yet
Development

No branches or pull requests

3 participants