Update pom.xml, DatabaseMapDictionary.java, and 6 more files...
This commit is contained in:
parent
38e27bd6c1
commit
9918ef3258
5
pom.xml
5
pom.xml
@ -31,6 +31,11 @@
|
||||
<artifactId>common-utils</artifactId>
|
||||
<version>1.1.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.netty</groupId>
|
||||
<artifactId>netty-buffer</artifactId>
|
||||
<version>4.1.58.Final</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
|
@ -13,11 +13,12 @@ import reactor.core.publisher.GroupedFlux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
// todo: implement optimized methods
|
||||
public class DatabaseMapDictionaryParent<U, US extends DatabaseStage<U>> implements DatabaseStageMap<byte[], U, US> {
|
||||
public class DatabaseMapDictionary<T, U, US extends DatabaseStage<U>> implements DatabaseStageMap<T, U, US> {
|
||||
|
||||
public static final byte[] EMPTY_BYTES = new byte[0];
|
||||
private final LLDictionary dictionary;
|
||||
private final SubStageGetter<U, US> subStageGetter;
|
||||
private final FixedLengthSerializer<T> suffixKeySerializer;
|
||||
private final byte[] keyPrefix;
|
||||
private final int keySuffixLength;
|
||||
private final int keyExtLength;
|
||||
@ -65,13 +66,14 @@ public class DatabaseMapDictionaryParent<U, US extends DatabaseStage<U>> impleme
|
||||
}
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public DatabaseMapDictionaryParent(LLDictionary dictionary, SubStageGetter<U, US> subStageGetter, int keyLength, int keyExtLength) {
|
||||
this(dictionary, subStageGetter, EMPTY_BYTES, keyLength, keyExtLength);
|
||||
public DatabaseMapDictionary(LLDictionary dictionary, SubStageGetter<U, US> subStageGetter, FixedLengthSerializer<T> keySerializer, int keyLength, int keyExtLength) {
|
||||
this(dictionary, subStageGetter, keySerializer, EMPTY_BYTES, keyLength, keyExtLength);
|
||||
}
|
||||
|
||||
public DatabaseMapDictionaryParent(LLDictionary dictionary, SubStageGetter<U, US> subStageGetter, byte[] prefixKey, int keySuffixLength, int keyExtLength) {
|
||||
public DatabaseMapDictionary(LLDictionary dictionary, SubStageGetter<U, US> subStageGetter, FixedLengthSerializer<T> suffixKeySerializer, byte[] prefixKey, int keySuffixLength, int keyExtLength) {
|
||||
this.dictionary = dictionary;
|
||||
this.subStageGetter = subStageGetter;
|
||||
this.suffixKeySerializer = suffixKeySerializer;
|
||||
this.keyPrefix = prefixKey;
|
||||
this.keySuffixLength = keySuffixLength;
|
||||
this.keyExtLength = keyExtLength;
|
||||
@ -152,23 +154,32 @@ public class DatabaseMapDictionaryParent<U, US extends DatabaseStage<U>> impleme
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<US> at(@Nullable CompositeSnapshot snapshot, byte[] keySuffix) {
|
||||
public Mono<US> at(@Nullable CompositeSnapshot snapshot, T keySuffix) {
|
||||
byte[] keySuffixData = serializeSuffix(keySuffix);
|
||||
Flux<byte[]> rangeKeys = this
|
||||
.dictionary.getRangeKeys(resolveSnapshot(snapshot), toExtRange(keySuffix)
|
||||
.dictionary.getRangeKeys(resolveSnapshot(snapshot), toExtRange(keySuffixData)
|
||||
);
|
||||
return this.subStageGetter
|
||||
.subStage(dictionary, snapshot, toKeyWithoutExt(keySuffix), rangeKeys);
|
||||
.subStage(dictionary, snapshot, toKeyWithoutExt(keySuffixData), rangeKeys);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Flux<Entry<byte[], US>> getAllStages(@Nullable CompositeSnapshot snapshot) {
|
||||
public Flux<Entry<T, US>> getAllStages(@Nullable CompositeSnapshot snapshot) {
|
||||
Flux<GroupedFlux<byte[], byte[]>> groupedFlux = dictionary
|
||||
.getRangeKeys(resolveSnapshot(snapshot), range)
|
||||
.groupBy(this::removeExtFromFullKey);
|
||||
return groupedFlux
|
||||
.flatMap(rangeKeys -> this.subStageGetter
|
||||
.subStage(dictionary, snapshot, rangeKeys.key(), rangeKeys)
|
||||
.map(us -> Map.entry(rangeKeys.key(), us))
|
||||
.map(us -> Map.entry(this.deserializeSuffix(this.stripPrefix(rangeKeys.key())), us))
|
||||
);
|
||||
}
|
||||
|
||||
private T deserializeSuffix(byte[] suffix) {
|
||||
return (T) new Object();
|
||||
}
|
||||
|
||||
private byte[] serializeSuffix(T keySuffix) {
|
||||
return new byte[0];
|
||||
}
|
||||
}
|
@ -13,7 +13,7 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @deprecated Use DatabaseMapDictionaryParent with SubStageGetterSingle
|
||||
* @deprecated Use DatabaseMapDictionary with SubStageGetterSingle
|
||||
*/
|
||||
@Deprecated
|
||||
public class DatabaseMapDictionaryRange implements DatabaseStageMap<byte[], byte[], DatabaseStageEntry<byte[]>> {
|
||||
|
@ -0,0 +1,24 @@
|
||||
package it.cavallium.dbengine.database.collections;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
public interface FixedLengthSerializer<B> {
|
||||
|
||||
B deserialize(ByteBuf serialized, int length);
|
||||
|
||||
void serialize(B deserialized, ByteBuf output, int length);
|
||||
|
||||
static FixedLengthSerializer<ByteBuf> noop() {
|
||||
return new FixedLengthSerializer<>() {
|
||||
@Override
|
||||
public ByteBuf deserialize(ByteBuf serialized, int length) {
|
||||
return serialized.readSlice(length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(ByteBuf deserialized, ByteBuf output, int length) {
|
||||
output.writeBytes(deserialized, length);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
package it.cavallium.dbengine.database.collections;
|
||||
|
||||
import it.cavallium.dbengine.database.LLDictionary;
|
||||
|
||||
public class MapBuilder {
|
||||
|
||||
private final LLDictionary dictionary;
|
||||
|
||||
public MapBuilder(LLDictionary dictionary) {
|
||||
this.dictionary = dictionary;
|
||||
}
|
||||
|
||||
public static MapBuilder of(LLDictionary dictionary) {
|
||||
return new MapBuilder(dictionary);
|
||||
}
|
||||
|
||||
public MapBuilder2<byte[], byte[]> map() {
|
||||
return MapBuilder2.fromDictionary(dictionary);
|
||||
}
|
||||
|
||||
public static class MapBuilder2<K, V> {
|
||||
|
||||
private final LLDictionary dictionary;
|
||||
private final MapBuilder2<?, ?> parent;
|
||||
private final SerializationOptions<?, K, ?, V> serializationOptions;
|
||||
|
||||
public MapBuilder2(LLDictionary dictionary, SerializationOptions<byte[], K, byte[], V> serializationOptions) {
|
||||
this.dictionary = dictionary;
|
||||
this.parent = null;
|
||||
this.serializationOptions = serializationOptions;
|
||||
}
|
||||
|
||||
private <K1, V1> MapBuilder2(MapBuilder2<K1, V1> parent, SerializationOptions<K1, K, V1, V> serializationOptions) {
|
||||
this.dictionary = null;
|
||||
this.parent = parent;
|
||||
this.serializationOptions = serializationOptions;
|
||||
}
|
||||
|
||||
public static MapBuilder2<byte[], byte[]> fromDictionary(LLDictionary dictionary) {
|
||||
return new MapBuilder2<>(dictionary, SerializationOptions.noop());
|
||||
}
|
||||
|
||||
public <K2, V2> MapBuilder2<K2, V2> serialize(SerializationOptions<K, K2, V, V2> serializationOptions) {
|
||||
return new MapBuilder2<>(this, serializationOptions);
|
||||
}
|
||||
|
||||
public static class SerializationOptions<K1, K2, V1, V2> {
|
||||
|
||||
public static SerializationOptions<byte[], byte[], byte[], byte[]> noop() {
|
||||
return new SerializationOptions<>();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -25,6 +25,6 @@ public class SubStageGetterMapDeep<U, US extends DatabaseStage<U>> implements
|
||||
@Nullable CompositeSnapshot snapshot,
|
||||
byte[] prefixKey,
|
||||
Flux<byte[]> keyFlux) {
|
||||
return Mono.just(new DatabaseMapDictionaryParent<>(dictionary, subStageGetter, prefixKey, keyLength, keyExtLength));
|
||||
return Mono.just(new DatabaseMapDictionary<>(dictionary, subStageGetter, prefixKey, keyLength, keyExtLength));
|
||||
}
|
||||
}
|
||||
|
3
src/test/java/it/cavallium/dbengine/client/Database.java
Normal file
3
src/test/java/it/cavallium/dbengine/client/Database.java
Normal file
@ -0,0 +1,3 @@
|
||||
package it.cavallium.dbengine.client;
|
||||
|
||||
public class Database {}
|
Loading…
Reference in New Issue
Block a user