package com.alibaba.druid.sql.dialect.dm.ast.stmt;

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.ast.SQLCommentHint;
import com.alibaba.druid.sql.ast.SQLHint;
import com.alibaba.druid.sql.ast.statement.SQLErrorLoggingClause;
import com.alibaba.druid.sql.ast.statement.SQLInsertStatement;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.dialect.dm.ast.clause.DmReturningClause;
import com.alibaba.druid.sql.dialect.dm.visitor.DmASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTOutputVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;
import java.util.ArrayList;
import java.util.List;

public class DmInsertStatement extends SQLInsertStatement implements DmStatement {
   private SQLSelect select;
   private String selectAlias;
   private boolean selectAsToken;
   private DmReturningClause returning;
   private SQLErrorLoggingClause errorLogging;
   private List<SQLHint> hints = new ArrayList();

   public DmInsertStatement() {
      this.dbType = DbType.dm;
   }

   public void cloneTo(DmInsertStatement x) {
      if (x.getSelect() != null) {
         x.setSelect(this.select.clone());
      }

      super.cloneTo(x);
      if (this.returning != null) {
         x.setReturning(this.returning.clone());
      }

      if (this.errorLogging != null) {
         x.setErrorLogging(this.errorLogging.clone());
      }

      for(SQLHint hint : this.hints) {
         SQLHint h2 = hint.clone();
         h2.setParent(x);
         x.hints.add(h2);
      }

   }

   public List<SQLHint> getHints() {
      return this.hints;
   }

   public void setHints(List<SQLHint> hints) {
      this.hints = hints;
   }

   public DmReturningClause getReturning() {
      return this.returning;
   }

   public void setReturning(DmReturningClause returning) {
      this.returning = returning;
   }

   public SQLErrorLoggingClause getErrorLogging() {
      return this.errorLogging;
   }

   public void setErrorLogging(SQLErrorLoggingClause errorLogging) {
      this.errorLogging = errorLogging;
   }

   protected void accept0(SQLASTVisitor v) {
      if (v instanceof DmASTVisitor) {
         this.accept0((DmASTVisitor)v);
      } else {
         if (v instanceof SQLASTOutputVisitor) {
            ((SQLASTOutputVisitor)v).print(this.toString());
         }

      }
   }

   public void accept0(DmASTVisitor visitor) {
      if (visitor.visit(this)) {
         this.acceptChild(visitor, this.select);
         if (this.tableSource != null) {
            this.acceptChild(visitor, this.getTableSource());
         }

         this.acceptChild(visitor, this.getColumns());
         this.acceptChild(visitor, this.getValuesList());
         this.acceptChild(visitor, this.getQuery());
         this.acceptChild(visitor, this.returning);
         this.acceptChild(visitor, this.errorLogging);
      }

      visitor.endVisit(this);
   }

   public DmInsertStatement clone() {
      DmInsertStatement x = new DmInsertStatement();
      this.cloneTo(x);
      return x;
   }

   public List<SQLCommentHint> getHeadHintsDirect() {
      return null;
   }

   public SQLSelect getSelect() {
      return this.select;
   }

   public void setSelect(SQLSelect select) {
      this.select = select;
   }

   public String getSelectAlias() {
      return this.selectAlias;
   }

   public void setSelectAlias(String selectAlias) {
      this.selectAlias = selectAlias;
   }

   public boolean isSelectAsToken() {
      return this.selectAsToken;
   }

   public void setSelectAsToken(boolean selectAsToken) {
      this.selectAsToken = selectAsToken;
   }
}
