PdbWriter is no longer in the API of DataStore
This commit is contained in:
@@ -24,7 +24,6 @@ import org.lucares.pdb.blockstorage.BSFile;
|
|||||||
import org.lucares.pdb.blockstorage.LongStreamFile;
|
import org.lucares.pdb.blockstorage.LongStreamFile;
|
||||||
import org.lucares.pdb.datastore.Doc;
|
import org.lucares.pdb.datastore.Doc;
|
||||||
import org.lucares.pdb.datastore.PdbFile;
|
import org.lucares.pdb.datastore.PdbFile;
|
||||||
import org.lucares.pdb.datastore.PdbWriter;
|
|
||||||
import org.lucares.pdb.datastore.Proposal;
|
import org.lucares.pdb.datastore.Proposal;
|
||||||
import org.lucares.pdb.datastore.ReadException;
|
import org.lucares.pdb.datastore.ReadException;
|
||||||
import org.lucares.pdb.datastore.WriteException;
|
import org.lucares.pdb.datastore.WriteException;
|
||||||
@@ -117,6 +116,11 @@ public class DataStore implements AutoCloseable {
|
|||||||
return dataDirectory.resolve(SUBDIR_STORAGE);
|
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
|
// visible for test
|
||||||
QueryCompletionIndex getQueryCompletionIndex() {
|
QueryCompletionIndex getQueryCompletionIndex() {
|
||||||
return queryCompletionIndex;
|
return queryCompletionIndex;
|
||||||
@@ -312,7 +316,7 @@ public class DataStore implements AutoCloseable {
|
|||||||
return diskStorage;
|
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));
|
return writerCache.putIfAbsent(tags, () -> getWriter(tags));
|
||||||
}
|
}
|
||||||
@@ -403,4 +407,5 @@ public class DataStore implements AutoCloseable {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package org.lucares.pdb.datastore;
|
package org.lucares.pdb.datastore.internal;
|
||||||
|
|
||||||
import java.io.Flushable;
|
import java.io.Flushable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -6,6 +6,9 @@ import java.util.Optional;
|
|||||||
|
|
||||||
import org.lucares.pdb.api.Entry;
|
import org.lucares.pdb.api.Entry;
|
||||||
import org.lucares.pdb.blockstorage.TimeSeriesFile;
|
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.lucares.pdb.diskstorage.DiskStorage;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
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);
|
private static final Logger LOGGER = LoggerFactory.getLogger(PdbWriter.class);
|
||||||
|
|
||||||
@@ -39,13 +42,7 @@ public class PdbWriter implements AutoCloseable, Flushable {
|
|||||||
return lastEpochMilli;
|
return lastEpochMilli;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write(final Entry entry) throws WriteException, InvalidValueException {
|
public void write(final long epochMilli, final long value) 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 {
|
|
||||||
try {
|
try {
|
||||||
bsFile.appendTimeValue(epochMilli, value);
|
bsFile.appendTimeValue(epochMilli, value);
|
||||||
|
|
||||||
@@ -71,7 +68,7 @@ public class PdbWriter implements AutoCloseable, Flushable {
|
|||||||
throws IOException {
|
throws IOException {
|
||||||
try (PdbWriter writer = new PdbWriter(pdbFile, diskStorage)) {
|
try (PdbWriter writer = new PdbWriter(pdbFile, diskStorage)) {
|
||||||
for (final Entry entry : entries) {
|
for (final Entry entry : entries) {
|
||||||
writer.write(entry);
|
writer.write(entry.getEpochMilli(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,11 +24,9 @@ import javax.swing.JFrame;
|
|||||||
import javax.swing.JTextArea;
|
import javax.swing.JTextArea;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
import org.lucares.pdb.api.Entry;
|
|
||||||
import org.lucares.pdb.api.Tags;
|
import org.lucares.pdb.api.Tags;
|
||||||
import org.lucares.pdb.blockstorage.BSFile;
|
import org.lucares.pdb.blockstorage.BSFile;
|
||||||
import org.lucares.pdb.datastore.Doc;
|
import org.lucares.pdb.datastore.Doc;
|
||||||
import org.lucares.pdb.datastore.PdbWriter;
|
|
||||||
import org.lucares.pdb.datastore.Proposal;
|
import org.lucares.pdb.datastore.Proposal;
|
||||||
import org.lucares.utils.CollectionUtils;
|
import org.lucares.utils.CollectionUtils;
|
||||||
import org.lucares.utils.DateUtils;
|
import org.lucares.utils.DateUtils;
|
||||||
@@ -216,12 +214,12 @@ public class DataStoreTest {
|
|||||||
final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
|
final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
|
||||||
|
|
||||||
final PdbWriter writerForDayA = dataStore.getWriter(dayA, tags);
|
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);
|
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);
|
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, writerForDayB);
|
||||||
Assert.assertSame(writerForDayA, writerForDayC);
|
Assert.assertSame(writerForDayA, writerForDayC);
|
||||||
@@ -237,10 +235,10 @@ public class DataStoreTest {
|
|||||||
final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
|
final Tags tags = Tags.createAndAddToDictionary("myKey", "myValue");
|
||||||
|
|
||||||
final PdbWriter fileA = dataStore.getWriter(timestamp, tags);
|
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);
|
final PdbWriter fileB = dataStore.getWriter(timestamp, tags);
|
||||||
fileA.write(new Entry(timestamp, 2, tags));
|
fileA.write(timestamp, 2);
|
||||||
|
|
||||||
Assert.assertEquals(fileA, fileB);
|
Assert.assertEquals(fileA, fileB);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,6 @@ import org.lucares.pdb.api.Result;
|
|||||||
import org.lucares.pdb.api.Tags;
|
import org.lucares.pdb.api.Tags;
|
||||||
import org.lucares.pdb.datastore.InvalidValueException;
|
import org.lucares.pdb.datastore.InvalidValueException;
|
||||||
import org.lucares.pdb.datastore.PdbFile;
|
import org.lucares.pdb.datastore.PdbFile;
|
||||||
import org.lucares.pdb.datastore.PdbWriter;
|
|
||||||
import org.lucares.pdb.datastore.Proposal;
|
import org.lucares.pdb.datastore.Proposal;
|
||||||
import org.lucares.pdb.datastore.WriteException;
|
import org.lucares.pdb.datastore.WriteException;
|
||||||
import org.lucares.pdb.datastore.internal.DataStore;
|
import org.lucares.pdb.datastore.internal.DataStore;
|
||||||
@@ -77,10 +76,10 @@ public class PerformanceDb implements AutoCloseable {
|
|||||||
try {
|
try {
|
||||||
final Tags tags = entry.getTags();
|
final Tags tags = entry.getTags();
|
||||||
final long dateAsEpochMilli = entry.getEpochMilli();
|
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++;
|
count++;
|
||||||
insertionsSinceLastSync++;
|
insertionsSinceLastSync++;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user