Search in sources :

Example 1 with QueryTerminalNode

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

the class QueryTerminalNodeVisitor method doVisit.

@Override
protected void doVisit(NetworkNode node, Stack<NetworkNode> nodeStack, StatefulKnowledgeSessionInfo info) {
    QueryTerminalNode rtn = (QueryTerminalNode) node;
    RuleImpl rule = rtn.getRule();
    // first thing, associate all nodes belonging to this rule
    for (NetworkNode snode : nodeStack) {
        info.assign(snode, rule);
    }
// Query Terminal Nodes no longer have memory
// TODO delete this
// final LinkedList<?> memory = (LinkedList<?>) info.getSession().getNodeMemory( rtn );
// final DefaultNodeInfo ni = (DefaultNodeInfo) info.getNodeInfo( node );
// ni.setMemoryEnabled( true );
// ni.setTupleMemorySize( memory.size() );
}
Also used : QueryTerminalNode(org.drools.core.reteoo.QueryTerminalNode) RuleImpl(org.drools.core.definitions.rule.impl.RuleImpl) NetworkNode(org.drools.core.common.NetworkNode)

Example 2 with QueryTerminalNode

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

the class StatefulKnowledgeSessionImpl method internalGetQueryResult.

protected QueryResultsImpl internalGetQueryResult(boolean calledFromRHS, String queryName, Object... arguments) {
    try {
        startOperation();
        this.lock.lock();
        this.kBase.executeQueuedActions();
        // eventually enqueued by events that have been inserted when already expired
        if (calledFromRHS) {
            flushPropagations();
            flushPropagations();
        } else {
            agenda.executeFlush();
            agenda.executeFlush();
        }
        DroolsQuery queryObject = new DroolsQuery(queryName, arguments, getQueryListenerInstance(), false, null, null, null, null, null);
        InternalFactHandle handle = this.handleFactory.newFactHandle(queryObject, null, this, this);
        final PropagationContext pCtx = pctxFactory.createPropagationContext(getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, null, null, handle, getEntryPoint());
        BaseNode[] tnodes = evalQuery(queryName, queryObject, handle, pCtx, calledFromRHS);
        List<Map<String, Declaration>> decls = new ArrayList<Map<String, Declaration>>();
        if (tnodes != null) {
            for (BaseNode node : tnodes) {
                decls.add(((QueryTerminalNode) node).getSubRule().getOuterDeclarations());
            }
        }
        this.handleFactory.destroyFactHandle(handle);
        return new QueryResultsImpl((List<QueryRowWithSubruleIndex>) queryObject.getQueryResultCollector().getResults(), decls.toArray(new Map[decls.size()]), this, (queryObject.getQuery() != null) ? queryObject.getQuery().getParameters() : new Declaration[0]);
    } finally {
        this.lock.unlock();
        endOperation();
    }
}
Also used : QueryRowWithSubruleIndex(org.drools.core.base.QueryRowWithSubruleIndex) QueryResultsImpl(org.drools.core.QueryResultsImpl) PropagationContext(org.drools.core.spi.PropagationContext) BaseNode(org.drools.core.common.BaseNode) ArrayList(java.util.ArrayList) QueryTerminalNode(org.drools.core.reteoo.QueryTerminalNode) Declaration(org.drools.core.rule.Declaration) InternalFactHandle(org.drools.core.common.InternalFactHandle) Map(java.util.Map) TreeMap(java.util.TreeMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DroolsQuery(org.drools.core.base.DroolsQuery)

Example 3 with QueryTerminalNode

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

the class AbstractQueryViewListener method rowAdded.

public void rowAdded(final RuleImpl rule, final LeftTuple tuple, final PropagationContext context, final InternalWorkingMemory workingMemory) {
    InternalFactHandle[] handles = new InternalFactHandle[tuple.getIndex() + 1];
    LeftTuple entry = tuple;
    // Add all the FactHandles
    while (entry != null) {
        InternalFactHandle handle = entry.getFactHandle();
        if (handle != null) {
            handles[entry.getIndex()] = getHandle(handle);
        }
        entry = entry.getParent();
    }
    QueryTerminalNode node = (QueryTerminalNode) tuple.getTupleSink();
    this.results.add(new QueryRowWithSubruleIndex(handles, node.getSubruleIndex()));
}
Also used : QueryTerminalNode(org.drools.core.reteoo.QueryTerminalNode) InternalFactHandle(org.drools.core.common.InternalFactHandle) LeftTuple(org.drools.core.reteoo.LeftTuple)

Aggregations

QueryTerminalNode (org.drools.core.reteoo.QueryTerminalNode)3 InternalFactHandle (org.drools.core.common.InternalFactHandle)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 DroolsQuery (org.drools.core.base.DroolsQuery)1 QueryRowWithSubruleIndex (org.drools.core.base.QueryRowWithSubruleIndex)1 BaseNode (org.drools.core.common.BaseNode)1 NetworkNode (org.drools.core.common.NetworkNode)1 RuleImpl (org.drools.core.definitions.rule.impl.RuleImpl)1 LeftTuple (org.drools.core.reteoo.LeftTuple)1 Declaration (org.drools.core.rule.Declaration)1 PropagationContext (org.drools.core.spi.PropagationContext)1