[rules-users] Same rules applies twice

Nicolas Héron nicolas.heron.java at gmail.com
Mon Nov 8 05:51:04 EST 2010


Hello,
I made a small test
class result
package com.sample;

public class Result {
private long resultId;

public long getResultId() {
return resultId;
}

public void setResultId(long resultId) {
this.resultId = resultId;
}

public Result(long resultId) {
super();
this.resultId = resultId;
}
}
class test
package com.sample; public class Test { private Result result; public Result
getResult() { return result; } public void setResult(Result result) {
this.result = result; } }
Rule file
package com.sample

import com.sample.Result;
import com.sample.Test;

rule "Reload test" salience 10000
    when
        $result: Result( $resultId:resultId)
        not (exists Test(result.resultId ==$result.resultId))
    then
        Test test = new Test();
        test.setResult($result);
         insert(test);
         System.out.println("rule started for id ="+$resultId);
end
Main program
public static final void main(String[] args) {
try {
// load up the knowledge base
KnowledgeBase kbase = readKnowledgeBase();
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
KnowledgeRuntimeLogger logger =
KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "test");
// go !
Result r1 = new Result(1);
Result r2 = new Result(2);
ksession.insert(r1);
ksession.insert(r2);
ksession.fireAllRules();
logger.close();
System.out.println();
} catch (Throwable t) {
t.printStackTrace();
}
}

and the log you get
rule started for id =2
rule started for id =1
so for each Result you put, it creates a test and the rules applies on,which
is normal
Does it help ?
Regards
Nicolas


2010/11/8 jc7442 <jc7442 at yahoo.fr>

>
> My technical id is a long. But if I just do an equals id does not chage the
> issue.
>
>
> --
> View this message in context:
> http://drools-java-rules-engine.46999.n3.nabble.com/Same-rules-applies-twice-tp1861724p1861859.html
> Sent from the Drools - User mailing list archive at Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20101108/d2d70d99/attachment.html 


More information about the rules-users mailing list