Great stuff. Things are very clear now . It raised some more questions though :-
-- Say we use the one shot insert at the very start of the rule. And i am using this rule to validate some
100,000 User facts . Will these inserts be done only once or as many times as new facts are inserted
in WM. Is there something that we can use to determine this as per the need.
-- As done in the example below there will be as many UserResult objects inserted in the memory as there are User facts. We insert them in the WM at the start and update them as the rule executes . At the very end should we retract them as well from the WM . Is that a suggested practice or doesn't really matter .
-- Does WM automatically remove objects if they have not been used for long time or it's the responsibility of the application developer to keep track of what's goes in and out.
-- Instead of inserting one fact at a time if we insert a collection at one go in the WM how does this rule get applied . Sequentially to all the objects or in parallel ?
Regards,
Manav
From: Wolfgang Laun <wolfgang.laun@gmail.com>
To: Manav <manav7574@yahoo.com>
Cc: rules-users@lists.jboss.org
Sent: Fri, August 13, 2010 11:41:53 PM
Subject: Re: [rules-users] Caching results in temperory variables
On 13 August 2010 18:36, Manav
<manav7574@yahoo.com> wrote:
Your explanation is absolutely superb. I modified my drl as per your suggestions and it's just been completely transformed. Just one question regarding one suggestion below :
-- is this something like a for each loop in java . This is the first example i have seen in drl
In a way, yes. Since
Foo( ... ) # match any Foo according to constraints, if any
Bar( ... ) # match any Bar according to constraints, if any
these two patterns produce the Cartesian product, such as a nested loop does. BUT, the order of the pairings is indeterministic, and changes in WM might influence this loop, even make it infinitive. Therefore, "in a way".
-- will this automatically iterate over as many languages as have been inserted ?
That's the whole idea :-)
-- the inserts .. don't they have to be within a rule block ? or did you just omit other things to keep it simple
You can do it in the Java application framework. You can also write a high-salience one-shot rule such as
rule "1st shot"
when
then
insert( new Language( "Japanese" ) );
insert( new Language( "French" ) );
// more of the same
end
Cheers
Wolfgang