use of org.drools.core.base.DroolsQuery in project drools by kiegroup.
the class StatefulKnowledgeSessionImpl method openLiveQuery.
public LiveQuery openLiveQuery(final String query, final Object[] arguments, final ViewChangedEventListener listener) {
try {
startOperation();
this.lock.lock();
this.kBase.executeQueuedActions();
agenda.executeFlush();
DroolsQuery queryObject = new DroolsQuery(query, arguments, new OpenQueryViewChangedEventListenerAdapter(listener), true, 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());
evalQuery(queryObject.getName(), queryObject, handle, pCtx, false);
return new LiveQueryImpl(this, handle);
} finally {
this.lock.unlock();
endOperation();
}
}
use of org.drools.core.base.DroolsQuery 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();
}
}
use of org.drools.core.base.DroolsQuery in project drools by kiegroup.
the class UnificationConstraint method evaluateUnification.
private boolean evaluateUnification(InternalFactHandle handle, Tuple tuple, InternalWorkingMemory workingMemory) {
if (!unification) {
return evaluator.evaluate(handle, tuple, workingMemory);
}
DroolsQuery query = (DroolsQuery) tuple.getObject(0);
if (query.getVariables()[declaration.getExtractor().getIndex()] != null) {
return true;
}
if (evaluator != null) {
return evaluator.evaluate(handle, tuple, workingMemory);
}
Object argument = declaration.getValue(null, query);
return handle.getObject().equals(argument);
}
use of org.drools.core.base.DroolsQuery in project drools by kiegroup.
the class PhreakQueryNode method doLeftDeletes.
public void doLeftDeletes(QueryElementNodeMemory qmem, InternalWorkingMemory wm, 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(), wm, 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;
}
}
use of org.drools.core.base.DroolsQuery in project drools by kiegroup.
the class PhreakQueryTerminalNode method doLeftUpdates.
public void doLeftUpdates(QueryTerminalNode qtnNode, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, LinkedList<StackEntry> stack) {
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
PropagationContext pCtx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, leftTuple.getPropagationContext());
// qtnNode.modifyLeftTuple( leftTuple, leftTuple.getPropagationContext(), wm );
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().rowUpdated(qtnNode.getQuery(), leftTuple, pCtx, agenda.getWorkingMemory());
leftTuple.clearStaged();
leftTuple = next;
}
}
Aggregations