See below I have tried the example from the page below. Every things works fine but I am not getting the rule applied, and generated status applicable from this rule.
Location of sample code: http://dilipsarangi.blogspot.co.uk/2015/09/drools-610-dynamic-rules-in-database.html
I am able to load data from table in to the test case. but when System.out.println(aa.getName() + "," + aa.getStatus());
The aa.getstatus
is null.
The dynamic generated rule .
package org.drools.template.jdbc;
dialect "mvel"
rule "ageRule_7"
when
$person : Person(age>=81 && age<100)
then
$person.status=":" + "Old Aged";
end
rule "ageRule_6"
when
$person : Person(age>=61 && age<81)
then
$person.status=":" + "Senior Citizen";
end
rule "ageRule_5"
when
$person : Person(age>=41 && age<61)
then
$person.status=":" + "Middle Aged";
end
rule "ageRule_4"
when
$person : Person(age>=18 && age<41)
then
$person.status=":" + "Youth";
end
rule "ageRule_3"
when
$person : Person(age>=13 && age<18)
then
$person.status=":" + "Juvenile";
end
rule "ageRule_2"
when
$person : Person(age>=6 && age<13)
then
$person.status=":" + "Young Age";
end
rule "ageRule_1"
when
$person : Person(age>=2 && age<6)
then
$person.status=":" + "Baby";
end
rule "ageRule_0"
when
$person : Person(age>=0 && age<2)
then
$person.status=":" + "Infant";
end
You need to update the $person object in each rule, after amending the status property:
update($person);
Without doing this, any change to the object is not set in the working memory.
Although the above works, you are better using the modify keyword instead:
modify($person) {$person.setStatus=":" + "Infant"};
And similar for each of the rules. In this case the update keyword is not required.
There is some functionality such as property reactive beans where update cannot be used, so it is best to use modify as best-practice.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.