public override void compileSingleCE(Rule.IRule rule) { ICondition[] conds = rule.Conditions; ICondition condition = conds[0]; ExistCondition cond = (ExistCondition)condition; BaseNode base_Renamed = cond.LastNode; BaseJoin bjoin = new ExistJoinFrst(ruleCompiler.Engine.nextNodeId()); if (base_Renamed != null) { if (base_Renamed is BaseAlpha) { ((BaseAlpha)base_Renamed).addSuccessorNode(bjoin, ruleCompiler.Engine, ruleCompiler.Memory); } else if (base_Renamed is BaseJoin) { ((BaseJoin)base_Renamed).addSuccessorNode(bjoin, ruleCompiler.Engine, ruleCompiler.Memory); } } else { // the rule doesn't have a literal constraint so we need to Add // ExistJoinFrst as a child ObjectTypeNode otn = ruleCompiler.findObjectTypeNode(cond.TemplateName); otn.addSuccessorNode(bjoin, ruleCompiler.Engine, ruleCompiler.Memory); } // important, do not call this before ExistJoinFrst is added // if it's called first, the List<Object> will return index // out of bound, since there's nothing in the list cond.addNode(bjoin); rule.addJoinNode(bjoin); }
public override void compileSingleCE(Rule.IRule rule) { ICondition[] conds = rule.Conditions; ObjectCondition oc = (ObjectCondition)conds[0]; if (oc.Negated) { // the ObjectCondition is negated, so we need to // handle it appropriate. This means we need to // Add a LIANode to _IntialFact and attach a NOTNode // to the LIANode. ObjectTypeNode otn = (ObjectTypeNode)ruleCompiler.Inputnodes.Get(ruleCompiler.Engine.InitFact); LIANode lianode = ruleCompiler.findLIANode(otn); NotJoin njoin = new NotJoin(ruleCompiler.Engine.nextNodeId()); njoin.Bindings = new Binding[0]; lianode.addSuccessorNode(njoin, ruleCompiler.Engine, ruleCompiler.Memory); // Add the join to the rule object rule.addJoinNode(njoin); oc.LastNode.addSuccessorNode(njoin, ruleCompiler.Engine, ruleCompiler.Memory); } else if (oc.Nodes.Count == 0) { // this means the rule has a binding, but no conditions ObjectTypeNode otn = ruleCompiler.findObjectTypeNode(oc.TemplateName); LIANode lianode = new LIANode(ruleCompiler.Engine.nextNodeId()); otn.addSuccessorNode(lianode, ruleCompiler.Engine, ruleCompiler.Memory); rule.Conditions[0].addNode(lianode); } }
public override void compileFirstJoin(ICondition condition, Rule.IRule rule) { ObjectCondition cond = (ObjectCondition)condition; ObjectTypeNode otn = ruleCompiler.findObjectTypeNode(cond.TemplateName); // the LeftInputAdapterNode is the first node to propogate to // the first joinNode of the rule LIANode node = new LIANode(ruleCompiler.Engine.nextNodeId()); // if the condition doesn't have any nodes, we want to Add it to // the objectType node if one doesn't already exist. // otherwise we Add it to the last AlphaNode if (cond.Nodes.Count == 0) { // try to find the existing LIANode for the given ObjectTypeNode // if we don't do this, we end up with multiple LIANodes // descending directly from the ObjectTypeNode LIANode existingLIANode = ruleCompiler.findLIANode(otn); if (existingLIANode == null) { otn.addSuccessorNode(node, ruleCompiler.Engine, ruleCompiler.Memory); cond.addNode(node); } else { existingLIANode.incrementUseCount(); cond.addNode(existingLIANode); } } else { // Add the LeftInputAdapterNode to the last alphaNode // In the case of node sharing, the LIANode could be the last // alphaNode, so we have to check and only Add the node to // the condition if it isn't a LIANode BaseAlpha old = (BaseAlpha)cond.LastNode; //if the last node of condition has a LIANode successor, //the LIANode should be shared with the new CE followed by another CE. // Houzhanbin,10/16/2007 BaseNode[] successors = (BaseNode[])old.SuccessorNodes; for (int i = 0; i < successors.Length; i++) { if (successors[i] is LIANode) { cond.addNode(successors[i]); return; } } if (!(old is LIANode)) { old.addSuccessorNode(node, ruleCompiler.Engine, ruleCompiler.Memory); cond.addNode(node); } } }
/// <summary> The first step is to connect the exist join to the parent on the left side. /// The second step is to connect it to the parent on the right. For the right /// side, if the objectCondition doesn't have any nodes, we attach it to the /// objectType node. /// </summary> public void connectJoinNode(ICondition previousCondition, ICondition condition, BaseJoin previousJoinNode, BaseJoin joinNode) { if (previousJoinNode != null) { ruleCompiler.attachJoinNode(previousJoinNode, (BaseJoin)joinNode); } else { ruleCompiler.attachJoinNode(previousCondition.LastNode, (BaseJoin)joinNode); } // Current we have to Add the ExistJoin for the right side, which should be either // an alphaNode or the objectTypeNode ObjectCondition oc = getObjectCondition(condition); ObjectTypeNode otn = ruleCompiler.findObjectTypeNode(oc.TemplateName); if (oc.Nodes.Count > 0) { ruleCompiler.attachJoinNode(oc.LastNode, (BaseJoin)joinNode); } else { otn.addSuccessorNode(joinNode, ruleCompiler.Engine, ruleCompiler.Engine.WorkingMemory); } }