<br> I do suggest you open a JIRA and attach your test case. I will need to do some debugging to understand what is happening.<br><br> []s<br> Edson<br><br><div><span class="gmail_quote">2007/8/22, pentarious <<a href="mailto:cristiano.giuffrida@gmail.com">
cristiano.giuffrida@gmail.com</a>>:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><br>I hope you can help me find a solution. In the meantime I've tried your
<br>workaround, adding an addOption() method with no success. When I use that<br>method in the rule I get the following exception (and I can't understand<br>why):<br> java.lang.ClassNotFoundException: org.test.ItemShadowProxy
<br>org.test.Item is the full qualified name of the bean Item. Any idea?<br><br>Regards,<br><br>CG<br><br><br>Edson Tirelli-3 wrote:<br>><br>> I think I know what is happening. The getOptions() method is returning
<br>> the shadowed options collections, i.e., when you are adding the option,<br>> you<br>> are adding to the shadow instead of the real object.<br>><br>> Now, I'm not sure how we should handle such thing, since we do need to
<br>> shadow the options collection.<br>><br>> Mark, any idea?<br>><br>> A workaround is: create an addOption() method to the Item class to add<br>> options, instead of doing getOptions().add(). This way the shadow proxy
<br>> will<br>> delegate the call to your real class, instead of adding it to the shadow.<br>><br>> []s<br>> Edson<br>><br>> 2007/8/22, pentarious <<a href="mailto:cristiano.giuffrida@gmail.com">
cristiano.giuffrida@gmail.com</a>>:<br>>><br>>><br>>> Actually, before opening a JIRA I would like to show you my actual<br>>> code...<br>>> Here it is:<br>>><br>>> rule "My Rule"
<br>>> no-loop true<br>>> when<br>>> $list : ArrayList() from collect( Item( type == "MY TYPE" ) )<br>>> then<br>>> Item item = (Item) $list.get(0);<br>
>> ItemOption option = new ItemOption( item, "MY OPTION" );<br>>> item.setType("MY NEW TYPE");<br>>> item.getOptions().add( option );<br>>> insert(option);
<br>>> update(item);<br>>> end<br>>><br>>> Basically we have some items (Item) and we need to take into<br>>> considerations<br>>> just items of type "MY TYPE", adding a new option "MY OPTION" to the list
<br>>> of<br>>> the options of the first item in $list. Item is a bean with a field as<br>>> follows:<br>>> private Collection<ItemOption > options = new<br>>> ArrayList<ItemOption>();
<br>>> I thought it was worth writing again before opening a JIRA, as I've<br>>> looked<br>>> further into the problem and I found out another interesting thing. As<br>>> you<br>>> may have noticed I put two lines in my code:
<br>>> item.setType("MY NEW TYPE");<br>>> item.getOptions().add( option );<br>>> It's interesting to notice that the first line works as expected (i.e.<br>>> after<br>>> executing the rule the item has a new type called "MY NEW TYPE"), while
<br>>> the<br>>> second line doesn't (i.e. after executing the rule the item doesn't have<br>>> a<br>>> new option in its option list). So, do you think I should definitively<br>>> open
<br>>> a JIRA (I've never opened one before, can you give a link just in case?)<br>>> or<br>>> I'm just missing something and there is a trivial solution to this issue?<br>>><br>>> Regards,
<br>>><br>>> CG<br>>><br>>><br>>> Edson Tirelli-3 wrote:<br>>> ><br>>> > Well, it must work. Can you open a JIRA with a self contained test<br>>> > case<br>>> > please? I will investigate.
<br>>> ><br>>> > []s<br>>> > Edson<br>>> ><br>>> > 2007/8/22, pentarious <<a href="mailto:cristiano.giuffrida@gmail.com">cristiano.giuffrida@gmail.com</a>>:<br>>> >>
<br>>> >><br>>> >> I know. Actually I didn't put any update or insert statement in the<br>>> code<br>>> >> just<br>>> >> to make it simpler. The actual code looks like:
<br>>> >> when<br>>> >> $itemList : ArrayList() from collect( Item( category == "VIDEO"<br>>> )<br>>> )<br>>> >> then<br>>> >> ItemDiscount disc = new ItemDiscount(10);
<br>>> >> insert(disc);<br>>> >> $myFirstItem = (Item)$itemList.get(0);<br>>> >> $mySecondItem = (Item)$itemList.get(1);<br>>> >> $myFirstItem.addDiscount(disc);
<br>>> >> $mySecondItem.addDiscount(disc);<br>>> >> update($myFirstItem);<br>>> >> update($mySecondItem);<br>>> >> Now, why this doesn't work at all? It does work if I write a rule for
<br>>> >> each<br>>> >> item using in the when clause $item : Item from $itemList, but as I<br>>> said<br>>> >> I<br>>> >> need to write a list-oriented rule.<br>>> >>
<br>>> >> Regards,<br>>> >><br>>> >> CG<br>>> >><br>>> >><br>>> >> Edson Tirelli-3 wrote:<br>>> >> ><br>>> >> > If you want the "engine to see" your changes, in a way you affect
<br>>> >> other<br>>> >> > rules, you must call update( object ) for the object you are<br>>> changing.<br>>> >> > Otherwise, the change will happen to the original object, but not to
<br>>> >> the<br>>> >> > shadow proxy that the engine uses to ensure consistency.<br>>> >> ><br>>> >> > []s<br>>> >> > Edson<br>>> >> >
<br>>> >> > 2007/8/22, pentarious <<a href="mailto:cristiano.giuffrida@gmail.com">cristiano.giuffrida@gmail.com</a>>:<br>>> >> >><br>>> >> >><br>>> >> >> Ok, I'm still working on that, I'll publish my solution asap. In
<br>>> the<br>>> >> >> meantime<br>>> >> >> it turns out our requirements need something more than that. We<br>>> have<br>>> >> an<br>>> >> >> ordered list of beans (items) and we have to be able to modify a
<br>>> >> specific<br>>> >> >> subset of the list (adding a discount). Now I tried to solve this<br>>> >> problem<br>>> >> >> by<br>>> >> >> working directly on the list of items. But I can't understand why
<br>>> this<br>>> >> >> doesn't work:<br>>> >> >> when<br>>> >> >> $itemList : ArrayList() from collect( Item( category ==<br>>> "VIDEO"
<br>>> )<br>>> >> )<br>>> >> >> then<br>>> >> >> ItemDiscount disc = new ItemDiscount(10);<br>>> >> >> $myFirstItem = (Item)$itemList.get(0);
<br>>> >> >> $mySecondItem = (Item)$itemList.get(1);<br>>> >> >> $myFirstItem.addDiscount(disc);<br>>> >> >> $mySecondItem.addDiscount(disc);<br>>> >> >>
<br>>> >> >> After executing this rule it's like nothing happened! I mean no<br>>> >> discount<br>>> >> >> has<br>>> >> >> been added to the two items! The problem seems to be related to
<br>>> >> >> extracting<br>>> >> >> items from the list. Apparently, every time we get an item from the<br>>> >> list,<br>>> >> >> it<br>>> >> >> looses its link with the original item (I don't know if it's a copy
<br>>> of<br>>> >> >> the<br>>> >> >> original item or whatever), so that every update doesn't affect the<br>>> >> >> original<br>>> >> >> item any more. But of course that's what we're interested in! We
<br>>> want<br>>> >> to<br>>> >> >> modify original items in the rule session. Am I missing something?<br>>> Or<br>>> >> Is<br>>> >> >> it<br>>> >> >> a bug?
<br>>> >> >><br>>> >> >> Regards,<br>>> >> >><br>>> >> >> CG<br>>> >> >><br>>> >> >><br>>> >> >>
<br>>> >> >> Edson Tirelli-3 wrote:<br>>> >> >> ><br>>> >> >> > Please, share with us! Send to the list!<br>>> >> >> ><br>>> >> >> > Edson
<br>>> >> >> ><br>>> >> >> > 2007/8/21, pentarious <<a href="mailto:cristiano.giuffrida@gmail.com">cristiano.giuffrida@gmail.com</a>>:<br>>> >> >> >>
<br>>> >> >> >><br>>> >> >> >> I found an interesting implementation to do that. If anyone is<br>>> >> >> interested<br>>> >> >> >> I
<br>>> >> >> >> could share my solution.<br>>> >> >> >><br>>> >> >> >> Regards,<br>>> >> >> >><br>>> >> >> >> CG
<br>>> >> >> >><br>>> >> >> >><br>>> >> >> >> Mark Proctor wrote:<br>>> >> >> >> ><br>>> >> >> >> > There is no supported way to do this. You could use an
<br>>> >> inline-eval<br>>> >> >> >> > against a global, but that is very clunkey. However it does<br>>> seem<br>>> >> >> like<br>>> >> >> a
<br>>> >> >> >> > good feature idea for a future release, open a jira and I'll<br>>> look<br>>> >> >> into<br>>> >> >> >> > getting it included.
<br>>> >> >> >> ><br>>> >> >> >> > Mark<br>>> >> >> >> > pentarious wrote:<br>>> >> >> >> >> Does anyone know a method to limit the number of results from
<br>>> a<br>>> >> >> >> collect<br>>> >> >> >> >> statement? I was just wondering how to do something like<br>>> this:<br>>> >> >> >> >> $myList : List() from collect( MyObject(myField ==
<br>>> "something")<br>>> >> )<br>>> >> >> >> limit<br>>> >> >> >> 3<br>>> >> >> >> >> //it should put in $myList just the first 3 objects retrieved
<br>>> >> >> >> >> I'm quite sure there is nothing in Drools which can natively<br>>> >> >> support<br>>> >> >> >> >> something like that. So, how to do that, if needed? I tried
<br>>> >> this,<br>>> >> >> but<br>>> >> >> >> it<br>>> >> >> >> >> seems not to be working (I can't understand why, though):<br>>> >> >> >> >> $myList : List() from collect( MyObject(myField ==
<br>>> "something")<br>>> >> )<br>>> >> >> >> >> $myObject : MyObject() from $myList<br>>> >> >> >> >> eval( $myList.indexOf($myObject) < 3 )
<br>>> >> >> >> >> Indeed, it doesn't work because the link beetween $myList and<br>>> >> >> >> $myObject<br>>> >> >> >> >> seems to be released during any execution of the rule (In
<br>>> fact<br>>> >> >> >> >> $myList.contains($myObject) returns false! Again, I can't<br>>> >> >> understand<br>>> >> >> >> >> why...)
<br>>> >> >> >> >><br>>> >> >> >> >> Any advice would be really appreciated!<br>>> >> >> >> >><br>>> >> >> >> >> Regards,
<br>>> >> >> >> >><br>>> >> >> >> >> CG<br>>> >> >> >> >><br>>> >> >> >> ><br>>> >> >> >> > _______________________________________________
<br>>> >> >> >> > rules-users mailing list<br>>> >> >> >> > <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>> >> >> >> >
<a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>>> >> >> >> ><br>>> >> >> >> ><br>>> >> >> >>
<br>>> >> >> >> --<br>>> >> >> >> View this message in context:<br>>> >> >> >><br>>> >> >><br>>> >><br>>> <a href="http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12249025">
http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12249025</a><br>>> >> >> >> Sent from the drools - user mailing list archive at <a href="http://Nabble.com">Nabble.com
</a>.<br>>> >> >> >><br>>> >> >> >> _______________________________________________<br>>> >> >> >> rules-users mailing list<br>>> >> >> >>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>> >> >> >> <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users
</a><br>>> >> >> >><br>>> >> >> ><br>>> >> >> ><br>>> >> >> ><br>>> >> >> > --<br>>> >> >> > Edson Tirelli
<br>>> >> >> > Software Engineer - JBoss Rules Core Developer<br>>> >> >> > Office: +55 11 3529-6000<br>>> >> >> > Mobile: +55 11 9287-5646<br>>> >> >> > JBoss, a division of Red Hat @
<a href="http://www.jboss.com">www.jboss.com</a><br>>> >> >> ><br>>> >> >> > _______________________________________________<br>>> >> >> > rules-users mailing list
<br>>> >> >> > <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>> >> >> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users
</a><br>>> >> >> ><br>>> >> >> ><br>>> >> >><br>>> >> >> --<br>>> >> >> View this message in context:<br>>> >> >>
<br>>> >><br>>> <a href="http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12270505">http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12270505
</a><br>>> >> >> Sent from the drools - user mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br>>> >> >><br>>> >> >> _______________________________________________
<br>>> >> >> rules-users mailing list<br>>> >> >> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>> >> >> <a href="https://lists.jboss.org/mailman/listinfo/rules-users">
https://lists.jboss.org/mailman/listinfo/rules-users</a><br>>> >> >><br>>> >> ><br>>> >> ><br>>> >> ><br>>> >> > --<br>>> >> > Edson Tirelli
<br>>> >> > Software Engineer - JBoss Rules Core Developer<br>>> >> > Office: +55 11 3529-6000<br>>> >> > Mobile: +55 11 9287-5646<br>>> >> > JBoss, a division of Red Hat @
<a href="http://www.jboss.com">www.jboss.com</a><br>>> >> ><br>>> >> > _______________________________________________<br>>> >> > rules-users mailing list<br>>> >> >
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>> >> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
<br>>> >> ><br>>> >> ><br>>> >><br>>> >> --<br>>> >> View this message in context:<br>>> >><br>>> <a href="http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12272536">
http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12272536</a><br>>> >> Sent from the drools - user mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br>>> >>
<br>>> >> _______________________________________________<br>>> >> rules-users mailing list<br>>> >> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>>> >>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>>> >><br>>> ><br>>> ><br>>> ><br>>> > --<br>>> > Edson Tirelli
<br>>> > Software Engineer - JBoss Rules Core Developer<br>>> > Office: +55 11 3529-6000<br>>> > Mobile: +55 11 9287-5646<br>>> > JBoss, a division of Red Hat @ <a href="http://www.jboss.com">
www.jboss.com</a><br>>> ><br>>> > _______________________________________________<br>>> > rules-users mailing list<br>>> > <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org
</a><br>>> > <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>>> ><br>>> ><br>>><br>>> --<br>>> View this message in context:
<br>>> <a href="http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12274411">http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12274411</a><br>>> Sent from the drools - user mailing list archive at
<a href="http://Nabble.com">Nabble.com</a>.<br>>><br>>> _______________________________________________<br>>> rules-users mailing list<br>>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org
</a><br>>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>>><br>><br>><br>><br>> --<br>> Edson Tirelli<br>> Software Engineer - JBoss Rules Core Developer
<br>> Office: +55 11 3529-6000<br>> Mobile: +55 11 9287-5646<br>> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>><br>> _______________________________________________
<br>> rules-users mailing list<br>> <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>> <a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users
</a><br>><br>><br><br>--<br>View this message in context: <a href="http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12278683">http://www.nabble.com/How-to-limit-results-from-a-collect-statement-tf4235669.html#a12278683
</a><br>Sent from the drools - user mailing list archive at <a href="http://Nabble.com">Nabble.com</a>.<br><br>_______________________________________________<br>rules-users mailing list<br><a href="mailto:rules-users@lists.jboss.org">
rules-users@lists.jboss.org</a><br><a href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a><br></blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli
<br> Software Engineer - JBoss Rules Core Developer<br> Office: +55 11 3529-6000<br> Mobile: +55 11 9287-5646<br> JBoss, a division of Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a>