// This rule prints all objects in WM. rule findObject when $o: Object() then System.out.println( "Object: " + $o ); end
Happily I get Object: 42 Object: a String object Object: org.drools.reteoo.InitialFactImpl@4dde85f0 Now the query way: query object( Object o ) o := Object() end rule findObjectByQuery when object( $a ; ) then System.out.println( "Object by query: " + $a ); end Surprisingly, I get just one: Object by query: org.drools.reteoo.InitialFactImpl@4dde85f0 A marvellous effect can be observed when the condition in rule findObjectByQuery is modified to when Object() object( $a ; ) then I'd have guessed that the above result would appear repeatedly, once for each Object in WM, but that's not so. For N-1 facts the rule fires N*(N+1)/2 times, showing the "initial object" N times, the first inserted object N-1 times, the second one N-2 times and, finally, the last one once. Object by query: 42 Object by query: org.drools.reteoo.InitialFactImpl@4dde85f0 Object by query: a String object Object by query: 100 Object by query: 42 Object by query: org.drools.reteoo.InitialFactImpl@4dde85f0 Object by query: a String object Object by query: org.drools.reteoo.InitialFactImpl@4dde85f0 Object by query: a String object Object by query: org.drools.reteoo.InitialFactImpl@4dde85f0 -W
_______________________________________________ rules-dev mailing list rules-dev@lists.jboss.org https://lists.jboss.org/mailman/listinfo/rules-dev