No the rule is run multiple times, once per a matching A.
If you did only want the rule to run once regardless of how many matching As you have then
you would use exists:
Exists A( property == "123" )
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Justin Beltran
Sent: 21 July 2010 16:47
To: 'Rules Users List'
Subject: Re: [rules-users] Rules not firing when expected after retracting object in list
Thanks for the reply.
What if you have multiple A's set with 123? Don't you need to collect them to
retract all A's that match that property?
My main concern is if you retract one or more of the A's, it's possible that you
should still have some A's that are NOT retracted, so rule B should still fire right?
Justin
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Swindells, Thomas
Sent: Wednesday, July 21, 2010 8:39 AM
To: Rules Users List
Subject: Re: [rules-users] Rules not firing when expected after retracting object in list
Why is rule 1 written the way it is? Why can't you just do:
rule "Rule 1 - Remove all A's that have property set to 123"
salience 1000
when
$anA : A( property == "123" )
then
retract ($anA)
end
Thomas
From: rules-users-bounces(a)lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org] On
Behalf Of Justin Beltran
Sent: 21 July 2010 16:28
To: rules-users(a)lists.jboss.org
Subject: [rules-users] Rules not firing when expected after retracting object in list
Hi,
I'm coming across some weird behavior in Drools 4.0.7, but maybe it's just cause I
don't understand I how Drools works. Assume, there's a class "A" that
has a property called "property".
As facts, I have the following list of A's:
A1, property = 123
A2, property = 345
A3, property = 123
I have two rules as follows:
rule "Rule 1 - Remove all A's that have property set to 123"
salience 1000
lock-on-active true
when
$listOfAs : ArrayList collect(A( property == "123" ))
then
for (Object a: $listOfAs ) {
retract (a)
}
end
rule "Rule 2 - Do stuff with remaining A's"
salience 900
lock-on-active true
when
$listOfAs : ArrayList collect(A())
then
...
end
My understanding is "Rule 1" will remove the facts of class A that have property
to 123. When it gets to "Rule 2", shouldn't the "listOfAs" only
have that one A that remains (i.e. the one where property is set to "345").
What I'm noticing is that "Rule 2" just doesn't execute at all even
though I'm assuming there is still one "A" object that hasn't been
retracted. If I comment out the "retract" it executes "Rule 2" fine.
Am I missing something about these rules work?
Thanks.
Justin
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received
this message in error, please immediately notify the postmaster(a)nds.com and delete it from
your system as well as any copies. The content of e-mails as well as traffic data may be
monitored by NDS for employment and security purposes. To protect the environment please
do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United
Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603
8808 40-00
**************************************************************************************
________________________________
**************************************************************************************
This message is confidential and intended only for the addressee. If you have received
this message in error, please immediately notify the postmaster(a)nds.com and delete it from
your system as well as any copies. The content of e-mails as well as traffic data may be
monitored by NDS for employment and security purposes. To protect the environment please
do not print this e-mail unless necessary.
NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United
Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603
8808 40-00
**************************************************************************************