com.scalar.db.sql.statement.DropNamespaceStatement Maven / Gradle / Ivy
package com.scalar.db.sql.statement;
import java.util.Objects;
import javax.annotation.concurrent.Immutable;
@Immutable
public class DropNamespaceStatement implements DdlStatement {
public final String namespaceName;
public final boolean ifExists;
public final boolean cascade;
private DropNamespaceStatement(String namespaceName, boolean ifExists, boolean cascade) {
this.namespaceName = Objects.requireNonNull(namespaceName);
this.ifExists = ifExists;
this.cascade = cascade;
}
@Override
public String toSql() {
StringBuilder builder = new StringBuilder("DROP NAMESPACE ");
if (ifExists) {
builder.append("IF EXISTS ");
}
StatementUtils.appendObjectName(builder, namespaceName);
if (cascade) {
builder.append(" CASCADE");
}
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 String toString() {
return toSql();
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (!(o instanceof DropNamespaceStatement)) {
return false;
}
DropNamespaceStatement that = (DropNamespaceStatement) o;
return ifExists == that.ifExists
&& cascade == that.cascade
&& Objects.equals(namespaceName, that.namespaceName);
}
@Override
public int hashCode() {
return Objects.hash(namespaceName, ifExists, cascade);
}
public static DropNamespaceStatement create(
String namespaceName, boolean ifExists, boolean cascade) {
return new DropNamespaceStatement(namespaceName, ifExists, cascade);
}
}