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

import com.alibaba.druid.DbType;
import com.alibaba.druid.sql.SQLUtils;
import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.SQLName;
import com.alibaba.druid.sql.ast.SQLStatement;
import com.alibaba.druid.sql.ast.statement.SQLExplainStatement;
import com.alibaba.druid.sql.dialect.mariadb.ast.MariadbObject;
import com.alibaba.druid.sql.dialect.mariadb.visitor.MariadbASTVisitor;
import com.alibaba.druid.sql.dialect.mysql.visitor.MySqlASTVisitor;
import com.alibaba.druid.sql.visitor.SQLASTVisitor;

public class MariadbExplainStatement extends SQLExplainStatement implements SQLStatement, MariadbObject {
   private boolean describe;
   private SQLName tableName;
   private SQLName columnName;
   private SQLExpr wild;
   private SQLExpr connectionId;
   private boolean distributeInfo = false;

   public MariadbExplainStatement() {
      super(DbType.mariadb);
   }

   public MariadbExplainStatement(DbType dbType) {
      super(dbType);
   }

   public void accept0(MariadbASTVisitor visitor) {
      if (visitor.visit(this)) {
         if (this.tableName != null) {
            this.tableName.accept(visitor);
            if (this.columnName != null) {
               this.columnName.accept(visitor);
            } else if (this.wild != null) {
               this.wild.accept(visitor);
            }
         } else if (this.connectionId != null) {
            this.connectionId.accept(visitor);
         } else if (this.statement != null) {
            this.statement.accept(visitor);
         }
      }

      visitor.endVisit(this);
   }

   protected void accept0(SQLASTVisitor visitor) {
      if (visitor instanceof MySqlASTVisitor) {
         this.accept0((SQLASTVisitor)((MySqlASTVisitor)visitor));
      } else {
         super.accept0(visitor);
      }

   }

   public String toString() {
      return SQLUtils.toMySqlString(this);
   }

   public boolean isDescribe() {
      return this.describe;
   }

   public void setDescribe(boolean describe) {
      this.describe = describe;
   }

   public SQLName getTableName() {
      return this.tableName;
   }

   public void setTableName(SQLName tableName) {
      this.tableName = tableName;
   }

   public SQLName getColumnName() {
      return this.columnName;
   }

   public void setColumnName(SQLName columnName) {
      this.columnName = columnName;
   }

   public SQLExpr getWild() {
      return this.wild;
   }

   public void setWild(SQLExpr wild) {
      this.wild = wild;
   }

   public SQLExpr getConnectionId() {
      return this.connectionId;
   }

   public void setConnectionId(SQLExpr connectionId) {
      this.connectionId = connectionId;
   }

   public boolean isDistributeInfo() {
      return this.distributeInfo;
   }

   public void setDistributeInfo(boolean distributeInfo) {
      this.distributeInfo = distributeInfo;
   }
}
