Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
com.scalar.db.sql.statement.builder.DeleteStatementBuilder Maven / Gradle / Ivy
package com.scalar.db.sql.statement.builder;
import com.google.common.collect.ImmutableList;
import com.scalar.db.sql.AndPredicateList;
import com.scalar.db.sql.OrPredicateList;
import com.scalar.db.sql.Predicate;
import com.scalar.db.sql.TableRef;
import com.scalar.db.sql.statement.DeleteStatement;
import java.util.List;
import javax.annotation.Nullable;
public final class DeleteStatementBuilder {
private DeleteStatementBuilder() {}
public static class Start extends AsOrDeleteWhereStart {
Start(@Nullable String namespaceName, String tableName) {
super(namespaceName, tableName);
}
}
public static class AsOrDeleteWhereStart extends DeleteWhereStart {
private AsOrDeleteWhereStart(@Nullable String namespaceName, String tableName) {
super(namespaceName, tableName, null);
}
/**
* Specifies the alias of the target table.
*
* @param alias the alias of the target table
* @return a builder object
*/
public DeleteWhereStart as(String alias) {
return new DeleteWhereStart(namespaceName, tableName, alias);
}
}
public static class DeleteWhereStart extends Buildable
implements WhereStart {
private DeleteWhereStart(
@Nullable String namespaceName, String tableName, @Nullable String alias) {
super(
namespaceName, tableName, alias, null, ImmutableList.builder(), ImmutableList.builder());
}
@Override
public DeleteOngoingWhere where(Predicate predicate) {
return new DeleteOngoingWhere(
namespaceName,
tableName,
alias,
predicate,
andPredicateListsBuilder,
orPredicateListsBuilder);
}
@Override
public DeleteOngoingWhereOr where(List predicates) {
return where(AndPredicateList.predicates(ImmutableList.copyOf(predicates)).build());
}
@Override
public DeleteOngoingWhereOr where(AndPredicateList andPredicateList) {
return new DeleteOngoingWhereOr(
namespaceName,
tableName,
alias,
andPredicateListsBuilder.add(andPredicateList),
orPredicateListsBuilder);
}
@Override
public DeleteOngoingWhereAnd where(OrPredicateList orPredicateList) {
return new DeleteOngoingWhereAnd(
namespaceName,
tableName,
alias,
andPredicateListsBuilder,
orPredicateListsBuilder.add(orPredicateList));
}
@Override
public DeleteOngoingWhereOr whereOr(List andPredicateLists) {
return new DeleteOngoingWhereOr(
namespaceName,
tableName,
alias,
andPredicateListsBuilder.addAll(andPredicateLists),
orPredicateListsBuilder);
}
@Override
public DeleteOngoingWhereAnd whereAnd(List orPredicateLists) {
return new DeleteOngoingWhereAnd(
namespaceName,
tableName,
alias,
andPredicateListsBuilder,
orPredicateListsBuilder.addAll(orPredicateLists));
}
}
public static class DeleteOngoingWhere extends Buildable
implements OngoingWhere {
private DeleteOngoingWhere(
@Nullable String namespaceName,
String tableName,
@Nullable String alias,
@Nullable Predicate predicate,
ImmutableList.Builder andPredicateListsBuilder,
ImmutableList.Builder orPredicateListsBuilder) {
super(
namespaceName,
tableName,
alias,
predicate,
andPredicateListsBuilder,
orPredicateListsBuilder);
}
@Override
public DeleteOngoingWhereAnd and(Predicate predicate) {
return new DeleteOngoingWhereAnd(
namespaceName,
tableName,
alias,
andPredicateListsBuilder,
orPredicateListsBuilder
.add(OrPredicateList.predicate(this.predicate).build())
.add(OrPredicateList.predicate(predicate).build()));
}
@Override
public DeleteOngoingWhereAnd and(OrPredicateList orPredicateList) {
return new DeleteOngoingWhereAnd(
namespaceName,
tableName,
alias,
andPredicateListsBuilder,
orPredicateListsBuilder
.add(OrPredicateList.predicate(this.predicate).build())
.add(orPredicateList));
}
@Override
public DeleteOngoingWhereOr or(Predicate predicate) {
return new DeleteOngoingWhereOr(
namespaceName,
tableName,
alias,
andPredicateListsBuilder
.add(AndPredicateList.predicate(this.predicate).build())
.add(AndPredicateList.predicate(predicate).build()),
orPredicateListsBuilder);
}
@Override
public DeleteOngoingWhereOr or(AndPredicateList andPredicateList) {
return new DeleteOngoingWhereOr(
namespaceName,
tableName,
alias,
andPredicateListsBuilder
.add(AndPredicateList.predicate(this.predicate).build())
.add(andPredicateList),
orPredicateListsBuilder);
}
}
public static class DeleteOngoingWhereAnd extends Buildable
implements OngoingWhereAnd {
private DeleteOngoingWhereAnd(
@Nullable String namespaceName,
String tableName,
@Nullable String alias,
ImmutableList.Builder andPredicateListsBuilder,
ImmutableList.Builder orPredicateListsBuilder) {
super(
namespaceName, tableName, alias, null, andPredicateListsBuilder, orPredicateListsBuilder);
}
@Override
public DeleteOngoingWhereAnd and(Predicate predicate) {
orPredicateListsBuilder.add(OrPredicateList.predicate(predicate).build());
return this;
}
@Override
public DeleteOngoingWhereAnd and(OrPredicateList orPredicateList) {
orPredicateListsBuilder.add(orPredicateList);
return this;
}
}
public static class DeleteOngoingWhereOr extends Buildable
implements OngoingWhereOr {
private DeleteOngoingWhereOr(
@Nullable String namespaceName,
String tableName,
@Nullable String alias,
ImmutableList.Builder andPredicateListsBuilder,
ImmutableList.Builder orPredicateListsBuilder) {
super(
namespaceName, tableName, alias, null, andPredicateListsBuilder, orPredicateListsBuilder);
}
@Override
public DeleteOngoingWhereOr or(Predicate predicate) {
andPredicateListsBuilder.add(AndPredicateList.predicate(predicate).build());
return this;
}
@Override
public DeleteOngoingWhereOr or(AndPredicateList andPredicateList) {
andPredicateListsBuilder.add(andPredicateList);
return this;
}
}
public static class Buildable {
@Nullable protected final String namespaceName;
protected final String tableName;
@Nullable protected final String alias;
@Nullable protected final Predicate predicate;
protected final ImmutableList.Builder andPredicateListsBuilder;
protected final ImmutableList.Builder orPredicateListsBuilder;
private Buildable(
@Nullable String namespaceName,
String tableName,
@Nullable String alias,
@Nullable Predicate predicate,
ImmutableList.Builder andPredicateListsBuilder,
ImmutableList.Builder orPredicateListsBuilder) {
this.namespaceName = namespaceName;
this.tableName = tableName;
this.alias = alias;
this.predicate = predicate;
this.andPredicateListsBuilder = andPredicateListsBuilder;
this.orPredicateListsBuilder = orPredicateListsBuilder;
}
/**
* Builds a DeleteStatement object.
*
* @return a DeleteStatement object
*/
public DeleteStatement build() {
return DeleteStatement.create(
TableRef.of(namespaceName, tableName),
alias,
StatementBuilderUtils.buildAndPredicateLists(predicate, andPredicateListsBuilder),
StatementBuilderUtils.buildOrPredicateLists(orPredicateListsBuilder));
}
}
}