public static IncrementOperation build( long storeId, Keyspace keyspace, ByteString key, long delta) { KeyValueAction.Builder b = KeyValueAction.newBuilder(); b.setAction(ActionType.INCREMENT); b.setStoreId(storeId); b.setKeyspaceId(keyspace.getKeyspaceId()); b.setKey(key); b.setValue(ByteString.copyFrom(Value.fromLong(delta).asBytes())); return new IncrementOperation(b.build()); }
@Override public Value doAction(Value oldValue) { long oldValueLong = 0; if (oldValue != null) { oldValueLong = oldValue.asLong(); } Value incrementBy = Value.fromRawBytes(entry.getValue()); long newValueLong = oldValueLong + incrementBy.asLong(); Value newValue = Value.fromLong(newValueLong); log.debug("Increment: {} -> {}", oldValueLong, newValueLong); // this.newValue = newValue.duplicate(); Builder eb = response.addEntryBuilder(); eb.setKey(entry.getKey()); eb.setValue(ByteString.copyFrom(newValue.asBytes())); return newValue; }