remove the wrapper class PdbDB

It did not serve any purpose and could be replaced by DataStore.
This commit is contained in:
2018-10-04 18:43:27 +02:00
parent 01b93e32ca
commit 8939332004
6 changed files with 41 additions and 102 deletions

View File

@@ -1,60 +0,0 @@
package org.lucares.pdb.datastore;
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.SortedSet;
import org.lucares.pdb.api.Tags;
import org.lucares.pdb.datastore.internal.DataStore;
import org.lucares.pdb.datastore.internal.Proposer;
import org.lucares.pdb.diskstorage.DiskStorage;
public class PdbDB implements AutoCloseable {
private final DataStore dataStore;
private final Proposer proposer;
public PdbDB(final Path dataDirectory) throws IOException {
dataStore = new DataStore(dataDirectory);
proposer = new Proposer(dataStore);
}
public List<Doc> search(final String query) {
return dataStore.search(query);
}
public long createNewFile(final Tags tags) throws IOException {
return dataStore.createNewFile(tags);
}
public List<String> getAvailableFields() {
return dataStore.getAvailableFields();
}
public SortedSet<String> getAvailableValuesForKey(final String query, final String fieldName) {
return dataStore.getAvailableValuesForKey(query, fieldName);
}
public List<Proposal> propose(final String query, final int caretIndex) {
return proposer.propose(query, caretIndex);
}
public List<Doc> getByTags(final Tags tags) {
return dataStore.getByTags(tags);
}
public Path getStorageBasePath() {
return dataStore.getStorageBasePath();
}
@Override
public void close() throws IOException {
dataStore.close();
}
public DiskStorage getDiskStorage() {
return dataStore.getDiskStorage();
}
}

View File

@@ -23,6 +23,7 @@ import org.lucares.collections.IntList;
import org.lucares.pdb.api.StringCompressor;
import org.lucares.pdb.api.Tags;
import org.lucares.pdb.datastore.Doc;
import org.lucares.pdb.datastore.Proposal;
import org.lucares.pdb.datastore.lang.Expression;
import org.lucares.pdb.datastore.lang.ExpressionToDocIdVisitor;
import org.lucares.pdb.datastore.lang.ExpressionToDocIdVisitor.AllDocIds;
@@ -265,15 +266,15 @@ public class DataStore implements AutoCloseable {
return result;
}
public Path getStorageBasePath() {
return storageBasePath;
}
@Override
public void close() throws IOException {
diskStorage.close();
}
public List<Proposal> propose(final String query, final int caretIndex) {
return new Proposer(this).propose(query, caretIndex);
}
private void initListingFileIfNotExists() throws IOException {
if (!Files.exists(listingFilePath)) {

View File

@@ -8,7 +8,6 @@ import java.util.Collections;
import java.util.List;
import org.lucares.pdb.api.Tags;
import org.lucares.pdb.datastore.PdbDB;
import org.lucares.pdb.datastore.Proposal;
import org.lucares.utils.CollectionUtils;
import org.lucares.utils.file.FileUtils;
@@ -21,7 +20,7 @@ import org.testng.annotations.Test;
public class ProposerTest {
private Path dataDirectory;
private PdbDB db;
private DataStore dataStore;
@BeforeClass
public void beforeClass() throws Exception {
@@ -32,13 +31,13 @@ public class ProposerTest {
@AfterClass
public void afterClass() throws IOException {
FileUtils.delete(dataDirectory);
db.close();
db = null;
dataStore.close();
dataStore = null;
Tags.STRING_COMPRESSOR = null;
}
private void initDatabase() throws Exception {
db = new PdbDB(dataDirectory);
dataStore = new DataStore(dataDirectory);
final Tags eagleTim = Tags.create("bird", "eagle", "name", "Tim");
final Tags eagleTimothy = Tags.create("bird", "eagle", "name", "Timothy");
@@ -47,12 +46,12 @@ public class ProposerTest {
final Tags labradorJenny = Tags.create("dog", "labrador", "name", "Jenny");
final Tags labradorTim = Tags.create("dog", "labrador", "name", "Tim");
db.createNewFile(eagleTim);
db.createNewFile(eagleTimothy);
db.createNewFile(pigeonJennifer);
db.createNewFile(flamingoJennifer);
db.createNewFile(labradorJenny);
db.createNewFile(labradorTim);
dataStore.createNewFile(eagleTim);
dataStore.createNewFile(eagleTimothy);
dataStore.createNewFile(pigeonJennifer);
dataStore.createNewFile(flamingoJennifer);
dataStore.createNewFile(labradorJenny);
dataStore.createNewFile(labradorTim);
}
public void testEmptyQuery() throws Exception {
@@ -142,7 +141,7 @@ public class ProposerTest {
private void assertProposals(final String query, final int caretIndex, final Proposal... expected)
throws InterruptedException {
final List<Proposal> actual = db.propose(query, caretIndex);
final List<Proposal> actual = dataStore.propose(query, caretIndex);
final List<Proposal> expectedList = Arrays.asList(expected);
Collections.sort(expectedList);