use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class JdbcService method mutate.
public boolean mutate(List<? extends Mutation> mutations, Connection connection) throws SQLException, ExecutionException {
checkArgument(mutations.size() != 0);
operationChecker.check(mutations);
for (Mutation mutation : mutations) {
if (mutation instanceof Put) {
if (!put((Put) mutation, connection)) {
return false;
}
} else {
if (!delete((Delete) mutation, connection)) {
return false;
}
}
}
return true;
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class ProtoUtils method toMutation.
public static Mutation toMutation(com.scalar.db.rpc.Mutation mutation, TableMetadata metadata) {
Key partitionKey = toKey(mutation.getPartitionKey(), metadata);
Key clusteringKey;
if (mutation.hasClusteringKey()) {
clusteringKey = toKey(mutation.getClusteringKey(), metadata);
} else {
clusteringKey = null;
}
Mutation ret;
if (mutation.getType() == com.scalar.db.rpc.Mutation.Type.PUT) {
Put put = new Put(partitionKey, clusteringKey);
mutation.getValueList().forEach(v -> put.withValue(toColumn(v.getName(), v, metadata)));
ret = put;
} else {
ret = new Delete(partitionKey, clusteringKey);
}
if (!mutation.getNamespace().isEmpty()) {
ret.forNamespace(mutation.getNamespace());
}
if (!mutation.getTable().isEmpty()) {
ret.forTable(mutation.getTable());
}
ret.withConsistency(toConsistency(mutation.getConsistency()));
if (mutation.hasCondition()) {
ret.withCondition(toCondition(mutation.getCondition(), metadata));
}
return ret;
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class Dynamo method mutate.
@Override
public void mutate(List<? extends Mutation> mutations) throws ExecutionException {
checkArgument(mutations.size() != 0);
if (mutations.size() == 1) {
Mutation mutation = mutations.get(0);
if (mutation instanceof Put) {
put((Put) mutation);
} else if (mutation instanceof Delete) {
delete((Delete) mutation);
}
return;
}
mutations = copyAndSetTargetToIfNot(mutations);
operationChecker.check(mutations);
for (Mutation mutation : mutations) {
operationChecker.check(mutation);
}
batchHandler.handle(mutations);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class ConditionalMutator method visit.
@Override
public void visit(DeleteIf condition) {
Delete delete = (Delete) mutation;
DeleteQuery deleteQuery = queryBuilder.deleteFrom(delete.forNamespace().get(), delete.forTable().get(), tableMetadata).where(delete.getPartitionKey(), delete.getClusteringKey(), condition.getExpressions()).build();
executeMutate(deleteQuery);
}
use of com.scalar.db.api.Delete in project scalardb by scalar-labs.
the class ConditionalMutator method visit.
@Override
public void visit(DeleteIfExists condition) {
Delete delete = (Delete) mutation;
DeleteQuery deleteQuery = queryBuilder.deleteFrom(delete.forNamespace().get(), delete.forTable().get(), tableMetadata).where(delete.getPartitionKey(), delete.getClusteringKey()).build();
executeMutate(deleteQuery);
}
Aggregations