Search in sources :

Example 21 with DroolsQuery

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

the class PhreakQueryNode method doLeftDeletes.

public void doLeftDeletes(QueryElementNodeMemory qmem, ReteEvaluator reteEvaluator, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
    for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
        LeftTuple next = leftTuple.getStagedNext();
        InternalFactHandle fh = (InternalFactHandle) leftTuple.getContextObject();
        DroolsQuery dquery = (DroolsQuery) fh.getObject();
        if (dquery.isOpen()) {
            LeftInputAdapterNode lian = (LeftInputAdapterNode) qmem.getQuerySegmentMemory().getRootNode();
            LiaNodeMemory lm = (LiaNodeMemory) qmem.getQuerySegmentMemory().getNodeMemories().get(0);
            // there is only one, all other LTs are peers
            LeftTuple childLeftTuple = fh.getFirstLeftTuple();
            LeftInputAdapterNode.doDeleteObject(childLeftTuple, childLeftTuple.getPropagationContext(), qmem.getQuerySegmentMemory(), reteEvaluator, lian, false, lm);
        } else {
            LeftTuple childLeftTuple = leftTuple.getFirstChild();
            while (childLeftTuple != null) {
                LeftTuple nextChild = childLeftTuple.getHandleNext();
                RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
                childLeftTuple = nextChild;
            }
        }
        leftTuple.clearStaged();
        leftTuple = next;
    }
}
Also used : InternalFactHandle(org.drools.core.common.InternalFactHandle) LeftTuple(org.drools.core.reteoo.LeftTuple) LiaNodeMemory(org.drools.core.reteoo.LeftInputAdapterNode.LiaNodeMemory) DroolsQuery(org.drools.core.base.DroolsQuery) LeftInputAdapterNode(org.drools.core.reteoo.LeftInputAdapterNode)

Example 22 with DroolsQuery

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

the class UnificationConstraint method evaluateUnification.

private boolean evaluateUnification(InternalFactHandle handle, Tuple tuple, ReteEvaluator reteEvaluator) {
    if (!unification) {
        return evaluator.evaluate(handle, tuple, reteEvaluator);
    }
    DroolsQuery query = (DroolsQuery) tuple.getObject(0);
    if (query.getVariables()[indexingDeclaration.getExtractor().getIndex()] != null) {
        return true;
    }
    if (evaluator != null) {
        return evaluator.evaluate(handle, tuple, reteEvaluator);
    }
    Object argument = indexingDeclaration.getValue(null, query);
    return handle.getObject().equals(argument);
}
Also used : DroolsQuery(org.drools.core.base.DroolsQuery)

Example 23 with DroolsQuery

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

the class MVELConstraint method isAllowedCachedRight.

public boolean isAllowedCachedRight(Tuple tuple, ContextEntry context) {
    if (isUnification) {
        DroolsQuery query = (DroolsQuery) tuple.get(0).getObject();
        Variable v = query.getVariables()[((UnificationContextEntry) context).getReader().getIndex()];
        if (v != null) {
            return true;
        }
        context = ((UnificationContextEntry) context).getContextEntry();
    }
    MvelContextEntry mvelContextEntry = (MvelContextEntry) context;
    return evaluate(mvelContextEntry.rightHandle, mvelContextEntry.reteEvaluator, tuple);
}
Also used : Variable(org.kie.api.runtime.rule.Variable) DroolsQuery(org.drools.core.base.DroolsQuery)

Example 24 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, ReteEvaluator reteEvaluator) {
    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, reteEvaluator), 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)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