Drools 6.4 多重修改和命名结果
Drools 6.4 Multiple modify and named consequences
我是 Drools 的新手,我想知道是否可以仅在 RHS 结束时触发 modify/update 事实。
寻找这个样本:
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
部分永远不会被调用....
一个想法?
谢谢 :)
过程式编程的诱惑已经通过 do[] 和 then[] 引入。坚持清晰的逻辑——你需要的是两条规则:
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
我是 Drools 的新手,我想知道是否可以仅在 RHS 结束时触发 modify/update 事实。
寻找这个样本:
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
部分永远不会被调用....
一个想法?
谢谢 :)
过程式编程的诱惑已经通过 do[] 和 then[] 引入。坚持清晰的逻辑——你需要的是两条规则:
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