Update Example.java, LLDatabaseConnection.java, and 4 more files...
This commit is contained in:
parent
da0ba7d6bb
commit
345bc81252
17
src/example/java/it.cavallium.dbengine.client/Example.java
Normal file
17
src/example/java/it.cavallium.dbengine.client/Example.java
Normal file
@ -0,0 +1,17 @@
|
||||
package it.cavallium.dbengine.client;
|
||||
|
||||
import it.cavallium.dbengine.database.Column;
|
||||
import it.cavallium.dbengine.database.disk.LLLocalDatabaseConnection;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
public class Example {
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("Test");
|
||||
new LLLocalDatabaseConnection(Path.of("/tmp/"), true)
|
||||
.connect()
|
||||
.flatMap(conn -> conn.getDatabase("testdb", List.of(Column.hashMap("testmap")), false))
|
||||
.block();
|
||||
}
|
||||
}
|
@ -1,23 +1,22 @@
|
||||
package it.cavallium.dbengine.database;
|
||||
|
||||
import it.cavallium.dbengine.database.analyzer.TextFieldsAnalyzer;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public interface LLDatabaseConnection {
|
||||
|
||||
Mono<Void> connect();
|
||||
Mono<? extends LLDatabaseConnection> connect();
|
||||
|
||||
LLKeyValueDatabase getDatabase(String name, List<Column> columns, boolean lowMemory) throws IOException;
|
||||
Mono<? extends LLKeyValueDatabase> getDatabase(String name, List<Column> columns, boolean lowMemory);
|
||||
|
||||
LLLuceneIndex getLuceneIndex(String name,
|
||||
Mono<? extends LLLuceneIndex> getLuceneIndex(String name,
|
||||
int instancesCount,
|
||||
TextFieldsAnalyzer textFieldsAnalyzer,
|
||||
Duration queryRefreshDebounceTime,
|
||||
Duration commitDebounceTime,
|
||||
boolean lowMemory) throws IOException;
|
||||
boolean lowMemory);
|
||||
|
||||
Mono<Void> disconnect();
|
||||
}
|
||||
|
@ -7,24 +7,35 @@ import org.jetbrains.annotations.Nullable;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
public class SubStageGetterMapDeep<U, US extends DatabaseStage<U>> implements
|
||||
SubStageGetter<Map<byte[], U>, DatabaseStageEntry<Map<byte[], U>>> {
|
||||
public class SubStageGetterMapDeep<T, U, US extends DatabaseStage<U>> implements
|
||||
SubStageGetter<Map<T, U>, DatabaseStageEntry<Map<T, U>>> {
|
||||
|
||||
private final SubStageGetter<U, US> subStageGetter;
|
||||
private final FixedLengthSerializer<T> keySerializer;
|
||||
private final int keyLength;
|
||||
private final int keyExtLength;
|
||||
|
||||
public SubStageGetterMapDeep(SubStageGetter<U, US> subStageGetter, int keyLength, int keyExtLength) {
|
||||
public SubStageGetterMapDeep(SubStageGetter<U, US> subStageGetter,
|
||||
FixedLengthSerializer<T> keySerializer,
|
||||
int keyLength,
|
||||
int keyExtLength) {
|
||||
this.subStageGetter = subStageGetter;
|
||||
this.keySerializer = keySerializer;
|
||||
this.keyLength = keyLength;
|
||||
this.keyExtLength = keyExtLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<DatabaseStageEntry<Map<byte[], U>>> subStage(LLDictionary dictionary,
|
||||
public Mono<DatabaseStageEntry<Map<T, U>>> subStage(LLDictionary dictionary,
|
||||
@Nullable CompositeSnapshot snapshot,
|
||||
byte[] prefixKey,
|
||||
Flux<byte[]> keyFlux) {
|
||||
return Mono.just(new DatabaseMapDictionary<>(dictionary, subStageGetter, prefixKey, keyLength, keyExtLength));
|
||||
return Mono.just(new DatabaseMapDictionary<>(dictionary,
|
||||
subStageGetter,
|
||||
keySerializer,
|
||||
prefixKey,
|
||||
keyLength,
|
||||
keyExtLength
|
||||
));
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,14 @@
|
||||
package it.cavallium.dbengine.database.disk;
|
||||
|
||||
import java.io.IOException;
|
||||
import it.cavallium.dbengine.database.Column;
|
||||
import it.cavallium.dbengine.database.LLDatabaseConnection;
|
||||
import it.cavallium.dbengine.database.LLLuceneIndex;
|
||||
import it.cavallium.dbengine.database.analyzer.TextFieldsAnalyzer;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.time.Duration;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import it.cavallium.dbengine.database.Column;
|
||||
import it.cavallium.dbengine.database.LLDatabaseConnection;
|
||||
import it.cavallium.dbengine.database.LLLuceneIndex;
|
||||
import it.cavallium.dbengine.database.analyzer.TextFieldsAnalyzer;
|
||||
import reactor.core.publisher.Mono;
|
||||
import reactor.core.scheduler.Schedulers;
|
||||
|
||||
@ -24,48 +23,59 @@ public class LLLocalDatabaseConnection implements LLDatabaseConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Mono<Void> connect() {
|
||||
public Mono<LLDatabaseConnection> connect() {
|
||||
return Mono
|
||||
.<Void>fromCallable(() -> {
|
||||
.<LLDatabaseConnection>fromCallable(() -> {
|
||||
if (Files.notExists(basePath)) {
|
||||
Files.createDirectories(basePath);
|
||||
}
|
||||
return null;
|
||||
return this;
|
||||
})
|
||||
.subscribeOn(Schedulers.boundedElastic());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LLLocalKeyValueDatabase getDatabase(String name, List<Column> columns, boolean lowMemory) throws IOException {
|
||||
return new LLLocalKeyValueDatabase(name, basePath.resolve("database_" + name), columns, new LinkedList<>(),
|
||||
crashIfWalError, lowMemory);
|
||||
public Mono<LLLocalKeyValueDatabase> getDatabase(String name, List<Column> columns, boolean lowMemory) {
|
||||
return Mono
|
||||
.<LLLocalKeyValueDatabase>fromCallable(() -> new LLLocalKeyValueDatabase(name,
|
||||
basePath.resolve("database_" + name),
|
||||
columns,
|
||||
new LinkedList<>(),
|
||||
crashIfWalError,
|
||||
lowMemory
|
||||
))
|
||||
.subscribeOn(Schedulers.boundedElastic());
|
||||
}
|
||||
|
||||
@Override
|
||||
public LLLuceneIndex getLuceneIndex(String name,
|
||||
public Mono<LLLuceneIndex> getLuceneIndex(String name,
|
||||
int instancesCount,
|
||||
TextFieldsAnalyzer textFieldsAnalyzer,
|
||||
Duration queryRefreshDebounceTime,
|
||||
Duration commitDebounceTime,
|
||||
boolean lowMemory) throws IOException {
|
||||
if (instancesCount != 1) {
|
||||
return new LLLocalMultiLuceneIndex(basePath.resolve("lucene"),
|
||||
name,
|
||||
instancesCount,
|
||||
textFieldsAnalyzer,
|
||||
queryRefreshDebounceTime,
|
||||
commitDebounceTime,
|
||||
lowMemory
|
||||
);
|
||||
} else {
|
||||
return new LLLocalLuceneIndex(basePath.resolve("lucene"),
|
||||
name,
|
||||
textFieldsAnalyzer,
|
||||
queryRefreshDebounceTime,
|
||||
commitDebounceTime,
|
||||
lowMemory
|
||||
);
|
||||
}
|
||||
boolean lowMemory) {
|
||||
return Mono
|
||||
.fromCallable(() -> {
|
||||
if (instancesCount != 1) {
|
||||
return new LLLocalMultiLuceneIndex(basePath.resolve("lucene"),
|
||||
name,
|
||||
instancesCount,
|
||||
textFieldsAnalyzer,
|
||||
queryRefreshDebounceTime,
|
||||
commitDebounceTime,
|
||||
lowMemory
|
||||
);
|
||||
} else {
|
||||
return new LLLocalLuceneIndex(basePath.resolve("lucene"),
|
||||
name,
|
||||
textFieldsAnalyzer,
|
||||
queryRefreshDebounceTime,
|
||||
commitDebounceTime,
|
||||
lowMemory
|
||||
);
|
||||
}
|
||||
})
|
||||
.subscribeOn(Schedulers.boundedElastic());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -61,6 +61,8 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
Options options = openRocksDb(path, crashIfWalError, lowMemory);
|
||||
try {
|
||||
List<ColumnFamilyDescriptor> descriptors = new LinkedList<>();
|
||||
descriptors
|
||||
.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||
for (Column column : columns) {
|
||||
descriptors
|
||||
.add(new ColumnFamilyDescriptor(column.getName().getBytes(StandardCharsets.US_ASCII)));
|
||||
@ -240,6 +242,7 @@ public class LLLocalKeyValueDatabase implements LLKeyValueDatabase {
|
||||
});
|
||||
|
||||
List<ColumnFamilyDescriptor> descriptors = new LinkedList<>();
|
||||
descriptors.add(new ColumnFamilyDescriptor(RocksDB.DEFAULT_COLUMN_FAMILY));
|
||||
for (byte[] existingColumnFamily : existingColumnFamilies) {
|
||||
descriptors.add(new ColumnFamilyDescriptor(existingColumnFamily));
|
||||
}
|
||||
|
@ -1,3 +1,5 @@
|
||||
package it.cavallium.dbengine.client;
|
||||
|
||||
public class Database {}
|
||||
public class Database {
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user