Search in sources :

Example 16 with Mutation

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();
}
Also used : List(java.util.List) Value(com.scalar.db.io.Value) Map(java.util.Map) AttributeValue(software.amazon.awssdk.services.dynamodb.model.AttributeValue) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Mutation(com.scalar.db.api.Mutation) HashMap(java.util.HashMap) Put(com.scalar.db.api.Put) TableMetadata(com.scalar.db.api.TableMetadata) Nonnull(javax.annotation.Nonnull) Immutable(javax.annotation.concurrent.Immutable) ArrayList(java.util.ArrayList) Mutation(com.scalar.db.api.Mutation) Nonnull(javax.annotation.Nonnull)

Example 17 with Mutation

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;
}
Also used : HashMap(java.util.HashMap) ConditionalExpression(com.scalar.db.api.ConditionalExpression) Mutation(com.scalar.db.api.Mutation) Nonnull(javax.annotation.Nonnull)

Example 18 with Mutation

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);
}
Also used : Delete(com.scalar.db.api.Delete) Mutation(com.scalar.db.api.Mutation) Put(com.scalar.db.api.Put)

Example 19 with Mutation

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);
}
Also used : Delete(com.scalar.db.api.Delete) Mutation(com.scalar.db.api.Mutation) Key(com.scalar.db.io.Key) Put(com.scalar.db.api.Put) Test(org.junit.jupiter.api.Test)

Example 20 with Mutation

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);
}
Also used : Delete(com.scalar.db.api.Delete) Mutation(com.scalar.db.api.Mutation) Put(com.scalar.db.api.Put)

Aggregations

Mutation (com.scalar.db.api.Mutation)24 Put (com.scalar.db.api.Put)16 Delete (com.scalar.db.api.Delete)14 Key (com.scalar.db.io.Key)7 Nonnull (javax.annotation.Nonnull)7 Test (org.junit.jupiter.api.Test)5 TableMetadata (com.scalar.db.api.TableMetadata)4 ConditionalExpression (com.scalar.db.api.ConditionalExpression)2 ExecutionException (com.scalar.db.exception.storage.ExecutionException)2 NoMutationException (com.scalar.db.exception.storage.NoMutationException)2 RetriableExecutionException (com.scalar.db.exception.storage.RetriableExecutionException)2 HashMap (java.util.HashMap)2 BatchStatement (com.datastax.driver.core.BatchStatement)1 ResultSet (com.datastax.driver.core.ResultSet)1 WriteTimeoutException (com.datastax.driver.core.exceptions.WriteTimeoutException)1 MutationCondition (com.scalar.db.api.MutationCondition)1 PutIf (com.scalar.db.api.PutIf)1 PutIfExists (com.scalar.db.api.PutIfExists)1 PutIfNotExists (com.scalar.db.api.PutIfNotExists)1 Value (com.scalar.db.io.Value)1