Search in sources :

Example 1 with NonCloningQueryViewListener

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

the class RuleUnitExecutorImpl method getQueryResults.

@Override
public QueryResults getQueryResults(String queryName, Object... arguments) {
    activationsManager.flushPropagations();
    DroolsQuery queryObject = new DroolsQuery(queryName, arguments, new NonCloningQueryViewListener(), false);
    InternalFactHandle handle = this.handleFactory.newFactHandle(queryObject, null, this, getDefaultEntryPoint());
    final PropagationContext pCtx = new PhreakPropagationContext(getNextPropagationIdCounter(), PropagationContext.Type.INSERTION, null, null, handle, getDefaultEntryPointId());
    PropagationEntry.ExecuteQuery executeQuery = new PropagationEntry.ExecuteQuery(queryName, queryObject, handle, pCtx, false);
    addPropagation(executeQuery);
    TerminalNode[] terminalNodes = executeQuery.getResult();
    List<Map<String, Declaration>> decls = new ArrayList<>();
    if (terminalNodes != null) {
        for (TerminalNode node : terminalNodes) {
            decls.add(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]);
}
Also used : QueryRowWithSubruleIndex(org.drools.core.base.QueryRowWithSubruleIndex) PhreakPropagationContext(org.drools.core.common.PhreakPropagationContext) QueryResultsImpl(org.drools.core.QueryResultsImpl) PhreakPropagationContext(org.drools.core.common.PhreakPropagationContext) PropagationContext(org.drools.core.spi.PropagationContext) ArrayList(java.util.ArrayList) PropagationEntry(org.drools.core.phreak.PropagationEntry) Declaration(org.drools.core.rule.Declaration) InternalFactHandle(org.drools.core.common.InternalFactHandle) TerminalNode(org.drools.core.reteoo.TerminalNode) Map(java.util.Map) NonCloningQueryViewListener(org.drools.core.base.NonCloningQueryViewListener) DroolsQuery(org.drools.core.base.DroolsQuery)

Aggregations

ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 QueryResultsImpl (org.drools.core.QueryResultsImpl)1 DroolsQuery (org.drools.core.base.DroolsQuery)1 NonCloningQueryViewListener (org.drools.core.base.NonCloningQueryViewListener)1 QueryRowWithSubruleIndex (org.drools.core.base.QueryRowWithSubruleIndex)1 InternalFactHandle (org.drools.core.common.InternalFactHandle)1 PhreakPropagationContext (org.drools.core.common.PhreakPropagationContext)1 PropagationEntry (org.drools.core.phreak.PropagationEntry)1 TerminalNode (org.drools.core.reteoo.TerminalNode)1 Declaration (org.drools.core.rule.Declaration)1 PropagationContext (org.drools.core.spi.PropagationContext)1