Search in sources :

Example 11 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 12 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)

Aggregations

DroolsQuery (org.drools.core.base.DroolsQuery)12 LeftTuple (org.drools.core.reteoo.LeftTuple)6 PropagationContext (org.drools.core.spi.PropagationContext)6 InternalFactHandle (org.drools.core.common.InternalFactHandle)5 LeftInputAdapterNode (org.drools.core.reteoo.LeftInputAdapterNode)3 LiaNodeMemory (org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory)3 Declaration (org.drools.core.rule.Declaration)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 QueryResultsImpl (org.drools.core.QueryResultsImpl)1 QueryRowWithSubruleIndex (org.drools.core.base.QueryRowWithSubruleIndex)1 BaseNode (org.drools.core.common.BaseNode)1 QueryTerminalNode (org.drools.core.reteoo.QueryTerminalNode)1 SegmentMemory (org.drools.core.reteoo.SegmentMemory)1 Pattern (org.drools.core.rule.Pattern)1 TypeDeclaration (org.drools.core.rule.TypeDeclaration)1 WindowDeclaration (org.drools.core.rule.WindowDeclaration)1