use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class DynamoMutation method getConditionBindMap.
@Nonnull
public Map<String, AttributeValue> getConditionBindMap() {
ValueBinder binder = new ValueBinder(CONDITION_VALUE_ALIAS);
Mutation mutation = (Mutation) getOperation();
mutation.getCondition().ifPresent(c -> c.getExpressions().forEach(e -> e.getColumn().accept(binder)));
return binder.build();
}
use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class DynamoMutation method getConditionColumnMap.
@Nonnull
public Map<String, String> getConditionColumnMap() {
Map<String, String> ret = new HashMap<>();
Mutation mutation = (Mutation) getOperation();
if (mutation.getCondition().isPresent()) {
int index = 0;
for (ConditionalExpression expression : mutation.getCondition().get().getExpressions()) {
ret.put(CONDITION_COLUMN_NAME_ALIAS + index, expression.getName());
index++;
}
}
return ret;
}
use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class MultiStorage 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);
getStorage(mutations.get(0)).mutate(mutations);
}
use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class GrpcStorageTest method mutate_StubThrowFailedPreconditionError_ShouldThrowNoMutationException.
@Test
public void mutate_StubThrowFailedPreconditionError_ShouldThrowNoMutationException() {
// Arrange
Key partitionKey = new Key("col1", 1);
List<Mutation> mutations = Arrays.asList(new Put(partitionKey), new Delete(partitionKey));
when(blockingStub.mutate(any())).thenThrow(Status.FAILED_PRECONDITION.asRuntimeException());
// Act
assertThatThrownBy(() -> storage.mutate(mutations)).isInstanceOf(NoMutationException.class);
}
use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.
the class Cassandra 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);
}
batch.handle(mutations);
}
Aggregations