Search in sources :

Example 1 with TupleSetsImpl

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;
}
Also used : TupleSetsImpl(org.drools.core.common.TupleSetsImpl) SegmentMemory(org.drools.core.reteoo.SegmentMemory) PathEndNode(org.drools.core.reteoo.PathEndNode) AbstractTerminalNode(org.drools.core.reteoo.AbstractTerminalNode) TerminalNode(org.drools.core.reteoo.TerminalNode) LeftTuple(org.drools.core.reteoo.LeftTuple) PathMemory(org.drools.core.reteoo.PathMemory)

Example 2 with TupleSetsImpl

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();
}
Also used : TupleSetsImpl(org.drools.core.common.TupleSetsImpl) BetaMemory(org.drools.core.reteoo.BetaMemory) RightTuple(org.drools.core.reteoo.RightTuple) LeftTuple(org.drools.core.reteoo.LeftTuple) Accumulate(org.drools.core.rule.Accumulate)

Aggregations

TupleSetsImpl (org.drools.core.common.TupleSetsImpl)2 LeftTuple (org.drools.core.reteoo.LeftTuple)2 AbstractTerminalNode (org.drools.core.reteoo.AbstractTerminalNode)1 BetaMemory (org.drools.core.reteoo.BetaMemory)1 PathEndNode (org.drools.core.reteoo.PathEndNode)1 PathMemory (org.drools.core.reteoo.PathMemory)1 RightTuple (org.drools.core.reteoo.RightTuple)1 SegmentMemory (org.drools.core.reteoo.SegmentMemory)1 TerminalNode (org.drools.core.reteoo.TerminalNode)1 Accumulate (org.drools.core.rule.Accumulate)1