com.scalar.db.sql.statement.TruncateTableStatement Maven / Gradle / Ivy
package com.scalar.db.sql.statement;
import com.scalar.db.sql.TableRef;
import java.util.Objects;
import javax.annotation.concurrent.Immutable;
@Immutable
public class TruncateTableStatement
implements DdlStatement, NamespaceNameOmittable {
public final TableRef table;
private TruncateTableStatement(TableRef table) {
this.table = Objects.requireNonNull(table);
}
@Override
public String toSql() {
StringBuilder builder = new StringBuilder("TRUNCATE TABLE ");
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 TruncateTableStatement 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 TruncateTableStatement)) {
return false;
}
TruncateTableStatement that = (TruncateTableStatement) o;
return Objects.equals(table, that.table);
}
@Override
public int hashCode() {
return Objects.hash(table);
}
public static TruncateTableStatement create(TableRef table) {
return new TruncateTableStatement(table);
}
}