CavalliumDBEngine/src/main/java/it/cavallium/dbengine/database/LLDictionary.java

104 lines
3.5 KiB
Java
Raw Normal View History

2020-12-07 22:15:18 +01:00
package it.cavallium.dbengine.database;
import java.util.List;
2020-12-07 22:15:18 +01:00
import java.util.Map.Entry;
2021-02-06 19:21:31 +01:00
import java.util.Optional;
2021-01-30 00:24:55 +01:00
import java.util.function.Function;
2020-12-07 22:15:18 +01:00
import org.jetbrains.annotations.Nullable;
import org.warp.commonutils.concurrency.atomicity.NotAtomic;
2021-01-30 00:24:55 +01:00
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
2020-12-07 22:15:18 +01:00
2021-02-03 14:37:02 +01:00
@SuppressWarnings("unused")
2020-12-07 22:15:18 +01:00
@NotAtomic
public interface LLDictionary extends LLKeyValueDatabaseStructure {
2021-03-18 16:19:41 +01:00
Mono<byte[]> get(@Nullable LLSnapshot snapshot, byte[] key, boolean existsAlmostCertainly);
default Mono<byte[]> get(@Nullable LLSnapshot snapshot, byte[] key) {
return get(snapshot, key, false);
}
2020-12-07 22:15:18 +01:00
2021-01-30 00:24:55 +01:00
Mono<byte[]> put(byte[] key, byte[] value, LLDictionaryResultType resultType);
2020-12-07 22:15:18 +01:00
2021-03-18 16:19:41 +01:00
Mono<Boolean> update(byte[] key, Function<Optional<byte[]>, Optional<byte[]>> updater, boolean existsAlmostCertainly);
default Mono<Boolean> update(byte[] key, Function<Optional<byte[]>, Optional<byte[]>> updater) {
return update(key, updater, false);
}
2021-02-06 19:21:31 +01:00
2021-03-14 03:13:19 +01:00
Mono<Void> clear();
2021-01-30 00:24:55 +01:00
Mono<byte[]> remove(byte[] key, LLDictionaryResultType resultType);
2020-12-07 22:15:18 +01:00
2021-03-18 16:19:41 +01:00
Flux<Entry<byte[], byte[]>> getMulti(@Nullable LLSnapshot snapshot, Flux<byte[]> keys, boolean existsAlmostCertainly);
default Flux<Entry<byte[], byte[]>> getMulti(@Nullable LLSnapshot snapshot, Flux<byte[]> keys) {
return getMulti(snapshot, keys, false);
}
2020-12-07 22:15:18 +01:00
2021-01-30 00:24:55 +01:00
Flux<Entry<byte[], byte[]>> putMulti(Flux<Entry<byte[], byte[]>> entries, boolean getOldValues);
2020-12-07 22:15:18 +01:00
2021-03-18 16:19:41 +01:00
Flux<Entry<byte[], byte[]>> getRange(@Nullable LLSnapshot snapshot, LLRange range, boolean existsAlmostCertainly);
2020-12-07 22:15:18 +01:00
2021-03-18 16:19:41 +01:00
default Flux<Entry<byte[], byte[]>> getRange(@Nullable LLSnapshot snapshot, LLRange range) {
return getRange(snapshot, range, false);
}
Flux<List<Entry<byte[], byte[]>>> getRangeGrouped(@Nullable LLSnapshot snapshot,
LLRange range,
int prefixLength,
boolean existsAlmostCertainly);
default Flux<List<Entry<byte[], byte[]>>> getRangeGrouped(@Nullable LLSnapshot snapshot,
LLRange range,
int prefixLength) {
return getRangeGrouped(snapshot, range, prefixLength, false);
}
Flux<byte[]> getRangeKeys(@Nullable LLSnapshot snapshot, LLRange range);
Flux<List<byte[]>> getRangeKeysGrouped(@Nullable LLSnapshot snapshot, LLRange range, int prefixLength);
2021-03-14 13:24:46 +01:00
Flux<byte[]> getRangeKeyPrefixes(@Nullable LLSnapshot snapshot, LLRange range, int prefixLength);
2021-01-30 00:24:55 +01:00
Flux<Entry<byte[], byte[]>> setRange(LLRange range, Flux<Entry<byte[], byte[]>> entries, boolean getOldValues);
2020-12-07 22:15:18 +01:00
2021-03-18 16:19:41 +01:00
default Mono<Void> replaceRange(LLRange range,
boolean canKeysChange,
Function<Entry<byte[], byte[]>, Mono<Entry<byte[], byte[]>>> entriesReplacer,
boolean existsAlmostCertainly) {
return Mono.defer(() -> {
if (canKeysChange) {
return this
.setRange(range, this
2021-03-18 16:19:41 +01:00
.getRange(null, range, existsAlmostCertainly)
.flatMap(entriesReplacer), false)
.then();
} else {
return this
.putMulti(this
2021-03-18 16:19:41 +01:00
.getRange(null, range, existsAlmostCertainly)
.flatMap(entriesReplacer), false)
.then();
}
});
2021-01-30 00:24:55 +01:00
}
2020-12-07 22:15:18 +01:00
2021-03-18 16:19:41 +01:00
default Mono<Void> replaceRange(LLRange range,
boolean canKeysChange,
Function<Entry<byte[], byte[]>, Mono<Entry<byte[], byte[]>>> entriesReplacer) {
return replaceRange(range, canKeysChange, entriesReplacer, false);
}
2021-01-30 00:24:55 +01:00
Mono<Boolean> isRangeEmpty(@Nullable LLSnapshot snapshot, LLRange range);
2020-12-07 22:15:18 +01:00
2021-01-30 00:24:55 +01:00
Mono<Long> sizeRange(@Nullable LLSnapshot snapshot, LLRange range, boolean fast);
2020-12-07 22:15:18 +01:00
Mono<Entry<byte[], byte[]>> getOne(@Nullable LLSnapshot snapshot, LLRange range);
Mono<byte[]> getOneKey(@Nullable LLSnapshot snapshot, LLRange range);
2021-01-30 00:24:55 +01:00
Mono<Entry<byte[], byte[]>> removeOne(LLRange range);
2020-12-07 22:15:18 +01:00
}