Yes, Thomas' comments are very pertinent.

   Just to explain by example, in the given example of A having a collection of B that has a collection of C, if you only insert A into the working memory, you can still reason over B and C by doing (where "..." means whatever constraints you are applying):

when
    $a : A( ... )
    $b : B( ... ) from $a.collectionOfBs
    $c : C( ... ) from $b.collectionOfCs

   The problem with that approach is performance, as you are forcing the engine to, for every A, iterate over all Bs sequentially and for every B, iterate all Cs sequentially. That is clearly as inefficient as nested loops in imperative programming languages.
   If you insert all As, Bs, and Cs (your application will obviously do the same iteration, but it will happen only once) you enable the engine to properly do its relational magic and very efficiently find your Bs and Cs. Instead of using "from",  you would do:

when
    $a : A( ... )
    $b : B( this memberOf $a.collectionOfBs, ... )
    $c : C( this memberOf $b.collectionOfCs, ... )

    It is not that different syntactically, but makes a huge difference on performance for some cases. Back to Thomas' comments, if you change a C, for instance, in the first case it would force the recalculation of all As', Bs' and Cs' constraints, when in the second case, only that single instance of C that changed would be recalculated. It is huge. Of course, if you have just a couple rules on that form and you don't change your facts, then performance will be similar with both approaches.

    Edson

2009/12/4 Swindells, Thomas <TSwindells@nds.com>
The problem is when you come to modify the object. When you modify something you should tell drools that fact so it can calculate which rules have conditions that may have been modified and need to be re-evaluated.

If you only tell drools about the root object then the only object you can tell drools that you have modified is the root object which means any time you do a modification all your rules will be re-evaluated. This means you are much more likely to end up with rule loops and actions being repeated if you aren't careful.

It seems the best way to write rules is to treat your data as for a relational database and fully normalise it with object references used as keys. However this does make it harder to integrate with other parts of the system.

Thomas
> -----Original Message-----
> From: rules-users-bounces@lists.jboss.org [mailto:rules-users-
> bounces@lists.jboss.org] On Behalf Of Pritam
> Sent: 04 December 2009 16:14
> To: rules-users@lists.jboss.org
> Subject: Re: [rules-users] Need help related to collection of data
> accessingin rule file.
>
>
> I'm still not sure why this is a "bad idea"
> I've flattened out my fact class. Now instead of a collection A has a B
>
> In my decision table, I declare the variable
> $a : Region
>
> and one of the conditions is
> $a.widget.id
>
> (assuming that Region class has a Widget class)
>
> I get the following error on invoking rules
> xstream.mapper.CannotResolveClassException: widget : widget
>
> It's hard for me to image a "flattened" pojo for rules to understand.
> In
> real world, a "Person" has an "Address" and Address has a "State" and
> it
> goes on. Ideally I would like to give the root object to a rule engine
> and
> write the conditions by drilling down the root object.
>
> Unless I'm doing something wrong here, is this possible in drools?
>
>
> Ross H wrote:
> >
> > Just added this point to the wiki on usage patterns:
> >
> > http://www.jboss.org/community/wiki/UsagePatterns
> >
> >
> > On Fri, Dec 4, 2009 at 8:09 PM, Ross H <rossh00@gmail.com> wrote:
> >
> >> Thanks Thomas, you've added a very important category to my
> thoughts:
> >> what
> >> does and what doesn't work easily in drools. I think this is the
> most
> >> important category. Every framework has a degree of flexibility and
> >> whilst
> >> drools is extremely flexible, the consequences may not be that
> pleasant.
> >>
> >> 2009/12/4 Swindells, Thomas <TSwindells@nds.com>
> >>
> >>  I’d agree, and to join up with the other thread is the exact reason
> why
> >>> we need some decent ‘design pattern’ documentation to explain what
> does
> >>> and
> >>> doesn’t easily work in drools.
> >>>
> >>> Depending what you are trying to do you may be able to use eval to
> >>> perform
> >>> the logic for you, though this will probably involve you writing
> the
> >>> logic
> >>> manually in java. See the thread Re: [rules-users] Can we use
> 'from' CE
> >>> in
> >>> Decision Tables ? for details.
> >>>
> >>>
> >>>
> >>> Thomas
> >>>
> >>>
> >>>
> >>>
> >>>
> >>> *From:* rules-users-bounces@lists.jboss.org [mailto:
> >>> rules-users-bounces@lists.jboss.org] *On Behalf Of *Ross H
> >>> *Sent:* 04 December 2009 08:18
> >>> *To:* Rules Users List
> >>> *Subject:* Re: [rules-users] Need help related to collection of
> data
> >>> accessingin rule file.
> >>>
> >>>
> >>>
> >>> In my limited experience, I'm not sure you can do this in decision
> >>> tables,
> >>> but given the flexibility of Drools there may be a way, but I'm not
> sure
> >>> this is a good thing.
> >>>
> >>>
> >>>
> >>> I suspect the rules you create will be really ugly and not support
> your
> >>> longer term goals of flexibility. It might be better to transform
> your
> >>> data
> >>> into a better fact model that gives you the ability to create real
> >>> business
> >>> rules that are understandable.
> >>>
> >>>
> >>>
> >>> It appears that it is better to create a fact model that is more
> shallow
> >>> and uses almost relational concepts to relate the facts together
> rather
> >>> than
> >>> a deeply nested model (I suspect you are getting this from some
> really
> >>> ugly
> >>> xml structure). So whilst it's a pain, I would reconsider your core
> >>> domain/fact model.
> >>>
> >>> On Fri, Dec 4, 2009 at 4:08 PM, Pritam <infinity2heaven@gmail.com>
> >>> wrote:
> >>>
> >>>
> >>> I have the same problem as I'm trying to create a decision table
> via
> >>> excel
> >>> where the fact is a root object A where A has a collection B, and B
> has
> >>> a
> >>> collection C. My rules are based out of the instance A, loop for
> each
> >>> object
> >>> in B, and within that, loop each object in C. Not sure how I can
> write
> >>> an
> >>> expression for the same.
> >>>
> >>> >From the examples, I see that one can access a particular element
> in A
> >>> by
> >>> $a.listname[1] but in my case, I need to access all elements in the
> >>> loop.
> >>>
> >>> Any suggestions?
> >>>
> >>>
> >>> prasad raju sagi wrote:
> >>> >
> >>> > Hi ,
> >>> >
> >>> > I am trying to create rule  on a fact , which contains arraylist
> of
> >>> > collection and the object in the collection internally contains
> an
> >>> > arraylist of another collection of objects.
> >>> >
> >>> > This looks like  object A contains collection of objects B and B
> >>> contains
> >>> > collection object C
> >>> >
> >>> > A ->  blist ( Arraylist )
> >>> >
> >>> > B -> clist (ArrayList<C> )
> >>> >
> >>> > C-> dlist( ArrayList<D>)
> >>> >
> >>> > D-> type ( string)
> >>> >
> >>> > I am inseting A as fact to the working memory.
> >>> >
> >>> > I am in confusion state like how to write the rule to place
> conditions
> >>>  on
> >>> > collection C.
> >>> >
> >>> > Can I use from in the form of nested from in rule statment.
> >>> > Thanks
> >>> > Prasad Raju Sagi
> >>> > Mobile: 847-644-4103
> >>> >
> >>> >
> >>> >
> >>> >
> >>> > ________________________________
> >>> > From: Aziz Boxwala <boxwala@yahoo.com>
> >>> > To: rules-users@lists.jboss.org
> >>> > Sent: Thursday, June 11, 2009 1:58:28 PM
> >>> > Subject: [rules-users] process order example not working fully
> >>> >
> >>> >
> >>> > I am trying to execute a ruleflow and use rules to assign tasks
> within
> >>> the
> >>> > ruleflow in Drools 5.0.1. I have a drl file included in my
> knowledge
> >>> base
> >>> > that tries to assign a task to a user when a new human task is
> >>> created.
> >>> > This is based on the example in org.drools.example.process.order.
> I
> >>> can't
> >>> > get my code to work. I don't the rules in the example are working
> >>> either
> >>> > (dslr for the task assignment or the drl for dynamic logging).
> After
> >>> some
> >>> > attempts, I found that this condition
> >>> >     WorkItemNodeInstance()
> >>> > does not evaluate to true ever.
> >>> >
> >>> > Do I have to do anything special to make the WorkItemNodeInstance
> >>> appear
> >>> > in working memory?
> >>> >
> >>> > Thanks for any help.
> >>> >
> >>> > --Aziz
> >>> >
> >>> >
> >>> >
> >>> > _______________________________________________
> >>> > rules-users mailing list
> >>> > rules-users@lists.jboss.org
> >>> > https://lists.jboss.org/mailman/listinfo/rules-users
> >>> >
> >>> >
> >>>
> >>> --
> >>> View this message in context:
> >>> http://n3.nabble.com/Re-Need-help-related-to-collection-of-data-
> accessing-in-rule-file-tp60311p67858.html
> >>> Sent from the Drools - User mailing list archive at Nabble.com.
> >>>
> >>> _______________________________________________
> >>> rules-users mailing list
> >>> rules-users@lists.jboss.org
> >>> https://lists.jboss.org/mailman/listinfo/rules-users
> >>>
> >>>
> >>>
> >>> ------------------------------
> >>>
> >>>
> >>>
> ***********************************************************************
> ***************
> >>> This message is confidential and intended only for the addressee.
> If you
> >>> have received this message in error, please immediately notify the
> >>> postmaster@nds.com and delete it from your system as well as any
> copies.
> >>> The content of e-mails as well as traffic data may be monitored by
> NDS
> >>> for
> >>> employment and security purposes. To protect the environment please
> do
> >>> not
> >>> print this e-mail unless necessary.
> >>>
> >>> NDS Limited. Registered Office: One London Road, Staines,
> Middlesex,
> >>> TW18
> >>> 4EX, United Kingdom. A company registered in England and Wales.
> >>> Registered
> >>> no. 3080780. VAT no. GB 603 8808 40-00
> >>>
> >>>
> ***********************************************************************
> ***************
> >>>
> >>> ------------------------------
> >>> This message is confidential and intended only for the addressee.
> If you
> >>> have received this message in error, please immediately notify the
> >>> postmaster@nds.com and delete it from your system as well as any
> copies.
> >>> The content of e-mails as well as traffic data may be monitored by
> NDS
> >>> for
> >>> employment and security purposes.
> >>> To protect the environment please do not print this e-mail unless
> >>> necessary.
> >>>
> >>> An NDS Group Limited company. www.nds.com
> >>>
> >>> _______________________________________________
> >>> rules-users mailing list
> >>> rules-users@lists.jboss.org
> >>> https://lists.jboss.org/mailman/listinfo/rules-users
> >>>
> >>>
> >>
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users@lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> --
> View this message in context: http://n3.nabble.com/Re-Need-help-
> related-to-collection-of-data-accessing-in-rule-file-tp60311p68353.html
> Sent from the Drools - User mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users


**************************************************************************************
This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes. To protect the environment please do not print this e-mail unless necessary.

NDS Limited. Registered Office: One London Road, Staines, Middlesex, TW18 4EX, United Kingdom. A company registered in England and Wales. Registered no. 3080780. VAT no. GB 603 8808 40-00
**************************************************************************************

This message is confidential and intended only for the addressee. If you have received this message in error, please immediately notify the postmaster@nds.com and delete it from your system as well as any copies. The content of e-mails as well as traffic data may be monitored by NDS for employment and security purposes.
To protect the environment please do not print this e-mail unless necessary.

An NDS Group Limited company. www.nds.com

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users



--
 Edson Tirelli
 JBoss Drools Core Development
 JBoss by Red Hat @ www.jboss.com