diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index ccb64411..e8e12dbe 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -42,7 +42,7 @@ jobs: # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL - uses: github/codeql-action/init@v1 + uses: github/codeql-action/init@v2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. @@ -53,7 +53,7 @@ jobs: # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild - uses: github/codeql-action/autobuild@v1 + uses: github/codeql-action/autobuild@v2 # ℹī¸ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl @@ -67,4 +67,4 @@ jobs: # make release - name: Perform CodeQL Analysis - uses: github/codeql-action/analyze@v1 + uses: github/codeql-action/analyze@v2 diff --git a/README.md b/README.md index 5bb6e7ae..5625cbc3 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ This open source plugin can be used to analyze the ESQL-sourcecode of IBM App Co ## History +- 3.5.0 - Parsing of COMMIT and ROLLBACK statements and rules for them - 3.4.0 - New coverage format, bugfixes, Sonar 9.4 - 3.3.0 - Upgrade to SonarQube 8.9 - 3.0.0 - Bugfixes, upgrade to sonar SonarQube 7.9 diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckList.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckList.java index 3744a918..e0e0be16 100644 --- a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckList.java +++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CheckList.java @@ -53,6 +53,7 @@ public static List> getChecks() { CommentRegularExpressionCheck.class, CommentedCodeCheck.class, CommentsCheck.class, + CommitCheck.class, ConditionParenthesisCheck.class, CyclomaticComplexityCheck.class, DeclareCombineCheck.class, @@ -91,6 +92,7 @@ public static List> getChecks() { PropagateConsistencyCheck.class, PropagateToLabelCheck.class, RecursionCheck.class, + RollbackCheck.class, RoutineCommentsCheck.class, RoutineWithExcessiveReturnsCheck.class, SelectAllCheck.class, diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommitCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommitCheck.java new file mode 100644 index 00000000..874691a1 --- /dev/null +++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/CommitCheck.java @@ -0,0 +1,33 @@ +/* + * Sonar ESQL Plugin + * Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG + * http://www.exxeta.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exxeta.iss.sonar.esql.check; + +import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck; +import com.exxeta.iss.sonar.esql.tree.impl.statement.CommitStatementTreeImpl; +import org.sonar.check.Rule; + +@Rule(key="Commit") +public class CommitCheck extends DoubleDispatchVisitorCheck { + + public static final String MESSAGE = "COMMIT should not be called explicitly. Otherwise the messageflow can't handle the transaction."; + @Override + public void visitCommitStatement(CommitStatementTreeImpl tree) { + addIssue(tree.commitKeyword(), MESSAGE); + super.visitCommitStatement(tree); + } +} diff --git a/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RollbackCheck.java b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RollbackCheck.java new file mode 100644 index 00000000..b0354a46 --- /dev/null +++ b/esql-checks/src/main/java/com/exxeta/iss/sonar/esql/check/RollbackCheck.java @@ -0,0 +1,33 @@ +/* + * Sonar ESQL Plugin + * Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG + * http://www.exxeta.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exxeta.iss.sonar.esql.check; + +import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitorCheck; +import com.exxeta.iss.sonar.esql.tree.impl.statement.RollbackStatementTreeImpl; +import org.sonar.check.Rule; + +@Rule(key="Rollback") +public class RollbackCheck extends DoubleDispatchVisitorCheck { + + public static final String MESSAGE = "ROLLBACK should not be called explicitly. Otherwise the messageflow can't handle the transaction."; + @Override + public void visitRollbackStatement(RollbackStatementTreeImpl tree) { + addIssue(tree.rollbackKeyword(), MESSAGE); + super.visitRollbackStatement(tree); + } +} diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Commit.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Commit.html new file mode 100644 index 00000000..d6426628 --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Commit.html @@ -0,0 +1,6 @@ +

Avoid using the COMMIT statement in ESQL code, as it can undermine the transaction + handling mechanism of the message flow. Instead, consider restructuring the flow + to handle smaller transactions or committing all changes at once. This approach + helps ensure that the transaction handling mechanism operates correctly and reliably, + without risking unexpected behavior or data loss. By avoiding the use of COMMIT statements, + you can help maintain the integrity and consistency of the message flow's data.

\ No newline at end of file diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Commit.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Commit.json new file mode 100644 index 00000000..be384e74 --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Commit.json @@ -0,0 +1,13 @@ +{ + "title": "COMMIT should not be used.", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "20min" + }, + "tags": [ + "bad-practice" + ], + "defaultSeverity": "Major" +} \ No newline at end of file diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Rollback.html b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Rollback.html new file mode 100644 index 00000000..9ee99902 --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Rollback.html @@ -0,0 +1,5 @@ +

Avoid using the ROLLBACK statement in ESQL code, as it can undermine the transaction + handling mechanism of the message flow. Instead, consider using the THROW statement to + raise an exception and trigger a rollback of the entire message flow. This approach helps + ensure that the transaction handling mechanism operates correctly and reliably, without + risking unexpected behavior or data loss.

diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Rollback.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Rollback.json new file mode 100644 index 00000000..8dcbcbed --- /dev/null +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Rollback.json @@ -0,0 +1,13 @@ +{ + "title": "ROLLBACK should not be used.", + "type": "CODE_SMELL", + "status": "ready", + "remediation": { + "func": "Constant\/Issue", + "constantCost": "20min" + }, + "tags": [ + "bad-practice" + ], + "defaultSeverity": "Major" +} \ No newline at end of file diff --git a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Sonar_way_profile.json b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Sonar_way_profile.json index 3be4bc37..bd921805 100644 --- a/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Sonar_way_profile.json +++ b/esql-checks/src/main/resources/org/sonar/l10n/esql/rules/esql/Sonar_way_profile.json @@ -10,6 +10,7 @@ "CaseWithoutElse", "CommentedCode", "Comments", + "Commit", "CyclomaticComplexity", "DeleteFromWithoutWhere", "DeprecatedMethod", @@ -40,6 +41,7 @@ "OneStatementPerLine", "ParameterWithDirection", "PassThruStatement", + "Rollback", "PropagateConsistency", "PropagateToLabel", "RoutineWithExcessiveReturns", diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommitCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommitCheckTest.java new file mode 100644 index 00000000..19ddd387 --- /dev/null +++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/CommitCheckTest.java @@ -0,0 +1,16 @@ +package com.exxeta.iss.sonar.esql.check; + +import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier; +import java.io.File; +import org.junit.jupiter.api.Test; + +class CommitCheckTest { + + @Test + void test() { + + EsqlCheckVerifier.issues(new RollbackCheck(), new File("src/test/resources/commitRollback.esql")) + .next().atLine(5).withMessage("ROLLBACK should not be called explicitly. Otherwise the messageflow can't handle the transaction.") + .noMore(); + } +} diff --git a/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RollbackCheckTest.java b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RollbackCheckTest.java new file mode 100644 index 00000000..0dcf7950 --- /dev/null +++ b/esql-checks/src/test/java/com/exxeta/iss/sonar/esql/check/RollbackCheckTest.java @@ -0,0 +1,16 @@ +package com.exxeta.iss.sonar.esql.check; + +import com.exxeta.iss.sonar.esql.checks.verifier.EsqlCheckVerifier; +import java.io.File; +import org.junit.jupiter.api.Test; + +class RollbackCheckTest { + + @Test + void test() { + + EsqlCheckVerifier.issues(new CommitCheck(), new File("src/test/resources/commitRollback.esql")) + .next().atLine(6).withMessage("COMMIT should not be called explicitly. Otherwise the messageflow can't handle the transaction.") + .noMore(); + } +} diff --git a/esql-checks/src/test/resources/commitRollback.esql b/esql-checks/src/test/resources/commitRollback.esql new file mode 100644 index 00000000..fba9f036 --- /dev/null +++ b/esql-checks/src/test/resources/commitRollback.esql @@ -0,0 +1,9 @@ +CREATE COMPUTE MODULE CommitRollback + + CREATE FUNCTION Main() RETURNS BOOLEAN + BEGIN + ROLLBACK; + COMMIT; + END; + +END MODULE; \ No newline at end of file diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlNonReservedKeyword.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlNonReservedKeyword.java index 45062084..da25032a 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlNonReservedKeyword.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/EsqlNonReservedKeyword.java @@ -43,6 +43,7 @@ public enum EsqlNonReservedKeyword implements TokenType, GrammarRuleKey { CHAR("CHAR"), CHARACTER("CHARACTER"), CLR("CLR"), + COMMIT("COMMIT"), COMPUTE("COMPUTE"), CONDITION("CONDITION"), CONSTANT("CONSTANT"), @@ -170,6 +171,7 @@ public enum EsqlNonReservedKeyword implements TokenType, GrammarRuleKey { RESULT("RESULT"), RETURN("RETURN"), RETURNS("RETURNS"), + ROLLBACK("ROLLBACK"), ROW("ROW"), SAMEFIELD("SAMEFIELD"), SCHEMA("SCHEMA"), diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/Tree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/Tree.java index af30fd42..9298a404 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/Tree.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/Tree.java @@ -17,6 +17,8 @@ */ package com.exxeta.iss.sonar.esql.api.tree; +import com.exxeta.iss.sonar.esql.tree.impl.statement.CommitStatementTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.statement.RollbackStatementTreeImpl; import java.util.stream.Stream; import com.exxeta.iss.sonar.esql.api.tree.statement.JavaClassloaderServiceTree; @@ -266,7 +268,9 @@ public enum Kind implements GrammarRuleKey, Kinds { VARIABLE_REFERENCE(VariableReferenceTree.class), LIST_CONSTRUCTOR_FUNCTION(ListConstructorFunctionTree.class), NULLABLE(NullableTree.class), - JAVA_CLASSLOADER_SERVICE(JavaClassloaderServiceTree.class); + JAVA_CLASSLOADER_SERVICE(JavaClassloaderServiceTree.class), + ROLLBACK_STATEMENT(RollbackStatementTreeImpl.class), + COMMIT_STATEMENT(CommitStatementTreeImpl.class); final Class associatedInterface; diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CommitStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CommitStatementTree.java new file mode 100644 index 00000000..38b37ea8 --- /dev/null +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/CommitStatementTree.java @@ -0,0 +1,28 @@ +/* + * Sonar ESQL Plugin + * Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG + * http://www.exxeta.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exxeta.iss.sonar.esql.api.tree.statement; + +import com.exxeta.iss.sonar.esql.api.tree.FieldReferenceTree; +import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken; + +public interface CommitStatementTree extends StatementTree{ + + SyntaxToken commitKeyword(); + FieldReferenceTree databaseReference(); + SyntaxToken semi(); +} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RollbackStatementTree.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RollbackStatementTree.java new file mode 100644 index 00000000..4e4062e3 --- /dev/null +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/tree/statement/RollbackStatementTree.java @@ -0,0 +1,28 @@ +/* + * Sonar ESQL Plugin + * Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG + * http://www.exxeta.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exxeta.iss.sonar.esql.api.tree.statement; + +import com.exxeta.iss.sonar.esql.api.tree.FieldReferenceTree; +import com.exxeta.iss.sonar.esql.api.tree.lexical.SyntaxToken; + +public interface RollbackStatementTree extends StatementTree{ + + SyntaxToken rollbackKeyword(); + FieldReferenceTree databaseReference(); + SyntaxToken semi(); +} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitor.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitor.java index 884dd162..a0a1ae8b 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitor.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/api/visitors/DoubleDispatchVisitor.java @@ -17,6 +17,8 @@ */ package com.exxeta.iss.sonar.esql.api.visitors; +import com.exxeta.iss.sonar.esql.tree.impl.statement.CommitStatementTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.statement.RollbackStatementTreeImpl; import java.util.Iterator; import java.util.List; @@ -606,4 +608,10 @@ public void javaClassloaderService(JavaClassloaderServiceTree tree){ scanChildren(tree); } + public void visitRollbackStatement(RollbackStatementTreeImpl tree) { + scanChildren(tree); + } + public void visitCommitStatement(CommitStatementTreeImpl tree) { + scanChildren(tree); + } } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlGrammar.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlGrammar.java index fbe5eede..ef26a71d 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlGrammar.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/EsqlGrammar.java @@ -93,6 +93,7 @@ import com.exxeta.iss.sonar.esql.tree.impl.statement.BeginEndStatementTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.CallStatementTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.CaseStatementTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.statement.CommitStatementTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.ControlsTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.CreateFunctionStatementTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.CreateModuleStatementTreeImpl; @@ -131,6 +132,7 @@ import com.exxeta.iss.sonar.esql.tree.impl.statement.ResultSetTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.ReturnStatementTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.ReturnTypeTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.statement.RollbackStatementTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.RoutineBodyTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.SetColumnTreeImpl; import com.exxeta.iss.sonar.esql.tree.impl.statement.SetStatementTreeImpl; @@ -453,7 +455,7 @@ private StatementTree OTHER_STATEMENT() { } private StatementTree DATABASE_UPDATE_STATEMENT() { - return b.firstOf(DELETE_FROM_STATEMENT(), INSERT_STATEMENT(), PASSTHRU_STATEMENT(), UPDATE_STATEMENT()); + return b.firstOf(COMMIT_STATEMENT(), DELETE_FROM_STATEMENT(), INSERT_STATEMENT(), PASSTHRU_STATEMENT(), ROLLBACK_STATEMENT(), UPDATE_STATEMENT()); } private StatementTree NODE_INTERACTION_STATEMENT() { @@ -1097,7 +1099,15 @@ public NameClausesTreeImpl NAME_CLAUSES(){ ) )); } - + + public CommitStatementTreeImpl COMMIT_STATEMENT(){ + return b.nonterminal(Kind.COMMIT_STATEMENT).is (f.commitStatement( + b.token(EsqlNonReservedKeyword.COMMIT),b.optional(FIELD_REFERENCE()), + b.token(EsqlLegacyGrammar.EOS) + )); + } + + public DeleteFromStatementTreeImpl DELETE_FROM_STATEMENT(){ return b.nonterminal(Kind.DELETE_FROM_STATEMENT).is (f.deleteFromStatement( b.token(EsqlNonReservedKeyword.DELETE),b.token(EsqlReservedKeyword.FROM),FIELD_REFERENCE(), @@ -1125,7 +1135,13 @@ public PassthruStatementTreeImpl PASSTHRU_STATEMENT(){ )), b.token(EsqlLegacyGrammar.EOS) )); } - + + public RollbackStatementTreeImpl ROLLBACK_STATEMENT(){ + return b.nonterminal(Kind.ROLLBACK_STATEMENT).is (f.rollbackStatement( + b.token(EsqlNonReservedKeyword.ROLLBACK),b.optional(FIELD_REFERENCE()), + b.token(EsqlLegacyGrammar.EOS) + )); + } public UpdateStatementTreeImpl UPDATE_STATEMENT(){ return b.nonterminal(Kind.UPDATE_STATEMENT).is(f.updateStatement( b.token(EsqlNonReservedKeyword.UPDATE), diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/TreeFactory.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/TreeFactory.java index b093970d..3b0e8d43 100644 --- a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/TreeFactory.java +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/parser/TreeFactory.java @@ -17,6 +17,8 @@ */ package com.exxeta.iss.sonar.esql.parser; +import com.exxeta.iss.sonar.esql.tree.impl.statement.CommitStatementTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.statement.RollbackStatementTreeImpl; import java.util.Collections; import java.util.HashMap; import java.util.List; @@ -1734,6 +1736,19 @@ public InsertStatementTreeImpl insertStatement(InternalSyntaxToken insertKeyword expressionList(expression, restExpression), closingParenthesis, semi); } + public CommitStatementTreeImpl commitStatement(InternalSyntaxToken commitKeyword, + Optional databaseReference, + InternalSyntaxToken semi) { + + return new CommitStatementTreeImpl(commitKeyword, databaseReference.orNull(), semi); + } + public RollbackStatementTreeImpl rollbackStatement(InternalSyntaxToken rollbackKeyword, + Optional databaseReference, + InternalSyntaxToken semi) { + + return new RollbackStatementTreeImpl(rollbackKeyword, databaseReference.orNull(), semi); + } + public PassthruStatementTreeImpl passthruExpressionList(ParameterListTreeImpl expressionList) { return new PassthruStatementTreeImpl(expressionList); } diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CommitStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CommitStatementTreeImpl.java new file mode 100644 index 00000000..0870ddb6 --- /dev/null +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/CommitStatementTreeImpl.java @@ -0,0 +1,77 @@ +/* + * Sonar ESQL Plugin + * Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG + * http://www.exxeta.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exxeta.iss.sonar.esql.tree.impl.statement; + +import com.exxeta.iss.sonar.esql.api.tree.Tree; +import com.exxeta.iss.sonar.esql.api.tree.expression.ExpressionTree; +import com.exxeta.iss.sonar.esql.api.tree.statement.CommitStatementTree; +import com.exxeta.iss.sonar.esql.api.tree.statement.PassthruStatementTree; +import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitor; +import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree; +import com.exxeta.iss.sonar.esql.tree.impl.declaration.FieldReferenceTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.declaration.ParameterListTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; +import com.google.common.collect.Iterators; +import java.util.Iterator; + +public class CommitStatementTreeImpl extends EsqlTree implements CommitStatementTree { + + private InternalSyntaxToken commitKeyword; + private FieldReferenceTreeImpl databaseReference; + private InternalSyntaxToken semi; + + public CommitStatementTreeImpl(InternalSyntaxToken commitKeyword, + FieldReferenceTreeImpl databaseReference, InternalSyntaxToken semi) { + super(); + this.commitKeyword=commitKeyword; + this.databaseReference = databaseReference; + this.semi=semi; + } + + @Override + public InternalSyntaxToken commitKeyword() { + return commitKeyword; + } + + @Override + public FieldReferenceTreeImpl databaseReference() { + return databaseReference; + } + + @Override + public InternalSyntaxToken semi() { + return semi; + } + + @Override + public void accept(DoubleDispatchVisitor visitor) { + visitor.visitCommitStatement(this); + } + + @Override + public Kind getKind() { + return Kind.COMMIT_STATEMENT; + } + + @Override + public Iterator childrenIterator() { + return Iterators.forArray(commitKeyword, databaseReference, semi); + } + + +} diff --git a/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RollbackStatementTreeImpl.java b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RollbackStatementTreeImpl.java new file mode 100644 index 00000000..54f453f0 --- /dev/null +++ b/esql-frontend/src/main/java/com/exxeta/iss/sonar/esql/tree/impl/statement/RollbackStatementTreeImpl.java @@ -0,0 +1,78 @@ +/* + * Sonar ESQL Plugin + * Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG + * http://www.exxeta.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exxeta.iss.sonar.esql.tree.impl.statement; + +import com.exxeta.iss.sonar.esql.api.tree.Tree; +import com.exxeta.iss.sonar.esql.api.tree.expression.ExpressionTree; +import com.exxeta.iss.sonar.esql.api.tree.statement.PassthruStatementTree; +import com.exxeta.iss.sonar.esql.api.tree.statement.RollbackStatementTree; +import com.exxeta.iss.sonar.esql.api.visitors.DoubleDispatchVisitor; +import com.exxeta.iss.sonar.esql.tree.impl.EsqlTree; +import com.exxeta.iss.sonar.esql.tree.impl.declaration.FieldReferenceTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.declaration.ParameterListTreeImpl; +import com.exxeta.iss.sonar.esql.tree.impl.lexical.InternalSyntaxToken; +import com.google.common.collect.Iterators; +import java.util.Iterator; + +public class RollbackStatementTreeImpl extends EsqlTree implements RollbackStatementTree { + + private InternalSyntaxToken rollbackKeyword; + private FieldReferenceTreeImpl databaseReference; + private InternalSyntaxToken semi; + + public RollbackStatementTreeImpl(InternalSyntaxToken rollbackKeyword, + FieldReferenceTreeImpl databaseReference, InternalSyntaxToken semi) { + super(); + this.rollbackKeyword=rollbackKeyword; + this.databaseReference = databaseReference; + this.semi=semi; + } + + @Override + public InternalSyntaxToken rollbackKeyword() { + return rollbackKeyword; + } + + @Override + public FieldReferenceTreeImpl databaseReference() { + return databaseReference; + } + + @Override + public InternalSyntaxToken semi() { + return semi; + } + + @Override + public void accept(DoubleDispatchVisitor visitor) { + visitor.visitRollbackStatement(this); + } + + @Override + public Kind getKind() { + return Kind.ROLLBACK_STATEMENT; + } + + @Override + public Iterator childrenIterator() { + return Iterators.forArray(rollbackKeyword, databaseReference, semi); + } + + + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CommitStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CommitStatementTest.java new file mode 100644 index 00000000..87ceee25 --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/CommitStatementTest.java @@ -0,0 +1,48 @@ +/* + * Sonar ESQL Plugin + * Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG + * http://www.exxeta.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exxeta.iss.sonar.esql.api.tree.statement; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; +import org.junit.jupiter.api.Test; + +class CommitStatementTest extends EsqlTreeModelTest { + + + @Test + void commitStatement(){ + assertThat(Kind.COMMIT_STATEMENT) + .matches("COMMIT;"); + + } + + @Test + void modelTest() throws Exception { + CommitStatementTree tree = parse("COMMIT Database.{Source};", Kind.COMMIT_STATEMENT); + assertNotNull(tree.commitKeyword()); + + assertNotNull(tree.databaseReference()); + + assertNotNull(tree.semi()); + + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/RollbackStatementTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/RollbackStatementTest.java new file mode 100644 index 00000000..17eea70b --- /dev/null +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/api/tree/statement/RollbackStatementTest.java @@ -0,0 +1,48 @@ +/* + * Sonar ESQL Plugin + * Copyright (C) 2013-2023 Thomas Pohl and EXXETA AG + * http://www.exxeta.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.exxeta.iss.sonar.esql.api.tree.statement; + +import static com.exxeta.iss.sonar.esql.utils.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertNotNull; + +import com.exxeta.iss.sonar.esql.api.tree.Tree.Kind; +import com.exxeta.iss.sonar.esql.utils.EsqlTreeModelTest; +import org.junit.jupiter.api.Test; + +class RollbackStatementTest extends EsqlTreeModelTest { + + + @Test + void commitStatement(){ + assertThat(Kind.ROLLBACK_STATEMENT) + .matches("ROLLBACK;"); + + } + + @Test + void modelTest() throws Exception { + RollbackStatementTree tree = parse("ROLLBACK Database.{Source};", Kind.ROLLBACK_STATEMENT); + assertNotNull(tree.rollbackKeyword()); + + assertNotNull(tree.databaseReference()); + + assertNotNull(tree.semi()); + + } + +} diff --git a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlKeywordTest.java b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlKeywordTest.java index 0cc2f0ba..a624eabb 100644 --- a/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlKeywordTest.java +++ b/esql-frontend/src/test/java/com/exxeta/iss/sonar/esql/lexer/EsqlKeywordTest.java @@ -36,7 +36,7 @@ void esqlReservedKeyword() { @Test void esqlNonReservedKeyword() { - assertThat(EsqlNonReservedKeyword.values().length).isEqualTo(214); + assertThat(EsqlNonReservedKeyword.values().length).isEqualTo(216); assertThat(EsqlNonReservedKeyword.keywordValues().length).isEqualTo(EsqlNonReservedKeyword.values().length); for (EsqlNonReservedKeyword keyword : EsqlNonReservedKeyword.values()) {