Search in sources :

Example 1 with CompareResult

use of org.apache.bookkeeper.api.kv.op.CompareResult in project bookkeeper by apache.

the class TableStoreUtils method fromProtoCompare.

static CompareOp<byte[], byte[]> fromProtoCompare(OpFactory<byte[], byte[]> opFactory, RoutingHeader header, Compare compare) {
    ByteString rKey = header.getRKey();
    ByteString lKey = compare.getKey();
    byte[] storeKey = newStoreKey(rKey, lKey);
    CompareResult result = fromProtoCompareResult(compare.getResult());
    switch(compare.getTarget()) {
        case MOD:
            return opFactory.compareModRevision(result, storeKey, compare.getModRevision());
        case CREATE:
            return opFactory.compareCreateRevision(result, storeKey, compare.getCreateRevision());
        case VERSION:
            return opFactory.compareVersion(result, storeKey, compare.getVersion());
        case VALUE:
            return opFactory.compareValue(result, storeKey, (null == compare.getValue() || compare.getValue().size() == 0) ? null : compare.getValue().toByteArray());
        default:
            throw new IllegalArgumentException("Invalid compare target " + compare.getTarget());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) CompareResult(org.apache.bookkeeper.api.kv.op.CompareResult)

Aggregations

ByteString (com.google.protobuf.ByteString)1 CompareResult (org.apache.bookkeeper.api.kv.op.CompareResult)1