Search code examples
syntaxdrools

Suggestion with basic drools syntax


The following is a basic drools syntax:

$customer : Customer( )
Account( ) from $customer.accounts

As far as I know the first line create a new variable and assign it to the fact. However I can't quite understand the second line especially what the "Account()" part means...


Solution

  • You have written class Customer, or must know it to understand what's going on here. Presumably it contains a Collection<Account> accounts (see note), which is (by the engine) retrieved one by one so that the rule fires for each Account object contained in Customer's object.

    The rule will fire once for each Account object stored in any of the collections contained in all the Customer facts in working memory, with $customer being bound to the containing Customer.

    You can bind another variable to Account.

    Note: It could also contain a field Account accounts, but I hope the name was chosen carefully.