use of org.drools.core.base.DroolsQuery in project drools by kiegroup.
the class PhreakQueryNode method doLeftUpdates.
public void doLeftUpdates(QueryElementNode queryNode, QueryElementNodeMemory qmem, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples) {
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
InternalFactHandle fh = (InternalFactHandle) leftTuple.getContextObject();
DroolsQuery dquery = (DroolsQuery) fh.getObject();
dquery.setParameters(queryNode.getActualArguments(leftTuple, wm));
SegmentMemory qsmem = qmem.getQuerySegmentMemory();
LeftInputAdapterNode lian = (LeftInputAdapterNode) qsmem.getRootNode();
LiaNodeMemory lmem = (LiaNodeMemory) qsmem.getNodeMemories().getFirst();
if (dquery.isOpen()) {
// there is only one, all other LTs are peers
LeftTuple childLeftTuple = fh.getFirstLeftTuple();
LeftInputAdapterNode.doUpdateObject(childLeftTuple, childLeftTuple.getPropagationContext(), wm, lian, false, lmem, qmem.getQuerySegmentMemory());
} else {
if (fh.getFirstLeftTuple() != null) {
// @TODO remove later (mdp)
throw new RuntimeException("defensive programming while testing");
}
LiaNodeMemory lm = (LiaNodeMemory) qmem.getQuerySegmentMemory().getNodeMemories().get(0);
LeftInputAdapterNode.doInsertObject(fh, leftTuple.getPropagationContext(), lian, wm, lm, false, dquery.isOpen());
}
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.base.DroolsQuery in project drools by kiegroup.
the class PhreakQueryNode method doLeftInserts.
public void doLeftInserts(QueryElementNode queryNode, QueryElementNodeMemory qmem, StackEntry stackEntry, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples) {
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
PropagationContext pCtx = leftTuple.getPropagationContext();
InternalFactHandle handle = queryNode.createFactHandle(pCtx, wm, leftTuple);
DroolsQuery dquery = queryNode.createDroolsQuery(leftTuple, handle, stackEntry, qmem.getSegmentMemory().getPathMemories(), qmem, stackEntry.getSink(), wm);
LeftInputAdapterNode lian = (LeftInputAdapterNode) qmem.getQuerySegmentMemory().getRootNode();
LiaNodeMemory lm = (LiaNodeMemory) qmem.getQuerySegmentMemory().getNodeMemories().get(0);
LeftInputAdapterNode.doInsertObject(handle, pCtx, lian, wm, lm, false, dquery.isOpen());
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.base.DroolsQuery in project drools by kiegroup.
the class PhreakQueryTerminalNode method doLeftInserts.
public void doLeftInserts(QueryTerminalNode qtnNode, InternalAgenda agenda, TupleSets<LeftTuple> srcLeftTuples, LinkedList<StackEntry> stack) {
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
// qtnNode.assertLeftTuple( leftTuple, leftTuple.getPropagationContext(), wm );
PropagationContext pCtx = RuleTerminalNode.findMostRecentPropagationContext(leftTuple, leftTuple.getPropagationContext());
// find the DroolsQuery object
Tuple rootEntry = leftTuple.getRootTuple();
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().rowAdded(qtnNode.getQuery(), leftTuple, pCtx, agenda.getWorkingMemory());
leftTuple.clearStaged();
leftTuple = next;
}
}
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.workingMemory, tuple);
}
use of org.drools.core.base.DroolsQuery in project drools by kiegroup.
the class KiePackagesBuilder method addQueryPattern.
private void addQueryPattern(Query query, QueryImpl queryImpl, RuleContext ctx) {
Pattern pattern = new Pattern(ctx.getNextPatternIndex(), // tupleIndex is 0 by default
0, // patternIndex is 0 by default
0, ClassObjectType.DroolsQuery_ObjectType, null);
InternalReadAccessor extractor = new LambdaReadAccessor(DroolsQuery.class, q -> ((DroolsQuery) q).getName());
QueryNameConstraint constraint = new QueryNameConstraint(extractor, query.getName());
pattern.addConstraint(constraint);
queryImpl.getLhs().addChild(pattern);
Variable<?>[] args = query.getArguments();
Declaration[] declarations = new Declaration[args.length];
for (int i = 0; i < args.length; i++) {
int index = i;
LambdaReadAccessor accessor = new LambdaReadAccessor(index, args[index].getType(), obj -> ((DroolsQuery) obj).getElements()[index]);
declarations[i] = new Declaration(args[i].getName(), accessor, pattern, false);
pattern.addDeclaration(declarations[i]);
ctx.addQueryDeclaration(args[i], declarations[i]);
}
queryImpl.setParameters(declarations);
}
Aggregations