use of org.drools.compiler.oopath.model.Child in project drools by kiegroup.
the class OOPathMultilevelTest method testClassThreeLevelPath.
@Test
public void testClassThreeLevelPath() {
final String drl = "import org.drools.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Man( $toyName: /wife/children/toys/name )\n" + "then\n" + " list.add( $toyName );\n" + "end\n";
final KieSession ksession = new KieHelper().addContent(drl, ResourceType.DRL).build().newKieSession();
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
final Woman alice = new Woman("Alice", 38);
final Man bob = new Man("Bob", 40);
bob.setWife(alice);
final Child charlie = new Child("Charles", 12);
alice.addChild(charlie);
charlie.addToy(new Toy("car"));
charlie.addToy(new Toy("ball"));
ksession.insert(bob);
ksession.fireAllRules();
Assertions.assertThat(list).containsExactlyInAnyOrder("car", "ball");
}
use of org.drools.compiler.oopath.model.Child in project drools by kiegroup.
the class OOPathBenchmarkTest method testRelational.
public static long[] testRelational(KieBase kbase, int n) {
final long[] result = new long[2];
final KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
final List<Man> model = generateModel(n);
final List<Child> toBeModified = getChildToBeModified(model);
long start = System.nanoTime();
final List<InternalFactHandle> fhs = insertFullModel(ksession, model);
ksession.fireAllRules();
result[0] = System.nanoTime() - start;
list.clear();
start = System.nanoTime();
for (Child child : toBeModified) {
child.setAge(11);
}
for (InternalFactHandle fh : fhs) {
ksession.update(fh, fh.getObject());
}
ksession.fireAllRules();
result[1] = System.nanoTime() - start;
Assertions.assertThat(n).isEqualTo(list.size());
ksession.dispose();
return result;
}
use of org.drools.compiler.oopath.model.Child in project drools by kiegroup.
the class OOPathBenchmarkTest method testFrom.
public static long[] testFrom(KieBase kbase, int n) {
final long[] result = new long[2];
final KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
final List<Man> model = generateModel(n);
final List<Child> toBeModified = getChildToBeModified(model);
long start = System.nanoTime();
final List<InternalFactHandle> fhs = insertModel(ksession, model);
ksession.fireAllRules();
result[0] = System.nanoTime() - start;
list.clear();
start = System.nanoTime();
for (Child child : toBeModified) {
child.setAge(11);
}
for (InternalFactHandle fh : fhs) {
ksession.update(fh, fh.getObject());
}
ksession.fireAllRules();
result[1] = System.nanoTime() - start;
Assertions.assertThat(n * 3).isEqualTo(list.size());
ksession.dispose();
return result;
}
use of org.drools.compiler.oopath.model.Child in project drools by kiegroup.
the class OOPathBenchmarkTest method generateModel.
private static List<Man> generateModel(int nr) {
final List<Man> model = new ArrayList<Man>();
for (int i = 0; i < nr; i++) {
final Man man = new Man("m" + i, 40);
model.add(man);
final Woman woman = new Woman("w" + i, 35);
man.setWife(woman);
woman.setHusband(man.getName());
final Child childA = new Child("cA" + i, 12);
woman.addChild(childA);
childA.setMother(woman.getName());
final Child childB = new Child("cB" + i, 10);
woman.addChild(childB);
childB.setMother(woman.getName());
final Toy toyA = new Toy("tA" + i);
toyA.setOwner(childA.getName());
childA.addToy(toyA);
final Toy toyB = new Toy("tB" + i);
toyB.setOwner(childA.getName());
childA.addToy(toyB);
final Toy toyC = new Toy("tC" + i);
toyC.setOwner(childB.getName());
childB.addToy(toyC);
}
return model;
}
use of org.drools.compiler.oopath.model.Child in project drools by kiegroup.
the class OOPathBenchmarkTest method testOOPath.
public static long[] testOOPath(KieBase kbase, int n) {
final long[] result = new long[2];
final KieSession ksession = kbase.newKieSession();
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
final List<Man> model = generateModel(n);
final List<Child> toBeModified = getChildToBeModified(model);
long start = System.nanoTime();
insertModel(ksession, model);
ksession.fireAllRules();
result[0] = System.nanoTime() - start;
list.clear();
start = System.nanoTime();
for (Child child : toBeModified) {
child.setAge(11);
}
ksession.fireAllRules();
result[1] = System.nanoTime() - start;
Assertions.assertThat(n).isEqualTo(list.size());
ksession.dispose();
return result;
}
Aggregations