Search in sources :

Example 21 with Mutation

use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.

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

Example 22 with Mutation

use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.

the class CosmosMutation method makeRecord.

@Nonnull
public Record makeRecord() {
    Mutation mutation = (Mutation) getOperation();
    Record record = new Record();
    if (mutation instanceof Delete) {
        return record;
    }
    Put put = (Put) mutation;
    record.setId(getId());
    record.setConcatenatedPartitionKey(getConcatenatedPartitionKey());
    record.setPartitionKey(toMap(put.getPartitionKey().getColumns()));
    put.getClusteringKey().ifPresent(k -> record.setClusteringKey(toMap(k.getColumns())));
    record.setValues(toMapForPut(put));
    return record;
}
Also used : Delete(com.scalar.db.api.Delete) Mutation(com.scalar.db.api.Mutation) Put(com.scalar.db.api.Put) Nonnull(javax.annotation.Nonnull)

Example 23 with Mutation

use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.

the class PutStatementHandler method execute.

@Override
protected List<Record> execute(Operation operation) throws CosmosException, ExecutionException {
    Mutation mutation = (Mutation) operation;
    TableMetadata tableMetadata = metadataManager.getTableMetadata(mutation);
    executeStoredProcedure(mutation, tableMetadata);
    return Collections.emptyList();
}
Also used : TableMetadata(com.scalar.db.api.TableMetadata) Mutation(com.scalar.db.api.Mutation)

Example 24 with Mutation

use of com.scalar.db.api.Mutation in project scalardb by scalar-labs.

the class ProtoUtils method toMutation.

public static Mutation toMutation(com.scalar.db.rpc.Mutation mutation) {
    Key partitionKey = toKey(mutation.getPartitionKey());
    Key clusteringKey;
    if (mutation.hasClusteringKey()) {
        clusteringKey = toKey(mutation.getClusteringKey());
    } 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 -> {
            Value<?> value = toValue(v);
            if (value == null) {
                put.withNullValue(v.getName());
            } else {
                put.withValue(value);
            }
        });
        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()));
    }
    return ret;
}
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)

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