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);
}
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;
}
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);
}
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);
}
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);
}
Aggregations