[rules-users] Maps in Drools

Edson Tirelli tirelli at post.com
Wed Aug 19 09:24:06 EDT 2009


"On the general issue, is it received wisdom that it's better not to insert
map objects direct, at least for now until map support is fully there - or
is it 6 of one / half a dozen?"

   Maps are data structures, not Domain entities. Using maps as domain
entities is possible, but usually makes your rules unreadable. That is why
it is bad to use any data structures or simple numbers, strings, dates as
isolated facts... they don't have a well known business semantic in a given
business model (not to mention how they get mixed with each other and cause
cross products, etc). A rule like the following has no explicit meaning:

       when
               $str: String()
               $m: Map( this[$str] == 1 )
       then

    But when you write something like:

        when
               Customer( $custId : id )
               DailyOrders( count[$custId] == 1 )
        then

    Things are clear just by looking at them, even if $custId is a String
and count is a Map as in the original example.

    Regarding the bug, it was a regression that was fixed. All the syntax
support we intended to have for them is in Drools. Not sure what you mean by
"support is fully there".

    Hope it helps.

    []s
    Edson

2009/8/18 KDR <dr.soprano at neverbox.com>

>
> Many thanks for your replies André and Edson. For some reason they hadn't
> shown up on my computer before I posted my follow up info.
>
> I'll download the updated jar and cross my fingers!
>
> On the general issue, is it received wisdom that it's better not to insert
> map objects direct, at least for now until map support is fully there - or
> is it 6 of one / half a dozen?
>
> André on your point below:
>
> André Thieme-4 wrote:
> >
> > KDR schrieb:
> >> I'd also need to test for null i.e. whether a key/value pair exists for
> a
> >> given String as the key.
> >
> > This seems to be only true when you go the route that I go, namely using
> > the default rule syntax, i.e., eval.
> >
>
> - I don't think I quite follow? If I need to check whether the key/value
> pair exists for a particular String key i.e. whether the get(key) returns
> null, is the only way to do that currently by using the eval?
>
> Cheers and thanks again for the help.
> --
> View this message in context:
> http://www.nabble.com/Maps-in-Drools-tp25031348p25034293.html
> Sent from the drools - user mailing list archive at Nabble.com.
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



-- 
 Edson Tirelli
 JBoss Drools Core Development
 JBoss by Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090819/76268c73/attachment.html 


More information about the rules-users mailing list