Fixed Tx properties
This commit is contained in:
parent
2a709113fe
commit
e687eef42c
|
@ -13,7 +13,7 @@ package com.minres.scviewer.database.leveldb;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import org.iq80.leveldb.impl.SeekingIterator;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
@ -27,20 +27,22 @@ import com.minres.scviewer.database.ITxStream;
|
||||||
|
|
||||||
public class Tx implements ITx {
|
public class Tx implements ITx {
|
||||||
|
|
||||||
private StringDBWrapper levelDb;
|
private TxDBWrapper levelDb;
|
||||||
private TxStream trStream;
|
private TxStream trStream;
|
||||||
private TxGenerator trGenerator;
|
private TxGenerator trGenerator;
|
||||||
private long id;
|
private long id;
|
||||||
private JSONObject dbVal;
|
private long start_time=0;
|
||||||
|
private long end_time=0;
|
||||||
|
private int concurency_index;
|
||||||
|
private boolean initialized=false;
|
||||||
private List<ITxAttribute> attributes;
|
private List<ITxAttribute> attributes;
|
||||||
private List<ITxRelation> incoming, outgoing;
|
private List<ITxRelation> incoming, outgoing;
|
||||||
|
|
||||||
public Tx(StringDBWrapper levelDb, TxStream trStream, TxGenerator trGenerator, long id) {
|
public Tx(TxDBWrapper levelDb, TxStream trStream, TxGenerator trGenerator, long id) {
|
||||||
this.levelDb=levelDb;
|
this.levelDb=levelDb;
|
||||||
this.trStream=trStream;
|
this.trStream=trStream;
|
||||||
this.trGenerator=trGenerator;
|
this.trGenerator=trGenerator;
|
||||||
this.id=id;
|
this.id=id;
|
||||||
this.dbVal=null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -60,49 +62,65 @@ public class Tx implements ITx {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getConcurrencyIndex() {
|
public int getConcurrencyIndex() {
|
||||||
checkDb();
|
if(!initialized) loadFromDb();
|
||||||
return dbVal.getInt("conc");
|
return concurency_index;
|
||||||
}
|
|
||||||
|
|
||||||
private void checkDb() throws JSONException {
|
|
||||||
if(dbVal==null) {
|
|
||||||
dbVal = new JSONObject(levelDb.get("x~"+ String.format("%016x", id)));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getBeginTime() {
|
public Long getBeginTime() {
|
||||||
checkDb();
|
if(!initialized) loadFromDb();
|
||||||
return dbVal.getLong("START_TIME");
|
return start_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Long getEndTime() {
|
public Long getEndTime() {
|
||||||
checkDb();
|
loadFromDb();
|
||||||
return dbVal.getLong("END_TIME");
|
return end_time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<ITxAttribute> getAttributes() {
|
public List<ITxAttribute> getAttributes() {
|
||||||
if(attributes==null) {
|
if(attributes==null) {
|
||||||
checkDb();
|
loadFromDb();
|
||||||
attributes=new ArrayList<>();
|
|
||||||
JSONArray arr = dbVal.getJSONArray("attr");
|
|
||||||
arr.forEach(entry -> {
|
|
||||||
TxAttribute attr = new TxAttribute(this, (JSONObject) entry);
|
|
||||||
attributes.add(attr);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ITxRelation> getIncomingRelations() {
|
public Collection<ITxRelation> getIncomingRelations() {
|
||||||
|
if(incoming==null) {
|
||||||
|
incoming = new ArrayList<ITxRelation>();
|
||||||
|
SeekingIterator<String, String> it = levelDb.iterator();
|
||||||
|
String key = "ri~"+String.format("%016x", id);
|
||||||
|
it.seek(key);
|
||||||
|
while(it.hasNext()) {
|
||||||
|
String val = it.next().getKey();
|
||||||
|
if(!val.startsWith(key)) break;;
|
||||||
|
String[] token = val.split("~");
|
||||||
|
long otherId = Long.parseLong(token[2], 16);
|
||||||
|
incoming.add(createRelation(otherId, token[3], false));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return incoming;
|
return incoming;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Collection<ITxRelation> getOutgoingRelations() {
|
public Collection<ITxRelation> getOutgoingRelations() {
|
||||||
|
if(outgoing==null) {
|
||||||
|
outgoing = new ArrayList<ITxRelation>();
|
||||||
|
SeekingIterator<String, String> it = levelDb.iterator();
|
||||||
|
String key="ro~"+String.format("%016x", id);
|
||||||
|
it.seek(key);
|
||||||
|
while(it.hasNext()) {
|
||||||
|
String val = it.next().getKey();
|
||||||
|
if(!val.startsWith(key)) break;
|
||||||
|
String[] token = val.split("~");
|
||||||
|
long otherId = Long.parseLong(token[2], 16);
|
||||||
|
outgoing.add(createRelation(otherId, token[3], true));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
return outgoing;
|
return outgoing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -119,4 +137,36 @@ public class Tx implements ITx {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "tx#"+getId()+"["+getBeginTime()/1000000+"ns - "+getEndTime()/1000000+"ns]";
|
return "tx#"+getId()+"["+getBeginTime()/1000000+"ns - "+getEndTime()/1000000+"ns]";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void loadFromDb() throws JSONException {
|
||||||
|
JSONObject dbVal = new JSONObject(levelDb.get("x~"+ String.format("%016x", id)));
|
||||||
|
start_time=dbVal.getLong("START_TIME") * levelDb.getTimeResolution();
|
||||||
|
end_time=dbVal.getLong("END_TIME") * levelDb.getTimeResolution();
|
||||||
|
concurency_index=dbVal.getInt("conc");
|
||||||
|
attributes=new ArrayList<>();
|
||||||
|
JSONArray arr = dbVal.getJSONArray("attr");
|
||||||
|
arr.forEach(entry -> {
|
||||||
|
TxAttribute attr = new TxAttribute(this, (JSONObject) entry);
|
||||||
|
attributes.add(attr);
|
||||||
|
});
|
||||||
|
initialized=true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private ITxRelation createRelation(long otherId, String name, boolean outgoing) {
|
||||||
|
try {
|
||||||
|
JSONObject otherTxVal = new JSONObject(levelDb.get("x~"+ String.format("%016x", otherId)));
|
||||||
|
if(otherTxVal.isEmpty()) return null;
|
||||||
|
JSONObject otherStreamVal = new JSONObject(levelDb.get("s~"+ String.format("%016x", otherTxVal.getLong("s"))));
|
||||||
|
if(otherStreamVal.isEmpty()) return null;
|
||||||
|
TxStream tgtStream = (TxStream) trStream.getDb().getStreamByName(otherStreamVal.getString("name"));
|
||||||
|
Tx that = (Tx) tgtStream.getTransactions().get(otherId);
|
||||||
|
return outgoing?
|
||||||
|
new TxRelation(trStream.getRelationType(name), this, that):
|
||||||
|
new TxRelation(trStream.getRelationType(name), that, this);
|
||||||
|
} catch (SecurityException | IllegalArgumentException | JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue