2021-01-09 10:34:22 +01:00
|
|
|
/*******************************************************************************
|
2021-01-09 14:26:49 +01:00
|
|
|
* Copyright (c) 2015-2021 MINRES Technologies GmbH and others.
|
2021-01-09 10:34:22 +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
|
|
|
|
*******************************************************************************/
|
|
|
|
package com.minres.scviewer.database.sqlite;
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map.Entry;
|
|
|
|
|
2021-02-27 13:26:07 +01:00
|
|
|
import com.minres.scviewer.database.EventEntry;
|
2021-01-09 10:34:22 +01:00
|
|
|
import com.minres.scviewer.database.EventKind;
|
|
|
|
import com.minres.scviewer.database.HierNode;
|
|
|
|
import com.minres.scviewer.database.IEvent;
|
2021-02-26 12:57:54 +01:00
|
|
|
import com.minres.scviewer.database.IEventList;
|
|
|
|
import com.minres.scviewer.database.EventList;
|
2021-01-09 10:34:22 +01:00
|
|
|
import com.minres.scviewer.database.IWaveform;
|
|
|
|
import com.minres.scviewer.database.RelationType;
|
|
|
|
import com.minres.scviewer.database.RelationTypeFactory;
|
|
|
|
import com.minres.scviewer.database.WaveformType;
|
|
|
|
import com.minres.scviewer.database.sqlite.db.IDatabase;
|
|
|
|
import com.minres.scviewer.database.tx.ITx;
|
|
|
|
|
|
|
|
abstract class AbstractTxStream extends HierNode implements IWaveform {
|
|
|
|
|
|
|
|
protected IDatabase database;
|
|
|
|
|
|
|
|
private long streamId;
|
|
|
|
|
|
|
|
private Integer maxConcurrency;
|
|
|
|
|
2021-02-27 13:26:07 +01:00
|
|
|
private IEventList events;
|
2021-01-09 10:34:22 +01:00
|
|
|
|
|
|
|
private List<RelationType> usedRelationsList;
|
|
|
|
|
2021-01-14 23:36:07 +01:00
|
|
|
protected AbstractTxStream(IDatabase database, String name, long streamId) {
|
2021-01-09 10:34:22 +01:00
|
|
|
super(name);
|
|
|
|
this.database=database;
|
|
|
|
this.streamId=streamId;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-01-14 23:13:11 +01:00
|
|
|
public int getRowCount() {
|
2021-01-09 10:34:22 +01:00
|
|
|
if(maxConcurrency==null){
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
sb.append("SELECT MAX(concurrencyLevel) as concurrencyLevel FROM ScvTx where stream=");
|
|
|
|
sb.append(streamId);
|
|
|
|
try(
|
|
|
|
java.sql.Connection connection = database.createConnection();
|
|
|
|
java.sql.Statement statement = connection.createStatement();
|
|
|
|
java.sql.ResultSet resultSet = statement.executeQuery(sb.toString());
|
|
|
|
) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
if(maxConcurrency==null) maxConcurrency=0;
|
|
|
|
Object value = resultSet.getObject("concurrencyLevel");
|
|
|
|
if(value!=null)
|
|
|
|
maxConcurrency=(Integer) value;
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
if(maxConcurrency==null) maxConcurrency=0;
|
|
|
|
}
|
|
|
|
maxConcurrency+=1;
|
|
|
|
}
|
|
|
|
return maxConcurrency;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 13:26:07 +01:00
|
|
|
public IEventList getEvents(){
|
2021-01-09 10:34:22 +01:00
|
|
|
if(events==null){
|
2021-02-27 13:26:07 +01:00
|
|
|
events=new EventList();
|
2021-01-09 10:34:22 +01:00
|
|
|
for(Entry<Integer, ITx> entry:getTransactions().entrySet()){
|
|
|
|
putEvent(new TxEvent(EventKind.BEGIN, entry.getValue()));
|
|
|
|
putEvent(new TxEvent(EventKind.END, entry.getValue()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
|
|
|
private void putEvent(TxEvent ev){
|
2021-02-27 14:47:37 +01:00
|
|
|
events.put(ev.getTime(), ev);
|
2021-01-09 10:34:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected abstract Map<Integer, ITx> getTransactions();
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 14:59:00 +01:00
|
|
|
public IEvent[] getEventsAtTime(long time) {
|
2021-01-09 10:34:22 +01:00
|
|
|
return getEvents().get(time);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setRelationTypeList(List<RelationType> usedRelationsList){
|
|
|
|
this.usedRelationsList=usedRelationsList;
|
|
|
|
}
|
|
|
|
|
|
|
|
public RelationType getRelationType(String name) {
|
|
|
|
RelationType relType=RelationTypeFactory.create(name);
|
|
|
|
if(!usedRelationsList.contains(relType)) usedRelationsList.add(relType);
|
|
|
|
return relType;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-02-27 14:59:00 +01:00
|
|
|
public IEvent[] getEventsBeforeTime(long time) {
|
2021-02-27 13:26:07 +01:00
|
|
|
EventEntry e = events.floorEntry(time);
|
2021-01-09 10:34:22 +01:00
|
|
|
if(e==null)
|
|
|
|
return new IEvent[]{};
|
|
|
|
else
|
2021-02-27 13:26:07 +01:00
|
|
|
return events.floorEntry(time).events;
|
2021-01-09 10:34:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public WaveformType getType() {
|
|
|
|
return WaveformType.TRANSACTION;
|
|
|
|
}
|
|
|
|
|
2021-01-14 23:13:11 +01:00
|
|
|
/**
|
|
|
|
* Calculate concurrency.
|
|
|
|
*/
|
|
|
|
public void calculateConcurrency() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-09 10:34:22 +01:00
|
|
|
}
|