Added support for VCD Database
This commit is contained in:
@@ -1,52 +0,0 @@
|
||||
package com.minres.scviewer.database.sqlite;
|
||||
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.ITrHierNode;
|
||||
|
||||
public class HierNode implements ITrHierNode {
|
||||
|
||||
protected String name;
|
||||
|
||||
protected ArrayList<ITrHierNode> childs;
|
||||
|
||||
public HierNode(String name) {
|
||||
this.name=name;
|
||||
childs = new ArrayList<ITrHierNode>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addPropertyChangeListener(PropertyChangeListener l) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePropertyChangeListener(PropertyChangeListener l) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getFullName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String name) {
|
||||
this.name=name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITrHierNode> getChildNodes() {
|
||||
return childs;
|
||||
}
|
||||
|
||||
}
|
@@ -9,23 +9,25 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.EventTime;
|
||||
import com.minres.scviewer.database.ITrAttribute;
|
||||
import com.minres.scviewer.database.ITrDb;
|
||||
import com.minres.scviewer.database.ITrHierNode;
|
||||
import com.minres.scviewer.database.ITrStream;
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IHierNode;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.IWaveform;
|
||||
import com.minres.scviewer.database.InputFormatException;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
||||
import com.minres.scviewer.database.sqlite.db.SQLiteDatabase;
|
||||
import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvSimProps;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvStream;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTxEvent;
|
||||
|
||||
public class SQLiteDb extends HierNode implements ITrDb {
|
||||
public class SQLiteDb extends HierNode implements IWaveformDb {
|
||||
|
||||
protected IDatabase database;
|
||||
|
||||
protected List<ITrStream> streams;
|
||||
protected List<IWaveform> streams;
|
||||
|
||||
long timeResolution=1;
|
||||
|
||||
@@ -55,13 +57,13 @@ public class SQLiteDb extends HierNode implements ITrDb {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITrStream> getAllStreams() {
|
||||
public List<IWaveform> getAllWaves() {
|
||||
if(streams==null){
|
||||
SQLiteDatabaseSelectHandler<ScvStream> handler = new SQLiteDatabaseSelectHandler<ScvStream>(ScvStream.class, database);
|
||||
streams=new ArrayList<ITrStream>();
|
||||
streams=new ArrayList<IWaveform>();
|
||||
try {
|
||||
for(ScvStream scvStream:handler.selectObjects()){
|
||||
streams.add(new Stream(this, scvStream));
|
||||
streams.add(new TxStream(this, scvStream));
|
||||
}
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
@@ -83,7 +85,7 @@ public class SQLiteDb extends HierNode implements ITrDb {
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
addHierarchyNodes();
|
||||
buildHierarchyNodes();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -92,31 +94,27 @@ public class SQLiteDb extends HierNode implements ITrDb {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITrStream getStreamByName(String name) {
|
||||
for (ITrStream n : getAllStreams()) {
|
||||
if (n.getName().equals(name)) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
public IWaveform getStreamByName(String name) {
|
||||
for (IWaveform n : getAllWaves())
|
||||
if (n.getName().equals(name))
|
||||
return n;
|
||||
return null;
|
||||
}
|
||||
|
||||
public ITrStream getStreamById(long id) {
|
||||
for (ITrStream n : getAllStreams()) {
|
||||
if (n.getId().equals(id)) {
|
||||
return n;
|
||||
}
|
||||
}
|
||||
public ITxStream getStreamById(long id) {
|
||||
for (IWaveform n : getAllWaves())
|
||||
if (n.getId().equals(id))
|
||||
return (ITxStream) n;
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addHierarchyNodes() throws InputFormatException{
|
||||
for(ITrStream stream:getAllStreams()){
|
||||
private void buildHierarchyNodes() throws InputFormatException{
|
||||
for(IWaveform stream:getAllWaves()){
|
||||
String[] hier = stream.getFullName().split("\\./");
|
||||
ITrHierNode node = this;
|
||||
IHierNode node = this;
|
||||
for(String name:hier){
|
||||
ITrHierNode n1 = null;
|
||||
for (ITrHierNode n : node.getChildNodes()) {
|
||||
IHierNode n1 = null;
|
||||
for (IHierNode n : node.getChildNodes()) {
|
||||
if (n.getName().equals(name)) {
|
||||
n1=n;
|
||||
break;
|
||||
|
@@ -3,10 +3,10 @@ package com.minres.scviewer.database.sqlite;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
|
||||
import com.minres.scviewer.database.ITrDb;
|
||||
import com.minres.scviewer.database.ITransactionDbFactory;
|
||||
import com.minres.scviewer.database.IWaveformDb;
|
||||
import com.minres.scviewer.database.IWaveformDbFactory;
|
||||
|
||||
public class SQLiteDbFactory implements ITransactionDbFactory {
|
||||
public class SQLiteDbFactory implements IWaveformDbFactory {
|
||||
|
||||
private byte[] x = "SQLite format 3".getBytes();
|
||||
|
||||
@@ -14,7 +14,7 @@ public class SQLiteDbFactory implements ITransactionDbFactory {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITrDb createDatabase(File file) {
|
||||
public IWaveformDb createDatabase(File file) {
|
||||
try {
|
||||
FileInputStream fis = new FileInputStream(file);
|
||||
byte[] buffer = new byte[x.length];
|
||||
|
@@ -9,27 +9,27 @@ import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.EventTime;
|
||||
import com.minres.scviewer.database.ITrAttribute;
|
||||
import com.minres.scviewer.database.ITrGenerator;
|
||||
import com.minres.scviewer.database.ITrRelation;
|
||||
import com.minres.scviewer.database.ITrStream;
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxRelation;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTx;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTxAttribute;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTxEvent;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTxRelation;
|
||||
|
||||
public class Transaction implements ITransaction {
|
||||
public class Tx implements ITx {
|
||||
|
||||
private Stream trStream;
|
||||
private Generator trGenerator;
|
||||
private TxStream trStream;
|
||||
private TxGenerator trGenerator;
|
||||
private ScvTx scvTx;
|
||||
private List<ITrAttribute> attributes;
|
||||
private List<ITxAttribute> attributes;
|
||||
private EventTime begin, end;
|
||||
private List<ITrRelation> incoming, outgoing;
|
||||
private List<ITxRelation> incoming, outgoing;
|
||||
|
||||
public Transaction(Stream trStream, Generator trGenerator, ScvTx scvTx) {
|
||||
public Tx(TxStream trStream, TxGenerator trGenerator, ScvTx scvTx) {
|
||||
this.trStream=trStream;
|
||||
this.trGenerator=trGenerator;
|
||||
this.scvTx=scvTx;
|
||||
@@ -41,12 +41,12 @@ public class Transaction implements ITransaction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITrStream getStream() {
|
||||
public ITxStream getStream() {
|
||||
return trStream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITrGenerator getGenerator() {
|
||||
public ITxGenerator getGenerator() {
|
||||
return trGenerator;
|
||||
}
|
||||
|
||||
@@ -83,14 +83,14 @@ public class Transaction implements ITransaction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITrAttribute> getAttributes() {
|
||||
public List<ITxAttribute> getAttributes() {
|
||||
if(attributes==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxAttribute> handler = new SQLiteDatabaseSelectHandler<ScvTxAttribute>(
|
||||
ScvTxAttribute.class, trStream.getDb().getDb(), "tx="+scvTx.getId());
|
||||
try {
|
||||
attributes = new ArrayList<ITrAttribute>();
|
||||
attributes = new ArrayList<ITxAttribute>();
|
||||
for(ScvTxAttribute scvAttribute:handler.selectObjects()){
|
||||
attributes.add(new Attribute(this, scvAttribute));
|
||||
attributes.add(new TxAttribute(this, scvAttribute));
|
||||
|
||||
}
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
@@ -101,12 +101,12 @@ public class Transaction implements ITransaction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITrRelation> getIncomingRelations() {
|
||||
public Collection<ITxRelation> getIncomingRelations() {
|
||||
if(incoming==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<ScvTxRelation>(
|
||||
ScvTxRelation.class, trStream.getDb().getDb(), "sink="+scvTx.getId());
|
||||
try {
|
||||
incoming = new ArrayList<ITrRelation>();
|
||||
incoming = new ArrayList<ITxRelation>();
|
||||
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
||||
incoming.add(createRelation(scvRelation, false));
|
||||
}
|
||||
@@ -118,12 +118,12 @@ public class Transaction implements ITransaction {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<ITrRelation> getOutgoingRelations() {
|
||||
public Collection<ITxRelation> getOutgoingRelations() {
|
||||
if(outgoing==null){
|
||||
SQLiteDatabaseSelectHandler<ScvTxRelation> handler = new SQLiteDatabaseSelectHandler<ScvTxRelation>(
|
||||
ScvTxRelation.class, trStream.getDb().getDb(), "src="+scvTx.getId());
|
||||
try {
|
||||
outgoing = new ArrayList<ITrRelation>();
|
||||
outgoing = new ArrayList<ITxRelation>();
|
||||
for(ScvTxRelation scvRelation:handler.selectObjects()){
|
||||
outgoing.add(createRelation(scvRelation, true));
|
||||
}
|
||||
@@ -134,17 +134,17 @@ public class Transaction implements ITransaction {
|
||||
return outgoing;
|
||||
}
|
||||
|
||||
private ITrRelation createRelation(ScvTxRelation rel, boolean outgoing) {
|
||||
private ITxRelation createRelation(ScvTxRelation rel, boolean outgoing) {
|
||||
long otherId = outgoing?rel.getSink():rel.getSrc();
|
||||
try {
|
||||
List<ScvTx> scvTx=new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, trStream.getDb().getDb(), "id="+otherId).selectObjects();
|
||||
assert(scvTx.size()==1);
|
||||
ITrStream stream = trStream.getDb().getStreamById(scvTx.get(0).getStream());
|
||||
Transaction that=(Transaction) stream.getTransactionById(otherId);
|
||||
ITxStream stream = trStream.getDb().getStreamById(scvTx.get(0).getStream());
|
||||
Tx that=(Tx) stream.getTransactionById(otherId);
|
||||
if(outgoing)
|
||||
return new Relation(trStream.getDb().getRelationType(rel.getName()), this, that);
|
||||
return new TxRelation(trStream.getDb().getRelationType(rel.getName()), this, that);
|
||||
else
|
||||
return new Relation(trStream.getDb().getRelationType(rel.getName()), that, this);
|
||||
return new TxRelation(trStream.getDb().getRelationType(rel.getName()), that, this);
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
}
|
@@ -2,15 +2,15 @@ package com.minres.scviewer.database.sqlite;
|
||||
|
||||
import com.minres.scviewer.database.AssociationType;
|
||||
import com.minres.scviewer.database.DataType;
|
||||
import com.minres.scviewer.database.ITrAttribute;
|
||||
import com.minres.scviewer.database.ITxAttribute;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTxAttribute;
|
||||
|
||||
public class Attribute implements ITrAttribute{
|
||||
public class TxAttribute implements ITxAttribute{
|
||||
|
||||
Transaction trTransaction;
|
||||
Tx trTransaction;
|
||||
ScvTxAttribute scvAttribute;
|
||||
|
||||
public Attribute(Transaction trTransaction, ScvTxAttribute scvAttribute) {
|
||||
public TxAttribute(Tx trTransaction, ScvTxAttribute scvAttribute) {
|
||||
this.trTransaction=trTransaction;
|
||||
this.scvAttribute=scvAttribute;
|
||||
}
|
@@ -2,16 +2,16 @@ package com.minres.scviewer.database.sqlite;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.ITrGenerator;
|
||||
import com.minres.scviewer.database.ITrStream;
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvGenerator;
|
||||
|
||||
public class Generator implements ITrGenerator {
|
||||
public class TxGenerator implements ITxGenerator {
|
||||
|
||||
private ITrStream stream;
|
||||
private ITxStream stream;
|
||||
private ScvGenerator scvGenerator;
|
||||
public Generator(ITrStream stream, ScvGenerator scvGenerator) {
|
||||
public TxGenerator(ITxStream stream, ScvGenerator scvGenerator) {
|
||||
this.stream=stream;
|
||||
this.scvGenerator=scvGenerator;
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class Generator implements ITrGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITrStream getStream() {
|
||||
public ITxStream getStream() {
|
||||
return stream;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ public class Generator implements ITrGenerator {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITransaction> getTransactions() {
|
||||
public List<ITx> getTransactions() {
|
||||
return null;
|
||||
}
|
||||
|
@@ -1,15 +1,15 @@
|
||||
package com.minres.scviewer.database.sqlite;
|
||||
|
||||
import com.minres.scviewer.database.ITrRelation;
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
import com.minres.scviewer.database.ITxRelation;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.RelationType;
|
||||
|
||||
public class Relation implements ITrRelation {
|
||||
public class TxRelation implements ITxRelation {
|
||||
|
||||
RelationType relationType;
|
||||
Transaction source, target;
|
||||
Tx source, target;
|
||||
|
||||
public Relation(RelationType relationType, Transaction source, Transaction target) {
|
||||
public TxRelation(RelationType relationType, Tx source, Tx target) {
|
||||
this.source = source;
|
||||
this.target = target;
|
||||
this.relationType = relationType;
|
||||
@@ -21,12 +21,12 @@ public class Relation implements ITrRelation {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITransaction getSource() {
|
||||
public ITx getSource() {
|
||||
return source;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITransaction getTarget() {
|
||||
public ITx getTarget() {
|
||||
return target;
|
||||
}
|
||||
|
@@ -4,29 +4,31 @@ import java.beans.IntrospectionException;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.minres.scviewer.database.ITrDb;
|
||||
import com.minres.scviewer.database.ITrGenerator;
|
||||
import com.minres.scviewer.database.ITrStream;
|
||||
import com.minres.scviewer.database.ITransaction;
|
||||
import com.minres.scviewer.database.HierNode;
|
||||
import com.minres.scviewer.database.ITxGenerator;
|
||||
import com.minres.scviewer.database.ITxStream;
|
||||
import com.minres.scviewer.database.ITx;
|
||||
import com.minres.scviewer.database.sqlite.db.SQLiteDatabaseSelectHandler;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvGenerator;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvStream;
|
||||
import com.minres.scviewer.database.sqlite.tables.ScvTx;
|
||||
|
||||
public class Stream extends HierNode implements ITrStream {
|
||||
public class TxStream extends HierNode implements ITxStream {
|
||||
|
||||
private String fullName;
|
||||
|
||||
private SQLiteDb db;
|
||||
|
||||
private ScvStream scvStream;
|
||||
private HashMap<Integer, Generator> generators;
|
||||
|
||||
private List<ITransaction> transactions;
|
||||
private HashMap<Integer, TxGenerator> generators;
|
||||
|
||||
public Stream(SQLiteDb trSQLiteDb, ScvStream scvStream) {
|
||||
private List<ITx> transactions;
|
||||
|
||||
public TxStream(SQLiteDb trSQLiteDb, ScvStream scvStream) {
|
||||
super(scvStream.getName());
|
||||
fullName=scvStream.getName();
|
||||
this.scvStream=scvStream;
|
||||
@@ -54,33 +56,33 @@ public class Stream extends HierNode implements ITrStream {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITrGenerator> getGenerators() {
|
||||
public List<ITxGenerator> getGenerators() {
|
||||
if(generators==null){
|
||||
SQLiteDatabaseSelectHandler<ScvGenerator> handler = new SQLiteDatabaseSelectHandler<ScvGenerator>(
|
||||
ScvGenerator.class, db.getDb(), "stream="+scvStream.getId());
|
||||
generators=new HashMap<Integer, Generator>();
|
||||
generators=new HashMap<Integer, TxGenerator>();
|
||||
try {
|
||||
for(ScvGenerator scvGenerator:handler.selectObjects()){
|
||||
generators.put(scvGenerator.getId(), new Generator(this, scvGenerator));
|
||||
generators.put(scvGenerator.getId(), new TxGenerator(this, scvGenerator));
|
||||
}
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return new ArrayList<ITrGenerator>(generators.values());
|
||||
return new ArrayList<ITxGenerator>(generators.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ITransaction> getTransactions() {
|
||||
public List<ITx> getTransactions() {
|
||||
checkTransactions();
|
||||
return transactions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITransaction getTransactionById(long id) {
|
||||
public ITx getTransactionById(long id) {
|
||||
checkTransactions();
|
||||
for(ITransaction trans:transactions){
|
||||
for(ITx trans:transactions){
|
||||
if(trans.getId()==id)
|
||||
return trans;
|
||||
}
|
||||
@@ -92,10 +94,10 @@ public class Stream extends HierNode implements ITrStream {
|
||||
if(generators==null) getGenerators();
|
||||
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<ScvTx>(ScvTx.class, db.getDb(),
|
||||
"stream="+scvStream.getId());
|
||||
transactions=new ArrayList<ITransaction>();
|
||||
transactions=new ArrayList<ITx>();
|
||||
try {
|
||||
for(ScvTx scvTx:handler.selectObjects()){
|
||||
transactions.add(new Transaction(this, generators.get(scvTx.getGenerator()), scvTx));
|
||||
transactions.add(new Tx(this, generators.get(scvTx.getGenerator()), scvTx));
|
||||
}
|
||||
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
||||
| InvocationTargetException | SQLException | IntrospectionException e) {
|
@@ -1,4 +1,4 @@
|
||||
package com.minres.scviewer.database.sqlite;
|
||||
package com.minres.scviewer.database.sqlite.db;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.DriverManager;
|
||||
@@ -7,8 +7,6 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
|
||||
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
||||
|
||||
public class SQLiteDatabase implements IDatabase {
|
||||
|
||||
protected String dbFileName;
|
Reference in New Issue
Block a user