Search in sources :

Example 1 with QUERY_INVOCATION_CALL

use of org.drools.modelcompiler.builder.generator.DslMethodNames.QUERY_INVOCATION_CALL in project drools by kiegroup.

the class QueryCall method buildPattern.

@Override
public void buildPattern() {
    MethodCallExpr callMethod = new MethodCallExpr(new NameExpr(queryDef), QUERY_INVOCATION_CALL);
    callMethod.addArgument("" + !pattern.isQuery());
    String queryName = context.getQueryName().orElseThrow(RuntimeException::new);
    List<QueryParameter> parameters = packageModel.getQueryDefWithType().get(queryDef).getContext().getQueryParameters();
    for (int i = 0; i < parameters.size(); i++) {
        String variableName = getVariableName(i);
        Expression parameter = context.getQueryParameterByName(variableName).map(qp -> (Expression) new MethodCallExpr(new NameExpr(queryName), QueryGenerator.toQueryArg(qp.getIndex()))).orElseGet(() -> context.getUnificationId(variableName).map(name -> context.getVarExpr(name)).orElseGet(() -> context.getVarExpr(variableName)));
        callMethod.addArgument(parameter);
    }
    context.addExpression(callMethod);
}
Also used : PackageModel(org.drools.modelcompiler.builder.PackageModel) RuleContext(org.drools.modelcompiler.builder.generator.RuleContext) List(java.util.List) DSLNode(org.drools.modelcompiler.builder.generator.visitor.DSLNode) QueryGenerator(org.drools.modelcompiler.builder.generator.QueryGenerator) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr) QueryParameter(org.drools.modelcompiler.builder.generator.QueryParameter) QUERY_INVOCATION_CALL(org.drools.modelcompiler.builder.generator.DslMethodNames.QUERY_INVOCATION_CALL) Expression(com.github.javaparser.ast.expr.Expression) PatternDescr(org.drools.drl.ast.descr.PatternDescr) NameExpr(com.github.javaparser.ast.expr.NameExpr) ExprConstraintDescr(org.drools.drl.ast.descr.ExprConstraintDescr) QueryParameter(org.drools.modelcompiler.builder.generator.QueryParameter) Expression(com.github.javaparser.ast.expr.Expression) NameExpr(com.github.javaparser.ast.expr.NameExpr) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

Expression (com.github.javaparser.ast.expr.Expression)1 MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)1 NameExpr (com.github.javaparser.ast.expr.NameExpr)1 List (java.util.List)1 ExprConstraintDescr (org.drools.drl.ast.descr.ExprConstraintDescr)1 PatternDescr (org.drools.drl.ast.descr.PatternDescr)1 PackageModel (org.drools.modelcompiler.builder.PackageModel)1 QUERY_INVOCATION_CALL (org.drools.modelcompiler.builder.generator.DslMethodNames.QUERY_INVOCATION_CALL)1 QueryGenerator (org.drools.modelcompiler.builder.generator.QueryGenerator)1 QueryParameter (org.drools.modelcompiler.builder.generator.QueryParameter)1 RuleContext (org.drools.modelcompiler.builder.generator.RuleContext)1 DSLNode (org.drools.modelcompiler.builder.generator.visitor.DSLNode)1