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

com.scalar.db.sql.statement.DropIndexStatement 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 DropIndexStatement
    implements DdlStatement, NamespaceNameOmittable {

  public final TableRef table;
  public final String columnName;
  public final boolean ifExists;

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

  @Override
  public String toSql() {
    StringBuilder builder = new StringBuilder("DROP INDEX ");
    if (ifExists) {
      builder.append("IF EXISTS ");
    }
    builder.append("ON ");
    StatementUtils.appendTable(builder, table);
    builder.append('(');
    StatementUtils.appendObjectName(builder, columnName);
    return builder.append(')').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 DropIndexStatement setNamespaceNameIfOmitted(String namespaceName) {
    if (namespaceNameOmitted()) {
      return create(TableRef.of(namespaceName, table.tableName), columnName, ifExists);
    }
    return this;
  }

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

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

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

  public static DropIndexStatement create(TableRef table, String columnName, boolean ifExists) {
    return new DropIndexStatement(table, columnName, ifExists);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy