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