Search in sources :

Example 91 with Delete

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

Example 92 with Delete

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;
}
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)

Example 93 with Delete

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

Example 94 with Delete

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);
}
Also used : Delete(com.scalar.db.api.Delete) DeleteQuery(com.scalar.db.storage.jdbc.query.DeleteQuery)

Example 95 with Delete

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);
}
Also used : Delete(com.scalar.db.api.Delete) DeleteQuery(com.scalar.db.storage.jdbc.query.DeleteQuery)

Aggregations

Delete (com.scalar.db.api.Delete)174 Key (com.scalar.db.io.Key)112 Test (org.junit.jupiter.api.Test)111 Put (com.scalar.db.api.Put)59 Get (com.scalar.db.api.Get)29 Result (com.scalar.db.api.Result)29 Test (org.junit.Test)25 DeleteIfExists (com.scalar.db.api.DeleteIfExists)24 ConditionalExpression (com.scalar.db.api.ConditionalExpression)16 DeleteIf (com.scalar.db.api.DeleteIf)15 Mutation (com.scalar.db.api.Mutation)14 MutationCondition (com.scalar.db.api.MutationCondition)11 Scan (com.scalar.db.api.Scan)11 PutIfNotExists (com.scalar.db.api.PutIfNotExists)10 TextValue (com.scalar.db.io.TextValue)10 ExecutionException (com.scalar.db.exception.storage.ExecutionException)8 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)6 GrpcTransaction (com.scalar.db.transaction.rpc.GrpcTransaction)6 DeleteItemRequest (software.amazon.awssdk.services.dynamodb.model.DeleteItemRequest)6 PartitionKey (com.azure.cosmos.models.PartitionKey)5