View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.shardingsphere.sql.parser.oracle.visitor.statement.type;
19  
20  import org.apache.shardingsphere.infra.database.core.type.DatabaseType;
21  import org.apache.shardingsphere.sql.parser.api.ASTNode;
22  import org.apache.shardingsphere.sql.parser.api.visitor.statement.type.TCLStatementVisitor;
23  import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.CommitContext;
24  import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.LockContext;
25  import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.RollbackContext;
26  import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.SavepointContext;
27  import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.SetConstraintsContext;
28  import org.apache.shardingsphere.sql.parser.autogen.OracleStatementParser.SetTransactionContext;
29  import org.apache.shardingsphere.sql.parser.oracle.visitor.statement.OracleStatementVisitor;
30  import org.apache.shardingsphere.sql.parser.statement.core.statement.type.lcl.LockStatement;
31  import org.apache.shardingsphere.sql.parser.statement.core.statement.type.tcl.CommitStatement;
32  import org.apache.shardingsphere.sql.parser.statement.core.statement.type.tcl.RollbackStatement;
33  import org.apache.shardingsphere.sql.parser.statement.core.statement.type.tcl.SavepointStatement;
34  import org.apache.shardingsphere.sql.parser.statement.core.statement.type.tcl.SetConstraintsStatement;
35  import org.apache.shardingsphere.sql.parser.statement.core.statement.type.tcl.SetTransactionStatement;
36  import org.apache.shardingsphere.sql.parser.statement.core.value.identifier.IdentifierValue;
37  
38  import java.util.Collections;
39  
40  /**
41   * TCL statement visitor for Oracle.
42   */
43  public final class OracleTCLStatementVisitor extends OracleStatementVisitor implements TCLStatementVisitor {
44      
45      public OracleTCLStatementVisitor(final DatabaseType databaseType) {
46          super(databaseType);
47      }
48      
49      @Override
50      public ASTNode visitSetTransaction(final SetTransactionContext ctx) {
51          return new SetTransactionStatement(getDatabaseType());
52      }
53      
54      @Override
55      public ASTNode visitCommit(final CommitContext ctx) {
56          return new CommitStatement(getDatabaseType());
57      }
58      
59      @Override
60      public ASTNode visitRollback(final RollbackContext ctx) {
61          return null == ctx.savepointClause().savepointName() ? new RollbackStatement(getDatabaseType())
62                  : new RollbackStatement(getDatabaseType(), ((IdentifierValue) visit(ctx.savepointClause().savepointName())).getValue());
63      }
64      
65      @Override
66      public ASTNode visitSavepoint(final SavepointContext ctx) {
67          return new SavepointStatement(getDatabaseType(), ((IdentifierValue) visit(ctx.savepointName())).getValue());
68      }
69      
70      @Override
71      public ASTNode visitSetConstraints(final SetConstraintsContext ctx) {
72          return new SetConstraintsStatement(getDatabaseType());
73      }
74      
75      @Override
76      public ASTNode visitLock(final LockContext ctx) {
77          return new LockStatement(getDatabaseType(), Collections.emptyList());
78      }
79  }