2021-01-31 00:36:21 +01:00
|
|
|
package it.cavallium.dbengine.database.collections;
|
|
|
|
|
|
|
|
import it.cavallium.dbengine.client.CompositeSnapshot;
|
|
|
|
import it.cavallium.dbengine.database.LLDictionary;
|
2021-02-02 19:40:37 +01:00
|
|
|
import it.cavallium.dbengine.database.serialization.Serializer;
|
2021-01-31 15:47:48 +01:00
|
|
|
import java.util.Arrays;
|
2021-01-31 00:36:21 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import reactor.core.publisher.Flux;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
2021-01-31 19:52:47 +01:00
|
|
|
public class SubStageGetterSingle<T> implements SubStageGetter<T, DatabaseStageEntry<T>> {
|
|
|
|
|
2021-02-01 12:19:17 +01:00
|
|
|
private final Serializer<T, byte[]> serializer;
|
2021-01-31 19:52:47 +01:00
|
|
|
|
2021-02-01 12:19:17 +01:00
|
|
|
public SubStageGetterSingle(Serializer<T, byte[]> serializer) {
|
2021-01-31 19:52:47 +01:00
|
|
|
this.serializer = serializer;
|
|
|
|
}
|
2021-01-31 00:36:21 +01:00
|
|
|
|
|
|
|
@Override
|
2021-01-31 19:52:47 +01:00
|
|
|
public Mono<DatabaseStageEntry<T>> subStage(LLDictionary dictionary,
|
2021-01-31 00:36:21 +01:00
|
|
|
@Nullable CompositeSnapshot snapshot,
|
|
|
|
byte[] keyPrefix,
|
|
|
|
Flux<byte[]> keyFlux) {
|
2021-02-02 00:09:46 +01:00
|
|
|
return keyFlux
|
|
|
|
.singleOrEmpty()
|
|
|
|
.flatMap(key -> Mono
|
|
|
|
.<DatabaseStageEntry<T>>fromCallable(() -> {
|
|
|
|
if (!Arrays.equals(keyPrefix, key)) {
|
|
|
|
throw new IndexOutOfBoundsException("Found more than one element!");
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.then(Mono.fromSupplier(() -> {
|
2021-02-03 14:37:02 +01:00
|
|
|
return new DatabaseSingle<>(dictionary,
|
2021-02-02 00:09:46 +01:00
|
|
|
keyPrefix,
|
|
|
|
serializer
|
|
|
|
);
|
|
|
|
}));
|
2021-01-31 19:52:47 +01:00
|
|
|
}
|
|
|
|
|
2021-02-02 15:36:11 +01:00
|
|
|
@Override
|
|
|
|
public boolean needsKeyFlux() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-31 00:36:21 +01:00
|
|
|
}
|