You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by du...@apache.org on 2022/02/23 00:44:32 UTC

[shardingsphere] branch master updated: proofread SET TRANSACTION, and SET IMPLICIT_TRANSACTIONS statements and modify sql-case accordingly (#15574)

This is an automated email from the ASF dual-hosted git repository.

duanzhengqiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shardingsphere.git


The following commit(s) were added to refs/heads/master by this push:
     new 01e79f6  proofread SET TRANSACTION, and SET IMPLICIT_TRANSACTIONS statements and modify sql-case accordingly (#15574)
01e79f6 is described below

commit 01e79f618eba6dbdf5221113a5403b14ba399471
Author: Thanoshan MV <48...@users.noreply.github.com>
AuthorDate: Wed Feb 23 06:13:11 2022 +0530

    proofread SET TRANSACTION, and SET IMPLICIT_TRANSACTIONS statements and modify sql-case accordingly (#15574)
---
 .../antlr4/imports/sqlserver/SQLServerKeyword.g4   |  8 ++++++++
 .../main/antlr4/imports/sqlserver/TCLStatement.g4  |  8 ++++++--
 .../impl/SQLServerTCLStatementSQLVisitor.java      | 22 +++++++++++++++++++++-
 .../common/constant/TransactionIsolationLevel.java |  1 +
 .../main/resources/case/tcl/set-transaction.xml    |  1 +
 .../sql/supported/tcl/set-auto-commit.xml          |  2 +-
 .../sql/supported/tcl/set-transaction.xml          |  7 ++++---
 7 files changed, 42 insertions(+), 7 deletions(-)

diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4
index b14950d..302e0b8 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/SQLServerKeyword.g4
@@ -1782,3 +1782,11 @@ PROVIDER
 SID
     : S I D
     ;
+
+UNCOMMITTED
+    : U N C O M M I T T E D
+    ;
+
+COMMITTED
+    : C O M M I T T E D
+    ;
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/TCLStatement.g4 b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/TCLStatement.g4
index a2095b2..3590e4d 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/TCLStatement.g4
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/antlr4/imports/sqlserver/TCLStatement.g4
@@ -20,11 +20,15 @@ grammar TCLStatement;
 import BaseRule;
 
 setTransaction
-    : SET TRANSACTION
+    : SET TRANSACTION ISOLATION LEVEL isolationLevel
+    ;
+
+isolationLevel
+    : READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SNAPSHOT | SERIALIZABLE
     ;
 
 setImplicitTransactions
-    : (IF AT_ AT_ TRANCOUNT GT_ NUMBER_ COMMIT TRAN)? SET IMPLICIT_TRANSACTIONS implicitTransactionsValue
+    : SET IMPLICIT_TRANSACTIONS implicitTransactionsValue
     ;
 
 implicitTransactionsValue
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerTCLStatementSQLVisitor.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerTCLStatementSQLVisitor.java
index cf5ad18..dc97887 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerTCLStatementSQLVisitor.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-dialect/shardingsphere-sql-parser-sqlserver/src/main/java/org/apache/shardingsphere/sql/parser/sqlserver/visitor/statement/impl/SQLServerTCLStatementSQLVisitor.java
@@ -25,11 +25,13 @@ import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.Beg
 import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.BeginTransactionContext;
 import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.CommitContext;
 import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.CommitWorkContext;
+import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.IsolationLevelContext;
 import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.RollbackContext;
 import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.RollbackWorkContext;
 import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SavepointContext;
 import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SetImplicitTransactionsContext;
 import org.apache.shardingsphere.sql.parser.autogen.SQLServerStatementParser.SetTransactionContext;
+import org.apache.shardingsphere.sql.parser.sql.common.constant.TransactionIsolationLevel;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.tcl.SQLServerBeginDistributedTransactionStatement;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.tcl.SQLServerBeginTransactionStatement;
 import org.apache.shardingsphere.sql.parser.sql.dialect.statement.sqlserver.tcl.SQLServerCommitStatement;
@@ -52,7 +54,25 @@ public final class SQLServerTCLStatementSQLVisitor extends SQLServerStatementSQL
     
     @Override
     public ASTNode visitSetTransaction(final SetTransactionContext ctx) {
-        return new SQLServerSetTransactionStatement();
+        SQLServerSetTransactionStatement result = new SQLServerSetTransactionStatement();
+        result.setIsolationLevel(getTransactionIsolationLevel(ctx.isolationLevel()));
+        return result;
+    }
+    
+    private TransactionIsolationLevel getTransactionIsolationLevel(final IsolationLevelContext ctx) {
+        TransactionIsolationLevel result;
+        if (null != ctx.UNCOMMITTED()) {
+            result = TransactionIsolationLevel.READ_UNCOMMITTED;
+        } else if (null != ctx.COMMITTED()) {
+            result = TransactionIsolationLevel.READ_COMMITTED;
+        } else if (null != ctx.REPEATABLE()) {
+            result = TransactionIsolationLevel.REPEATABLE_READ;
+        } else if (null != ctx.SNAPSHOT()) {
+            result = TransactionIsolationLevel.SNAPSHOT;
+        } else {
+            result = TransactionIsolationLevel.SERIALIZABLE;
+        }
+        return result;
     }
     
     @Override
diff --git a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/TransactionIsolationLevel.java b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/TransactionIsolationLevel.java
index 275b779..3a2cb26 100644
--- a/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/TransactionIsolationLevel.java
+++ b/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/constant/TransactionIsolationLevel.java
@@ -31,6 +31,7 @@ public enum TransactionIsolationLevel {
     READ_UNCOMMITTED("READ_UNCOMMITTED"),
     READ_COMMITTED("READ_COMMITTED"),
     REPEATABLE_READ("REPEATABLE_READ"),
+    SNAPSHOT("SNAPSHOT"),
     SERIALIZABLE("SERIALIZABLE");
 
     private final String isolationLevel;
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/tcl/set-transaction.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/tcl/set-transaction.xml
index e5ee258..1f49ea6 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/tcl/set-transaction.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/case/tcl/set-transaction.xml
@@ -24,6 +24,7 @@
     <set-transaction sql-case-id="set_transaction_read_write_with_name" />
     <set-transaction sql-case-id="set_transaction_isolation_level_serializable" />
     <set-transaction sql-case-id="set_transaction_isolation_level_read_committed" />
+    <set-transaction sql-case-id="set_transaction_isolation_level_snapshot" />
     <set-transaction sql-case-id="set_transaction_use_rollback_segment" />
     <set-transaction sql-case-id="set_transaction_with_name" />
     <set-transaction sql-case-id="set_transaction_snapshot" />
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/tcl/set-auto-commit.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/tcl/set-auto-commit.xml
index 638c518..0721d24 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/tcl/set-auto-commit.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/tcl/set-auto-commit.xml
@@ -22,5 +22,5 @@
     <sql-case id="set_auto_commit_off" value="SET AUTOCOMMIT = 0" db-types="MySQL" />
     <sql-case id="set_auto_commit_off_with_scope" value="SET SESSION AUTOCOMMIT = OFF" db-types="MySQL" />
     <sql-case id="set_implicit_transactions_on" value="SET IMPLICIT_TRANSACTIONS ON" db-types="SQLServer" />
-    <sql-case id="set_implicit_transactions_off" value="IF @@TRANCOUNT > 0 COMMIT TRAN SET IMPLICIT_TRANSACTIONS OFF" db-types="SQLServer" />
+    <sql-case id="set_implicit_transactions_off" value="SET IMPLICIT_TRANSACTIONS OFF" db-types="SQLServer" />
 </sql-cases>
diff --git a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/tcl/set-transaction.xml b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/tcl/set-transaction.xml
index 6912b8e..2d33ddd 100644
--- a/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/tcl/set-transaction.xml
+++ b/shardingsphere-test/shardingsphere-parser-test/src/main/resources/sql/supported/tcl/set-transaction.xml
@@ -22,10 +22,11 @@
     <sql-case id="set_session_transaction" value="SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED" db-types="PostgreSQL,openGauss" />
     <sql-case id="set_transaction_read_only" value="SET TRANSACTION READ ONLY" db-types="MySQL,Oracle" />
     <sql-case id="set_transaction_read_write_with_name" value="SET TRANSACTION READ WRITE NAME 'Toronto'" db-types="Oracle" />
-    <sql-case id="set_transaction_isolation_level_serializable" value="SET TRANSACTION ISOLATION LEVEL SERIALIZABLE" db-types="Oracle" />
-    <sql-case id="set_transaction_isolation_level_read_committed" value="SET TRANSACTION ISOLATION LEVEL READ COMMITTED" db-types="Oracle" />
+    <sql-case id="set_transaction_isolation_level_serializable" value="SET TRANSACTION ISOLATION LEVEL SERIALIZABLE" db-types="Oracle, SQLServer" />
+    <sql-case id="set_transaction_isolation_level_read_committed" value="SET TRANSACTION ISOLATION LEVEL READ COMMITTED" db-types="Oracle, SQLServer" />
+    <sql-case id="set_transaction_isolation_level_snapshot" value="SET TRANSACTION ISOLATION LEVEL SNAPSHOT" db-types="SQLServer" />
     <sql-case id="set_transaction_use_rollback_segment" value="SET TRANSACTION USE ROLLBACK SEGMENT rbs_ts" db-types="Oracle" />
-    <sql-case id="set_transaction_with_name" value="SET TRANSACTION NAME 'comment1'" db-types="Oracle,SQLServer" />
+    <sql-case id="set_transaction_with_name" value="SET TRANSACTION NAME 'comment1'" db-types="Oracle" />
     <sql-case id="set_transaction_snapshot" value="SET TRANSACTION SNAPSHOT 'snapshot1'" db-types="PostgreSQL,openGauss" />
     <sql-case id="xa_recover" value="XA RECOVER" db-types="MySQL" />
     <sql-case id="xa_start" value="XA start 'abcdef7' join" db-types="MySQL" />