Hi Mike,<div><br></div><div>I see your point, it's very valid for the snippet rule, but can't be apply to the real one since I need to run a function using eval().</div><div><br clear="all">Patrik Dufresne<br>
<br><br><div class="gmail_quote">On Tue, Mar 13, 2012 at 4:45 PM, Mike Melton <span dir="ltr"><<a href="mailto:mike.melton@gmail.com">mike.melton@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Let the rule engine do what it does best. You are fighting against the optimizations of the engine by trying to control the flow. You can rewrite your rule as<div><br></div><div>rule "my-rule"</div><div> when</div>
<div> $entity : Entity( closed == false )</div><div> then</div><div> modify($entity) { setClosed(true); }</div><div>end</div><div><br></div><div>The rule will fire (once) for each Entity which matches the condition. I haven't taken the time to apply the same exercise to your more complex rule, but a general rule you should abide by is "No looping in the consequence unless I have a really good reason."</div>
<div><br></div><div>Mike</div><div><br></div><div><br><div class="gmail_quote">2012/3/13 Patrik Dufresne <span dir="ltr"><<a href="mailto:ikus060@gmail.com" target="_blank">ikus060@gmail.com</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5">
Hi,<div><br></div><div>I have some trouble to figure out how to stop / start the propagation of updates within a Then block.</div><div>Here is a snippet to represent the problem I have.</div><div><br></div><div>rule "my-rule"</div>
<div> when</div><div> $objects : List()</div><div> from accumulate( $entity : Entity(closed==false), collectList($entity) )<br></div><div> then<br></div><div> for(Object obj : $objects) {</div>
<div> ((Entity) obj).setClosed(true);<br></div><div> update(obj);<br></div><div> }</div><div>end</div><div><br></div><div>When this rule's consequence is called first, the first enity in the list is 'update', but then update if propagated to immediately causing the rule to be evaluated with all the entities minus the updated one. So I'm wondering if there is a transaction like operation allowing me to update all the entities in the list and then fire the rules.</div>
<div><br></div><div>According to the documentation no-loop should have help me for this.</div><div><br></div><div>Here is the original rules</div><div><div>rule "close-shift"</div><div><span style="white-space:pre-wrap">        </span>salience -1</div>
<div><span style="white-space:pre-wrap">        </span>when</div><div><span style="white-space:pre-wrap">                </span>$shift : Shift( )</div><div><span style="white-space:pre-wrap">                </span>$assignments : List( size > 0 )</div>
<div><span style="white-space:pre-wrap">                                </span>from accumulate (</div><div><span style="white-space:pre-wrap">                                        </span>$assignment : PlanifEventAssignment( </div><div><span style="white-space:pre-wrap">                                                </span>close == false, </div>
<div><span style="white-space:pre-wrap">                                                </span>shift == $shift ),</div><div><span style="white-space:pre-wrap">                                        </span>collectList($assignment) )</div><div><span style="white-space:pre-wrap">                </span>$availables : List( size >= $assignments.size )</div>
<div><span style="white-space:pre-wrap">                                </span>from accumulate ( ( and</div><div><span style="white-space:pre-wrap">                                        </span>ShiftAssignment(</div><div><span style="white-space:pre-wrap">                                                </span>shift == $shift,</div>
<div><span style="white-space:pre-wrap">                                                </span>$employee : employee)</div><div><span style="white-space:pre-wrap">                                        </span>$available : EmployeeAvailable (</div><div><span style="white-space:pre-wrap">                                                </span>employee == $employee,</div>
<div><span style="white-space:pre-wrap">                                                </span>assignment.shift == $shift) ),</div><div><span style="white-space:pre-wrap">                                        </span>collectList($available) )</div><div><span style="white-space:pre-wrap">                </span>eval( Dfs.search($assignments, $availables) != null )</div>
<div><span style="white-space:pre-wrap">        </span>then</div><div><span style="white-space:pre-wrap">                </span>// Recalculate the result.</div><div><span style="white-space:pre-wrap">                </span>Map table = Dfs.search($assignments, $availables);</div>
<div><span style="white-space:pre-wrap">                </span>for(Object entry : table.entrySet()) {</div><div><span style="white-space:pre-wrap">                        </span>PlanifEventAssignment assignment = (PlanifEventAssignment)((Entry)entry).getKey();</div>
<div><span style="white-space:pre-wrap">                        </span>EmployeeValue employee = (EmployeeValue)((Entry)entry).getValue();</div><div><span style="white-space:pre-wrap">                        </span>assignment.setClose(true);</div>
<div><span style="white-space:pre-wrap">                        </span>assignment.setEmployee(employee);</div><div><span style="white-space:pre-wrap">                        </span>update(assignment);</div><div><span style="white-space:pre-wrap">                </span>}</div>
<div>end</div></div><span><font color="#888888"><div><br></div><div><br></div><div>Patrik Dufresne<br>
</div>
</font></span><br></div></div>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br></div>
<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br></div>