Search in sources :

Example 1 with BetaNodeFieldConstraint

use of org.drools.core.spi.BetaNodeFieldConstraint in project drools by kiegroup.

the class BetaNode method writeExternal.

public void writeExternal(ObjectOutput out) throws IOException {
    BetaNodeFieldConstraint[] betaCconstraints = this.constraints.getConstraints();
    if (betaCconstraints.length > 0) {
        BetaNodeFieldConstraint c = betaCconstraints[0];
        if (IndexUtil.isIndexable(c, getType()) && ((IndexableConstraint) c).isUnification()) {
            setConstraints(this.constraints.getOriginalConstraint());
        }
    }
    out.writeObject(constraints);
    out.writeBoolean(objectMemory);
    out.writeBoolean(tupleMemoryEnabled);
    out.writeObject(rightDeclaredMask);
    out.writeObject(rightInferredMask);
    out.writeObject(rightNegativeMask);
    out.writeObject(leftListenedProperties);
    out.writeObject(rightListenedProperties);
    out.writeBoolean(rightInputIsPassive);
    super.writeExternal(out);
}
Also used : BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint)

Example 2 with BetaNodeFieldConstraint

use of org.drools.core.spi.BetaNodeFieldConstraint in project drools by kiegroup.

the class DefaultBetaConstraints method cloneIfInUse.

public DefaultBetaConstraints cloneIfInUse() {
    if (constraints[0] instanceof MutableTypeConstraint && ((MutableTypeConstraint) constraints[0]).setInUse()) {
        BetaNodeFieldConstraint[] clonedConstraints = new BetaNodeFieldConstraint[constraints.length];
        for (int i = 0; i < constraints.length; i++) {
            clonedConstraints[i] = constraints[i].cloneIfInUse();
        }
        DefaultBetaConstraints clone = new DefaultBetaConstraints();
        clone.constraints = clonedConstraints;
        clone.disableIndexing = disableIndexing;
        clone.indexPrecedenceOption = indexPrecedenceOption;
        clone.indexed = indexed;
        return clone;
    }
    return this;
}
Also used : MutableTypeConstraint(org.drools.core.rule.MutableTypeConstraint) BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint) BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint) MutableTypeConstraint(org.drools.core.rule.MutableTypeConstraint) MvelConstraint(org.drools.core.rule.constraint.MvelConstraint) IndexableConstraint(org.drools.core.rule.IndexableConstraint)

Example 3 with BetaNodeFieldConstraint

use of org.drools.core.spi.BetaNodeFieldConstraint in project drools by kiegroup.

the class JavaDialectTest method testEvalDetectionInBetaNode.

@Test
public void testEvalDetectionInBetaNode() {
    // Tests evals are generated and executed with Java dialect
    String drl = "";
    drl += "package org.drools.compiler.test\n";
    drl += "import org.drools.compiler.Person\n";
    drl += "global java.util.List list\n";
    drl += "rule test1\n";
    drl += "when\n";
    drl += "   $s  : String()\n";
    drl += "   $p1 : Person( eval( name \n != $s ), name == ( new String($s+\"xxx\") ) )\n";
    drl += "then\n";
    drl += "end\n";
    KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
    kbuilder.add(ResourceFactory.newReaderResource(new StringReader(drl)), ResourceType.DRL);
    KnowledgeBuilderErrors errors = kbuilder.getErrors();
    if (kbuilder.hasErrors()) {
        fail(kbuilder.getErrors().toString());
    }
    assertFalse(kbuilder.hasErrors());
    InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
    kbase.addPackages(kbuilder.getKnowledgePackages());
    List<ObjectTypeNode> nodes = ((KnowledgeBaseImpl) kbase).getRete().getObjectTypeNodes();
    ObjectTypeNode node = null;
    for (ObjectTypeNode n : nodes) {
        if (((ClassObjectType) n.getObjectType()).getClassType() == Person.class) {
            node = n;
            break;
        }
    }
    BetaNode betaanode = (BetaNode) node.getObjectSinkPropagator().getSinks()[0];
    BetaNodeFieldConstraint[] constraint = betaanode.getConstraints();
    PredicateConstraint c = (PredicateConstraint) constraint[0];
    assertTrue(c.getPredicateExpression() instanceof PredicateExpression);
    assertTrue(c.getPredicateExpression() instanceof CompiledInvoker);
}
Also used : BetaNode(org.drools.core.reteoo.BetaNode) KnowledgeBuilderErrors(org.kie.internal.builder.KnowledgeBuilderErrors) ObjectTypeNode(org.drools.core.reteoo.ObjectTypeNode) PredicateExpression(org.drools.core.spi.PredicateExpression) BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint) CompiledInvoker(org.drools.core.spi.CompiledInvoker) KnowledgeBuilder(org.kie.internal.builder.KnowledgeBuilder) StringReader(java.io.StringReader) PredicateConstraint(org.drools.core.rule.PredicateConstraint) InternalKnowledgeBase(org.drools.core.impl.InternalKnowledgeBase) Test(org.junit.Test)

Example 4 with BetaNodeFieldConstraint

use of org.drools.core.spi.BetaNodeFieldConstraint in project drools by kiegroup.

the class DefaultBetaConstraintsTest method testTripleIndexNotFirst.

@Test
public void testTripleIndexNotFirst() {
    BetaNodeFieldConstraint constraint0 = getConstraint("cheeseType1", Operator.NOT_EQUAL, "type", Cheese.class);
    BetaNodeFieldConstraint constraint1 = getConstraint("cheeseType2", Operator.EQUAL, "type", Cheese.class);
    BetaNodeFieldConstraint constraint2 = getConstraint("cheeseType3", Operator.NOT_EQUAL, "type", Cheese.class);
    BetaNodeFieldConstraint constraint3 = getConstraint("cheeseType4", Operator.EQUAL, "type", Cheese.class);
    BetaNodeFieldConstraint constraint4 = getConstraint("cheeseType5", Operator.EQUAL, "type", Cheese.class);
    BetaNodeFieldConstraint[] constraints = new BetaNodeFieldConstraint[] { constraint0, constraint1, constraint2, constraint3, constraint4 };
    checkBetaConstraints(constraints, DefaultBetaConstraints.class);
}
Also used : BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint) Test(org.junit.Test)

Example 5 with BetaNodeFieldConstraint

use of org.drools.core.spi.BetaNodeFieldConstraint in project drools by kiegroup.

the class DefaultBetaConstraintsTest method testNoIndexConstraints.

@Test
public void testNoIndexConstraints() {
    BetaNodeFieldConstraint constraint0 = getConstraint("cheeseType0", Operator.NOT_EQUAL, "type", Cheese.class);
    BetaNodeFieldConstraint[] constraints = new BetaNodeFieldConstraint[] { constraint0 };
    checkBetaConstraints(constraints, DefaultBetaConstraints.class);
    BetaNodeFieldConstraint constraint1 = getConstraint("cheeseType1", Operator.NOT_EQUAL, "type", Cheese.class);
    constraints = new BetaNodeFieldConstraint[] { constraint0, constraint1 };
    checkBetaConstraints(constraints, DefaultBetaConstraints.class);
    BetaNodeFieldConstraint constraint2 = getConstraint("cheeseType2", Operator.NOT_EQUAL, "type", Cheese.class);
    constraints = new BetaNodeFieldConstraint[] { constraint0, constraint1, constraint2 };
    checkBetaConstraints(constraints, DefaultBetaConstraints.class);
    BetaNodeFieldConstraint constraint3 = getConstraint("cheeseType3", Operator.NOT_EQUAL, "type", Cheese.class);
    constraints = new BetaNodeFieldConstraint[] { constraint0, constraint1, constraint2, constraint3 };
    checkBetaConstraints(constraints, DefaultBetaConstraints.class);
    BetaNodeFieldConstraint constraint4 = getConstraint("cheeseType4", Operator.NOT_EQUAL, "type", Cheese.class);
    constraints = new BetaNodeFieldConstraint[] { constraint0, constraint1, constraint2, constraint3, constraint4 };
    checkBetaConstraints(constraints, DefaultBetaConstraints.class);
    BetaNodeFieldConstraint constraint5 = getConstraint("cheeseType5", Operator.NOT_EQUAL, "type", Cheese.class);
    constraints = new BetaNodeFieldConstraint[] { constraint0, constraint1, constraint2, constraint3, constraint5 };
    checkBetaConstraints(constraints, DefaultBetaConstraints.class);
    BetaNodeFieldConstraint constraint6 = getConstraint("cheeseType6", Operator.NOT_EQUAL, "type", Cheese.class);
    constraints = new BetaNodeFieldConstraint[] { constraint0, constraint1, constraint2, constraint3, constraint4, constraint5, constraint6 };
    checkBetaConstraints(constraints, DefaultBetaConstraints.class);
}
Also used : BetaNodeFieldConstraint(org.drools.core.spi.BetaNodeFieldConstraint) Test(org.junit.Test)

Aggregations

BetaNodeFieldConstraint (org.drools.core.spi.BetaNodeFieldConstraint)43 Test (org.junit.Test)28 MvelConstraint (org.drools.core.rule.constraint.MvelConstraint)8 IndexableConstraint (org.drools.core.rule.IndexableConstraint)7 Cheese (org.drools.core.test.model.Cheese)6 ArrayList (java.util.ArrayList)5 Constraint (org.drools.core.spi.Constraint)5 BetaConstraints (org.drools.core.common.BetaConstraints)4 MutableTypeConstraint (org.drools.core.rule.MutableTypeConstraint)4 RuleBaseConfiguration (org.drools.core.RuleBaseConfiguration)3 BetaMemory (org.drools.core.reteoo.BetaMemory)3 AlphaNodeFieldConstraint (org.drools.core.spi.AlphaNodeFieldConstraint)3 TupleIndexHashTable (org.drools.core.util.index.TupleIndexHashTable)3 TupleList (org.drools.core.util.index.TupleList)3 List (java.util.List)2 InternalFactHandle (org.drools.core.common.InternalFactHandle)2 SingleBetaConstraints (org.drools.core.common.SingleBetaConstraints)2 TupleStartEqualsConstraint (org.drools.core.common.TupleStartEqualsConstraint)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)2 AccumulateNode (org.drools.core.reteoo.AccumulateNode)2