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

feat: Implementing Connection#beginTransaction(TransactionDefinition) to support @Transactional annotation #738

Merged
merged 13 commits into from
Oct 30, 2023

Conversation

jainsahab
Copy link
Contributor

@jainsahab jainsahab commented Oct 11, 2023

Implemented the following classes and methods to conform to R2DBC SPI which enables supporting @Transactional annotation in Spring Data Dialect.

  • Connection#beginTransaction(TransactionDefinition) method so that it can be used by a TransactionManager when @Transactional annotation is used. ✅
  • Connection#getTransactionIsolationLevel returns SERIALIZABLE as it is the closest level to EXTERNAL_CONSISTENCY which spanner supports. ✅
  • Connection#setTransactionIsolationLevel(IsolationLevel) accepts only IsolationLevel.SERIALIZABLE and throw UnsupportedOperationException otherwise. ✅
  • Introduced SpannerTransactionDefinition, an implementation of TransactionDefinition(R2DBC spi) to configure the transaction attributes which will be used by Connection#beginTransaction(TransactionDefinition) method. ✅

Fixes #238

@jainsahab jainsahab marked this pull request as ready for review October 19, 2023 15:34
Copy link
Member

@burkedavison burkedavison left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR looks very nice. LGTM

@@ -51,7 +66,16 @@ public Publisher<Void> beginTransaction() {

@Override
public Publisher<Void> beginTransaction(TransactionDefinition definition) {
return Mono.error(new UnsupportedOperationException());
return validateIsolation(definition.getAttribute(ISOLATION_LEVEL))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this resolving #238?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partially yes,

#238 talks about read-only, read-write, stale-read and partitioned DML. Out of these first three are supported but not partitioned DML but that is not supported by the driver itself.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we create a separate issue for DML support, and close #238 as part of this PR?

Copy link
Contributor Author

@jainsahab jainsahab Oct 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, I've created #747.

and whenever you close this issue merge this PR, it'll will close #238

this.internalMap = internalMap;
}

private void validate(Map<Option<?>, Object> internalMap) {
if (FALSE.equals(internalMap.get(READ_ONLY)) && internalMap.containsKey(TIMESTAMP_BOUND)) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if the user has not set any value for READ_ONLY? The default is then read/write, and the TIMESTAMP_BOUND will be ignored. So should the test not also include a check whether there is no READ_ONLY option?
(And maybe centralize that in a single, simple method named something like isReadOnlyTransaction()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad 😓 , fixed that too now.

Copy link

@olavloite olavloite left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, with one tiny nit on the last check for using a stale read option with a (default) read/write transaction.

@sonarcloud
Copy link

sonarcloud bot commented Oct 27, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

97.7% 97.7% Coverage
0.0% 0.0% Duplication

warning The version of Java (11.0.21) you have used to run this analysis is deprecated and we will stop accepting it soon. Please update to at least Java 17.
Read more here

@meltsufin meltsufin merged commit bee69c1 into main Oct 30, 2023
11 checks passed
@meltsufin meltsufin deleted the transactional_annotation branch October 30, 2023 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the new extensible transaction definition in R2DBC SPI
4 participants