You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/07/26 14:22:31 UTC

[groovy] branch master updated: Reset flags even if exception is thrown when run GINQ

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 0dc7ffe  Reset flags even if exception is thrown when run GINQ
0dc7ffe is described below

commit 0dc7ffe000b5d14c5f8773d2a4d7de55e43d6a0f
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Jul 26 22:22:01 2021 +0800

    Reset flags even if exception is thrown when run GINQ
---
 .../ginq/provider/collection/GinqAstWalker.groovy  | 35 ++++++++++++----------
 1 file changed, 20 insertions(+), 15 deletions(-)

diff --git a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
index 235af22..e7f7520 100644
--- a/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
+++ b/subprojects/groovy-ginq/src/main/groovy/org/apache/groovy/ginq/provider/collection/GinqAstWalker.groovy
@@ -66,6 +66,7 @@ import org.codehaus.groovy.ast.expr.PropertyExpression
 import org.codehaus.groovy.ast.expr.TupleExpression
 import org.codehaus.groovy.ast.expr.VariableExpression
 import org.codehaus.groovy.ast.stmt.BlockStatement
+import org.codehaus.groovy.ast.stmt.EmptyStatement
 import org.codehaus.groovy.ast.stmt.Statement
 import org.codehaus.groovy.control.SourceUnit
 import org.codehaus.groovy.syntax.Types
@@ -76,6 +77,7 @@ import java.util.function.Consumer
 import java.util.stream.Collectors
 
 import static groovy.lang.Tuple.tuple
+import static org.apache.groovy.ginq.dsl.GinqAstBuilder.GINQ_SELECT_DISTINCT
 import static org.codehaus.groovy.ast.ClassHelper.DYNAMIC_TYPE
 import static org.codehaus.groovy.ast.ClassHelper.makeCached
 import static org.codehaus.groovy.ast.ClassHelper.makeWithoutCaching
@@ -97,8 +99,8 @@ import static org.codehaus.groovy.ast.tools.GeneralUtils.params
 import static org.codehaus.groovy.ast.tools.GeneralUtils.propX
 import static org.codehaus.groovy.ast.tools.GeneralUtils.returnS
 import static org.codehaus.groovy.ast.tools.GeneralUtils.stmt
+import static org.codehaus.groovy.ast.tools.GeneralUtils.tryCatchS
 import static org.codehaus.groovy.ast.tools.GeneralUtils.varX
-
 /**
  * Visit AST of GINQ to generate target method calls for GINQ
  *
@@ -201,21 +203,20 @@ class GinqAstWalker implements GinqAstVisitor<Expression>, SyntaxErrorReportable
             statementList << declS(localVarX(rowNumberName), ctorX(ATOMIC_LONG_TYPE, constX(-1L)))
         }
 
-        final resultName = "__r${System.nanoTime()}"
-
-        Boolean distinct = ginqExpression.getNodeMetaData(GinqAstBuilder.GINQ_SELECT_DISTINCT)
-        if (distinct) {
-            selectMethodCallExpression = callX(selectMethodCallExpression, "distinct")
-        }
-        statementList << declS(localVarX(resultName).tap {it.modifiers |= Opcodes.ACC_FINAL}, selectMethodCallExpression)
+        Boolean distinct = ginqExpression.getNodeMetaData(GINQ_SELECT_DISTINCT)
+        if (distinct) selectMethodCallExpression = callX(selectMethodCallExpression, "distinct")
 
-        if (parallelEnabled) {
-            statementList << stmt(callX(QUERYABLE_HELPER_TYPE, 'removeVar', args(constX(PARALLEL))))
-        }
-        if (useWindowFunction) {
-            statementList << stmt(callX(QUERYABLE_HELPER_TYPE, 'removeVar', args(constX(USE_WINDOW_FUNCTION))))
-        }
-        statementList << returnS(varX(resultName))
+        final resultName = "__r${System.nanoTime()}"
+        statementList << tryCatchS(
+                block(
+                        declS(localVarX(resultName).tap {it.modifiers |= Opcodes.ACC_FINAL}, selectMethodCallExpression),
+                        returnS(varX(resultName))
+                ),
+                block(
+                        parallelEnabled ? invokeRemoveVarMethod(PARALLEL) : EmptyStatement.INSTANCE,
+                        useWindowFunction ? invokeRemoveVarMethod(USE_WINDOW_FUNCTION) : EmptyStatement.INSTANCE
+                )
+        )
 
         def resultLambda = lambdaX(null, block(statementList as Statement[]))
         def result = parallelEnabled
@@ -226,6 +227,10 @@ class GinqAstWalker implements GinqAstVisitor<Expression>, SyntaxErrorReportable
         return result
     }
 
+    private static Statement invokeRemoveVarMethod(String varName) {
+        stmt(callX(QUERYABLE_HELPER_TYPE, 'removeVar', args(constX(varName))))
+    }
+
     private boolean isParallel() {
         return TRUE_STR == configuration.get(GinqGroovyMethods.CONF_PARALLEL)
     }