PdbWriter is no longer in the API of DataStore

This commit is contained in:
2019-02-16 16:24:14 +01:00
parent 92a47d9b56
commit 372a073b6d
4 changed files with 21 additions and 22 deletions

View File

@@ -24,7 +24,6 @@ import org.lucares.pdb.blockstorage.BSFile;
import org.lucares.pdb.blockstorage.LongStreamFile;
import org.lucares.pdb.datastore.Doc;
import org.lucares.pdb.datastore.PdbFile;
import org.lucares.pdb.datastore.PdbWriter;
import org.lucares.pdb.datastore.Proposal;
import org.lucares.pdb.datastore.ReadException;
import org.lucares.pdb.datastore.WriteException;
@@ -117,6 +116,11 @@ public class DataStore implements AutoCloseable {
return dataDirectory.resolve(SUBDIR_STORAGE);
}
public void write(final long dateAsEpochMilli, final Tags tags, final long value) {
final PdbWriter writer = getWriter(dateAsEpochMilli, tags);
writer.write(dateAsEpochMilli, value);
}
// visible for test
QueryCompletionIndex getQueryCompletionIndex() {
return queryCompletionIndex;
@@ -312,7 +316,7 @@ public class DataStore implements AutoCloseable {
return diskStorage;
}
public PdbWriter getWriter(final long dateAsEpochMilli, final Tags tags) throws ReadException, WriteException {
PdbWriter getWriter(final long dateAsEpochMilli, final Tags tags) throws ReadException, WriteException {
return writerCache.putIfAbsent(tags, () -> getWriter(tags));
}
@@ -403,4 +407,5 @@ public class DataStore implements AutoCloseable {
}
});
}
}

View File

@@ -1,4 +1,4 @@
package org.lucares.pdb.datastore;
package org.lucares.pdb.datastore.internal;
import java.io.Flushable;
import java.io.IOException;
@@ -6,6 +6,9 @@ import java.util.Optional;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.blockstorage.TimeSeriesFile;
import org.lucares.pdb.datastore.InvalidValueException;
import org.lucares.pdb.datastore.PdbFile;
import org.lucares.pdb.datastore.WriteException;
import org.lucares.pdb.diskstorage.DiskStorage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,7 +16,7 @@ import org.slf4j.LoggerFactory;
/**
*
*/
public class PdbWriter implements AutoCloseable, Flushable {
class PdbWriter implements AutoCloseable, Flushable {
private static final Logger LOGGER = LoggerFactory.getLogger(PdbWriter.class);
@@ -39,13 +42,7 @@ public class PdbWriter implements AutoCloseable, Flushable {
return lastEpochMilli;
}
public void write(final Entry entry) throws WriteException, InvalidValueException {
final long epochMilli = entry.getEpochMilli();
final long value = entry.getValue();
write(epochMilli, value);
}
private void write(final long epochMilli, final long value) throws WriteException, InvalidValueException {
public void write(final long epochMilli, final long value) throws WriteException, InvalidValueException {
try {
bsFile.appendTimeValue(epochMilli, value);
@@ -71,7 +68,7 @@ public class PdbWriter implements AutoCloseable, Flushable {
throws IOException {
try (PdbWriter writer = new PdbWriter(pdbFile, diskStorage)) {
for (final Entry entry : entries) {
writer.write(entry);
writer.write(entry.getEpochMilli(), entry.getValue());
}
}
}

View File

@@ -24,11 +24,9 @@ import javax.swing.JFrame;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import org.lucares.pdb.api.Entry;
import org.lucares.pdb.api.Tags;
import org.lucares.pdb.blockstorage.BSFile;
import org.lucares.pdb.datastore.Doc;
import org.lucares.pdb.datastore.PdbWriter;
import org.lucares.pdb.datastore.Proposal;
import org.lucares.utils.CollectionUtils;
import org.lucares.utils.DateUtils;
@@ -216,12 +214,12 @@ public class DataStoreTest {
final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
final PdbWriter writerForDayA = dataStore.getWriter(dayA, tags);
writerForDayA.write(new Entry(dayA, 1, tags));
writerForDayA.write(dayA, 1);
final PdbWriter writerForDayB = dataStore.getWriter(dayB, tags);
writerForDayB.write(new Entry(dayB, 2, tags));
writerForDayB.write(dayB, 2);
final PdbWriter writerForDayC = dataStore.getWriter(dayC, tags);
writerForDayC.write(new Entry(dayC, 3, tags));
writerForDayC.write(dayC, 3);
Assert.assertSame(writerForDayA, writerForDayB);
Assert.assertSame(writerForDayA, writerForDayC);
@@ -237,10 +235,10 @@ public class DataStoreTest {
final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
final PdbWriter fileA = dataStore.getWriter(timestamp, tags);
fileA.write(new Entry(timestamp, 1, tags));
fileA.write(timestamp, 1);
final PdbWriter fileB = dataStore.getWriter(timestamp, tags);
fileA.write(new Entry(timestamp, 2, tags));
fileA.write(timestamp, 2);
Assert.assertEquals(fileA, fileB);
}

View File

@@ -19,7 +19,6 @@ import org.lucares.pdb.api.Result;
import org.lucares.pdb.api.Tags;
import org.lucares.pdb.datastore.InvalidValueException;
import org.lucares.pdb.datastore.PdbFile;
import org.lucares.pdb.datastore.PdbWriter;
import org.lucares.pdb.datastore.Proposal;
import org.lucares.pdb.datastore.WriteException;
import org.lucares.pdb.datastore.internal.DataStore;
@@ -77,10 +76,10 @@ public class PerformanceDb implements AutoCloseable {
try {
final Tags tags = entry.getTags();
final long dateAsEpochMilli = entry.getEpochMilli();
final long value = entry.getValue();
final PdbWriter writer = dataStore.getWriter(dateAsEpochMilli, tags);
dataStore.write(dateAsEpochMilli, tags, value);
writer.write(entry);
count++;
insertionsSinceLastSync++;