2021-07-18 19:37:24 +02:00
|
|
|
package it.cavallium.dbengine.database.memory;
|
|
|
|
|
2022-03-16 13:47:56 +01:00
|
|
|
import io.netty5.buffer.api.Buffer;
|
|
|
|
import io.netty5.buffer.api.BufferAllocator;
|
2022-07-15 02:44:50 +02:00
|
|
|
import io.netty5.util.Send;
|
2021-11-12 02:05:44 +01:00
|
|
|
import it.cavallium.dbengine.database.LLDelta;
|
2021-07-18 19:37:24 +02:00
|
|
|
import it.cavallium.dbengine.database.LLDictionaryResultType;
|
|
|
|
import it.cavallium.dbengine.database.LLSingleton;
|
|
|
|
import it.cavallium.dbengine.database.LLSnapshot;
|
2021-11-12 02:05:44 +01:00
|
|
|
import it.cavallium.dbengine.database.UpdateReturnMode;
|
2022-04-01 01:30:56 +02:00
|
|
|
import it.cavallium.dbengine.database.disk.BinarySerializationFunction;
|
2021-11-12 02:05:44 +01:00
|
|
|
import it.cavallium.dbengine.database.serialization.SerializationFunction;
|
2021-07-18 19:37:24 +02:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
|
|
public class LLMemorySingleton implements LLSingleton {
|
|
|
|
|
|
|
|
private final LLMemoryDictionary dict;
|
2022-03-20 14:33:27 +01:00
|
|
|
private final String columnNameString;
|
2021-07-18 19:37:24 +02:00
|
|
|
private final byte[] singletonName;
|
2022-05-20 10:20:00 +02:00
|
|
|
private final Mono<Buffer> singletonNameBufMono;
|
2021-07-18 19:37:24 +02:00
|
|
|
|
2022-03-20 14:33:27 +01:00
|
|
|
public LLMemorySingleton(LLMemoryDictionary dict, String columnNameString, byte[] singletonName) {
|
2021-07-18 19:37:24 +02:00
|
|
|
this.dict = dict;
|
2022-03-20 14:33:27 +01:00
|
|
|
this.columnNameString = columnNameString;
|
2021-07-18 19:37:24 +02:00
|
|
|
this.singletonName = singletonName;
|
2022-05-20 10:20:00 +02:00
|
|
|
this.singletonNameBufMono = Mono.fromSupplier(() -> dict.getAllocator().allocate(singletonName.length)
|
|
|
|
.writeBytes(singletonName));
|
2021-07-18 19:37:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDatabaseName() {
|
|
|
|
return dict.getDatabaseName();
|
|
|
|
}
|
|
|
|
|
2021-11-12 02:05:44 +01:00
|
|
|
@Override
|
|
|
|
public BufferAllocator getAllocator() {
|
|
|
|
return dict.getAllocator();
|
|
|
|
}
|
|
|
|
|
2021-07-18 19:37:24 +02:00
|
|
|
@Override
|
2022-05-20 10:20:00 +02:00
|
|
|
public Mono<Buffer> get(@Nullable LLSnapshot snapshot) {
|
2022-03-24 21:14:17 +01:00
|
|
|
return dict.get(snapshot, singletonNameBufMono);
|
2021-07-18 19:37:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-05-20 10:20:00 +02:00
|
|
|
public Mono<Void> set(Mono<Buffer> value) {
|
2021-08-31 09:14:46 +02:00
|
|
|
var bbKey = singletonNameBufMono;
|
2021-08-22 18:20:05 +02:00
|
|
|
return dict
|
2022-03-20 14:33:27 +01:00
|
|
|
.put(bbKey, value, LLDictionaryResultType.VOID)
|
2021-07-18 19:37:24 +02:00
|
|
|
.then();
|
|
|
|
}
|
2021-11-12 02:05:44 +01:00
|
|
|
|
|
|
|
@Override
|
2022-05-20 10:20:00 +02:00
|
|
|
public Mono<Buffer> update(BinarySerializationFunction updater,
|
2021-11-12 02:05:44 +01:00
|
|
|
UpdateReturnMode updateReturnMode) {
|
2022-03-02 18:33:58 +01:00
|
|
|
return dict.update(singletonNameBufMono, updater, updateReturnMode);
|
2021-11-12 02:05:44 +01:00
|
|
|
}
|
2022-03-20 14:33:27 +01:00
|
|
|
|
|
|
|
@Override
|
2022-05-20 10:20:00 +02:00
|
|
|
public Mono<LLDelta> updateAndGetDelta(BinarySerializationFunction updater) {
|
2022-03-20 14:33:27 +01:00
|
|
|
return dict.updateAndGetDelta(singletonNameBufMono, updater);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getColumnName() {
|
|
|
|
return columnNameString;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getName() {
|
|
|
|
return new String(singletonName);
|
|
|
|
}
|
2021-07-18 19:37:24 +02:00
|
|
|
}
|