|
|
|
|
@@ -21,7 +21,6 @@ import java.util.Arrays;
|
|
|
|
|
import java.util.Collection;
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
import java.util.TreeMap;
|
|
|
|
|
import java.util.regex.Matcher;
|
|
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
import java.util.zip.GZIPInputStream;
|
|
|
|
|
@@ -41,8 +40,8 @@ import com.minres.scviewer.database.IWaveformDb;
|
|
|
|
|
import com.minres.scviewer.database.IWaveformDbLoader;
|
|
|
|
|
import com.minres.scviewer.database.InputFormatException;
|
|
|
|
|
import com.minres.scviewer.database.RelationType;
|
|
|
|
|
import com.minres.scviewer.database.RelationTypeFactory;
|
|
|
|
|
import com.minres.scviewer.database.tx.ITx;
|
|
|
|
|
import com.minres.scviewer.database.tx.ITxAttributeType;
|
|
|
|
|
|
|
|
|
|
public class TextDbLoader implements IWaveformDbLoader{
|
|
|
|
|
|
|
|
|
|
@@ -58,7 +57,9 @@ public class TextDbLoader implements IWaveformDbLoader{
|
|
|
|
|
|
|
|
|
|
BTreeMap<Long, ScvTx> transactions;
|
|
|
|
|
|
|
|
|
|
BTreeMap<Long[], ScvRelation> relations;
|
|
|
|
|
BTreeMap<Long[], ScvRelation> relationsIn;
|
|
|
|
|
|
|
|
|
|
BTreeMap<Long[], ScvRelation> relationsOut;
|
|
|
|
|
|
|
|
|
|
BTreeMap<String[], TxAttributeType> attributeTypes;
|
|
|
|
|
|
|
|
|
|
@@ -97,22 +98,27 @@ public class TextDbLoader implements IWaveformDbLoader{
|
|
|
|
|
mapDbFile.delete(); // we just need a file name
|
|
|
|
|
mapDbFile.deleteOnExit();
|
|
|
|
|
mapDb = DBMaker
|
|
|
|
|
.fileDB(mapDbFile)
|
|
|
|
|
.fileMmapEnableIfSupported()
|
|
|
|
|
.fileMmapPreclearDisable()
|
|
|
|
|
.memoryDirectDB()
|
|
|
|
|
// .fileDB(mapDbFile)
|
|
|
|
|
// .fileMmapEnable() // Always enable mmap
|
|
|
|
|
// .fileMmapEnableIfSupported()
|
|
|
|
|
// .fileMmapPreclearDisable()
|
|
|
|
|
.allocateStartSize(512*1024*1024)
|
|
|
|
|
.allocateIncrement(128*1024*1024)
|
|
|
|
|
.cleanerHackEnable()
|
|
|
|
|
.allocateStartSize(64*1024*1024)
|
|
|
|
|
.allocateIncrement(64*1024*1024)
|
|
|
|
|
.make();
|
|
|
|
|
TreeMapSink<Long, ScvTx> txSink = mapDb.treeMap("transactions", Serializer.LONG,Serializer.JAVA).createFromSink();
|
|
|
|
|
relations = mapDb
|
|
|
|
|
.treeMap("relations", new SerializerArrayTuple(Serializer.LONG, Serializer.LONG) ,Serializer.JAVA)
|
|
|
|
|
relationsIn = mapDb
|
|
|
|
|
.treeMap("relationsIn", new SerializerArrayTuple(Serializer.LONG, Serializer.LONG) ,Serializer.JAVA)
|
|
|
|
|
.createOrOpen();
|
|
|
|
|
relationsOut = mapDb
|
|
|
|
|
.treeMap("relationsOut", new SerializerArrayTuple(Serializer.LONG, Serializer.LONG) ,Serializer.JAVA)
|
|
|
|
|
.createOrOpen();
|
|
|
|
|
attributeTypes = mapDb
|
|
|
|
|
.treeMap("attributeTypes", new SerializerArrayTuple(Serializer.STRING, Serializer.STRING) ,Serializer.JAVA)
|
|
|
|
|
.createOrOpen();
|
|
|
|
|
try {
|
|
|
|
|
parser.setTransactionSink(txSink).setRelationMap(relations);
|
|
|
|
|
parser.setTransactionSink(txSink).setRelationMaps(relationsIn, relationsOut);
|
|
|
|
|
parser.parseInput(gzipped?new GZIPInputStream(new FileInputStream(file)):new FileInputStream(file));
|
|
|
|
|
} catch(IllegalArgumentException|ArrayIndexOutOfBoundsException e) {
|
|
|
|
|
} catch(Exception e) {
|
|
|
|
|
@@ -176,7 +182,9 @@ public class TextDbLoader implements IWaveformDbLoader{
|
|
|
|
|
|
|
|
|
|
private TreeMapSink<Long, ScvTx> txSink;
|
|
|
|
|
|
|
|
|
|
private BTreeMap<Long[], ScvRelation> relations;
|
|
|
|
|
private BTreeMap<Long[], ScvRelation> relationsIn;
|
|
|
|
|
|
|
|
|
|
private BTreeMap<Long[], ScvRelation> relationsOut;
|
|
|
|
|
|
|
|
|
|
public TextDbParser(TextDbLoader loader) {
|
|
|
|
|
super();
|
|
|
|
|
@@ -188,8 +196,9 @@ public class TextDbLoader implements IWaveformDbLoader{
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TextDbParser setRelationMap(BTreeMap<Long[], ScvRelation> relations) {
|
|
|
|
|
this.relations=relations;
|
|
|
|
|
public TextDbParser setRelationMaps(BTreeMap<Long[], ScvRelation> relationsIn, BTreeMap<Long[], ScvRelation> relationsOut) {
|
|
|
|
|
this.relationsIn=relationsIn;
|
|
|
|
|
this.relationsOut=relationsOut;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -218,11 +227,11 @@ public class TextDbLoader implements IWaveformDbLoader{
|
|
|
|
|
|
|
|
|
|
private String parseLine(String curLine, String nextLine) throws IOException{
|
|
|
|
|
String[] tokens = curLine.split("\\s+");
|
|
|
|
|
if("tx_record_attribute".equals(tokens[0])){//matcher = line =~ /^tx_record_attribute\s+(\d+)\s+"([^"]+)"\s+(\S+)\s*=\s*(.+)$/
|
|
|
|
|
if("tx_record_attribute".equals(tokens[0])){
|
|
|
|
|
Long id = Long.parseLong(tokens[1]);
|
|
|
|
|
String name = tokens[2].substring(1, tokens[2].length());
|
|
|
|
|
DataType type = DataType.valueOf(tokens[3]);
|
|
|
|
|
String remaining = tokens.length>5?String.join(" ", Arrays.copyOfRange(tokens, 5, tokens.length-1)):"";
|
|
|
|
|
String remaining = tokens.length>5?String.join(" ", Arrays.copyOfRange(tokens, 5, tokens.length)):"";
|
|
|
|
|
TxAttributeType attrType = getAttrType(name, type, AssociationType.RECORD);
|
|
|
|
|
transactionsById.get(id).attributes.add(new TxAttribute(attrType, remaining));
|
|
|
|
|
} else if("tx_begin".equals(tokens[0])){
|
|
|
|
|
@@ -245,7 +254,7 @@ public class TextDbLoader implements IWaveformDbLoader{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
txSink.put(tx.id, tx);
|
|
|
|
|
} else if("tx_end".equals(tokens[0])){//matcher = line =~ /^tx_end\s+(\d+)\s+(\d+)\s+(\d+)\s+([munpf]?s)/
|
|
|
|
|
} else if("tx_end".equals(tokens[0])){
|
|
|
|
|
Long id = Long.parseLong(tokens[1]);
|
|
|
|
|
ScvTx tx = transactionsById.get(id);
|
|
|
|
|
assert Long.parseLong(tokens[2])==tx.generatorId;
|
|
|
|
|
@@ -271,14 +280,15 @@ public class TextDbLoader implements IWaveformDbLoader{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
transactionsById.remove(tx.id);
|
|
|
|
|
} else if("tx_relation".equals(tokens[0])){//matcher = line =~ /^tx_relation\s+\"(\S+)\"\s+(\d+)\s+(\d+)$/
|
|
|
|
|
} else if("tx_relation".equals(tokens[0])){
|
|
|
|
|
Long tr2= Long.parseLong(tokens[2]);
|
|
|
|
|
Long tr1= Long.parseLong(tokens[3]);
|
|
|
|
|
String relType=tokens[1].substring(1, tokens[1].length()-2);
|
|
|
|
|
String relType=tokens[1].substring(1, tokens[1].length()-1);
|
|
|
|
|
if(!loader.relationTypes.containsKey(relType))
|
|
|
|
|
loader.relationTypes.put(relType, RelationType.create(relType));
|
|
|
|
|
loader.relationTypes.put(relType, RelationTypeFactory.create(relType));
|
|
|
|
|
ScvRelation rel = new ScvRelation(loader.relationTypes.get(relType), tr1, tr2);
|
|
|
|
|
relations.put(new Long[]{tr1, tr2}, rel);
|
|
|
|
|
relationsOut.put(new Long[]{tr1, tr2}, rel);
|
|
|
|
|
relationsIn.put(new Long[]{tr2, tr1}, rel);
|
|
|
|
|
} else if("scv_tr_stream".equals(tokens[0])){
|
|
|
|
|
Matcher matcher = scv_tr_stream.matcher(curLine);
|
|
|
|
|
if (matcher.matches()) {
|
|
|
|
|
|