use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.
the class BetaNodeBuilder method build.
public BetaNode build() {
NodeFactory nFactory = buildContext.getComponentFactory().getNodeFactoryService();
EntryPointNode epn = buildContext.getKnowledgeBase().getRete().getEntryPointNodes().values().iterator().next();
ObjectTypeNode otn = nFactory.buildObjectTypeNode(buildContext.getNextId(), epn, new ClassObjectType(leftType), buildContext);
LeftInputAdapterNode leftInput = nFactory.buildLeftInputAdapterNode(buildContext.getNextId(), otn, buildContext);
ObjectSource rightInput = nFactory.buildObjectTypeNode(buildContext.getNextId(), epn, new ClassObjectType(rightType), buildContext);
ReteTesterHelper reteTesterHelper = new ReteTesterHelper();
Pattern pattern = new Pattern(0, new ClassObjectType(leftType));
// BetaNodeFieldConstraint betaConstraint = null;
BetaConstraints betaConstraints = null;
if (constraintFieldName != null) {
ClassFieldAccessorStore store = (ClassFieldAccessorStore) reteTesterHelper.getStore();
InternalReadAccessor extractor = store.getReader(leftType, leftFieldName);
Declaration declr = new Declaration(leftVariableName, extractor, pattern);
betaConstraints = new SingleBetaConstraints(reteTesterHelper.getBoundVariableConstraint(rightType, constraintFieldName, declr, constraintOperator), buildContext.getKnowledgeBase().getConfiguration());
} else {
betaConstraints = new EmptyBetaConstraints();
}
switch(nodeType) {
case NodeTypeEnums.JoinNode:
return new JoinNode(0, leftInput, rightInput, betaConstraints, buildContext);
case NodeTypeEnums.NotNode:
return new NotNode(0, leftInput, rightInput, betaConstraints, buildContext);
case NodeTypeEnums.ExistsNode:
return new ExistsNode(0, leftInput, rightInput, betaConstraints, buildContext);
}
throw new IllegalStateException("Unable to build Node");
}
use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.
the class NodeSegmentUnlinkingTest method createBetaNode.
private BetaNode createBetaNode(int id, int type, LeftTupleSource leftTupleSource) {
MockObjectSource mockObjectSource = new MockObjectSource(8);
BetaNode betaNode = null;
switch(type) {
case JOIN_NODE:
{
betaNode = new JoinNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
break;
}
case EXISTS_NODE:
{
betaNode = new ExistsNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
break;
}
case NOT_NODE:
{
betaNode = new NotNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
break;
}
}
mockObjectSource.attach(buildContext);
betaNode.attach(buildContext);
return betaNode;
}
use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.
the class NodeSegmentUnlinkingTest method testSingleNodeinSegment.
@Test
public void testSingleNodeinSegment() {
rule1 = new RuleImpl("rule1");
rule2 = new RuleImpl("rule2");
rule3 = new RuleImpl("rule3");
KieBaseConfiguration kconf = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
kBase = (InternalKnowledgeBase) KnowledgeBaseFactory.newKnowledgeBase(kconf);
BuildContext buildContext = new BuildContext(kBase);
MockObjectSource mockObjectSource = new MockObjectSource(8);
MockTupleSource mockTupleSource = new MockTupleSource(9);
// n2 is only node in it's segment
ObjectTypeNode otn = new ObjectTypeNode(2, null, new ClassObjectType(String.class), buildContext);
BetaNode n1 = new JoinNode(10, new LeftInputAdapterNode(3, otn, buildContext), mockObjectSource, new EmptyBetaConstraints(), buildContext);
BetaNode n2 = new JoinNode(11, n1, mockObjectSource, new EmptyBetaConstraints(), buildContext);
BetaNode n3 = new JoinNode(12, n1, mockObjectSource, new EmptyBetaConstraints(), buildContext);
BetaNode n4 = new JoinNode(13, n2, mockObjectSource, new EmptyBetaConstraints(), buildContext);
BetaNode n5 = new JoinNode(14, n2, mockObjectSource, new EmptyBetaConstraints(), buildContext);
n1.addAssociation(rule1);
n1.addAssociation(rule2);
n1.addAssociation(rule3);
n2.addAssociation(rule2);
n2.addAssociation(rule3);
n3.addAssociation(rule1);
n4.addAssociation(rule2);
n5.addAssociation(rule3);
mockObjectSource.attach(buildContext);
mockTupleSource.attach(buildContext);
n1.attach(buildContext);
n2.attach(buildContext);
n3.attach(buildContext);
n4.attach(buildContext);
n5.attach(buildContext);
StatefulKnowledgeSessionImpl ksession = (StatefulKnowledgeSessionImpl) kBase.newKieSession();
createSegmentMemory(n2, ksession);
BetaMemory bm = (BetaMemory) ksession.getNodeMemory(n1);
assertNull(bm.getSegmentMemory());
bm = (BetaMemory) ksession.getNodeMemory(n3);
assertNull(bm.getSegmentMemory());
bm = (BetaMemory) ksession.getNodeMemory(n4);
assertNull(bm.getSegmentMemory());
bm = (BetaMemory) ksession.getNodeMemory(n2);
assertEquals(1, bm.getNodePosMaskBit());
assertEquals(1, bm.getSegmentMemory().getAllLinkedMaskTest());
}
use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.
the class RuleUnlinkingWithSegmentMemoryTest method createNetworkNode.
private NetworkNode createNetworkNode(int id, int type, LeftTupleSource leftTupleSource, RuleImpl rule) {
MockObjectSource mockObjectSource = new MockObjectSource(8);
LeftTupleSink networkNode = null;
switch(type) {
case JOIN_NODE:
{
networkNode = new JoinNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
break;
}
case EXISTS_NODE:
{
networkNode = new ExistsNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
break;
}
case NOT_NODE:
{
networkNode = new NotNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
break;
}
case RULE_TERMINAL_NODE:
{
networkNode = new RuleTerminalNode(id, leftTupleSource, rule, new GroupElement(Type.AND), 0, buildContext);
break;
}
}
mockObjectSource.attach();
if (NodeTypeEnums.isLeftTupleSource(networkNode)) {
((LeftTupleSource) networkNode).attach(buildContext);
} else {
((RuleTerminalNode) networkNode).attach(buildContext);
}
return networkNode;
}
use of org.drools.core.common.EmptyBetaConstraints in project drools by kiegroup.
the class RuleUnlinkingTest method createNetworkNode.
private NetworkNode createNetworkNode(int id, int type, LeftTupleSource leftTupleSource, RuleImpl rule) {
MockObjectSource mockObjectSource = new MockObjectSource(8);
LeftTupleSink networkNode = null;
switch(type) {
case JOIN_NODE:
{
networkNode = new JoinNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
break;
}
case EXISTS_NODE:
{
networkNode = new ExistsNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
break;
}
case NOT_NODE:
{
networkNode = new NotNode(id, leftTupleSource, mockObjectSource, new EmptyBetaConstraints(), buildContext);
break;
}
case RULE_TERMINAL_NODE:
{
networkNode = new RuleTerminalNode(id, leftTupleSource, rule, new GroupElement(Type.AND), 0, buildContext);
break;
}
}
mockObjectSource.attach();
if (NodeTypeEnums.isLeftTupleSource(networkNode)) {
((LeftTupleSource) networkNode).attach(buildContext);
} else {
((RuleTerminalNode) networkNode).attach(buildContext);
}
return networkNode;
}
Aggregations