default CompletableFuture<KeyValue<K, V>> getKv(K pKey, K lKey) { return get(pKey, lKey, Options.get()) .thenApply(result -> { try { if (result.count() == 0) { return null; } else { return result.getKvsAndClear().get(0); } } finally { result.close(); } }); }
default CompletableFuture<KeyValue<K, V>> getKv(K key) { return get(key, Options.get()) .thenApply(result -> { try { if (result.count() == 0) { return null; } else { return result.getKvsAndClear().get(0); } } finally { result.close(); } }); }
@Override default CompletableFuture<KeyValue<K, V>> getKeyValue(K key) { RangeOp<K, V> op = newGet(key); return range(op).thenCompose(result -> { try { if (Code.OK == result.code()) { if (result.kvs().isEmpty()) { return FutureUtils.value(null); } List<KeyValue<K, V>> records = result.getKvsAndClear(); KeyValue<K, V> record = records.get(0); return FutureUtils.value(record); } else { return failWithCode(result.code(), "Failed to retrieve key " + key + " from store " + name()); } } finally { result.close(); } }); }
@Override default CompletableFuture<List<KeyValue<K, V>>> range(K key, K endKey) { RangeOp<K, V> op = newRange(key, endKey); return range(op).thenCompose(result -> { try { if (Code.OK == result.code()) { return FutureUtils.value(result.getKvsAndClear()); } else { return failWithCode(result.code(), "Failed to retrieve range [" + key + ", " + endKey + "] from store " + name()); } } finally { result.close(); } }); }
default CompletableFuture<List<KeyValue<K, V>>> range(K pKey, K lStartKey, K lEndKey) { RangeOption<K> option = opFactory().optionFactory().newRangeOption() .countOnly(false) .keysOnly(false) .limit(Long.MAX_VALUE) .endKey(lEndKey) .build(); return get(pKey, lStartKey, option) .thenApply(result -> { try { return result.getKvsAndClear(); } finally { result.close(); } }) .whenComplete((value, cause) -> option.close()); }