Hi Mike,
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().
Patrik Dufresne
On Tue, Mar 13, 2012 at 4:45 PM, Mike Melton <mike.melton(a)gmail.com> wrote:
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
rule "my-rule"
when
$entity : Entity( closed == false )
then
modify($entity) { setClosed(true); }
end
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."
Mike
2012/3/13 Patrik Dufresne <ikus060(a)gmail.com>
> Hi,
>
> I have some trouble to figure out how to stop / start the propagation of
> updates within a Then block.
> Here is a snippet to represent the problem I have.
>
> rule "my-rule"
> when
> $objects : List()
> from accumulate( $entity : Entity(closed==false),
> collectList($entity) )
> then
> for(Object obj : $objects) {
> ((Entity) obj).setClosed(true);
> update(obj);
> }
> end
>
> 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.
>
> According to the documentation no-loop should have help me for this.
>
> Here is the original rules
> rule "close-shift"
> salience -1
> when
> $shift : Shift( )
> $assignments : List( size > 0 )
> from accumulate (
> $assignment : PlanifEventAssignment(
> close == false,
> shift == $shift ),
> collectList($assignment) )
> $availables : List( size >= $assignments.size )
> from accumulate ( ( and
> ShiftAssignment(
> shift == $shift,
> $employee : employee)
> $available : EmployeeAvailable (
> employee == $employee,
> assignment.shift == $shift) ),
> collectList($available) )
> eval( Dfs.search($assignments, $availables) != null )
> then
> // Recalculate the result.
> Map table = Dfs.search($assignments, $availables);
> for(Object entry : table.entrySet()) {
> PlanifEventAssignment assignment =
> (PlanifEventAssignment)((Entry)entry).getKey();
> EmployeeValue employee = (EmployeeValue)((Entry)entry).getValue();
> assignment.setClose(true);
> assignment.setEmployee(employee);
> update(assignment);
> }
> end
>
>
> Patrik Dufresne
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users