Search in sources :

Example 16 with DroolsQuery

use of org.drools.core.base.DroolsQuery in project drools by kiegroup.

the class PhreakQueryTerminalNode method doLeftUpdates.

public void doLeftUpdates(QueryTerminalNode qtnNode, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, LinkedList<StackEntry> stack) {
    for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        PropagationContext pCtx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, leftTuple.getPropagationContext());
        // qtnNode.modifyLeftTuple( leftTuple, leftTuple.getPropagationContext(), wm );
        LeftTuple rootEntry = leftTuple;
        // find the DroolsQuery object
        while (rootEntry.getParent() != null) {
            rootEntry = rootEntry.getParent();
        }
        DroolsQuery dquery = (DroolsQuery) rootEntry.getFactHandle().getObject();
        dquery.setQuery(qtnNode.getQuery());
        if (dquery.getStackEntry() != null) {
            checkAndTriggerQueryReevaluation(agenda, stack, rootEntry, dquery);
        }
        // Add results to the adapter
        dquery.getQueryResultCollector().rowUpdated(qtnNode.getQuery(), leftTuple, pCtx, agenda.getWorkingMemory());
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext) LeftTuple(org.drools.core.reteoo.LeftTuple) DroolsQuery(org.drools.core.base.DroolsQuery)

Example 17 with DroolsQuery

use of org.drools.core.base.DroolsQuery in project drools by kiegroup.

the class PhreakQueryTerminalNode method doLeftDeletes.

public void doLeftDeletes(QueryTerminalNode qtnNode, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, LinkedList<StackEntry> stack) {
    for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        // qtnNode.retractLeftTuple( leftTuple, leftTuple.getPropagationContext(), wm );
        PropagationContext pCtx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, leftTuple.getPropagationContext());
        LeftTuple rootEntry = leftTuple;
        // find the DroolsQuery object
        while (rootEntry.getParent() != null) {
            rootEntry = rootEntry.getParent();
        }
        DroolsQuery dquery = (DroolsQuery) rootEntry.getFactHandle().getObject();
        dquery.setQuery(qtnNode.getQuery());
        if (dquery.getStackEntry() != null) {
            checkAndTriggerQueryReevaluation(agenda, stack, rootEntry, dquery);
        }
        // Add results to the adapter
        dquery.getQueryResultCollector().rowRemoved(qtnNode.getQuery(), leftTuple, pCtx, agenda.getWorkingMemory());
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : PropagationContext(org.drools.core.spi.PropagationContext) LeftTuple(org.drools.core.reteoo.LeftTuple) DroolsQuery(org.drools.core.base.DroolsQuery)

Example 18 with DroolsQuery

use of org.drools.core.base.DroolsQuery in project drools by kiegroup.

the class QueryElementNode method createDroolsQuery.

public DroolsQuery createDroolsQuery(LeftTuple leftTuple, InternalFactHandle handle, StackEntry stackEntry, final List<PathMemory> pmems, QueryElementNodeMemory qmem, LeftTupleSink sink, InternalWorkingMemory workingMemory) {
    UnificationNodeViewChangedEventListener collector = createCollector(leftTuple, queryElement.getVariableIndexes(), this.tupleMemoryEnabled);
    boolean executeAsOpenQuery = openQuery;
    if (executeAsOpenQuery) {
        // There is no point in doing an open query if the caller is a non-open query.
        Object object = leftTuple.get(0).getObject();
        if (object instanceof DroolsQuery && !((DroolsQuery) object).isOpen()) {
            executeAsOpenQuery = false;
        }
    }
    DroolsQuery queryObject = new DroolsQuery(this.queryElement.getQueryName(), getActualArguments(leftTuple, workingMemory), collector, executeAsOpenQuery, stackEntry, pmems, qmem != null ? qmem.getResultLeftTuples() : null, qmem, sink);
    collector.setFactHandle(handle);
    handle.setObject(queryObject);
    // so it can be retracted later and destroyed
    leftTuple.setContextObject(handle);
    return queryObject;
}
Also used : DroolsQuery(org.drools.core.base.DroolsQuery)

Example 19 with DroolsQuery

use of org.drools.core.base.DroolsQuery in project drools by kiegroup.

the class PhreakQueryTerminalNode method doLeftDeletes.

public void doLeftDeletes(QueryTerminalNode qtnNode, ActivationsManager activationsManager, TupleSets<LeftTuple> srcLeftTuples, LinkedList<StackEntry> stack) {
    for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        // qtnNode.retractLeftTuple( leftTuple, leftTuple.getPropagationContext(), wm );
        // find the DroolsQuery object
        LeftTuple rootEntry = (LeftTuple) leftTuple.getRootTuple();
        DroolsQuery dquery = (DroolsQuery) rootEntry.getFactHandle().getObject();
        dquery.setQuery(qtnNode.getQuery());
        if (dquery.getStackEntry() != null) {
            checkAndTriggerQueryReevaluation(activationsManager, stack, rootEntry, dquery);
        }
        // Add results to the adapter
        dquery.getQueryResultCollector().rowRemoved(qtnNode.getQuery(), leftTuple, activationsManager.getReteEvaluator());
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : LeftTuple(org.drools.core.reteoo.LeftTuple) DroolsQuery(org.drools.core.base.DroolsQuery)

Example 20 with DroolsQuery

use of org.drools.core.base.DroolsQuery in project drools by kiegroup.

the class PhreakQueryTerminalNode method doLeftInserts.

public void doLeftInserts(QueryTerminalNode qtnNode, ActivationsManager activationsManager, TupleSets<LeftTuple> srcLeftTuples, LinkedList<StackEntry> stack) {
    for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        // qtnNode.assertLeftTuple( leftTuple, leftTuple.getPropagationContext(), wm );
        // find the DroolsQuery object
        Tuple rootEntry = leftTuple.getRootTuple();
        DroolsQuery dquery = (DroolsQuery) rootEntry.getFactHandle().getObject();
        dquery.setQuery(qtnNode.getQuery());
        if (dquery.getStackEntry() != null) {
            checkAndTriggerQueryReevaluation(activationsManager, stack, rootEntry, dquery);
        }
        // Add results to the adapter
        dquery.getQueryResultCollector().rowAdded(qtnNode.getQuery(), leftTuple, activationsManager.getReteEvaluator());
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : LeftTuple(org.drools.core.reteoo.LeftTuple) Tuple(org.drools.core.spi.Tuple) LeftTuple(org.drools.core.reteoo.LeftTuple) DroolsQuery(org.drools.core.base.DroolsQuery)

Aggregations

DroolsQuery (org.drools.core.base.DroolsQuery)24 LeftTuple (org.drools.core.reteoo.LeftTuple)12 InternalFactHandle (org.drools.core.common.InternalFactHandle)11 PropagationContext (org.drools.core.spi.PropagationContext)10 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)6 LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)6 Declaration (org.drools.core.rule.Declaration)4 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 QueryResultsImpl (org.drools.core.QueryResultsImpl)3 QueryRowWithSubruleIndex (org.drools.core.base.QueryRowWithSubruleIndex)3 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 QueryTerminalNode (org.drools.core.reteoo.QueryTerminalNode)2 SegmentMemory (org.drools.core.reteoo.SegmentMemory)2 TerminalNode (org.drools.core.reteoo.TerminalNode)2 LiveQueryImpl (org.drools.core.runtime.rule.impl.LiveQueryImpl)2 OpenQueryViewChangedEventListenerAdapter (org.drools.core.runtime.rule.impl.OpenQueryViewChangedEventListenerAdapter)2 Tuple (org.drools.core.spi.Tuple)2 TreeMap (java.util.TreeMap)1