【问题标题】:How to break the loops in Drools, Mvel dialect?如何打破 Drools,Mvel 方言中的循环?
【发布时间】:2018-08-06 14:25:44
【问题描述】:

在下面的规则中,then-part 中的逻辑正在为所有通过给定条件的子对象执行,我想在逻辑之后中断循环 在then-part中只执行一次,怎么做

rule "test"
            when
                Parent( $childList : childList != null, childList.empty == false)
                Child('testing'.equalsIgnoreCase(attribute)) from $childList
            then
                // testLogic
end

【问题讨论】:

    标签: drools rules rule mvel


    【解决方案1】:

    如果您不需要在RHS 中引用Child 对象(或其任何属性),那么您可以使用exists 运算符:

    rule "test"
    when
     Parent( $childList : childList != null, childList.empty == false)
     exists Child('testing'.equalsIgnoreCase(attribute)) from $childList
    then
     // testLogic
    end
    

    如果出于某种原因您确实需要 Child 对象或其任何属性,您可以执行以下操作(虽然不是很好):

    rule "test"
    when
     Parent( $childList : childList != null, childList.empty == false)
     $c: Child('testing'.equalsIgnoreCase(attribute)) from $childList.get(0)
    then
     // testLogic
    end
    

    希望对你有帮助,

    【讨论】:

    • 好。您能否将问题标记为已回答?谢谢
    【解决方案2】:

    无限循环的原因应该通过识别它是自循环还是复循环来知道。

    • 规则内的事实修改会激活相同的规则(自我)
    • 规则内的事实修改会激活不同的规则(复杂)并激活原始规则。

    您可以在规则名称旁边使用“no-loop”作为 no-loop true

    您还可以通过使用议程组、检查条件或类似标志来进行限制。这取决于您的复杂程度。

    【讨论】:

    • 问题不是无限循环,而是当你有多个激活时如何触发一次。
    猜你喜欢
    • 1970-01-01
    • 2023-03-26
    • 1970-01-01
    • 2019-02-14
    • 2013-01-30
    • 2015-10-04
    • 2013-08-31
    • 1970-01-01
    相关资源
    最近更新 更多