com.scalar.db.sql.statement.builder.StatementBuilder Maven / Gradle / Ivy
package com.scalar.db.sql.statement.builder;
import com.google.common.collect.ImmutableList;
import com.scalar.db.sql.ColumnRef;
import com.scalar.db.sql.Privilege;
import com.scalar.db.sql.Projection;
import com.scalar.db.sql.TransactionMode;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nullable;
public final class StatementBuilder {
private StatementBuilder() {}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.CreateNamespaceStatement}.
*
* @param namespaceName a namespace name to create
* @return a builder object
*/
public static CreateNamespaceStatementBuilder.Start createNamespace(String namespaceName) {
return new CreateNamespaceStatementBuilder.Start(namespaceName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.DropNamespaceStatement}.
*
* @param namespaceName a namespace name to drop
* @return a builder object
*/
public static DropNamespaceStatementBuilder.Start dropNamespace(String namespaceName) {
return new DropNamespaceStatementBuilder.Start(namespaceName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.CreateTableStatement}.
*
* @param namespaceName a namespace to create
* @param tableName a table name to create
* @return a builder object
*/
public static CreateTableStatementBuilder.Start createTable(
@Nullable String namespaceName, String tableName) {
return new CreateTableStatementBuilder.Start(namespaceName, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.CreateTableStatement}.
*
* @param tableName a table name to create
* @return a builder object
*/
public static CreateTableStatementBuilder.Start createTable(String tableName) {
return createTable(null, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.DropTableStatement}.
*
* @param namespaceName a namespace to drop
* @param tableName a table name to drop
* @return a builder object
*/
public static DropTableStatementBuilder.Start dropTable(
@Nullable String namespaceName, String tableName) {
return new DropTableStatementBuilder.Start(namespaceName, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.DropTableStatement}.
*
* @param tableName a table name to drop
* @return a builder object
*/
public static DropTableStatementBuilder.Start dropTable(String tableName) {
return dropTable(null, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.TruncateTableStatement}.
*
* @param namespaceName a namespace to truncate
* @param tableName a table name to truncate
* @return a builder object
*/
public static TruncateTableStatementBuilder.Start truncateTable(
@Nullable String namespaceName, String tableName) {
return new TruncateTableStatementBuilder.Start(namespaceName, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.TruncateTableStatement}.
*
* @param tableName a table name to truncate
* @return a builder object
*/
public static TruncateTableStatementBuilder.Start truncateTable(String tableName) {
return truncateTable(null, tableName);
}
/**
* Returns a builder object for {@link
* com.scalar.db.sql.statement.CreateCoordinatorTablesStatement}.
*
* @return a builder object
*/
public static CreateCoordinatorTablesStatementBuilder.Start createCoordinatorTables() {
return new CreateCoordinatorTablesStatementBuilder.Start();
}
/**
* Returns a builder object for {@link
* com.scalar.db.sql.statement.DropCoordinatorTablesStatement}.
*
* @return a builder object
*/
public static DropCoordinatorTablesStatementBuilder.Start dropCoordinatorTables() {
return new DropCoordinatorTablesStatementBuilder.Start();
}
/**
* Returns a builder object for {@link
* com.scalar.db.sql.statement.TruncateCoordinatorTablesStatement}.
*
* @return a builder object
*/
public static TruncateCoordinatorTablesStatementBuilder.Start truncateCoordinatorTables() {
return new TruncateCoordinatorTablesStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.CreateIndexStatement}.
*
* @return a builder object
*/
public static CreateIndexStatementBuilder.Start createIndex() {
return new CreateIndexStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.DropIndexStatement}.
*
* @return a builder object
*/
public static DropIndexStatementBuilder.Start dropIndex() {
return new DropIndexStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.AlterTableAddColumnStatement}.
*
* @param namespaceName a namespace to alter
* @param tableName a table name to alter
* @return a builder object
*/
public static AlterTableStatementBuilder.Start alterTable(
@Nullable String namespaceName, String tableName) {
return new AlterTableStatementBuilder.Start(namespaceName, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.AlterTableAddColumnStatement}.
*
* @param tableName a table name to alter
* @return a builder object
*/
public static AlterTableStatementBuilder.Start alterTable(String tableName) {
return alterTable(null, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.SelectStatement}.
*
* @return a builder object
*/
public static SelectStatementBuilder.Start select() {
return new SelectStatementBuilder.Start(Collections.emptyList());
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.SelectStatement} with
* projections.
*
* @param projectedColumnNames column names to project
* @return a builder object
*/
public static SelectStatementBuilder.Start select(String... projectedColumnNames) {
return new SelectStatementBuilder.Start(
Arrays.stream(projectedColumnNames)
.map(p -> Projection.column(ColumnRef.of(p)))
.collect(Collectors.toList()));
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.SelectStatement} with
* projections.
*
* @param projections projections
* @return a builder object
*/
public static SelectStatementBuilder.Start select(Projection... projections) {
return new SelectStatementBuilder.Start(Arrays.asList(projections));
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.SelectStatement} with
* projections.
*
* @param projections projections
* @return a builder object
*/
public static SelectStatementBuilder.Start select(List projections) {
return new SelectStatementBuilder.Start(projections);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.InsertStatement}.
*
* @param namespaceName the namespace name of the target table
* @param tableName the table name of the target table
* @return a builder object
*/
public static InsertStatementBuilder.Start insertInto(
@Nullable String namespaceName, String tableName) {
return new InsertStatementBuilder.Start(namespaceName, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.InsertStatement}.
*
* @param tableName the table name of the target table
* @return a builder object
*/
public static InsertStatementBuilder.Start insertInto(String tableName) {
return insertInto(null, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.UpsertStatement}.
*
* @param namespaceName the namespace name of the target table
* @param tableName the table name of the target table
* @return a builder object
*/
public static UpsertStatementBuilder.Start upsertInto(
@Nullable String namespaceName, String tableName) {
return new UpsertStatementBuilder.Start(namespaceName, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.UpsertStatement}.
*
* @param tableName the table name of the target table
* @return a builder object
*/
public static UpsertStatementBuilder.Start upsertInto(String tableName) {
return upsertInto(null, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.UpdateStatement}.
*
* @param namespaceName the namespace name of the target table
* @param tableName the table name of the target table
* @return a builder object
*/
public static UpdateStatementBuilder.Start update(
@Nullable String namespaceName, String tableName) {
return new UpdateStatementBuilder.Start(namespaceName, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.UpdateStatement}.
*
* @param tableName the table name of the target table
* @return a builder object
*/
public static UpdateStatementBuilder.Start update(String tableName) {
return update(null, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.DeleteStatement}.
*
* @param namespaceName the namespace name of the target table
* @param tableName the table name of the target table
* @return a builder object
*/
public static DeleteStatementBuilder.Start deleteFrom(
@Nullable String namespaceName, String tableName) {
return new DeleteStatementBuilder.Start(namespaceName, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.DeleteStatement}.
*
* @param tableName the table name of the target table
* @return a builder object
*/
public static DeleteStatementBuilder.Start deleteFrom(String tableName) {
return deleteFrom(null, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.CreateUserStatement}.
*
* @param username a username to create
* @return a builder object
*/
public static CreateUserStatementBuilder.Start createUser(String username) {
return new CreateUserStatementBuilder.Start(username);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.AlterUserStatement}.
*
* @param username a username to alter
* @return a builder object
*/
public static AlterUserStatementBuilder.Start alterUser(String username) {
return new AlterUserStatementBuilder.Start(username);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.DropUserStatement}.
*
* @param username a username to drop
* @return a builder object
*/
public static DropUserStatementBuilder.Start dropUser(String username) {
return new DropUserStatementBuilder.Start(username);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.GrantStatement}.
*
* @param privileges privileges to grant
* @return a builder object
*/
public static GrantStatementBuilder.Start grant(Privilege... privileges) {
return new GrantStatementBuilder.Start(privileges);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.RevokeStatement}.
*
* @param privileges privileges to revoke
* @return a builder object
*/
public static RevokeStatementBuilder.Start revoke(Privilege... privileges) {
return new RevokeStatementBuilder.Start(ImmutableList.copyOf(privileges));
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.BeginStatement}.
*
* @return a builder object
*/
public static BeginStatementBuilder.Start begin() {
return new BeginStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.StartTransactionStatement}.
*
* @return a builder object
*/
public static StartTransactionStatementBuilder.Start startTransaction() {
return new StartTransactionStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.JoinStatement}.
*
* @param transactionId a transaction ID to join
* @return a builder object
*/
public static JoinStatementBuilder.Start join(String transactionId) {
return new JoinStatementBuilder.Start(transactionId);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.SuspendStatement}.
*
* @return a builder object
*/
public static SuspendStatementBuilder.Start suspend() {
return new SuspendStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.ResumeStatement}.
*
* @param transactionId a transaction ID to resume
* @return a builder object
*/
public static ResumeStatementBuilder.Start resume(String transactionId) {
return new ResumeStatementBuilder.Start(transactionId);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.PrepareStatement}.
*
* @return a builder object
*/
public static PrepareStatementBuilder.Start prepare() {
return new PrepareStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.ValidateStatement}.
*
* @return a builder object
*/
public static ValidateStatementBuilder.Start validate() {
return new ValidateStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.CommitStatement}.
*
* @return a builder object
*/
public static CommitStatementBuilder.Start commit() {
return new CommitStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.RollbackStatement}.
*
* @return a builder object
*/
public static RollbackStatementBuilder.Start rollback() {
return new RollbackStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.AbortStatement}.
*
* @return a builder object
*/
public static AbortStatementBuilder.Start abort() {
return new AbortStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.UseStatement}.
*
* @param namespaceName the name of the target namespace
* @return a builder object
*/
public static UseStatementBuilder.Start use(String namespaceName) {
return new UseStatementBuilder.Start(namespaceName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.SetModeStatement}.
*
* @param transactionMode a transaction mode to set
* @return a builder object
*/
public static SetModeStatementBuilder.Start setMode(TransactionMode transactionMode) {
return new SetModeStatementBuilder.Start(transactionMode);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.ShowNamespacesStatement}.
*
* @return a builder object
*/
public static ShowNamespacesStatementBuilder.Start showNamespaces() {
return new ShowNamespacesStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.ShowTablesStatement}.
*
* @return a builder object
*/
public static ShowTablesStatementBuilder.Start showTables() {
return new ShowTablesStatementBuilder.Start();
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.DescribeStatement}.
*
* @param namespaceName the namespace name of the target table
* @param tableName the table name of the target table
* @return a builder object
*/
public static DescribeStatementBuilder.Start describe(
@Nullable String namespaceName, String tableName) {
return new DescribeStatementBuilder.Start(namespaceName, tableName);
}
/**
* Returns a builder object for {@link com.scalar.db.sql.statement.DescribeStatement}.
*
* @param tableName the table name of the target table
* @return a builder object
*/
public static DescribeStatementBuilder.Start describe(String tableName) {
return new DescribeStatementBuilder.Start(null, tableName);
}
}