All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.scalar.db.sql.statement.DropTableStatement Maven / Gradle / Ivy

There is a newer version: 3.14.0
Show newest version
package com.scalar.db.sql.statement;

import com.scalar.db.sql.TableRef;
import java.util.Objects;
import javax.annotation.concurrent.Immutable;

@Immutable
public class DropTableStatement
    implements DdlStatement, NamespaceNameOmittable {

  public final TableRef table;
  public final boolean ifExists;

  private DropTableStatement(TableRef table, boolean ifExists) {
    this.table = Objects.requireNonNull(table);
    this.ifExists = ifExists;
  }

  @Override
  public String toSql() {
    StringBuilder builder = new StringBuilder("DROP TABLE ");
    if (ifExists) {
      builder.append("IF EXISTS ");
    }
    StatementUtils.appendTable(builder, table);
    return builder.toString();
  }

  @Override
  public  R accept(StatementVisitor visitor, C context) {
    return visitor.visit(this, context);
  }

  @Override
  public  R accept(DdlStatementVisitor visitor, C context) {
    return visitor.visit(this, context);
  }

  @Override
  public boolean namespaceNameOmitted() {
    return table.namespaceName == null;
  }

  @Override
  public DropTableStatement setNamespaceNameIfOmitted(String namespaceName) {
    if (namespaceNameOmitted()) {
      return create(TableRef.of(namespaceName, table.tableName), ifExists);
    }
    return this;
  }

  @Override
  public String toString() {
    return toSql();
  }

  @Override
  public boolean equals(Object o) {
    if (this == o) {
      return true;
    }
    if (!(o instanceof DropTableStatement)) {
      return false;
    }
    DropTableStatement that = (DropTableStatement) o;
    return ifExists == that.ifExists && Objects.equals(table, that.table);
  }

  @Override
  public int hashCode() {
    return Objects.hash(table, ifExists);
  }

  public static DropTableStatement create(TableRef table, boolean ifExists) {
    return new DropTableStatement(table, ifExists);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy