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

import com.alibaba.druid.sql.ast.SQLExpr;
import com.alibaba.druid.sql.ast.statement.SQLSelect;
import com.alibaba.druid.sql.dialect.spark.ast.expr.SparkDefProperty;
import com.alibaba.druid.sql.dialect.spark.visitor.SparkVisitor;
import com.google.common.base.Objects;
import java.util.ArrayList;
import java.util.List;

public class SparkCacheTableStatement extends SparkStatementImpl {
   private boolean lazy;
   private SQLExpr table;
   private List<SparkDefProperty> options = new ArrayList();
   private SparkCacheTableStatementQuery query;

   public boolean isLazy() {
      return this.lazy;
   }

   public void setLazy(boolean lazy) {
      this.lazy = lazy;
   }

   public SQLExpr getTable() {
      return this.table;
   }

   public void setTable(SQLExpr table) {
      this.table = table;
   }

   public List<SparkDefProperty> getOptions() {
      return this.options;
   }

   public void setOptions(List<SparkDefProperty> options) {
      this.options = options;
   }

   public SparkCacheTableStatementQuery getQuery() {
      return this.query;
   }

   public void setQuery(SparkCacheTableStatementQuery query) {
      this.query = query;
   }

   public SparkCacheTableStatement clone() {
      SparkCacheTableStatement x = new SparkCacheTableStatement();
      x.table = this.table == null ? null : this.table.clone();
      x.query = this.query == null ? null : this.query.clone();

      for(SparkDefProperty option : this.options) {
         x.options.add(option.clone());
      }

      return x;
   }

   public boolean equals(Object o) {
      if (this == o) {
         return true;
      } else if (!this.objectNullEquals(this, o)) {
         return false;
      } else {
         SparkCacheTableStatement that = (SparkCacheTableStatement)o;
         if (this.lazy != that.lazy) {
            return false;
         } else if (!this.objectEquals(this.table, that.table)) {
            return false;
         } else if (!this.objectEquals(this.query, that.query)) {
            return false;
         } else if (this.options.size() != that.options.size()) {
            return false;
         } else {
            for(int i = 0; i < this.options.size(); ++i) {
               if (!this.objectEquals(this.options.get(i), that.options.get(i))) {
                  return false;
               }
            }

            return true;
         }
      }
   }

   public int hashCode() {
      int hash = this.lazy ? 1 : 0;
      hash = 31 * hash + (this.table == null ? 0 : this.table.hashCode());
      hash = 31 * hash + Objects.hashCode(new Object[]{this.options});
      hash = 31 * hash + (this.query == null ? 0 : this.query.hashCode());
      return hash;
   }

   public void accept0(SparkVisitor v) {
      if (v.visit(this)) {
         this.acceptChild(v, this.table);
         this.acceptChild(v, this.options);
         this.acceptChild(v, this.query);
      }

      v.endVisit(this);
   }

   public static class SparkCacheTableStatementQuery extends SparkStatementImpl {
      private SQLSelect query;
      private SQLExpr fromQuery;
      private SQLExpr tableQuery;

      public SQLSelect getQuery() {
         return this.query;
      }

      public void setQuery(SQLSelect query) {
         this.query = query;
      }

      public SQLExpr getFromQuery() {
         return this.fromQuery;
      }

      public void setFromQuery(SQLExpr fromQuery) {
         this.fromQuery = fromQuery;
      }

      public SQLExpr getTableQuery() {
         return this.tableQuery;
      }

      public void setTableQuery(SQLExpr tableQuery) {
         this.tableQuery = tableQuery;
      }

      public SparkCacheTableStatementQuery clone() {
         SparkCacheTableStatementQuery x = new SparkCacheTableStatementQuery();
         x.query = this.query == null ? null : this.query.clone();
         x.fromQuery = this.fromQuery == null ? null : this.fromQuery.clone();
         x.tableQuery = this.tableQuery == null ? null : this.tableQuery.clone();
         return x;
      }

      public boolean equals(Object o) {
         if (this == o) {
            return true;
         } else if (!this.objectNullEquals(this, o)) {
            return false;
         } else {
            SparkCacheTableStatementQuery that = (SparkCacheTableStatementQuery)o;
            if (!this.objectEquals(this.query, that.query)) {
               return false;
            } else if (!this.objectEquals(this.fromQuery, that.fromQuery)) {
               return false;
            } else {
               return this.objectEquals(this.tableQuery, that.tableQuery);
            }
         }
      }

      public int hashCode() {
         int hash = this.query == null ? 0 : this.query.hashCode();
         hash = 31 * hash + (this.fromQuery == null ? 0 : this.fromQuery.hashCode());
         hash = 31 * hash + (this.tableQuery == null ? 0 : this.tableQuery.hashCode());
         return hash;
      }

      public void accept0(SparkVisitor v) {
         if (v.visit(this)) {
            this.acceptChild(v, this.query);
            this.acceptChild(v, this.fromQuery);
            this.acceptChild(v, this.tableQuery);
         }

         v.endVisit(this);
      }
   }
}
