Drools 5.0 - Locally... Global
I'd like to declare a global variable that is scoped to only my rules file. For example: variable $reUseMe is onl开发者_JAVA百科y declared once.
rule 1
$reUseMe : POJO(val = 1) //other conditions
rule 2
$reUseMe > val
you can refer to globals in LHS via eval:
global SomeType variable
rule ... when ... eval(variable > something)
There are no scoped global variables, but in some cases rule inheritance helps.
rule "Rule 1"
when
$reUseMe :POJO( val == 1 )
then
end
rule "Rule 2" extends "Rule 1"
when
# You can use the variables from Rule 1
POJO( val > $reUseMe.val )
then
end
Only LHS is added. RHS from Rule 1 is ignored in Rule 2.
精彩评论