// order of left and right operations is to minimise wasted of innefficient joins.
// We need to collect which leftTuple where updated, so that we can
// add their result tuple to the real target tuples later
LeftTupleSets tempLeftTuples = new LeftTupleSetsImpl();
if (srcLeftTuples.getDeleteFirst() != null) {
// use the real target here, as dealing direct with left tuples
doLeftDeletes(accNode, am, wm, srcLeftTuples, trgLeftTuples);
}
if (srcRightTuples.getDeleteFirst() != null) {
doRightDeletes(accNode, am, wm, srcRightTuples, tempLeftTuples);
}
if (srcLeftTuples.getUpdateFirst() != null ) {
RuleNetworkEvaluator.doUpdatesReorderLeftMemory(am.getBetaMemory(),
srcLeftTuples);
}
if (srcRightTuples.getUpdateFirst() != null) {
RuleNetworkEvaluator.doUpdatesReorderRightMemory(am.getBetaMemory(),
srcRightTuples);
}
if (srcRightTuples.getUpdateFirst() != null) {
doRightUpdates(accNode, sink, am, wm, srcRightTuples, tempLeftTuples);
}
if (srcLeftTuples.getUpdateFirst() != null) {
doLeftUpdates(accNode, sink, am, wm, srcLeftTuples, tempLeftTuples);
}
if (srcRightTuples.getInsertFirst() != null) {
doRightInserts(accNode, sink, am, wm, srcRightTuples, tempLeftTuples);
}
if (srcLeftTuples.getInsertFirst() != null) {
doLeftInserts(accNode, sink, am, wm, srcLeftTuples, tempLeftTuples);
}
Accumulate accumulate = accNode.getAccumulate();
// we do not need collect retracts. RightTuple retracts end up as updates for lefttuples.
// LeftTuple retracts are already on the trgLeftTuples
for (LeftTuple leftTuple = tempLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
evaluateResultConstraints(accNode, sink, accumulate, leftTuple, leftTuple.getPropagationContext(),
wm, am, (AccumulateContext) leftTuple.getObject(), useLeftMemory,
trgLeftTuples, stagedLeftTuples);
leftTuple.clearStaged();
leftTuple = next;
}
for (LeftTuple leftTuple = tempLeftTuples.getUpdateFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
evaluateResultConstraints(accNode, sink, accumulate, leftTuple, leftTuple.getPropagationContext(),
wm, am, (AccumulateContext) leftTuple.getObject(), useLeftMemory,
trgLeftTuples, stagedLeftTuples);
leftTuple.clearStaged();