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>
|
<artifactId>common-utils</artifactId>
|
||||||
<version>1.1.2</version>
|
<version>1.1.2</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-buffer</artifactId>
|
||||||
|
<version>4.1.58.Final</version>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.xml.bind</groupId>
|
<groupId>javax.xml.bind</groupId>
|
||||||
<artifactId>jaxb-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
|
@ -13,11 +13,12 @@ import reactor.core.publisher.GroupedFlux;
|
|||||||
import reactor.core.publisher.Mono;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
// todo: implement optimized methods
|
// 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];
|
public static final byte[] EMPTY_BYTES = new byte[0];
|
||||||
private final LLDictionary dictionary;
|
private final LLDictionary dictionary;
|
||||||
private final SubStageGetter<U, US> subStageGetter;
|
private final SubStageGetter<U, US> subStageGetter;
|
||||||
|
private final FixedLengthSerializer<T> suffixKeySerializer;
|
||||||
private final byte[] keyPrefix;
|
private final byte[] keyPrefix;
|
||||||
private final int keySuffixLength;
|
private final int keySuffixLength;
|
||||||
private final int keyExtLength;
|
private final int keyExtLength;
|
||||||
@ -65,13 +66,14 @@ public class DatabaseMapDictionaryParent<U, US extends DatabaseStage<U>> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
public DatabaseMapDictionaryParent(LLDictionary dictionary, SubStageGetter<U, US> subStageGetter, int keyLength, int keyExtLength) {
|
public DatabaseMapDictionary(LLDictionary dictionary, SubStageGetter<U, US> subStageGetter, FixedLengthSerializer<T> keySerializer, int keyLength, int keyExtLength) {
|
||||||
this(dictionary, subStageGetter, EMPTY_BYTES, keyLength, 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.dictionary = dictionary;
|
||||||
this.subStageGetter = subStageGetter;
|
this.subStageGetter = subStageGetter;
|
||||||
|
this.suffixKeySerializer = suffixKeySerializer;
|
||||||
this.keyPrefix = prefixKey;
|
this.keyPrefix = prefixKey;
|
||||||
this.keySuffixLength = keySuffixLength;
|
this.keySuffixLength = keySuffixLength;
|
||||||
this.keyExtLength = keyExtLength;
|
this.keyExtLength = keyExtLength;
|
||||||
@ -152,23 +154,32 @@ public class DatabaseMapDictionaryParent<U, US extends DatabaseStage<U>> impleme
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
Flux<byte[]> rangeKeys = this
|
||||||
.dictionary.getRangeKeys(resolveSnapshot(snapshot), toExtRange(keySuffix)
|
.dictionary.getRangeKeys(resolveSnapshot(snapshot), toExtRange(keySuffixData)
|
||||||
);
|
);
|
||||||
return this.subStageGetter
|
return this.subStageGetter
|
||||||
.subStage(dictionary, snapshot, toKeyWithoutExt(keySuffix), rangeKeys);
|
.subStage(dictionary, snapshot, toKeyWithoutExt(keySuffixData), rangeKeys);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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
|
Flux<GroupedFlux<byte[], byte[]>> groupedFlux = dictionary
|
||||||
.getRangeKeys(resolveSnapshot(snapshot), range)
|
.getRangeKeys(resolveSnapshot(snapshot), range)
|
||||||
.groupBy(this::removeExtFromFullKey);
|
.groupBy(this::removeExtFromFullKey);
|
||||||
return groupedFlux
|
return groupedFlux
|
||||||
.flatMap(rangeKeys -> this.subStageGetter
|
.flatMap(rangeKeys -> this.subStageGetter
|
||||||
.subStage(dictionary, snapshot, rangeKeys.key(), rangeKeys)
|
.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;
|
import reactor.core.publisher.Mono;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @deprecated Use DatabaseMapDictionaryParent with SubStageGetterSingle
|
* @deprecated Use DatabaseMapDictionary with SubStageGetterSingle
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public class DatabaseMapDictionaryRange implements DatabaseStageMap<byte[], byte[], DatabaseStageEntry<byte[]>> {
|
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,
|
@Nullable CompositeSnapshot snapshot,
|
||||||
byte[] prefixKey,
|
byte[] prefixKey,
|
||||||
Flux<byte[]> keyFlux) {
|
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