Search in sources :

Example 1 with Value

use of org.drools.model.Value in project drools by kiegroup.

the class KiePackagesBuilder method buildQueryPattern.

private RuleConditionElement buildQueryPattern(RuleContext ctx, QueryCallPattern queryPattern) {
    Pattern pattern = new Pattern(ctx.getNextPatternIndex(), 0, ClassObjectType.ObjectArray_ObjectType, null);
    InternalReadAccessor arrayReader = new SelfReferenceClassFieldReader(Object[].class);
    QueryArgument[] arguments = new QueryArgument[queryPattern.getArguments().length];
    List<Integer> varIndexList = new ArrayList<>();
    List<Declaration> requiredDeclarations = new ArrayList<>();
    for (int i = 0; i < queryPattern.getArguments().length; i++) {
        Argument arg = queryPattern.getArguments()[i];
        if (arg instanceof Variable) {
            Variable var = ((Variable) arg);
            Declaration decl = ctx.getDeclaration(var);
            if (decl != null) {
                requiredDeclarations.add(decl);
                arguments[i] = new QueryArgument.Declr(decl);
            } else {
                ArrayElementReader reader = new ArrayElementReader(arrayReader, i, arg.getType());
                pattern.addDeclaration(var.getName()).setReadAccessor(reader);
                arguments[i] = QueryArgument.VAR;
                varIndexList.add(i);
            }
        } else if (arg instanceof Value) {
            arguments[i] = new QueryArgument.Literal(((Value) arg).getValue());
        } else {
            throw new UnsupportedOperationException();
        }
    }
    return new QueryElement(pattern, queryPattern.getQuery().getName(), arguments, varIndexList.stream().mapToInt(i -> i).toArray(), requiredDeclarations.toArray(new Declaration[requiredDeclarations.size()]), queryPattern.isOpen(), // TODO: query.isAbductive() );
    false);
}
Also used : QueryCallPattern(org.drools.model.patterns.QueryCallPattern) AccumulatePattern(org.drools.model.AccumulatePattern) Pattern(org.drools.core.rule.Pattern) QueryArgument(org.drools.core.rule.QueryArgument) PrototypeVariable(org.drools.model.PrototypeVariable) Variable(org.drools.model.Variable) QueryArgument(org.drools.core.rule.QueryArgument) Argument(org.drools.model.Argument) ArrayList(java.util.ArrayList) QueryElement(org.drools.core.rule.QueryElement) SingleConstraint(org.drools.model.SingleConstraint) QueryNameConstraint(org.drools.core.rule.constraint.QueryNameConstraint) LambdaConstraint(org.drools.modelcompiler.constraints.LambdaConstraint) FlowDSL.entryPoint(org.drools.model.FlowDSL.entryPoint) UnificationConstraint(org.drools.modelcompiler.constraints.UnificationConstraint) EntryPoint(org.drools.model.EntryPoint) Constraint(org.drools.model.Constraint) SalienceInteger(org.drools.core.base.SalienceInteger) SelfReferenceClassFieldReader(org.drools.core.base.extractors.SelfReferenceClassFieldReader) InternalReadAccessor(org.drools.core.spi.InternalReadAccessor) Value(org.drools.model.Value) ArrayElementReader(org.drools.core.base.extractors.ArrayElementReader) Declaration(org.drools.core.rule.Declaration) WindowDeclaration(org.drools.core.rule.WindowDeclaration) TypeDeclarationUtil.createTypeDeclaration(org.drools.modelcompiler.util.TypeDeclarationUtil.createTypeDeclaration) TypeDeclaration(org.drools.core.rule.TypeDeclaration)

Aggregations

ArrayList (java.util.ArrayList)1 SalienceInteger (org.drools.core.base.SalienceInteger)1 ArrayElementReader (org.drools.core.base.extractors.ArrayElementReader)1 SelfReferenceClassFieldReader (org.drools.core.base.extractors.SelfReferenceClassFieldReader)1 Declaration (org.drools.core.rule.Declaration)1 Pattern (org.drools.core.rule.Pattern)1 QueryArgument (org.drools.core.rule.QueryArgument)1 QueryElement (org.drools.core.rule.QueryElement)1 TypeDeclaration (org.drools.core.rule.TypeDeclaration)1 WindowDeclaration (org.drools.core.rule.WindowDeclaration)1 QueryNameConstraint (org.drools.core.rule.constraint.QueryNameConstraint)1 InternalReadAccessor (org.drools.core.spi.InternalReadAccessor)1 AccumulatePattern (org.drools.model.AccumulatePattern)1 Argument (org.drools.model.Argument)1 Constraint (org.drools.model.Constraint)1 EntryPoint (org.drools.model.EntryPoint)1 FlowDSL.entryPoint (org.drools.model.FlowDSL.entryPoint)1 PrototypeVariable (org.drools.model.PrototypeVariable)1 SingleConstraint (org.drools.model.SingleConstraint)1 Value (org.drools.model.Value)1