boolean tupleMemoryEnabled = true;
LeftTupleMemory ltm = bm.getLeftTupleMemory();
RightTupleMemory rtm = bm.getRightTupleMemory();
ContextEntry[] contextEntry = bm.getContext();
BetaConstraints constraints = existsNode.getRawConstraints();
FastIterator it = existsNode.getRightIterator( rtm );
for ( LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) {
LeftTuple next = leftTuple.getStagedNext();
PropagationContext context = leftTuple.getPropagationContext();
boolean useLeftMemory = true;
if ( !tupleMemoryEnabled ) {
// This is a hack, to not add closed DroolsQuery objects
Object object = ((InternalFactHandle) context.getFactHandle()).getObject();
if ( !(object instanceof DroolsQuery) || !((DroolsQuery) object).isOpen() ) {
useLeftMemory = false;
}
}
constraints.updateFromTuple( contextEntry,
wm,
leftTuple );
for ( RightTuple rightTuple = existsNode.getFirstRightTuple(leftTuple, rtm, context, it); rightTuple != null; rightTuple = (RightTuple) it.next(rightTuple)) {
if ( constraints.isAllowedCachedLeft( contextEntry,
rightTuple.getFactHandle() ) ) {
leftTuple.setBlocker( rightTuple );
if ( useLeftMemory ) {
rightTuple.addBlocked( leftTuple );
}
break;
}
}
if ( leftTuple.getBlocker() != null ) {
// tuple is not blocked to propagate
trgLeftTuples.addInsert( sink.createLeftTuple( leftTuple,
sink,
tupleMemory ) );
} else if ( useLeftMemory ) {
// LeftTuple is not blocked, so add to memory so other RightTuples can match
ltm.add( leftTuple );
}
leftTuple.clearStaged();
leftTuple = next;
}
srcLeftTuples.setInsert( null, 0 );
constraints.resetTuple( contextEntry );
}