You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shardingsphere.apache.org by GitBox <gi...@apache.org> on 2022/11/29 02:42:51 UTC

[GitHub] [shardingsphere] strongduanmu commented on a diff in pull request #22492: Fix postgresql set transaction isolation

strongduanmu commented on code in PR #22492:
URL: https://github.com/apache/shardingsphere/pull/22492#discussion_r1034246194


##########
sql-parser/dialect/postgresql/src/main/java/org/apache/shardingsphere/sql/parser/postgresql/visitor/statement/impl/PostgreSQLTCLStatementSQLVisitor.java:
##########
@@ -68,7 +71,40 @@ public PostgreSQLTCLStatementSQLVisitor(final Properties props) {
     
     @Override
     public ASTNode visitSetTransaction(final SetTransactionContext ctx) {
-        return new PostgreSQLSetTransactionStatement();
+        PostgreSQLSetTransactionStatement result = new PostgreSQLSetTransactionStatement();
+        if (null != ctx.transactionModeList()) {
+            ctx.transactionModeList().transactionModeItem().forEach(each -> {
+                setTransactionAccessType(result, each);
+                setTransactionIsolationLevel(result, each);
+            });
+        }
+        return result;
+    }
+    
+    private void setTransactionAccessType(final PostgreSQLSetTransactionStatement statement, final TransactionModeItemContext modeItemContext) {
+        TransactionAccessType accessType = null;
+        if (null != modeItemContext.ONLY()) {
+            accessType = TransactionAccessType.READ_ONLY;
+        } else if (null != modeItemContext.WRITE()) {
+            accessType = TransactionAccessType.READ_WRITE;
+        }
+        statement.setAccessMode(accessType);
+    }
+    
+    private void setTransactionIsolationLevel(final PostgreSQLSetTransactionStatement statement, final TransactionModeItemContext modeItemContext) {

Review Comment:
   Can we refactor this method to getTransactionIsolationLevel and then use guard clause?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@shardingsphere.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org