use of org.drools.core.common.TupleSetsImpl in project drools by kiegroup.
the class AddRemoveRule method flushLeftTupleIfNecessary.
public static boolean flushLeftTupleIfNecessary(InternalWorkingMemory wm, SegmentMemory sm, LeftTuple leftTuple, boolean streamMode, short stagedType) {
PathMemory pmem = streamMode ? sm.getPathMemories().get(0) : sm.getFirstDataDrivenPathMemory();
if (pmem == null) {
return false;
}
TupleSets<LeftTuple> leftTupleSets = new TupleSetsImpl<LeftTuple>();
if (leftTuple != null) {
switch(stagedType) {
case Tuple.INSERT:
leftTupleSets.addInsert(leftTuple);
break;
case Tuple.DELETE:
leftTupleSets.addDelete(leftTuple);
break;
case Tuple.UPDATE:
leftTupleSets.addUpdate(leftTuple);
break;
}
}
forceFlushLeftTuple(pmem, sm, wm, leftTupleSets);
if (pmem.isDataDriven() && pmem.getNodeType() == NodeTypeEnums.RightInputAdaterNode) {
for (PathEndNode pnode : pmem.getPathEndNode().getPathEndNodes()) {
if (pnode instanceof TerminalNode) {
PathMemory outPmem = wm.getNodeMemory((TerminalNode) pnode);
if (outPmem.isDataDriven()) {
SegmentMemory outSmem = outPmem.getSegmentMemories()[0];
if (outSmem != null) {
forceFlushLeftTuple(outPmem, outSmem, wm, new TupleSetsImpl<LeftTuple>());
}
}
}
}
}
return true;
}
use of org.drools.core.common.TupleSetsImpl in project drools by kiegroup.
the class PhreakAccumulateNode method doNode.
public void doNode(AccumulateNode accNode, LeftTupleSink sink, AccumulateMemory am, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
BetaMemory bm = am.getBetaMemory();
TupleSets<RightTuple> srcRightTuples = bm.getStagedRightTuples().takeAll();
// order of left and right operations is to minimise wasted of innefficient joins.
// We need to collect which leftTuple where updated, so that we can
// add their result tuple to the real target tuples later
TupleSets<LeftTuple> tempLeftTuples = new TupleSetsImpl<LeftTuple>();
if (srcLeftTuples.getDeleteFirst() != null) {
// use the real target here, as dealing direct with left tuples
doLeftDeletes(accNode, am, wm, srcLeftTuples, trgLeftTuples, stagedLeftTuples);
}
if (srcRightTuples.getDeleteFirst() != null) {
doRightDeletes(accNode, am, wm, srcRightTuples, tempLeftTuples);
}
if (srcRightTuples.getUpdateFirst() != null) {
RuleNetworkEvaluator.doUpdatesReorderRightMemory(bm, srcRightTuples);
doRightUpdates(accNode, am, wm, srcRightTuples, tempLeftTuples);
}
if (srcLeftTuples.getUpdateFirst() != null) {
RuleNetworkEvaluator.doUpdatesReorderLeftMemory(bm, srcLeftTuples);
doLeftUpdates(accNode, am, wm, srcLeftTuples, tempLeftTuples);
}
if (srcRightTuples.getInsertFirst() != null) {
doRightInserts(accNode, am, wm, srcRightTuples, tempLeftTuples);
}
if (srcLeftTuples.getInsertFirst() != null) {
doLeftInserts(accNode, am, wm, srcLeftTuples, tempLeftTuples);
}
Accumulate accumulate = accNode.getAccumulate();
// LeftTuple retracts are already on the trgLeftTuples
for (LeftTuple leftTuple = tempLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
evaluateResultConstraints(accNode, sink, accumulate, leftTuple, leftTuple.getPropagationContext(), wm, am, (AccumulateContext) leftTuple.getContextObject(), trgLeftTuples, stagedLeftTuples);
leftTuple.clearStaged();
leftTuple = next;
}
for (LeftTuple leftTuple = tempLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
evaluateResultConstraints(accNode, sink, accumulate, leftTuple, leftTuple.getPropagationContext(), wm, am, (AccumulateContext) leftTuple.getContextObject(), trgLeftTuples, stagedLeftTuples);
leftTuple.clearStaged();
leftTuple = next;
}
srcRightTuples.resetAll();
srcLeftTuples.resetAll();
}
Aggregations