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