Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

drools: how to assign to local variable

Tags:

java

drools

I'm stuck with Drools 5 and need a little help. What I'd like to do is use a passed in DAO and assign a value from that to a local variable, like this...

rule "test rule 1"
when
    $carDao : ICarDAO( )
    $x : $carDao.getMap()
    eval (
       $x.contains("a") && $x.contains("b")
    )
then
// do stuff
end

Drools 5 doesn't allow assignment of local variables though. I'd like to assign to a local variable so that I don't have to make the same call twice to the DAO.

So could someone point me in the correct direction please?

Thanks! Jeff Porter

like image 538
jeff porter Avatar asked Dec 05 '25 10:12

jeff porter


1 Answers

rule "test rule 1"
when
    $carDao : ICarDAO( )
    $x: java.util.Map( ) from  $carDao.getMap()
    eval (
       $x.contains("a") && $x.contains("b")
    )
then
// do stuff
end

ta..dar!

like image 111
jeff porter Avatar answered Dec 08 '25 00:12

jeff porter