Rule syntax

The following section will provide more details on rule (.drl) syntax. It will form the basis for later examples.

Rule concepts

A rule can contain one or many conditions/patterns. For example:

Account( balance == 200 )
Customer( name == "John" )

Code listing 5: Two rule conditions, one for type Account and one for type Customer

Drools will then try to match every Account object in the session whose balance is equal to 200 with every Customer whose name is equal to John. If we have three Account objects that meet this criteria and two that don't, five Customer objects that meet this criteria and three that don't, it would create (3+2)*(5+3)=40 possible matches; however, only 3*5=15 of them valid. Meaning that a rule with these two conditions ...

Get Drools JBoss Rules 5.X Developer's Guide now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.