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

import com.alibaba.druid.sql.ast.SQLDataType;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLObjectWithDataType;
import com.alibaba.druid.sql.ast.SQLParameter;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.SQLStatementImpl;
import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class SQLCreateFunctionStatement extends SQLStatementImpl implements SQLCreateStatement, SQLObjectWithDataType {
   protected SQLName definer;
   protected boolean create = true;
   protected boolean orReplace;
   protected SQLName name;
   protected SQLStatement block;
   protected List<SQLParameter> parameters = new ArrayList();
   private String javaCallSpec;
   private SQLName authid;
   SQLDataType returnDataType;
   private String comment;
   private boolean deterministic = false;
   private boolean containsSql;
   private boolean noSql;
   private boolean readSqlData;
   private boolean modifiesSqlData;
   private boolean parallelEnable;
   private boolean aggregate;
   private SQLName using;
   private boolean pipelined;
   private boolean resultCache;
   private String wrappedSource;
   private String language;
   private boolean temporary;
   private boolean ifNotExists;

   public SQLCreateFunctionStatement clone() {
      SQLCreateFunctionStatement x = new SQLCreateFunctionStatement();
      if (this.definer != null) {
         x.setDefiner(this.definer.clone());
      }

      x.create = this.create;
      x.orReplace = this.orReplace;
      if (this.name != null) {
         x.setName(this.name.clone());
      }

      if (this.block != null) {
         x.setBlock(this.block.clone());
      }

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

      x.javaCallSpec = this.javaCallSpec;
      if (this.authid != null) {
         x.setAuthid(this.authid.clone());
      }

      if (this.returnDataType != null) {
         x.setReturnDataType(this.returnDataType.clone());
      }

      x.comment = this.comment;
      x.deterministic = this.deterministic;
      x.pipelined = this.pipelined;
      x.language = this.language;
      return x;
   }

   public void accept0(SQLASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.definer);
         this.acceptChild(visitor, this.name);
         this.acceptChild(visitor, this.parameters);
         this.acceptChild(visitor, this.returnDataType);
         this.acceptChild(visitor, this.block);
      }

      visitor.endVisit(this);
   }

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

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

   public SQLName getName() {
      return this.name;
   }

   public void setName(SQLName x) {
      if (x != null) {
         x.setParent(this);
      }

      this.name = x;
   }

   public SQLStatement getBlock() {
      return this.block;
   }

   public void setBlock(SQLStatement block) {
      if (block != null) {
         block.setParent(this);
      }

      this.block = block;
   }

   public SQLName getAuthid() {
      return this.authid;
   }

   public void setAuthid(SQLName authid) {
      if (authid != null) {
         authid.setParent(this);
      }

      this.authid = authid;
   }

   public String getLanguage() {
      return this.language;
   }

   public void setLanguage(String language) {
      this.language = language;
   }

   public boolean isOrReplace() {
      return this.orReplace;
   }

   public void setOrReplace(boolean orReplace) {
      this.orReplace = orReplace;
   }

   public SQLName getDefiner() {
      return this.definer;
   }

   public void setDefiner(SQLName definer) {
      this.definer = definer;
   }

   public boolean isCreate() {
      return this.create;
   }

   public void setCreate(boolean create) {
      this.create = create;
   }

   public String getJavaCallSpec() {
      return this.javaCallSpec;
   }

   public void setJavaCallSpec(String javaCallSpec) {
      this.javaCallSpec = javaCallSpec;
   }

   public SQLDataType getReturnDataType() {
      return this.returnDataType;
   }

   public void setReturnDataType(SQLDataType returnDataType) {
      if (returnDataType != null) {
         returnDataType.setParent(this);
      }

      this.returnDataType = returnDataType;
   }

   public String getComment() {
      return this.comment;
   }

   public void setComment(String comment) {
      this.comment = comment;
   }

   public boolean isDeterministic() {
      return this.deterministic;
   }

   public void setDeterministic(boolean deterministic) {
      this.deterministic = deterministic;
   }

   public String getSchema() {
      SQLName name = this.getName();
      if (name == null) {
         return null;
      } else {
         return name instanceof SQLPropertyExpr ? ((SQLPropertyExpr)name).getOwnernName() : null;
      }
   }

   public SQLDataType getDataType() {
      return this.returnDataType;
   }

   public void setDataType(SQLDataType dataType) {
      this.setReturnDataType(dataType);
   }

   public boolean isParallelEnable() {
      return this.parallelEnable;
   }

   public void setParallelEnable(boolean parallel_enable) {
      this.parallelEnable = parallel_enable;
   }

   public boolean isAggregate() {
      return this.aggregate;
   }

   public void setAggregate(boolean aggregate) {
      this.aggregate = aggregate;
   }

   public SQLName getUsing() {
      return this.using;
   }

   public void setUsing(SQLName using) {
      this.using = using;
   }

   public boolean isPipelined() {
      return this.pipelined;
   }

   public void setPipelined(boolean pipelined) {
      this.pipelined = pipelined;
   }

   public boolean isResultCache() {
      return this.resultCache;
   }

   public void setResultCache(boolean resultCache) {
      this.resultCache = resultCache;
   }

   public String getWrappedSource() {
      return this.wrappedSource;
   }

   public void setWrappedSource(String wrappedSource) {
      this.wrappedSource = wrappedSource;
   }

   public boolean isTemporary() {
      return this.temporary;
   }

   public void setTemporary(boolean temporary) {
      this.temporary = temporary;
   }

   public boolean isIfNotExists() {
      return this.ifNotExists;
   }

   public void setIfNotExists(boolean ifNotExists) {
      this.ifNotExists = ifNotExists;
   }

   public boolean isContainsSql() {
      return this.containsSql;
   }

   public void setContainsSql(boolean containsSql) {
      this.containsSql = containsSql;
   }

   public boolean isNoSql() {
      return this.noSql;
   }

   public void setNoSql(boolean noSql) {
      this.noSql = noSql;
   }

   public boolean isReadSqlData() {
      return this.readSqlData;
   }

   public void setReadSqlData(boolean readSqlData) {
      this.readSqlData = readSqlData;
   }

   public boolean isModifiesSqlData() {
      return this.modifiesSqlData;
   }

   public void setModifiesSqlData(boolean modifiesSqlData) {
      this.modifiesSqlData = modifiesSqlData;
   }
}
