use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class PhreakJoinNode method doLeftDeletes.
public void doLeftDeletes(BetaMemory bm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
TupleMemory ltm = bm.getLeftTupleMemory();
for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
if (leftTuple.getMemory() != null) {
// it may have been staged and never actually added
ltm.remove(leftTuple);
}
if (leftTuple.getFirstChild() != null) {
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.reteoo.LeftTuple in project drools by kiegroup.
the class PhreakJoinNode method doRightUpdatesProcessChildren.
public LeftTuple doRightUpdatesProcessChildren(LeftTuple childLeftTuple, LeftTuple leftTuple, RightTuple rightTuple, TupleSets<LeftTuple> stagedLeftTuples, ContextEntry[] contextEntry, BetaConstraints constraints, LeftTupleSink sink, FastIterator it, TupleSets<LeftTuple> trgLeftTuples) {
if (childLeftTuple == null) {
// we had no children before, but there is a bucket to potentially match, so try as normal assert
for (; leftTuple != null; leftTuple = (LeftTuple) it.next(leftTuple)) {
if (leftTuple.getStagedType() == LeftTuple.UPDATE) {
// ignore, as it will get processed via left iteration. Children cannot be processed twice
continue;
}
if (constraints.isAllowedCachedRight(contextEntry, leftTuple)) {
insertChildLeftTuple(trgLeftTuples, leftTuple, rightTuple, null, null, sink, true);
}
}
} else {
// in the same bucket, so iterate and compare
for (; leftTuple != null; leftTuple = (LeftTuple) it.next(leftTuple)) {
if (leftTuple.getStagedType() == LeftTuple.UPDATE) {
// ignore, as it will get processed via left iteration. Children cannot be processed twice
continue;
}
if (constraints.isAllowedCachedRight(contextEntry, leftTuple)) {
// insert, childLeftTuple is not updated
if (childLeftTuple == null || childLeftTuple.getLeftParent() != leftTuple) {
insertChildLeftTuple(trgLeftTuples, leftTuple, rightTuple, null, childLeftTuple, sink, true);
} else {
// update, childLeftTuple is updated
childLeftTuple.setPropagationContext(rightTuple.getPropagationContext());
updateChildLeftTuple(childLeftTuple, stagedLeftTuples, trgLeftTuples);
LeftTuple nextChildLeftTuple = childLeftTuple.getRightParentNext();
childLeftTuple.reAddLeft();
childLeftTuple = nextChildLeftTuple;
}
} else if (childLeftTuple != null && childLeftTuple.getLeftParent() == leftTuple) {
// delete, childLeftTuple is updated
childLeftTuple.setPropagationContext(rightTuple.getPropagationContext());
LeftTuple nextChild = childLeftTuple.getRightParentNext();
RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
childLeftTuple = nextChild;
}
}
}
return childLeftTuple;
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class PhreakJoinNode method doLeftUpdatesProcessChildren.
public LeftTuple doLeftUpdatesProcessChildren(LeftTuple childLeftTuple, LeftTuple leftTuple, RightTuple rightTuple, TupleSets<LeftTuple> stagedLeftTuples, ContextEntry[] contextEntry, BetaConstraints constraints, LeftTupleSink sink, FastIterator it, TupleSets<LeftTuple> trgLeftTuples) {
if (childLeftTuple == null) {
// we had no children before, but there is a bucket to potentially match, so try as normal assert
for (; rightTuple != null; rightTuple = (RightTuple) it.next(rightTuple)) {
if (constraints.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandle())) {
insertChildLeftTuple(trgLeftTuples, leftTuple, rightTuple, null, null, sink, true);
}
}
} else {
// in the same bucket, so iterate and compare
for (; rightTuple != null; rightTuple = (RightTuple) it.next(rightTuple)) {
if (constraints.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandle())) {
// insert, childLeftTuple is not updated
if (childLeftTuple == null || childLeftTuple.getRightParent() != rightTuple) {
insertChildLeftTuple(trgLeftTuples, leftTuple, rightTuple, childLeftTuple, null, sink, true);
} else {
// update, childLeftTuple is updated
childLeftTuple.setPropagationContext(rightTuple.getPropagationContext());
updateChildLeftTuple(childLeftTuple, stagedLeftTuples, trgLeftTuples);
LeftTuple nextChildLeftTuple = childLeftTuple.getHandleNext();
childLeftTuple.reAddRight();
childLeftTuple = nextChildLeftTuple;
}
} else if (childLeftTuple != null && childLeftTuple.getRightParent() == rightTuple) {
// delete, childLeftTuple is updated
LeftTuple nextChild = childLeftTuple.getHandleNext();
RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
childLeftTuple = nextChild;
}
}
}
return childLeftTuple;
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class PhreakNotNode method doLeftUpdates.
public void doLeftUpdates(NotNode notNode, LeftTupleSink sink, BetaMemory bm, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
TupleMemory ltm = bm.getLeftTupleMemory();
TupleMemory rtm = bm.getRightTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = notNode.getRawConstraints();
boolean leftUpdateOptimizationAllowed = notNode.isLeftUpdateOptimizationAllowed();
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
FastIterator rightIt = notNode.getRightIterator(rtm);
RightTuple firstRightTuple = notNode.getFirstRightTuple(leftTuple, rtm, null, rightIt);
// If in memory, remove it, because we'll need to add it anyway if it's not blocked, to ensure iteration order
RightTuple blocker = leftTuple.getBlocker();
if (blocker == null) {
if (leftTuple.getMemory() != null) {
// memory can be null, if blocker was deleted in same do loop
ltm.remove(leftTuple);
}
} else {
// check if we changed bucket
if (rtm.isIndexed() && !rightIt.isFullIterator()) {
// if newRightTuple is null, we assume there was a bucket change and that bucket is empty
if (firstRightTuple == null || firstRightTuple.getMemory() != blocker.getMemory()) {
blocker.removeBlocked(leftTuple);
blocker = null;
}
}
}
constraints.updateFromTuple(contextEntry, wm, leftTuple);
if (!leftUpdateOptimizationAllowed && blocker != null) {
blocker.removeBlocked(leftTuple);
blocker = null;
}
// if we where not blocked before (or changed buckets), or the previous blocker no longer blocks, then find the next blocker
if (blocker == null || !constraints.isAllowedCachedLeft(contextEntry, blocker.getFactHandleForEvaluation())) {
if (blocker != null) {
// remove previous blocker if it exists, as we know it doesn't block any more
blocker.removeBlocked(leftTuple);
}
// find first blocker, because it's a modify, we need to start from the beginning again
for (RightTuple newBlocker = firstRightTuple; newBlocker != null; newBlocker = (RightTuple) rightIt.next(newBlocker)) {
if (constraints.isAllowedCachedLeft(contextEntry, newBlocker.getFactHandleForEvaluation())) {
leftTuple.setBlocker(newBlocker);
newBlocker.addBlocked(leftTuple);
break;
}
}
LeftTuple childLeftTuple = leftTuple.getFirstChild();
if (leftTuple.getBlocker() != null) {
// blocked
if (childLeftTuple != null) {
// blocked, with previous children, so must have not been previously blocked, so retract
// no need to remove, as we removed at the start
// to be matched against, as it's now blocked
// we have the righttuple, so use it for the pctx
childLeftTuple.setPropagationContext(leftTuple.getBlocker().getPropagationContext());
RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
}
// else: it's blocked now and no children so blocked before, thus do nothing
} else if (childLeftTuple == null) {
// not blocked, with no children, must have been previously blocked so assert
insertChildLeftTuple(sink, trgLeftTuples, ltm, leftTuple, leftTuple.getPropagationContext(), true);
} else {
updateChildLeftTuple(childLeftTuple, stagedLeftTuples, trgLeftTuples);
// not blocked, with children, so wasn't previous blocked and still isn't so modify
// add to memory so other fact handles can attempt to match
ltm.add(leftTuple);
childLeftTuple.reAddLeft();
}
}
leftTuple.clearStaged();
leftTuple = next;
}
constraints.resetTuple(contextEntry);
}
use of org.drools.core.reteoo.LeftTuple in project drools by kiegroup.
the class PhreakNotNode method doLeftInserts.
public void doLeftInserts(NotNode notNode, LeftTupleSink sink, BetaMemory bm, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) {
TupleMemory ltm = bm.getLeftTupleMemory();
TupleMemory rtm = bm.getRightTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = notNode.getRawConstraints();
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
boolean useLeftMemory = RuleNetworkEvaluator.useLeftMemory(notNode, leftTuple);
constraints.updateFromTuple(contextEntry, wm, leftTuple);
// This method will also remove rightTuples that are from subnetwork where no leftmemory use used
RuleNetworkEvaluator.findLeftTupleBlocker(notNode, rtm, contextEntry, constraints, leftTuple, useLeftMemory);
if (leftTuple.getBlocker() == null) {
insertChildLeftTuple(sink, trgLeftTuples, ltm, leftTuple, leftTuple.getPropagationContext(), useLeftMemory);
}
leftTuple.clearStaged();
leftTuple = next;
}
constraints.resetTuple(contextEntry);
}
Aggregations