2015-01-21 21:58:35 +01:00
|
|
|
/*******************************************************************************
|
2021-01-09 14:26:49 +01:00
|
|
|
* Copyright (c) 2015-2021 MINRES Technologies GmbH and others.
|
2015-01-21 21:58:35 +01:00
|
|
|
* All rights reserved. This program and the accompanying materials
|
|
|
|
* are made available under the terms of the Eclipse Public License v1.0
|
|
|
|
* which accompanies this distribution, and is available at
|
|
|
|
* http://www.eclipse.org/legal/epl-v10.html
|
|
|
|
*
|
|
|
|
* Contributors:
|
|
|
|
* MINRES Technologies GmbH - initial API and implementation
|
|
|
|
*******************************************************************************/
|
2015-01-03 16:34:32 +01:00
|
|
|
package com.minres.scviewer.database.sqlite;
|
|
|
|
|
|
|
|
import java.beans.IntrospectionException;
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2015-01-21 21:58:35 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.TreeMap;
|
2015-01-03 16:34:32 +01:00
|
|
|
|
2020-11-28 10:22:22 +01:00
|
|
|
import com.minres.scviewer.database.IEvent;
|
2015-10-22 00:02:58 +02:00
|
|
|
import com.minres.scviewer.database.IWaveform;
|
2015-01-10 00:23:46 +01:00
|
|
|
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
2015-01-03 16:34:32 +01:00
|
|
|
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;
|
2020-11-28 14:47:43 +01:00
|
|
|
import com.minres.scviewer.database.tx.ITx;
|
2015-01-03 16:34:32 +01:00
|
|
|
|
2021-01-09 10:34:22 +01:00
|
|
|
public class TxStream extends AbstractTxStream {
|
2015-01-10 00:23:46 +01:00
|
|
|
|
2015-01-03 16:34:32 +01:00
|
|
|
private String fullName;
|
2020-11-29 10:25:48 +01:00
|
|
|
|
2015-01-03 16:34:32 +01:00
|
|
|
private ScvStream scvStream;
|
2020-11-29 10:25:48 +01:00
|
|
|
|
2015-01-21 21:58:35 +01:00
|
|
|
private TreeMap<Integer, TxGenerator> generators;
|
2020-11-29 10:25:48 +01:00
|
|
|
|
2015-01-21 21:58:35 +01:00
|
|
|
private TreeMap<Integer, ITx> transactions;
|
2020-11-29 10:25:48 +01:00
|
|
|
|
2021-01-02 17:02:05 +01:00
|
|
|
public TxStream(IDatabase database, ScvStream scvStream) {
|
2021-01-09 10:34:22 +01:00
|
|
|
super(database, scvStream.getName(), scvStream.getId());
|
2015-01-03 16:34:32 +01:00
|
|
|
fullName=scvStream.getName();
|
|
|
|
this.scvStream=scvStream;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public String getFullName() {
|
|
|
|
return fullName;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Long getId() {
|
|
|
|
return (long) scvStream.getId();
|
|
|
|
}
|
|
|
|
|
2021-01-14 23:55:47 +01:00
|
|
|
public List<IWaveform> getGenerators() {
|
2015-01-03 16:34:32 +01:00
|
|
|
if(generators==null){
|
2020-11-29 10:25:48 +01:00
|
|
|
SQLiteDatabaseSelectHandler<ScvGenerator> handler = new SQLiteDatabaseSelectHandler<>(
|
2015-01-10 00:23:46 +01:00
|
|
|
ScvGenerator.class, database, "stream="+scvStream.getId());
|
2020-11-29 10:25:48 +01:00
|
|
|
generators=new TreeMap<>();
|
2015-01-03 16:34:32 +01:00
|
|
|
try {
|
|
|
|
for(ScvGenerator scvGenerator:handler.selectObjects()){
|
2021-01-09 10:34:22 +01:00
|
|
|
generators.put(scvGenerator.getId(), new TxGenerator(database, this, scvGenerator));
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
|
|
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
2021-02-18 07:32:14 +01:00
|
|
|
| InvocationTargetException | SQLException | IntrospectionException | NoSuchMethodException e) {
|
2015-01-03 16:34:32 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2020-11-29 10:25:48 +01:00
|
|
|
return new ArrayList<>(generators.values());
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
|
|
|
|
2015-01-21 21:58:35 +01:00
|
|
|
protected Map<Integer, ITx> getTransactions() {
|
2015-01-03 16:34:32 +01:00
|
|
|
if(transactions==null){
|
|
|
|
if(generators==null) getGenerators();
|
2020-11-29 10:25:48 +01:00
|
|
|
transactions = new TreeMap<>();
|
|
|
|
SQLiteDatabaseSelectHandler<ScvTx> handler = new SQLiteDatabaseSelectHandler<>(ScvTx.class, database,
|
2015-01-03 16:34:32 +01:00
|
|
|
"stream="+scvStream.getId());
|
|
|
|
try {
|
|
|
|
for(ScvTx scvTx:handler.selectObjects()){
|
2015-01-20 18:50:15 +01:00
|
|
|
transactions.put(scvTx.getId(), new Tx(database, this, generators.get(scvTx.getGenerator()), scvTx));
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
|
|
|
} catch (SecurityException | IllegalArgumentException | InstantiationException | IllegalAccessException
|
2021-02-18 07:32:14 +01:00
|
|
|
| InvocationTargetException | SQLException | IntrospectionException | NoSuchMethodException e) {
|
2015-01-03 16:34:32 +01:00
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
2015-01-20 18:50:15 +01:00
|
|
|
return transactions;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-11-28 10:22:22 +01:00
|
|
|
public IEvent[] getEventsAtTime(Long time) {
|
2015-01-20 18:50:15 +01:00
|
|
|
return getEvents().get(time);
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|
|
|
|
|
2015-10-22 00:02:58 +02:00
|
|
|
@Override
|
2020-11-29 10:25:48 +01:00
|
|
|
public boolean isSame(IWaveform other) {
|
2020-03-13 16:01:16 +01:00
|
|
|
return(other instanceof TxStream && this.getId().equals(other.getId()));
|
2015-10-22 00:02:58 +02:00
|
|
|
}
|
|
|
|
|
2020-11-28 10:22:22 +01:00
|
|
|
@Override
|
2021-01-09 10:34:22 +01:00
|
|
|
public String getKind() {
|
|
|
|
return scvStream.getKind();
|
2020-11-28 10:22:22 +01:00
|
|
|
}
|
2015-01-03 16:34:32 +01:00
|
|
|
}
|