Skip to content

Commit 039356f

Browse files
authored
Refactor SetTransactionHandler (#35489)
* Add DistSQLExecutorDatabaseAware interface to ShowShardingTableNodesExecutor * Refactor SetTransactionHandler
1 parent c603396 commit 039356f

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/tcl/SetTransactionHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import lombok.RequiredArgsConstructor;
2121
import org.apache.shardingsphere.infra.database.core.metadata.database.metadata.option.transaction.DialectTransactionOption;
22+
import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
2223
import org.apache.shardingsphere.infra.database.core.type.DatabaseTypeRegistry;
2324
import org.apache.shardingsphere.infra.exception.core.ShardingSpherePreconditions;
2425
import org.apache.shardingsphere.proxy.backend.handler.ProxyBackendHandler;
@@ -40,6 +41,8 @@ public final class SetTransactionHandler implements ProxyBackendHandler {
4041

4142
private final ConnectionSession connectionSession;
4243

44+
private final DatabaseType databaseType;
45+
4346
@Override
4447
public ResponseHeader execute() {
4548
ShardingSpherePreconditions.checkState(null != sqlStatement.getScope() || !connectionSession.getTransactionStatus().isInTransaction(), SwitchTypeInTransactionException::new);
@@ -63,7 +66,7 @@ private void setTransactionIsolationLevel() {
6366
if (!sqlStatement.getIsolationLevel().isPresent()) {
6467
return;
6568
}
66-
DialectTransactionOption transactionOption = new DatabaseTypeRegistry(sqlStatement.getDatabaseType()).getDialectDatabaseMetaData().getTransactionOption();
69+
DialectTransactionOption transactionOption = new DatabaseTypeRegistry(databaseType).getDialectDatabaseMetaData().getTransactionOption();
6770
connectionSession.setDefaultIsolationLevel(TransactionUtils.getTransactionIsolationLevel(transactionOption.getDefaultIsolationLevel()));
6871
connectionSession.setIsolationLevel(sqlStatement.getIsolationLevel().get());
6972
}

proxy/backend/core/src/main/java/org/apache/shardingsphere/proxy/backend/handler/tcl/TCLBackendHandlerFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public static ProxyBackendHandler newInstance(final SQLStatementContext sqlState
7878
: new TCLBackendHandler(tclStatement, TransactionOperationType.ROLLBACK, connectionSession);
7979
}
8080
if (tclStatement instanceof SetTransactionStatement && OperationScope.GLOBAL != ((SetTransactionStatement) tclStatement).getScope()) {
81-
return new SetTransactionHandler((SetTransactionStatement) tclStatement, connectionSession);
81+
return new SetTransactionHandler((SetTransactionStatement) tclStatement, connectionSession, sqlStatementContext.getDatabaseType());
8282
}
8383
if (tclStatement instanceof XAStatement) {
8484
return new XATCLHandler(sqlStatementContext, sql, connectionSession);

0 commit comments

Comments
 (0)