Drools 6.4多重修改和命名后果

时间:2016-08-08 07:12:10

标签: java drools rules

我在Drools中很新,我想知道是否有可能仅在RHS结束时触发修改/更新事实。

寻找这个样本:

rule "test"
    when
        $o1 : MyObject( isNew == null ) // isNew is a Boolean()
        do[initNew]
        $o2 : MySecondObject( name = "ABC" )
    then
       ... //do stuff
       modify($o1) { setNew(true) }; //set to true if we arrived here
       modify($o2) { setName("DEF") };
    then[initNew]
       ... //do stuff
       modify($o1) { setNew(false) }; //init to false
end

在此示例中,我想将isNew设置为false,事实上没有$o2,否则需要将其设置为true

当我测试此规则时,调用do[initNew],将触发修改,以便立即重播规则并且永远不会调用then部分....

一个想法?

谢谢:)

1 个答案:

答案 0 :(得分:1)

程序编程的诱惑已经用do []和[]引入。坚持清洁逻辑 - 你需要的是两个规则:

rule "test Second true"
when
    $o1 : MyObject( isNew == null ) // isNew is a Boolean()
    $o2 : MySecondObject( name = "ABC" )
then
    modify($o1) { setNew(true) };
    modify($o2) { setName("DEF") };
end

rule "test Second missing"
when
    $o1 : MyObject( isNew == null ) // isNew is a Boolean()
    not MySecondObject( name = "ABC" )
then
    modify($o1) { setNew(false) }; //init to false
end