2021-01-30 22:14:48 +01:00
|
|
|
package it.cavallium.dbengine.database.collections;
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2023-03-06 12:19:08 +01:00
|
|
|
import it.cavallium.buffer.BufDataInput;
|
|
|
|
import it.cavallium.buffer.BufDataOutput;
|
2020-12-07 22:15:18 +01:00
|
|
|
import it.cavallium.dbengine.database.LLKeyValueDatabaseStructure;
|
|
|
|
import it.cavallium.dbengine.database.LLSingleton;
|
|
|
|
import it.cavallium.dbengine.database.LLSnapshot;
|
2022-03-20 14:33:27 +01:00
|
|
|
import it.cavallium.dbengine.database.serialization.SerializerFixedBinaryLength;
|
2024-04-18 14:48:16 +02:00
|
|
|
import java.util.concurrent.ForkJoinPool;
|
2020-12-07 22:15:18 +01:00
|
|
|
import org.jetbrains.annotations.Nullable;
|
|
|
|
|
2021-01-31 00:36:21 +01:00
|
|
|
public class DatabaseInt implements LLKeyValueDatabaseStructure {
|
2020-12-07 22:15:18 +01:00
|
|
|
|
|
|
|
private final LLSingleton singleton;
|
2022-03-20 14:33:27 +01:00
|
|
|
private final SerializerFixedBinaryLength<Integer> serializer;
|
2020-12-07 22:15:18 +01:00
|
|
|
|
2021-01-31 00:36:21 +01:00
|
|
|
public DatabaseInt(LLSingleton singleton) {
|
2020-12-07 22:15:18 +01:00
|
|
|
this.singleton = singleton;
|
2023-02-09 23:34:25 +01:00
|
|
|
this.serializer = SerializerFixedBinaryLength.intSerializer();
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:34:25 +01:00
|
|
|
public Integer get(@Nullable LLSnapshot snapshot) {
|
|
|
|
var result = singleton.get(snapshot);
|
|
|
|
return serializer.deserialize(BufDataInput.create(result));
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
2023-02-09 23:34:25 +01:00
|
|
|
public void set(int value) {
|
|
|
|
var buf = BufDataOutput.createLimited(Integer.BYTES);
|
|
|
|
serializer.serialize(value, buf);
|
|
|
|
singleton.set(buf.asList());
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getDatabaseName() {
|
|
|
|
return singleton.getDatabaseName();
|
|
|
|
}
|
2024-04-18 14:48:16 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForkJoinPool getDbReadPool() {
|
|
|
|
return singleton.getDbReadPool();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForkJoinPool getDbWritePool() {
|
|
|
|
return singleton.getDbWritePool();
|
|
|
|
}
|
2020-12-07 22:15:18 +01:00
|
|
|
}
|