add a new facade in front of DataStore

This is done in preparation for the proposal API.
In order to compute proposals we need to consume the
API of the DataStore, but the code does not need to
be in the DataStore. 
Extracting the API allows us to separate these concerns.
This commit is contained in:
2017-04-16 10:11:46 +02:00
parent 43d6eba7b7
commit 44f30aafee
8 changed files with 122 additions and 14 deletions

View File

@@ -22,7 +22,8 @@ import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.GroupResult;
import org.lucares.pdb.api.Result;
import org.lucares.pdb.api.Tags;
import org.lucares.pdb.datastore.DataStore;
import org.lucares.pdb.datastore.PdbDB;
import org.lucares.pdb.datastore.Proposal;
import org.lucares.pdb.datastore.lang.SyntaxException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,11 +34,11 @@ public class PerformanceDb implements AutoCloseable {
private final TagsToFile tagsToFile;
private final DataStore db;
private final PdbDB db;
public PerformanceDb(final Path dataDirectory) throws IOException {
db = new DataStore(dataDirectory);
db = new PdbDB(dataDirectory);
tagsToFile = new TagsToFile(db);
}

View File

@@ -1,78 +0,0 @@
package org.lucares.performance.db;
public class Proposal implements Comparable<Proposal> {
private final String proposedTag;
private final String proposedQuery;
private final long results;
public Proposal(final String proposedTag, final String proposedQuery, final long results) {
super();
this.proposedTag = proposedTag;
this.proposedQuery = proposedQuery;
this.results = results;
}
public String getProposedTag() {
return proposedTag;
}
public String getProposedQuery() {
return proposedQuery;
}
public long getResults() {
return results;
}
@Override
public String toString() {
return "Proposal [proposedTag=" + proposedTag + ", proposedQuery=" + proposedQuery + ", results=" + results
+ "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((proposedQuery == null) ? 0 : proposedQuery.hashCode());
result = prime * result + ((proposedTag == null) ? 0 : proposedTag.hashCode());
result = prime * result + (int) (results ^ (results >>> 32));
return result;
}
@Override
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
final Proposal other = (Proposal) obj;
if (proposedQuery == null) {
if (other.proposedQuery != null)
return false;
} else if (!proposedQuery.equals(other.proposedQuery))
return false;
if (proposedTag == null) {
if (other.proposedTag != null)
return false;
} else if (!proposedTag.equals(other.proposedTag))
return false;
if (results != other.results)
return false;
return true;
}
@Override
public int compareTo(final Proposal o) {
if (results != o.results) {
return results < o.results ? 1 : -1;
}
return proposedTag.compareToIgnoreCase(o.proposedTag);
}
}

View File

@@ -17,8 +17,8 @@ import java.util.function.Consumer;
import java.util.stream.Collectors;
import org.lucares.pdb.api.Tags;
import org.lucares.pdb.datastore.DataStore;
import org.lucares.pdb.datastore.Doc;
import org.lucares.pdb.datastore.PdbDB;
import org.lucares.utils.CollectionUtils;
import org.lucares.utils.file.FileUtils;
import org.slf4j.Logger;
@@ -64,11 +64,11 @@ public class TagsToFile implements AutoCloseable {
}
}
private final DataStore db;
private final PdbDB db;
private final Map<Tags, WriterCache> cachedWriters = new HashMap<>();
public TagsToFile(final DataStore db) {
public TagsToFile(final PdbDB db) {
this.db = db;
}

View File

@@ -8,7 +8,7 @@ import java.time.ZoneOffset;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.Tags;
import org.lucares.pdb.datastore.DataStore;
import org.lucares.pdb.datastore.PdbDB;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
@@ -31,7 +31,7 @@ public class TagsToFilesTest {
public void test() throws Exception {
final DataStore db = new DataStore(dataDirectory);
final PdbDB db = new PdbDB(dataDirectory);
try (final TagsToFile tagsToFile = new TagsToFile(db)) {
final OffsetDateTime date = OffsetDateTime.now(ZoneOffset.UTC);
@@ -46,7 +46,7 @@ public class TagsToFilesTest {
}
public void testAppendingToSameFileIfNewDateIsAfter() throws Exception {
final DataStore db = new DataStore(dataDirectory);
final PdbDB db = new PdbDB(dataDirectory);
try (final TagsToFile tagsToFile = new TagsToFile(db);) {
final OffsetDateTime day1 = DateUtils.getDate(2016, 1, 1, 1, 1, 1);
@@ -66,7 +66,7 @@ public class TagsToFilesTest {
@Test(invocationCount = 1)
public void testNewFileIfDateIsTooOld() throws Exception {
final DataStore db = new DataStore(dataDirectory);
final PdbDB db = new PdbDB(dataDirectory);
try (final TagsToFile tagsToFile = new TagsToFile(db);) {
final OffsetDateTime afternoon = DateUtils.getDate(2016, 1, 1, 13, 1, 1);
@@ -104,7 +104,7 @@ public class TagsToFilesTest {
public void testIdenticalDatesGoIntoSameFile() throws Exception {
final DataStore db = new DataStore(dataDirectory);
final PdbDB db = new PdbDB(dataDirectory);
try (final TagsToFile tagsToFile = new TagsToFile(db)) {
final OffsetDateTime timestamp = DateUtils.getDate(2016, 1, 1, 13, 1, 1);