Search in sources :

Example 6 with EvalConditionNode

use of org.drools.core.reteoo.EvalConditionNode in project drools by kiegroup.

the class LeftTupleIterator method getFirstLeftTuple.

public LeftTuple getFirstLeftTuple(LeftTupleSource source, LeftTupleSink sink, InternalWorkingMemory wm) {
    if (source instanceof AccumulateNode) {
        AccumulateMemory accmem = (AccumulateMemory) wm.getNodeMemory((MemoryFactory) source);
        BetaMemory memory = accmem.getBetaMemory();
        FastIterator localIt = memory.getLeftTupleMemory().fullFastIterator();
        Tuple leftTuple = BetaNode.getFirstTuple(memory.getLeftTupleMemory(), localIt);
        if (leftTuple != null) {
            AccumulateContext accctx = (AccumulateContext) leftTuple.getContextObject();
            return accctx.getResultLeftTuple();
        }
        return null;
    }
    if (source instanceof JoinNode || source instanceof NotNode || source instanceof FromNode || source instanceof AccumulateNode) {
        BetaMemory memory;
        FastIterator localIt;
        if (source instanceof FromNode) {
            memory = ((FromMemory) wm.getNodeMemory((MemoryFactory) source)).getBetaMemory();
        } else if (source instanceof AccumulateNode) {
            memory = ((AccumulateMemory) wm.getNodeMemory((MemoryFactory) source)).getBetaMemory();
        } else {
            memory = (BetaMemory) wm.getNodeMemory((MemoryFactory) source);
        }
        localIt = memory.getLeftTupleMemory().fullFastIterator();
        Tuple leftTuple = BetaNode.getFirstTuple(memory.getLeftTupleMemory(), localIt);
        while (leftTuple != null) {
            for (LeftTuple childleftTuple = leftTuple.getFirstChild(); childleftTuple != null; childleftTuple = childleftTuple.getHandleNext()) {
                if (childleftTuple.getTupleSink() == sink) {
                    return childleftTuple;
                }
            }
            leftTuple = (LeftTuple) localIt.next(leftTuple);
        }
    }
    if (source instanceof ExistsNode) {
        BetaMemory memory = (BetaMemory) wm.getNodeMemory((MemoryFactory) source);
        FastIterator localIt = memory.getRightTupleMemory().fullFastIterator();
        RightTuple rightTuple = (RightTuple) BetaNode.getFirstTuple(memory.getRightTupleMemory(), localIt);
        while (rightTuple != null) {
            if (rightTuple.getBlocked() != null) {
                for (LeftTuple leftTuple = rightTuple.getBlocked(); leftTuple != null; leftTuple = leftTuple.getBlockedNext()) {
                    for (LeftTuple childleftTuple = leftTuple.getFirstChild(); childleftTuple != null; childleftTuple = childleftTuple.getHandleNext()) {
                        if (childleftTuple.getTupleSink() == sink) {
                            return childleftTuple;
                        }
                    }
                }
            }
            rightTuple = (RightTuple) localIt.next(rightTuple);
        }
    } else if (source instanceof LeftInputAdapterNode) {
        ObjectSource os = ((LeftInputAdapterNode) source).getParentObjectSource();
        while (!(os instanceof ObjectTypeNode)) {
            os = os.getParentObjectSource();
        }
        ObjectTypeNode otn = (ObjectTypeNode) os;
        otnIterator = wm.getNodeMemory(otn).iterator();
        while (otnIterator.hasNext()) {
            InternalFactHandle handle = otnIterator.next();
            LeftTuple leftTuple = handle.findFirstLeftTuple(lt -> lt.getTupleSink() == sink);
            if (leftTuple != null) {
                return leftTuple;
            }
        }
    } else if (source instanceof EvalConditionNode || source instanceof QueryElementNode) {
        LeftTuple parentLeftTuple = getFirstLeftTuple(source.getLeftTupleSource(), (LeftTupleSink) source, wm);
        while (parentLeftTuple != null) {
            for (LeftTuple leftTuple = parentLeftTuple.getFirstChild(); leftTuple != null; leftTuple = leftTuple.getHandleNext()) {
                if (leftTuple.getTupleSink() == sink) {
                    return leftTuple;
                }
            }
            parentLeftTuple = getNextLeftTuple(source.getLeftTupleSource(), (LeftTupleSink) source, parentLeftTuple, wm);
        }
    }
    return null;
}
Also used : NotNode(org.drools.core.reteoo.NotNode) ExistsNode(org.drools.core.reteoo.ExistsNode) EvalConditionNode(org.drools.core.reteoo.EvalConditionNode) FastIterator(org.drools.core.util.FastIterator) AccumulateNode(org.drools.core.reteoo.AccumulateNode) AccumulateContext(org.drools.core.reteoo.AccumulateNode.AccumulateContext) BetaMemory(org.drools.core.reteoo.BetaMemory) JoinNode(org.drools.core.reteoo.JoinNode) FromNode(org.drools.core.reteoo.FromNode) LeftTuple(org.drools.core.reteoo.LeftTuple) RightTuple(org.drools.core.reteoo.RightTuple) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode) QueryElementNode(org.drools.core.reteoo.QueryElementNode) Tuple(org.drools.core.spi.Tuple) BetaNode(org.drools.core.reteoo.BetaNode) AccumulateMemory(org.drools.core.reteoo.AccumulateNode.AccumulateMemory) FromMemory(org.drools.core.reteoo.FromNode.FromMemory) ObjectSource(org.drools.core.reteoo.ObjectSource) LeftTupleSink(org.drools.core.reteoo.LeftTupleSink) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) Iterator(org.drools.core.util.Iterator) LeftTupleSource(org.drools.core.reteoo.LeftTupleSource) AccumulateMemory(org.drools.core.reteoo.AccumulateNode.AccumulateMemory) NotNode(org.drools.core.reteoo.NotNode) EvalConditionNode(org.drools.core.reteoo.EvalConditionNode) AccumulateNode(org.drools.core.reteoo.AccumulateNode) JoinNode(org.drools.core.reteoo.JoinNode) QueryElementNode(org.drools.core.reteoo.QueryElementNode) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) LeftTupleSink(org.drools.core.reteoo.LeftTupleSink) BetaMemory(org.drools.core.reteoo.BetaMemory) FromNode(org.drools.core.reteoo.FromNode) LeftTuple(org.drools.core.reteoo.LeftTuple) ExistsNode(org.drools.core.reteoo.ExistsNode) RightTuple(org.drools.core.reteoo.RightTuple) ObjectSource(org.drools.core.reteoo.ObjectSource) FastIterator(org.drools.core.util.FastIterator) LeftTuple(org.drools.core.reteoo.LeftTuple) RightTuple(org.drools.core.reteoo.RightTuple) Tuple(org.drools.core.spi.Tuple) AccumulateContext(org.drools.core.reteoo.AccumulateNode.AccumulateContext) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Aggregations

EvalConditionNode (org.drools.core.reteoo.EvalConditionNode)6 JoinNode (org.drools.core.reteoo.JoinNode)6 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)6 ObjectTypeNode (org.drools.core.reteoo.ObjectTypeNode)6 BetaMemory (org.drools.core.reteoo.BetaMemory)5 InternalWorkingMemory (org.drools.core.common.InternalWorkingMemory)4 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)4 ExistsNode (org.drools.core.reteoo.ExistsNode)4 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 List (java.util.List)2 AccumulateNode (org.drools.core.reteoo.AccumulateNode)2 AccumulateContext (org.drools.core.reteoo.AccumulateNode.AccumulateContext)2 AccumulateMemory (org.drools.core.reteoo.AccumulateNode.AccumulateMemory)2 BetaNode (org.drools.core.reteoo.BetaNode)2 FromNode (org.drools.core.reteoo.FromNode)2 FromMemory (org.drools.core.reteoo.FromNode.FromMemory)2 LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)2 LeftTuple (org.drools.core.reteoo.LeftTuple)2 LeftTupleSink (org.drools.core.reteoo.LeftTupleSink)2