I wonder if you can use a Global (or a static variable) to do
the same without really changing your rule.
Something like this.
Global Integer ruleFired;
rule "try not to loop"
when
$a : A($code : code)
$b : B(parentCode == $code)
then
if(ruleFired != 1)
{
addResult($a, $b);
Drools.getWorkingMemory().setGlobal(“ruleFired”,1);
}
end
From:
rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] On Behalf Of Maxim Veksler
Sent: Monday, January 26, 2009 5:52 PM
To: Rules Users List
Subject: [rules-users] Not looping the rule when more then 1 valid match
is found
Hello group,
Assuming I have the rule:
rule "try not to loop"
when
$a : A($code : code)
$b : B(parentCode == $code)
then
addResult($a, $b);
end
and the classes:
public class A {
int code;
}
public class B {
int parentCode;
}
I insert into the WM 4 objects :
A(code = 1), A(code = 2);
B(parentCode=1), B(parentCode = 2);
I would like that after calling fireAllRules() only 1 match will be returned. I
have no preference regarding which one, in the current situation 2 matches are
returned.
Anyone could suggest a method to enforce this ?
Thank you,
Maxim.
MASTEK LTD. Mastek is in NASSCOM's 'India Top 20' Software Service Exporters List. In the US, we're called MAJESCOMASTEK ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Opinions expressed in this e-mail are those of the individual and not that of Mastek Limited, unless specifically indicated to that effect. Mastek Limited does not accept any responsibility or liability for it. This e-mail and attachments (if any) transmitted with it are confidential and/or privileged and solely for the use of the intended person or entity to which it is addressed. Any review, re-transmission, dissemination or other use of or taking of any action in reliance upon this information by persons or entities other than the intended recipient is prohibited. This e-mail and its attachments have been scanned for the presence of computer viruses. It is the responsibility of the recipient to run the virus check on e-mails and attachments before opening them. If you have received this e-mail in error, kindly delete this e-mail from desktop and server. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |