blob: 74eb244e6989bec3559c3d39a5110573c11e0d3b [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004-2010 Abel Hegedus and Daniel Varro
* 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:
* Abel Hegedus - initial API and implementation
*******************************************************************************/
package org.eclipse.viatra2.core.tracebased.tracetree;
import org.eclipse.viatra2.core.notification.ICoreNotificationObject;
/**
* @author Abel Hegedus
*
*/
public class TransactionTraceTreeNode extends CompositeTraceTreeNode {
/**
* How deep the transaction is in the hierarchy of subtransactions
*/
private int level = 0;
private boolean subTransaction = false;
private boolean aborted = false;
private boolean undoable = false;
private boolean committed = false;
public TransactionTraceTreeNode(ITraceTreeNode parent, String id,
ICoreNotificationObject startEvent, boolean lowerThanParent, boolean undoable) {
this(parent, id, startEvent, lowerThanParent);
this.undoable = undoable;
}
/**
* @param parent
* @param id
* @param startEvent
*/
public TransactionTraceTreeNode(ITraceTreeNode parent, String id,
ICoreNotificationObject startEvent, boolean lowerThanParent) {
super(parent, id, startEvent);
if(parent instanceof TransactionTraceTreeNode){
// subtransaction level is based on the parent
level = ((TransactionTraceTreeNode) parent).getLevel();
if(lowerThanParent){
// inner subtransaction
level++;
} else{
// exit from subtransaction
if(level > 0){
level--;
}
committed = true;
}
if(level > 0 ){
subTransaction = true;
}
}
}
/**
* How deep the transaction is in the hierarchy of subtransactions
*
* @return the level
*/
public int getLevel() {
return level;
}
/**
* @return the subTransaction
*/
public boolean isSubTransaction() {
return subTransaction;
}
/**
* @param aborted the aborted to set
*/
public void setAborted(boolean aborted) {
this.aborted = aborted;
}
/**
* @return the aborted
*/
public boolean isAborted() {
return aborted;
}
/* (non-Javadoc)
* @see org.eclipse.viatra2.trace.trace.CompositeTraceTreeNode#toString()
*/
@Override
public String toString() {
String superString = super.toString();
StringBuilder sb = new StringBuilder();
sb.append(superString);
if(subTransaction){
sb.append("; SubTr - ");
sb.append(level);
}
if(aborted) {
sb.append("; Aborted");
} else if(committed) {
sb.append("; Committed");
}
return sb.toString();
}
/**
* @return the undoable
*/
public boolean isUndoable() {
return undoable;
}
/**
* @return the committed
*/
public boolean isCommitted() {
return committed;
}
/**
* @param committed the committed to set
*/
public void setCommitted(boolean committed) {
this.committed = committed;
}
}