Search in sources :

Example 1 with QueryRowWithSubruleIndex

use of org.drools.core.base.QueryRowWithSubruleIndex 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)

Aggregations

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 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 QueryTerminalNode (org.drools.core.reteoo.QueryTerminalNode)1 Declaration (org.drools.core.rule.Declaration)1 PropagationContext (org.drools.core.spi.PropagationContext)1