[rules-users] Drools & "Query by Example"?

Greg Barton greg_barton at yahoo.com
Fri Sep 5 10:25:33 EDT 2008


--- On Fri, 9/5/08, Michael Zimmermann <list at incunabulum.de> wrote:

> rule "MyRule"
> when
>   book(year==myYear, author==myAuthor ...)
> then
>   ....
> 
> This works only if all properties myYear, myAuthor ... are
> present. If one is undefined, the rule does not match.

You could have a function that returns true if the properties match or the property is null:

boolean matchesOrNull(Object o, Object p) {
  return p == null ? true : ( o == null ? true : o.equals(p) );
}

Call it using eval in the conditions.

Maybe if it's useful enough an operator could be added to Drools that does the same thing.  "~=" maybe?

GreG




      



More information about the rules-users mailing list