com.scalar.db.sql.statement.builder.DropIndexStatementBuilder Maven / Gradle / Ivy
package com.scalar.db.sql.statement.builder;
import com.scalar.db.sql.TableRef;
import com.scalar.db.sql.statement.DropIndexStatement;
import javax.annotation.Nullable;
public class DropIndexStatementBuilder {
private DropIndexStatementBuilder() {}
public static class Start extends OnTable {
Start() {
super(false);
}
/**
* Specifies that the index should be dropped only if it exists.
*
* @return a builder object
*/
public OnTable ifExists() {
return new OnTable(true);
}
/**
* Specifies whether the index should be dropped only if it exists.
*
* @param ifExists whether the index should be dropped only if it exists
* @return a builder object
*/
public OnTable ifExists(boolean ifExists) {
return new OnTable(ifExists);
}
}
public static class OnTable {
private final boolean ifExists;
private OnTable(boolean ifExists) {
this.ifExists = ifExists;
}
/**
* Specifies which table the index is on.
*
* @param namespaceName a namespace name of the target table
* @param tableName a table name of the target table
* @return a builder object
*/
public Column onTable(@Nullable String namespaceName, String tableName) {
return new Column(namespaceName, tableName, ifExists);
}
/**
* Specifies which table the index is on.
*
* @param tableName a table name of the target table
* @return a builder object
*/
public Column onTable(String tableName) {
return onTable(null, tableName);
}
}
public static class Column {
@Nullable private final String namespaceName;
private final String tableName;
private final boolean ifExists;
private Column(@Nullable String namespaceName, String tableName, boolean ifExists) {
this.namespaceName = namespaceName;
this.tableName = tableName;
this.ifExists = ifExists;
}
/**
* Specifies the column to create the index on.
*
* @param columnName a column name of the target column
* @return a builder object
*/
public Buildable column(String columnName) {
return new Buildable(namespaceName, tableName, columnName, ifExists);
}
}
public static class Buildable {
@Nullable private final String namespaceName;
private final String tableName;
private final String columnName;
private final boolean ifExists;
private Buildable(
@Nullable String namespaceName, String tableName, String columnName, boolean ifExists) {
this.namespaceName = namespaceName;
this.tableName = tableName;
this.columnName = columnName;
this.ifExists = ifExists;
}
/**
* Builds a DropIndexStatement object.
*
* @return a DropIndexStatement object
*/
public DropIndexStatement build() {
return DropIndexStatement.create(TableRef.of(namespaceName, tableName), columnName, ifExists);
}
}
}