minor database API change

This commit is contained in:
eyck committed 2021-01-14 23:13:11 +01:00
1 parent 26e8ea8a51
commit 0372e03abb
16 files changed
+206 -199

No files matched your search

@@ -28,14 +28,15 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.GZIPInputStream;
import org.eclipse.collections.impl.map.mutable.UnifiedMap;
import org.mapdb.DB;
import org.mapdb.DB.HashMapMaker;
import org.mapdb.DB.TreeMapSink;
import org.mapdb.DBMaker;
import org.mapdb.HTreeMap;
import org.mapdb.Serializer;
@@ -106,6 +107,26 @@ public class TextDbLoader implements IWaveformDbLoader {
/** The Constant x. */
static final byte[] x = "scv_tr_stream".getBytes();
/**
* Adds the property change listener.
*
* @param l the l
*/
@Override
public void addPropertyChangeListener(PropertyChangeListener l) {
pcs.addPropertyChangeListener(l);
}
/**
* Removes the property change listener.
*
* @param l the l
*/
@Override
public void removePropertyChangeListener(PropertyChangeListener l) {
pcs.removePropertyChangeListener(l);
}
/**
* Gets the max time.
*
@@ -116,8 +137,30 @@ public class TextDbLoader implements IWaveformDbLoader {
return maxTime;
}
/**
* Gets the transaction.
*
* @param txId the tx id
* @return the transaction
*/
public ITx getTransaction(long txId) {
if (txCache.containsKey(txId))
return txCache.get(txId);
if(transactions.containsKey(txId)) {
Tx tx = new Tx(this, txId);
txCache.put(txId, tx);
return tx;
} else {
Set<Long> keys = new TreeSet<>(transactions.keySet());
throw new IllegalArgumentException();
}
}
public ScvTx getScvTx(long id) {
return transactions.get(id);
if(transactions.containsKey(id))
return transactions.get(id);
else
throw new IllegalArgumentException();
}
/**
@@ -130,6 +173,15 @@ public class TextDbLoader implements IWaveformDbLoader {
return new ArrayList<>(txStreams.values());
}
/**
* Gets the all relation types.
*
* @return the all relation types
*/
public Collection<RelationType> getAllRelationTypes() {
return relationTypes.values();
}
/**
* Can load.
*
@@ -156,6 +208,22 @@ public class TextDbLoader implements IWaveformDbLoader {
return false;
}
/**
* Checks if is gzipped.
*
* @param f the f
* @return true, if is gzipped
*/
private static boolean isGzipped(File f) {
try (InputStream is = new FileInputStream(f)) {
byte[] signature = new byte[2];
int nread = is.read(signature); // read the gzip signature
return nread == 2 && signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b;
} catch (IOException e) {
return false;
}
}
/**
* Load.
*
@@ -197,19 +265,7 @@ public class TextDbLoader implements IWaveformDbLoader {
} catch (Exception e) {
throw new InputFormatException(e.toString());
}
for (TxStream stream : txStreams.values()) {
Thread t = new Thread() {
@Override
public void run() {
try {
stream.calculateConcurrency();
} catch (Exception e) {
/* don't let exceptions bubble up */ }
}
};
threads.add(t);
t.start();
}
txStreams.values().parallelStream().forEach(TxStream::calculateConcurrency);
}
/**
@@ -231,31 +287,6 @@ public class TextDbLoader implements IWaveformDbLoader {
}
}
/**
* Checks if is gzipped.
*
* @param f the f
* @return true, if is gzipped
*/
private static boolean isGzipped(File f) {
try (InputStream is = new FileInputStream(f)) {
byte[] signature = new byte[2];
int nread = is.read(signature); // read the gzip signature
return nread == 2 && signature[0] == (byte) 0x1f && signature[1] == (byte) 0x8b;
} catch (IOException e) {
return false;
}
}
/**
* Gets the all relation types.
*
* @return the all relation types
*/
public Collection<RelationType> getAllRelationTypes() {
return relationTypes.values();
}
/**
* The Class TextDbParser.
*/
@@ -321,6 +352,11 @@ public class TextDbLoader implements IWaveformDbLoader {
}
if (curLine != null)
parseLine(curLine, nextLine);
for(Entry<Long, ScvTx> e: transactionById.entrySet()) {
ScvTx scvTx = e.getValue();
scvTx.endTime=loader.maxTime;
txSink.put(e.getKey(), scvTx);
}
}
/**
@@ -368,8 +404,6 @@ public class TextDbLoader implements IWaveformDbLoader {
ScvTx scvTx = new ScvTx(id, gen.stream.getId(), genId,
Long.parseLong(tokens[3]) * stringToScale(tokens[4]));
loader.maxTime = loader.maxTime > scvTx.beginTime ? loader.maxTime : scvTx.beginTime;
TxStream stream = loader.txStreams.get(gen.stream.getId());
stream.setConcurrency(stream.getConcurrency() + 1);
if (nextLine != null && nextLine.charAt(0) == 'a') {
int idx = 0;
while (nextLine != null && nextLine.charAt(0) == 'a') {
@@ -402,7 +436,6 @@ public class TextDbLoader implements IWaveformDbLoader {
stream.addEvent(endEvt);
gen.addEvent(endEvt);
}
stream.setConcurrency(stream.getConcurrency() - 1);
if (nextLine != null && nextLine.charAt(0) == 'a') {
int idx = 0;
while (nextLine != null && nextLine.charAt(0) == 'a') {
@@ -521,38 +554,4 @@ public class TextDbLoader implements IWaveformDbLoader {
}
/**
* Gets the transaction.
*
* @param txId the tx id
* @return the transaction
*/
public ITx getTransaction(long txId) {
if (txCache.containsKey(txId))
return txCache.get(txId);
Tx tx = new Tx(this, txId);
txCache.put(txId, tx);
return tx;
}
/**
* Adds the property change listener.
*
* @param l the l
*/
@Override
public void addPropertyChangeListener(PropertyChangeListener l) {
pcs.addPropertyChangeListener(l);
}
/**
* Removes the property change listener.
*
* @param l the l
*/
@Override
public void removePropertyChangeListener(PropertyChangeListener l) {
pcs.removePropertyChangeListener(l);
}
}