use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class RuleNetworkEvaluator method doUpdatesExistentialReorderRightMemory.
public static void doUpdatesExistentialReorderRightMemory(BetaMemory bm, BetaNode betaNode, TupleSets<RightTuple> srcRightTuples) {
TupleMemory rtm = bm.getRightTupleMemory();
boolean resumeFromCurrent = !(betaNode.isIndexedUnificationJoin() || rtm.getIndexType().isComparison());
if (rtm.getIndexType() != TupleMemory.IndexType.NONE) {
for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
rtm.remove(rightTuple);
if (rightTuple.getBlocked() != null) {
rightTuple.removeBlocked(rightTuple.getBlocked());
}
}
}
for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
doRemoveExistentialRightMemoryForReorder(rtm, resumeFromCurrent, rightTuple);
}
for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
doAddExistentialRightMemoryForReorder(rtm, resumeFromCurrent, rightTuple);
}
if (rtm.getIndexType() != TupleMemory.IndexType.NONE) {
for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; rightTuple = rightTuple.getStagedNext()) {
rtm.add(rightTuple);
}
}
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakAccumulateNode method doRightUpdates.
public void doRightUpdates(AccumulateNode accNode, AccumulateMemory am, InternalWorkingMemory wm, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
BetaMemory bm = am.getBetaMemory();
TupleMemory ltm = bm.getLeftTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = accNode.getRawConstraints();
Accumulate accumulate = accNode.getAccumulate();
for (RightTuple rightTuple = srcRightTuples.getUpdateFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
if (ltm != null && ltm.size() > 0) {
LeftTuple childLeftTuple = rightTuple.getFirstChild();
FastIterator leftIt = accNode.getLeftIterator(ltm);
LeftTuple leftTuple = accNode.getFirstLeftTuple(rightTuple, ltm, leftIt);
constraints.updateFromFactHandle(contextEntry, wm, rightTuple.getFactHandleForEvaluation());
// We assume a bucket change if leftTuple == null
if (childLeftTuple != null && ltm.isIndexed() && !leftIt.isFullIterator() && (leftTuple == null || (leftTuple.getMemory() != childLeftTuple.getLeftParent().getMemory()))) {
// our index has changed, so delete all the previous matches
removePreviousMatchesForRightTuple(accNode, accumulate, rightTuple, wm, am, childLeftTuple, trgLeftTuples);
// null so the next check will attempt matches for new bucket
childLeftTuple = null;
}
// if LeftTupleMemory is empty, there are no matches to modify
if (leftTuple != null) {
if (leftTuple.getStagedType() == LeftTuple.NONE) {
trgLeftTuples.addUpdate(leftTuple);
}
doRightUpdatesProcessChildren(accNode, am, wm, bm, constraints, accumulate, leftIt, rightTuple, childLeftTuple, leftTuple, trgLeftTuples);
}
}
rightTuple.clearStaged();
rightTuple = next;
}
constraints.resetFactHandle(contextEntry);
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakAccumulateNode method doRightDeletes.
public void doRightDeletes(AccumulateNode accNode, AccumulateMemory am, InternalWorkingMemory wm, TupleSets<RightTuple> srcRightTuples, TupleSets<LeftTuple> trgLeftTuples) {
TupleMemory rtm = am.getBetaMemory().getRightTupleMemory();
Accumulate accumulate = accNode.getAccumulate();
for (RightTuple rightTuple = srcRightTuples.getDeleteFirst(); rightTuple != null; ) {
RightTuple next = rightTuple.getStagedNext();
if (rightTuple.getMemory() != null) {
// it may have been staged and never actually added
rtm.remove(rightTuple);
if (rightTuple.getFirstChild() != null) {
LeftTuple match = rightTuple.getFirstChild();
while (match != null) {
LeftTuple nextLeft = match.getRightParentNext();
LeftTuple leftTuple = match.getLeftParent();
final AccumulateContext accctx = (AccumulateContext) leftTuple.getContextObject();
removeMatch(accNode, accumulate, rightTuple, match, wm, am, accctx, true);
if (leftTuple.getStagedType() == LeftTuple.NONE) {
trgLeftTuples.addUpdate(leftTuple);
}
match = nextLeft;
}
}
}
rightTuple.clearStaged();
rightTuple = next;
}
}
use of org.drools.core.reteoo.TupleMemory in project drools by kiegroup.
the class PhreakJoinNode method doLeftInserts.
public void doLeftInserts(JoinNode joinNode, 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 = joinNode.getRawConstraints();
for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
boolean useLeftMemory = RuleNetworkEvaluator.useLeftMemory(joinNode, leftTuple);
if (useLeftMemory) {
ltm.add(leftTuple);
}
FastIterator it = joinNode.getRightIterator(rtm);
constraints.updateFromTuple(contextEntry, wm, leftTuple);
for (RightTuple rightTuple = joinNode.getFirstRightTuple(leftTuple, rtm, null, it); rightTuple != null; rightTuple = (RightTuple) it.next(rightTuple)) {
if (constraints.isAllowedCachedLeft(contextEntry, rightTuple.getFactHandle())) {
insertChildLeftTuple(trgLeftTuples, leftTuple, rightTuple, null, null, sink, useLeftMemory);
}
}
leftTuple.clearStaged();
leftTuple = next;
}
constraints.resetTuple(contextEntry);
}
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, InternalWorkingMemory wm, 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, wm, 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);
}
Aggregations