使用规则模板从数据库(DRL文件)生成Drools动态规则文件 [英] Drools Dynamic rule file generation from database (drl file) using Rule Template

查看:1318
本文介绍了使用规则模板从数据库(DRL文件)生成Drools动态规则文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参见下文,我已经尝试了以下页面中的示例。一切正常,但我没有应用该规则,也没有从该规则生成适用的状态。

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.

示例代码的位置:
http://dilipsarangi.blogspot.co.uk/2015 /09/drools-610-dynamic-rules-in-database.html

我能够将表中的数据加载到测试用例中。
,但是当 System.out.println(aa.getName()+, + aa.getStatus());

I am able to load data from table in to the test case. but when System.out.println(aa.getName() + "," + aa.getStatus());

aa.getstatus 为空。

动态生成的规则。

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.

尽管上述方法可行,但最好使用Modify关键字:

Although the above works, you are better using the modify keyword instead:

modify($person) {$person.setStatus=":" + "Infant"};

每个规则都类似。在这种情况下,不需要update关键字。

And similar for each of the rules. In this case the update keyword is not required.

有一些功能,例如无法使用更新的属性反应式Bean,因此最好使用Modify作为best-练习。

There is some functionality such as property reactive beans where update cannot be used, so it is best to use modify as best-practice.

这篇关于使用规则模板从数据库(DRL文件)生成Drools动态规则文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆