use of org.drools.model.Query1Def in project drools by kiegroup.
the class FlowTest method testQueryWithNamedArg.
@Test
public void testQueryWithNamedArg() {
Variable<Person> personV = declarationOf(Person.class, "$p");
Query1Def<Integer> qdef = query("olderThan", Integer.class, "ageArg");
Query query = qdef.build(expr("exprA", personV, qdef.getArg("ageArg", Integer.class), (p, a) -> p.getAge() > a));
Model model = new ModelImpl().addQuery(query);
KieBase kieBase = KieBaseBuilder.createKieBaseFromModel(model);
KieSession ksession = kieBase.newKieSession();
ksession.insert(new Person("Mark", 39));
ksession.insert(new Person("Mario", 41));
QueryResults results = ksession.getQueryResults("olderThan", 40);
assertEquals(1, results.size());
Person p = (Person) results.iterator().next().get("$p");
assertEquals("Mario", p.getName());
}
use of org.drools.model.Query1Def in project drools by kiegroup.
the class FlowTest method testQuery.
@Test
public void testQuery() {
Variable<Person> personV = declarationOf(Person.class, "$p");
Query1Def<Integer> qdef = query("olderThan", Integer.class);
Query query = qdef.build(expr("exprA", personV, qdef.getArg1(), (p, a) -> p.getAge() > a));
Model model = new ModelImpl().addQuery(query);
KieBase kieBase = KieBaseBuilder.createKieBaseFromModel(model);
KieSession ksession = kieBase.newKieSession();
ksession.insert(new Person("Mark", 39));
ksession.insert(new Person("Mario", 41));
QueryResults results = ksession.getQueryResults("olderThan", 40);
assertEquals(1, results.size());
Person p = (Person) results.iterator().next().get("$p");
assertEquals("Mario", p.getName());
}
use of org.drools.model.Query1Def in project drools by kiegroup.
the class FlowTest method testQueryInvokingQuery.
@Test
public void testQueryInvokingQuery() {
Variable<Relationship> relV = declarationOf(Relationship.class);
Query2Def<String, String> query1Def = query("isRelatedTo1", String.class, String.class);
Query2Def<String, String> query2Def = query("isRelatedTo2", String.class, String.class);
Query query2 = query2Def.build(expr("exprA", relV, query2Def.getArg1(), (r, s) -> r.getStart().equals(s)), expr("exprB", relV, query2Def.getArg2(), (r, e) -> r.getEnd().equals(e)));
Query query1 = query1Def.build(query2Def.call(query1Def.getArg1(), query1Def.getArg2()));
Model model = new ModelImpl().addQuery(query2).addQuery(query1);
KieBase kieBase = KieBaseBuilder.createKieBaseFromModel(model);
KieSession ksession = kieBase.newKieSession();
ksession.insert(new Relationship("A", "B"));
ksession.insert(new Relationship("B", "C"));
QueryResults results = ksession.getQueryResults("isRelatedTo1", "A", "B");
assertEquals(1, results.size());
assertEquals("B", results.iterator().next().get(query1Def.getArg2().getName()));
}
Aggregations