package com.chenyang.druid.sql.ast.statement;

import com.chenyang.druid.sql.ast.SQLParameter;
import com.chenyang.druid.sql.ast.SQLStatement;
import com.chenyang.druid.sql.ast.SQLStatementImpl;
import com.chenyang.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class SQLBlockStatement extends SQLStatementImpl {
   private String labelName;
   private String endLabel;
   private List<SQLParameter> parameters = new ArrayList();
   private List<SQLStatement> statementList = new ArrayList();
   public SQLStatement exception;
   private boolean endOfCommit;

   public List<SQLStatement> getStatementList() {
      return this.statementList;
   }

   public void setStatementList(List<SQLStatement> statementList) {
      this.statementList = statementList;
   }

   public String getLabelName() {
      return this.labelName;
   }

   public void setLabelName(String labelName) {
      this.labelName = labelName;
   }

   public void accept0(SQLASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.parameters);
         this.acceptChild(visitor, this.statementList);
         this.acceptChild(visitor, this.exception);
      }

      visitor.endVisit(this);
   }

   public List<SQLParameter> getParameters() {
      return this.parameters;
   }

   public void setParameters(List<SQLParameter> parameters) {
      this.parameters = parameters;
   }

   public SQLStatement getException() {
      return this.exception;
   }

   public void setException(SQLStatement exception) {
      if (exception != null) {
         exception.setParent(this);
      }

      this.exception = exception;
   }

   public String getEndLabel() {
      return this.endLabel;
   }

   public void setEndLabel(String endLabel) {
      this.endLabel = endLabel;
   }

   public SQLBlockStatement clone() {
      SQLBlockStatement x = new SQLBlockStatement();
      x.labelName = this.labelName;
      x.endLabel = this.endLabel;

      for(SQLParameter p : this.parameters) {
         SQLParameter p2 = p.clone();
         p2.setParent(x);
         x.parameters.add(p2);
      }

      for(SQLStatement stmt : this.statementList) {
         SQLStatement stmt2 = stmt.clone();
         stmt2.setParent(x);
         x.statementList.add(stmt2);
      }

      if (this.exception != null) {
         x.setException(this.exception.clone());
      }

      return x;
   }

   public SQLParameter findParameter(long hash) {
      for(SQLParameter param : this.parameters) {
         if (param.getName().nameHashCode64() == hash) {
            return param;
         }
      }

      return null;
   }

   public boolean isEndOfCommit() {
      return this.endOfCommit;
   }

   public void setEndOfCommit(boolean value) {
      this.endOfCommit = value;
   }
}
