com.scalar.db.api.DeleteBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of scalardb Show documentation
Show all versions of scalardb Show documentation
A universal transaction manager that achieves database-agnostic transactions and distributed transactions that span multiple databases
package com.scalar.db.api;
import static com.google.common.base.Preconditions.checkNotNull;
import com.scalar.db.api.OperationBuilder.ClearClusteringKey;
import com.scalar.db.api.OperationBuilder.ClearCondition;
import com.scalar.db.api.OperationBuilder.ClearNamespace;
import com.scalar.db.api.OperationBuilder.ClusteringKey;
import com.scalar.db.api.OperationBuilder.Condition;
import com.scalar.db.api.OperationBuilder.Consistency;
import com.scalar.db.api.OperationBuilder.PartitionKeyBuilder;
import com.scalar.db.api.OperationBuilder.TableBuilder;
import com.scalar.db.io.Key;
import javax.annotation.Nullable;
public class DeleteBuilder {
public static class Namespace
implements OperationBuilder.Namespace, OperationBuilder.Table {
Namespace() {}
@Override
public Table namespace(String namespaceName) {
checkNotNull(namespaceName);
return new Table(namespaceName);
}
@Override
public PartitionKey table(String tableName) {
checkNotNull(tableName);
return new PartitionKey(null, tableName);
}
}
public static class Table extends TableBuilder {
private Table(String namespaceName) {
super(namespaceName);
}
@Override
public PartitionKey table(String tableName) {
checkNotNull(tableName);
return new PartitionKey(namespace, tableName);
}
}
public static class PartitionKey extends PartitionKeyBuilder {
private PartitionKey(@Nullable String namespace, String table) {
super(namespace, table);
}
@Override
public Buildable partitionKey(Key partitionKey) {
checkNotNull(partitionKey);
return new Buildable(namespaceName, tableName, partitionKey);
}
}
public static class Buildable extends OperationBuilder.Buildable
implements ClusteringKey, Consistency, Condition {
@Nullable Key clusteringKey;
@Nullable com.scalar.db.api.Consistency consistency;
@Nullable MutationCondition condition;
private Buildable(@Nullable String namespace, String table, Key partitionKey) {
super(namespace, table, partitionKey);
}
@Override
public Buildable clusteringKey(Key clusteringKey) {
checkNotNull(clusteringKey);
this.clusteringKey = clusteringKey;
return this;
}
@Override
public Buildable condition(MutationCondition condition) {
checkNotNull(condition);
this.condition = condition;
return this;
}
@Override
public Buildable consistency(com.scalar.db.api.Consistency consistency) {
checkNotNull(consistency);
this.consistency = consistency;
return this;
}
@Override
public Delete build() {
Delete delete = new Delete(partitionKey, clusteringKey);
delete.forNamespace(namespaceName).forTable(tableName);
if (condition != null) {
delete.withCondition(condition);
}
if (consistency != null) {
delete.withConsistency(consistency);
}
return delete;
}
}
public static class BuildableFromExisting extends Buildable
implements OperationBuilder.Namespace,
OperationBuilder.Table,
OperationBuilder.PartitionKey,
ClearCondition,
ClearClusteringKey,
ClearNamespace {
BuildableFromExisting(Delete delete) {
super(
delete.forNamespace().orElse(null),
delete.forTable().orElse(null),
delete.getPartitionKey());
this.clusteringKey = delete.getClusteringKey().orElse(null);
this.consistency = delete.getConsistency();
this.condition = delete.getCondition().orElse(null);
}
@Override
public BuildableFromExisting namespace(String namespaceName) {
checkNotNull(namespaceName);
this.namespaceName = namespaceName;
return this;
}
@Override
public BuildableFromExisting table(String tableName) {
checkNotNull(tableName);
this.tableName = tableName;
return this;
}
@Override
public BuildableFromExisting partitionKey(Key partitionKey) {
checkNotNull(partitionKey);
this.partitionKey = partitionKey;
return this;
}
@Override
public BuildableFromExisting clusteringKey(Key clusteringKey) {
super.clusteringKey(clusteringKey);
return this;
}
@Override
public BuildableFromExisting consistency(com.scalar.db.api.Consistency consistency) {
super.consistency(consistency);
return this;
}
@Override
public BuildableFromExisting condition(MutationCondition condition) {
super.condition(condition);
return this;
}
@Override
public BuildableFromExisting clearCondition() {
this.condition = null;
return this;
}
@Override
public BuildableFromExisting clearClusteringKey() {
this.clusteringKey = null;
return this;
}
@Override
public BuildableFromExisting clearNamespace() {
this.namespaceName = null;
return this;
}
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy