use of org.drools.core.spi.BetaNodeFieldConstraint in project drools by kiegroup.
the class IndexUtil method sortEqualIndexable.
private static boolean sortEqualIndexable(int keyDepth, boolean[] indexable, BetaNodeFieldConstraint[] constraints, int start) {
boolean hasEqualIndexable = false;
int indexableCouter = 0;
for (int i = start; i < constraints.length; i++) {
if (isEqualIndexable(constraints[i])) {
hasEqualIndexable = true;
if (keyDepth > indexableCouter) {
swap(constraints, i, indexableCouter);
indexable[indexableCouter++] = true;
}
}
}
return hasEqualIndexable;
}
use of org.drools.core.spi.BetaNodeFieldConstraint in project drools by kiegroup.
the class PatternBuilder method createConstraints.
private Constraints createConstraints(BuildContext context, Pattern pattern) {
Constraints constraints = new Constraints();
// check if cross products for identity patterns should be disabled
checkRemoveIdentities(context, pattern, constraints.betaConstraints);
// checks if this pattern is nested inside a NOT CE
final boolean isNegative = isNegative(context);
for (Constraint constraint : pattern.getConstraints()) {
switch(constraint.getType()) {
case ALPHA:
linkAlphaConstraint((AlphaNodeFieldConstraint) constraint, constraints.alphaConstraints);
break;
case BETA:
linkBetaConstraint((BetaNodeFieldConstraint) constraint, constraints.betaConstraints);
if (isNegative && context.getKnowledgeBase().getConfiguration().getEventProcessingMode() == EventProcessingOption.STREAM && pattern.getObjectType().isEvent() && constraint.isTemporal()) {
checkDelaying(context, constraint);
}
break;
case XPATH:
constraints.xpathConstraints.add((XpathConstraint) constraint);
break;
default:
throw new RuntimeException("Unknown constraint type: " + constraint.getType() + ". This is a bug. Please contact development team.");
}
}
return constraints;
}
use of org.drools.core.spi.BetaNodeFieldConstraint in project drools by kiegroup.
the class AccumulateBuilder method build.
/**
* @inheritDoc
*/
public void build(final BuildContext context, final BuildUtils utils, final RuleConditionElement rce) {
final Accumulate accumulate = (Accumulate) rce;
boolean existSubNetwort = false;
context.pushRuleComponent(accumulate);
final List<BetaNodeFieldConstraint> resultBetaConstraints = context.getBetaconstraints();
final List<AlphaNodeFieldConstraint> resultAlphaConstraints = context.getAlphaConstraints();
RuleConditionElement source = accumulate.getSource();
if (source instanceof GroupElement) {
GroupElement ge = (GroupElement) source;
if (ge.isAnd() && ge.getChildren().size() == 1) {
source = ge.getChildren().get(0);
}
}
// get builder for the pattern
final ReteooComponentBuilder builder = utils.getBuilderFor(source);
// save tuple source and current pattern offset for later if needed
LeftTupleSource tupleSource = context.getTupleSource();
final int currentPatternIndex = context.getCurrentPatternOffset();
// builds the source pattern
builder.build(context, utils, source);
// if object source is null, then we need to adapt tuple source into a subnetwork
if (context.getObjectSource() == null) {
// attach right input adapter node to convert tuple source into an object source
RightInputAdapterNode riaNode = context.getComponentFactory().getNodeFactoryService().buildRightInputNode(context.getNextId(), context.getTupleSource(), tupleSource, context);
// attach right input adapter node to convert tuple source into an object source
context.setObjectSource(utils.attachNode(context, riaNode));
// restore tuple source from before the start of the sub network
context.setTupleSource(tupleSource);
// create a tuple start equals constraint and set it in the context
final TupleStartEqualsConstraint constraint = TupleStartEqualsConstraint.getInstance();
final List<BetaNodeFieldConstraint> betaConstraints = new ArrayList<BetaNodeFieldConstraint>();
betaConstraints.add(constraint);
context.setBetaconstraints(betaConstraints);
existSubNetwort = true;
}
NodeFactory nfactory = context.getComponentFactory().getNodeFactoryService();
final BetaConstraints resultsBinder = utils.createBetaNodeConstraint(context, resultBetaConstraints, true);
final BetaConstraints sourceBinder = utils.createBetaNodeConstraint(context, context.getBetaconstraints(), false);
AccumulateNode accNode = nfactory.buildAccumulateNode(context.getNextId(), context.getTupleSource(), context.getObjectSource(), resultAlphaConstraints.toArray(new AlphaNodeFieldConstraint[resultAlphaConstraints.size()]), sourceBinder, resultsBinder, accumulate, existSubNetwort, context);
context.setTupleSource(utils.attachNode(context, accNode));
// source pattern was bound, so nulling context
context.setObjectSource(null);
context.setCurrentPatternOffset(currentPatternIndex);
context.popRuleComponent();
}
Aggregations