|
27 | 27 | import static com.google.cloud.spanner.connection.ConnectionProperties.AUTO_PARTITION_MODE;
|
28 | 28 | import static com.google.cloud.spanner.connection.ConnectionProperties.DATA_BOOST_ENABLED;
|
29 | 29 | import static com.google.cloud.spanner.connection.ConnectionProperties.DDL_IN_TRANSACTION_MODE;
|
| 30 | +import static com.google.cloud.spanner.connection.ConnectionProperties.DEFAULT_ISOLATION_LEVEL; |
30 | 31 | import static com.google.cloud.spanner.connection.ConnectionProperties.DEFAULT_SEQUENCE_KIND;
|
31 | 32 | import static com.google.cloud.spanner.connection.ConnectionProperties.DELAY_TRANSACTION_START_UNTIL_FIRST_WRITE;
|
32 | 33 | import static com.google.cloud.spanner.connection.ConnectionProperties.DIRECTED_READ;
|
|
90 | 91 | import com.google.spanner.v1.DirectedReadOptions;
|
91 | 92 | import com.google.spanner.v1.ExecuteSqlRequest.QueryOptions;
|
92 | 93 | import com.google.spanner.v1.ResultSetStats;
|
| 94 | +import com.google.spanner.v1.TransactionOptions.IsolationLevel; |
93 | 95 | import io.opentelemetry.api.OpenTelemetry;
|
94 | 96 | import io.opentelemetry.api.common.Attributes;
|
95 | 97 | import io.opentelemetry.api.common.AttributesBuilder;
|
@@ -478,6 +480,7 @@ private void reset(Context context, boolean inTransaction) {
|
478 | 480 | this.connectionState.resetValue(RETRY_ABORTS_INTERNALLY, context, inTransaction);
|
479 | 481 | this.connectionState.resetValue(AUTOCOMMIT, context, inTransaction);
|
480 | 482 | this.connectionState.resetValue(READONLY, context, inTransaction);
|
| 483 | + this.connectionState.resetValue(DEFAULT_ISOLATION_LEVEL, context, inTransaction); |
481 | 484 | this.connectionState.resetValue(READ_ONLY_STALENESS, context, inTransaction);
|
482 | 485 | this.connectionState.resetValue(OPTIMIZER_VERSION, context, inTransaction);
|
483 | 486 | this.connectionState.resetValue(OPTIMIZER_STATISTICS_PACKAGE, context, inTransaction);
|
@@ -635,6 +638,24 @@ public boolean isReadOnly() {
|
635 | 638 | return getConnectionPropertyValue(READONLY);
|
636 | 639 | }
|
637 | 640 |
|
| 641 | + @Override |
| 642 | + public void setDefaultIsolationLevel(IsolationLevel isolationLevel) { |
| 643 | + ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG); |
| 644 | + ConnectionPreconditions.checkState( |
| 645 | + !isBatchActive(), "Cannot default isolation level while in a batch"); |
| 646 | + ConnectionPreconditions.checkState( |
| 647 | + !isTransactionStarted(), |
| 648 | + "Cannot set default isolation level while a transaction is active"); |
| 649 | + setConnectionPropertyValue(DEFAULT_ISOLATION_LEVEL, isolationLevel); |
| 650 | + clearLastTransactionAndSetDefaultTransactionOptions(); |
| 651 | + } |
| 652 | + |
| 653 | + @Override |
| 654 | + public IsolationLevel getDefaultIsolationLevel() { |
| 655 | + ConnectionPreconditions.checkState(!isClosed(), CLOSED_ERROR_MSG); |
| 656 | + return getConnectionPropertyValue(DEFAULT_ISOLATION_LEVEL); |
| 657 | + } |
| 658 | + |
638 | 659 | private void clearLastTransactionAndSetDefaultTransactionOptions() {
|
639 | 660 | setDefaultTransactionOptions();
|
640 | 661 | this.currentUnitOfWork = null;
|
@@ -2196,6 +2217,7 @@ UnitOfWork createNewUnitOfWork(
|
2196 | 2217 | .setUsesEmulator(options.usesEmulator())
|
2197 | 2218 | .setUseAutoSavepointsForEmulator(options.useAutoSavepointsForEmulator())
|
2198 | 2219 | .setDatabaseClient(dbClient)
|
| 2220 | + .setIsolationLevel(getConnectionPropertyValue(DEFAULT_ISOLATION_LEVEL)) |
2199 | 2221 | .setDelayTransactionStartUntilFirstWrite(
|
2200 | 2222 | getConnectionPropertyValue(DELAY_TRANSACTION_START_UNTIL_FIRST_WRITE))
|
2201 | 2223 | .setKeepTransactionAlive(getConnectionPropertyValue(KEEP_TRANSACTION_ALIVE))
|
|
0 commit comments