use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakFromNode method doLeftDeletes.
public void doLeftDeletes(FromMemory fm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
BetaMemory bm = fm.getBetaMemory();
TupleMemory ltm = bm.getLeftTupleMemory();
for (LeftTuple leftTuple = srcLeftTuples.getDeleteFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
ltm.remove(leftTuple);
Map<Object, RightTuple> matches = (Map<Object, RightTuple>) leftTuple.getContextObject();
if (leftTuple.getFirstChild() != null) {
LeftTuple childLeftTuple = leftTuple.getFirstChild();
while (childLeftTuple != null) {
childLeftTuple.setPropagationContext(leftTuple.getPropagationContext());
LeftTuple nextChild = childLeftTuple.getHandleNext();
RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
childLeftTuple = nextChild;
}
}
// if matches == null, the deletion might be happening before the fact was even propagated. See BZ-1019473 for details.
if (matches != null) {
// @TODO (mdp) is this really necessary? won't the entire FH and RightTuple chaines just et GC'd?
unlinkCreatedHandles(leftTuple);
}
leftTuple.clearStaged();
leftTuple = next;
}
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakJoinNode method doLeftUpdates.
public void doLeftUpdates(JoinNode joinNode, LeftTupleSink sink, BetaMemory bm, ReteEvaluator reteEvaluator, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
TupleMemory rtm = bm.getRightTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = joinNode.getRawConstraints();
for (LeftTuple leftTuple = srcLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
constraints.updateFromTuple(contextEntry, reteEvaluator, leftTuple);
FastIterator it = joinNode.getRightIterator(rtm);
RightTuple rightTuple = joinNode.getFirstRightTuple(leftTuple, rtm, it);
// if rightTuple is null, we assume there was a bucket change and that bucket is empty
if (rtm.isIndexed() && !it.isFullIterator()) {
// our index has changed, so delete all the previous propagations
for (LeftTuple childLeftTuple = leftTuple.getFirstChild(); childLeftTuple != null; ) {
LeftTuple nextChild = childLeftTuple.getHandleNext();
if (rightTuple == null || rightTuple.getMemory() != childLeftTuple.getRightParent().getMemory()) {
RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
}
childLeftTuple = nextChild;
}
}
// we can't do anything if RightTupleMemory is empty
if (rightTuple != null) {
doLeftUpdatesProcessChildren(leftTuple.getFirstChild(), leftTuple, rightTuple, stagedLeftTuples, contextEntry, constraints, sink, it, trgLeftTuples);
}
leftTuple.clearStaged();
leftTuple = next;
}
constraints.resetTuple(contextEntry);
}
use of org.drools.core.reteoo.TupleMemory 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.TupleMemory in project drools by kiegroup.
the class PhreakJoinNode method doRightInserts.
public void doRightInserts(JoinNode joinNode, LeftTupleSink sink, BetaMemory bm, ReteEvaluator reteEvaluator, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
TupleMemory ltm = bm.getLeftTupleMemory();
TupleMemory rtm = bm.getRightTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = joinNode.getRawConstraints();
if (srcRightTuples.getInsertSize() > 32 && rtm instanceof AbstractHashTable) {
((AbstractHashTable) rtm).ensureCapacity(srcRightTuples.getInsertSize());
}
for (RightTuple rightTuple = srcRightTuples.getInsertFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
rtm.add(rightTuple);
if (ltm != null && ltm.size() > 0) {
FastIterator it = joinNode.getLeftIterator(ltm);
constraints.updateFromFactHandle(contextEntry, reteEvaluator, rightTuple.getFactHandleForEvaluation());
for (LeftTuple leftTuple = joinNode.getFirstLeftTuple(rightTuple, ltm, it); 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);
}
}
}
rightTuple.clearStaged();
rightTuple = next;
}
constraints.resetFactHandle(contextEntry);
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakJoinNode method doRightUpdates.
public void doRightUpdates(JoinNode joinNode, LeftTupleSink sink, BetaMemory bm, ReteEvaluator reteEvaluator, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) {
TupleMemory ltm = bm.getLeftTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = joinNode.getRawConstraints();
for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
if (ltm != null && ltm.size() > 0) {
FastIterator it = joinNode.getLeftIterator(ltm);
LeftTuple leftTuple = joinNode.getFirstLeftTuple(rightTuple, ltm, it);
constraints.updateFromFactHandle(contextEntry, reteEvaluator, rightTuple.getFactHandleForEvaluation());
// first check our index (for indexed nodes only) hasn't changed and we are returning the same bucket
// We assume a bucket change if leftTuple == null
LeftTuple childLeftTuple = rightTuple.getFirstChild();
if (childLeftTuple != null && ltm.isIndexed() && !it.isFullIterator() && (leftTuple == null || (leftTuple.getMemory() != childLeftTuple.getLeftParent().getMemory()))) {
// our index has changed, so delete all the previous propagations
while (childLeftTuple != null) {
childLeftTuple.setPropagationContext(rightTuple.getPropagationContext());
LeftTuple nextChild = childLeftTuple.getRightParentNext();
RuleNetworkEvaluator.unlinkAndDeleteChildLeftTuple(childLeftTuple, trgLeftTuples, stagedLeftTuples);
childLeftTuple = nextChild;
}
// childLeftTuple is now null, so the next check will attempt matches for new bucket
}
// we can't do anything if LeftTupleMemory is empty
if (leftTuple != null) {
doRightUpdatesProcessChildren(childLeftTuple, leftTuple, rightTuple, stagedLeftTuples, contextEntry, constraints, sink, it, trgLeftTuples);
}
}
rightTuple.clearStaged();
rightTuple = next;
}
constraints.resetFactHandle(contextEntry);
}
Aggregations