-
Notifications
You must be signed in to change notification settings - Fork 29
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
Conversation
There was a problem hiding this 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
cloud-spanner-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerConstants.java
Outdated
Show resolved
Hide resolved
...er-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java
Outdated
Show resolved
Hide resolved
...2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnectionTest.java
Outdated
Show resolved
Hide resolved
...er-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java
Outdated
Show resolved
Hide resolved
@@ -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)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this resolving #238?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...er-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java
Show resolved
Hide resolved
...er-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java
Outdated
Show resolved
Hide resolved
...er-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java
Outdated
Show resolved
Hide resolved
...er-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java
Outdated
Show resolved
Hide resolved
...2dbc/src/test/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnectionTest.java
Outdated
Show resolved
Hide resolved
...er-r2dbc/src/main/java/com/google/cloud/spanner/r2dbc/v2/SpannerClientLibraryConnection.java
Show resolved
Hide resolved
this.internalMap = internalMap; | ||
} | ||
|
||
private void validate(Map<Option<?>, Object> internalMap) { | ||
if (FALSE.equals(internalMap.get(READ_ONLY)) && internalMap.containsKey(TIMESTAMP_BOUND)) { |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
Kudos, SonarCloud Quality Gate passed! 0 Bugs 97.7% Coverage 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. |
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 aTransactionManager
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 onlyIsolationLevel.SERIALIZABLE
and throwUnsupportedOperationException
otherwise. ✅SpannerTransactionDefinition
, an implementation ofTransactionDefinition
(R2DBC spi) to configure the transaction attributes which will be used byConnection#beginTransaction(TransactionDefinition)
method. ✅Fixes #238