public void doNode( FromNode fromNode, FromMemory fm, LeftTupleSink sink, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples, TupleSets<LeftTuple> stagedLeftTuples) { if (srcLeftTuples.getDeleteFirst() != null) { doLeftDeletes(fm, srcLeftTuples, trgLeftTuples, stagedLeftTuples); } if (srcLeftTuples.getUpdateFirst() != null) { doLeftUpdates(fromNode, fm, sink, wm, srcLeftTuples, trgLeftTuples, stagedLeftTuples); } if (srcLeftTuples.getInsertFirst() != null) { doLeftInserts(fromNode, fm, sink, wm, srcLeftTuples, trgLeftTuples); } srcLeftTuples.resetAll(); }
public void doLeftInserts( FromNode fromNode, FromMemory fm, LeftTupleSink sink, InternalWorkingMemory wm, TupleSets<LeftTuple> srcLeftTuples, TupleSets<LeftTuple> trgLeftTuples) { BetaMemory bm = fm.getBetaMemory(); ContextEntry[] context = bm.getContext(); BetaConstraints betaConstraints = fromNode.getBetaConstraints(); AlphaNodeFieldConstraint[] alphaConstraints = fromNode.getAlphaConstraints(); DataProvider dataProvider = fromNode.getDataProvider(); Class<?> resultClass = fromNode.getResultClass(); for (LeftTuple leftTuple = srcLeftTuples.getInsertFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); PropagationContext propagationContext = leftTuple.getPropagationContext(); Map<Object, RightTuple> matches = null; boolean useLeftMemory = RuleNetworkEvaluator.useLeftMemory(fromNode, leftTuple); if (useLeftMemory) { fm.getBetaMemory().getLeftTupleMemory().add(leftTuple); matches = new LinkedHashMap<Object, RightTuple>(); leftTuple.setContextObject(matches); } betaConstraints.updateFromTuple(context, wm, leftTuple); for (final java.util.Iterator<?> it = dataProvider.getResults(leftTuple, wm, propagationContext, fm.providerContext); it.hasNext(); ) { final Object object = it.next(); if ((object == null) || !resultClass.isAssignableFrom(object.getClass())) { continue; // skip anything if it not assignable } RightTuple rightTuple = fromNode.createRightTuple(leftTuple, propagationContext, wm, object); checkConstraintsAndPropagate( sink, leftTuple, rightTuple, alphaConstraints, betaConstraints, propagationContext, wm, fm, context, useLeftMemory, trgLeftTuples, null); if (useLeftMemory) { fromNode.addToCreatedHandlesMap(matches, rightTuple); } } leftTuple.clearStaged(); leftTuple = next; } betaConstraints.resetTuple(context); }
private void doRiaNode2( InternalWorkingMemory wm, TupleSets<LeftTuple> srcTuples, RightInputAdapterNode riaNode) { ObjectSink[] sinks = riaNode.getSinkPropagator().getSinks(); BetaNode betaNode = (BetaNode) sinks[0]; BetaMemory bm; Memory nodeMem = wm.getNodeMemory(betaNode); if (NodeTypeEnums.AccumulateNode == betaNode.getType()) { bm = ((AccumulateMemory) nodeMem).getBetaMemory(); } else { bm = (BetaMemory) nodeMem; } // Build up iteration array for other sinks BetaNode[] bns = null; BetaMemory[] bms = null; int length = sinks.length; if (length > 1) { bns = new BetaNode[sinks.length - 1]; bms = new BetaMemory[sinks.length - 1]; for (int i = 1; i < length; i++) { bns[i - 1] = (BetaNode) sinks[i]; Memory nodeMem2 = wm.getNodeMemory(bns[i - 1]); if (NodeTypeEnums.AccumulateNode == betaNode.getType()) { bms[i - 1] = ((AccumulateMemory) nodeMem2).getBetaMemory(); } else { bms[i - 1] = (BetaMemory) nodeMem2; } } } length--; // subtract one, as first is not in the array; for (LeftTuple leftTuple = srcTuples.getInsertFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); PropagationContext pctx = leftTuple.getPropagationContext(); InternalFactHandle handle = riaNode.createFactHandle(leftTuple, pctx, wm); RightTuple rightTuple = new RightTupleImpl(handle, betaNode); leftTuple.setContextObject(handle); rightTuple.setPropagationContext(pctx); if (bm.getStagedRightTuples().isEmpty()) { bm.setNodeDirtyWithoutNotify(); } bm.getStagedRightTuples().addInsert(rightTuple); if (bns != null) { // Add peered RightTuples, they are attached to FH - unlink LeftTuples that has a peer ref for (int i = 0; i < length; i++) { rightTuple = new RightTupleImpl(handle, bns[i]); rightTuple.setPropagationContext(pctx); if (bms[i].getStagedRightTuples().isEmpty()) { bms[i].setNodeDirtyWithoutNotify(); } bms[i].getStagedRightTuples().addInsert(rightTuple); } } leftTuple.clearStaged(); leftTuple = next; } for (LeftTuple leftTuple = srcTuples.getDeleteFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); InternalFactHandle handle = (InternalFactHandle) leftTuple.getContextObject(); RightTuple rightTuple = handle.getFirstRightTuple(); TupleSets<RightTuple> rightTuples = bm.getStagedRightTuples(); if (rightTuples.isEmpty()) { bm.setNodeDirtyWithoutNotify(); } rightTuples.addDelete(rightTuple); if (bns != null) { // Add peered RightTuples, they are attached to FH - unlink LeftTuples that has a peer ref for (int i = 0; i < length; i++) { rightTuple = rightTuple.getHandleNext(); rightTuples = bms[i].getStagedRightTuples(); if (rightTuples.isEmpty()) { bms[i].setNodeDirtyWithoutNotify(); } rightTuples.addDelete(rightTuple); } } leftTuple.clearStaged(); leftTuple = next; } for (LeftTuple leftTuple = srcTuples.getUpdateFirst(); leftTuple != null; ) { LeftTuple next = leftTuple.getStagedNext(); InternalFactHandle handle = (InternalFactHandle) leftTuple.getContextObject(); RightTuple rightTuple = handle.getFirstRightTuple(); TupleSets<RightTuple> rightTuples = bm.getStagedRightTuples(); if (rightTuples.isEmpty()) { bm.setNodeDirtyWithoutNotify(); } rightTuples.addUpdate(rightTuple); if (bns != null) { // Add peered RightTuples, they are attached to FH - unlink LeftTuples that has a peer ref for (int i = 0; i < length; i++) { rightTuple = rightTuple.getHandleNext(); rightTuples = bms[i].getStagedRightTuples(); if (rightTuples.isEmpty()) { bms[i].setNodeDirtyWithoutNotify(); } rightTuples.addUpdate(rightTuple); } } leftTuple.clearStaged(); leftTuple = next; } srcTuples.resetAll(); }