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

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

  public final TableRef table;

  private DescribeStatement(TableRef table) {
    this.table = Objects.requireNonNull(table);
  }

  @Override
  public String toSql() {
    StringBuilder builder = new StringBuilder("DESCRIBE ");
    StatementUtils.appendTable(builder, table);
    return builder.toString();
  }

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

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

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

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

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

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

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

  public static DescribeStatement create(TableRef table) {
    return new DescribeStatement(table);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy