com.scalar.db.sql.statement.ShowTablesStatement Maven / Gradle / Ivy
package com.scalar.db.sql.statement;
import java.util.Objects;
import javax.annotation.Nullable;
import javax.annotation.concurrent.Immutable;
@Immutable
public class ShowTablesStatement
implements CommandStatement, NamespaceNameOmittable {
@Nullable public final String namespaceName;
private ShowTablesStatement(@Nullable String namespaceName) {
this.namespaceName = namespaceName;
}
@Override
public String toSql() {
StringBuilder builder = new StringBuilder("SHOW TABLES");
if (namespaceName != null) {
builder.append(" FROM ");
StatementUtils.appendObjectName(builder, namespaceName);
}
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 namespaceName == null;
}
@Override
public ShowTablesStatement setNamespaceNameIfOmitted(String namespaceName) {
if (namespaceNameOmitted()) {
return create(namespaceName);
}
return this;
}
@Override
public String toString() {
return toSql();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof ShowTablesStatement)) {
return false;
}
ShowTablesStatement that = (ShowTablesStatement) o;
return Objects.equals(namespaceName, that.namespaceName);
}
@Override
public int hashCode() {
return Objects.hash(namespaceName);
}
public static ShowTablesStatement create(@Nullable String namespaceName) {
return new ShowTablesStatement(namespaceName);
}
}