SCViewer/com.minres.scviewer.databas.../src/com/minres/scviewer/database/text/Stream.groovy

87 lines
2.2 KiB
Groovy
Raw Normal View History

2012-06-17 20:34:50 +02:00
/*******************************************************************************
* Copyright (c) 2012 IT Just working.
* 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:
* IT Just working - initial API and implementation
*******************************************************************************/
package com.minres.scviewer.database.text
2012-06-17 19:53:05 +02:00
import java.beans.PropertyChangeListener;
import java.util.List;
import java.util.Map;
import com.minres.scviewer.database.ITrDb
import com.minres.scviewer.database.ITrGenerator
import com.minres.scviewer.database.ITrHierNode
import com.minres.scviewer.database.ITrStream
import com.minres.scviewer.database.ITransaction
2012-06-17 19:53:05 +02:00
class Stream extends HierNode implements ITrStream {
2015-01-01 23:17:32 +01:00
2012-06-17 19:53:05 +02:00
Long id;
2015-01-01 23:17:32 +01:00
TextDb database
2015-01-01 23:17:32 +01:00
2012-06-17 19:53:05 +02:00
String fullName;
2015-01-01 23:17:32 +01:00
2012-06-17 19:53:05 +02:00
String kind;
2015-01-01 23:17:32 +01:00
2012-06-17 19:53:05 +02:00
def generators = [];
2015-01-01 23:17:32 +01:00
private allTransactions;
2012-06-17 19:53:05 +02:00
public TrHierNode(String name){
this.name=name
}
2015-01-01 23:17:32 +01:00
Stream(int id, TextDb db, String name, String kind){
2012-06-17 19:53:05 +02:00
this.id=id
this.database=db
this.name=name
this.fullName=name
this.kind=kind
}
List<ITrGenerator> getGenerators(){
return generators as List<ITrGenerator>
}
@Override
public ITrDb getDb() {
return database;
}
// FIXME: maybe need to be somewhere else
2012-06-17 19:53:05 +02:00
public int getMaxConcurrrentTx() {
def rowendtime = [0]
getTransactions().each{Transaction tx ->
def rowIdx = 0
for(rowIdx=0; rowendtime.size()<rowIdx || rowendtime[rowIdx]>tx.beginTime.value; rowIdx++);
2015-01-01 23:17:32 +01:00
if(rowendtime.size<=rowIdx){
rowendtime<<tx.endTime?.value?:tx.beginTime.value+1
} else {
rowendtime[rowIdx]=tx.endTime?.value?:tx.beginTime.value+1
}
2012-06-17 19:53:05 +02:00
}
return rowendtime.size()
}
@Override
public List<ITransaction> getTransactions() {
if(!allTransactions)
allTransactions=generators.transactions.flatten().sort{it.beginTime.value}
return allTransactions
}
@Override
public ITransaction getTransactionById(long id) {
if(!allTransactions)
allTransactions=generators.transactions.flatten().sort{it.beginTime.value}
allTransactions.find{it.id==id}
}
2012-06-17 19:53:05 +02:00
}