Search in sources :

Example 11 with QueryDescr

use of org.drools.compiler.lang.descr.QueryDescr in project drools by kiegroup.

the class RuleBuilder method preProcess.

public static void preProcess(final RuleBuildContext context) {
    RuleDescr ruleDescr = context.getRuleDescr();
    // Query and get object instead of using String
    if (null != ruleDescr.getParentName() && null != context.getPkg().getRule(ruleDescr.getParentName())) {
        context.getRule().setParent(context.getPkg().getRule(ruleDescr.getParentName()));
    }
    parseUnitAnnotations(context, context.getRule(), ruleDescr);
    // add all the rule's meta attributes
    buildMetaAttributes(context);
    if (context.getRuleDescr() instanceof QueryDescr) {
        context.getDialect().getQueryBuilder().build(context, (QueryDescr) context.getRuleDescr());
    }
    context.initRule();
}
Also used : QueryDescr(org.drools.compiler.lang.descr.QueryDescr) RuleDescr(org.drools.compiler.lang.descr.RuleDescr)

Example 12 with QueryDescr

use of org.drools.compiler.lang.descr.QueryDescr in project drools by kiegroup.

the class RuleParserTest method testSimpleQuery.

@Test
public void testSimpleQuery() throws Exception {
    final QueryDescr query = (QueryDescr) parseResource("query", "simple_query.drl");
    assertNotNull(query);
    assertEquals("simple_query", query.getName());
    final AndDescr lhs = query.getLhs();
    assertNotNull(lhs);
    assertEquals(3, lhs.getDescrs().size());
    // Check first pattern
    final PatternDescr first = (PatternDescr) lhs.getDescrs().get(0);
    assertEquals("foo3", first.getIdentifier());
    assertEquals("Bar", first.getObjectType());
    assertEquals(1, first.getConstraint().getDescrs().size());
    AndDescr and = (AndDescr) first.getConstraint();
    ExprConstraintDescr fld = (ExprConstraintDescr) and.getDescrs().get(0);
    assertNotNull(fld);
    assertEquals("a==3", fld.getExpression());
    // Check second pattern
    final PatternDescr second = (PatternDescr) lhs.getDescrs().get(1);
    assertEquals("foo4", second.getIdentifier());
    assertEquals("Bar", second.getObjectType());
    assertEquals(1, second.getDescrs().size());
    // check it has field bindings.
    final ExprConstraintDescr bindingDescr = (ExprConstraintDescr) second.getDescrs().get(0);
    assertEquals("a4:a==4", bindingDescr.getExpression());
}
Also used : QueryDescr(org.drools.compiler.lang.descr.QueryDescr) PatternDescr(org.drools.compiler.lang.descr.PatternDescr) AndDescr(org.drools.compiler.lang.descr.AndDescr) ExprConstraintDescr(org.drools.compiler.lang.descr.ExprConstraintDescr) Test(org.junit.Test)

Aggregations

QueryDescr (org.drools.compiler.lang.descr.QueryDescr)12 RuleDescr (org.drools.compiler.lang.descr.RuleDescr)7 AndDescr (org.drools.compiler.lang.descr.AndDescr)6 PackageDescr (org.drools.compiler.lang.descr.PackageDescr)5 Test (org.junit.Test)5 PatternDescr (org.drools.compiler.lang.descr.PatternDescr)4 ExprConstraintDescr (org.drools.compiler.lang.descr.ExprConstraintDescr)3 Element (org.w3c.dom.Element)3 Cheese (org.drools.compiler.Cheese)2 KnowledgeBuilderImpl (org.drools.compiler.builder.impl.KnowledgeBuilderImpl)2 ConditionalElementDescr (org.drools.compiler.lang.descr.ConditionalElementDescr)2 MultiPatternDestinationDescr (org.drools.compiler.lang.descr.MultiPatternDestinationDescr)2 InternalKnowledgeBase (org.drools.core.impl.InternalKnowledgeBase)2 KiePackage (org.kie.api.definition.KiePackage)2 KieSession (org.kie.api.runtime.KieSession)2 InputStreamReader (java.io.InputStreamReader)1 List (java.util.List)1 Person (org.drools.compiler.Person)1 XmlPackageReader (org.drools.compiler.compiler.xml.XmlPackageReader)1 BindingDescr (org.drools.compiler.lang.descr.BindingDescr)1