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(); } }); }
default CompletableFuture<V> get(K key) { RangeOption<K> option = opFactory().optionFactory().newRangeOption().build(); return get(key, option) .thenApply(result -> { try { if (result.count() == 0) { return null; } else { return retain(result.kvs().get(0).value()); } } finally { result.close(); } }) .whenComplete((value, cause) -> option.close()); }
default CompletableFuture<V> get(K pKey, K lKey) { RangeOption<K> option = opFactory().optionFactory().newRangeOption().build(); return get(pKey, lKey, option) .thenApply(result -> { try { if (result.count() == 0) { return null; } else { return retain(result.kvs().get(0).value()); } } finally { result.close(); } }) .whenComplete((value, cause) -> option.close()); }
default CompletableFuture<Long> getNumber(K pKey, K lKey) { RangeOption<K> option = opFactory().optionFactory().newRangeOption().build(); return get(pKey, lKey, option) .thenCompose(result -> { try { if (result.count() == 0) { return FutureUtils.value(null); } else { KeyValue<K, V> kv = result.kvs().get(0); if (kv.isNumber()) { return FutureUtils.value(kv.numberValue()); } else { return FutureUtils.exception(new KvApiException( Code.ILLEGAL_OP, "Key (" + pKey + ", " + lKey + ") doesn't have any number value")); } } } finally { result.close(); } }) .whenComplete((value, cause) -> option.close()); }
default CompletableFuture<Long> getNumber(K key) { RangeOption<K> option = opFactory().optionFactory().newRangeOption().build(); return get(key, option) .thenCompose(result -> { try { if (result.count() == 0) { return FutureUtils.value(null); } else { KeyValue<K, V> kv = result.kvs().get(0); if (kv.isNumber()) { return FutureUtils.value(kv.numberValue()); } else { return FutureUtils.exception(new KvApiException( Code.ILLEGAL_OP, "Key (" + key + ") doesn't have any number value")); } } } finally { result.close(); } }) .whenComplete((value, cause) -> option.close()); }
Long getNumber(K key) { try (RangeOp<K, V> op = opFactory.newRange( key, opFactory.optionFactory().newRangeOption() .limit(1) .build())) { try (RangeResult<K, V> result = range(op)) { if (Code.OK != result.code()) { throw new MVCCStoreException(result.code(), "Failed to retrieve key from store " + name + " : code = " + result.code()); } if (result.count() <= 0) { return null; } else { return result.kvs().get(0).numberValue(); } } } }
@Override public synchronized V get(K key) { try (RangeOp<K, V> op = opFactory.newRange( key, opFactory.optionFactory().newRangeOption() .limit(1) .build())) { try (RangeResult<K, V> result = range(op)) { if (Code.OK != result.code()) { throw new MVCCStoreException(result.code(), "Failed to retrieve key from store " + name + " : code = " + result.code()); } if (result.count() <= 0) { return null; } else { return retain(result.kvs().get(0).value()); } } } }