<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=us-ascii">
<META content="MSHTML 6.00.2900.3243" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff size=2>Hi
Edson,</FONT></SPAN></DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff size=2>Thanks
for your help. I restructured my biz objects to avoid nested structures, which
makes it work now (I have new objects to hold allocatedHour per
subject).</FONT></SPAN></DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2>However, I have the feeling that this constraint has a certain
impact on o-o design (more flat objects vs composite object). The documentation
says that nested values should be considered immutable, unless using the modify
block (as you suggested) and retract/re-assert the objects in the workingMemory
; it also has a much greater performance cost.</FONT></SPAN></DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff size=2>Am I
getting it right when saying that the object design should really be like 'many
flat-type objects avoiding composite approach' to have Drools perform well or is
it more sensible to have a proper o-o design and tweak Drools (using modify
block, disabling cache, etc.)</FONT></SPAN></DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff size=2>Thanks
in advance for sharing your experience</FONT></SPAN></DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2>Regis</FONT></SPAN></DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV><B><FONT color=#960000 size=2>
<P align=left>when</P></B></FONT><FONT size=2>
<P align=left>$lesson : Lesson(allocated == </FONT><B><FONT color=#960000
size=2>false</B></FONT><FONT size=2>, session.type == Session.DISTINCT)</P>
<P align=left>$subjectAllocation : SubjectAllocation( subject ==
$lesson.subject, $allocatedDays : allocatedDays )</P>
<P align=left>$availableHour : Hour(allocated == </FONT><B><FONT color=#960000
size=2>false</B></FONT><FONT size=2>, day </FONT><B><FONT color=#960000
size=2>not</B></FONT><FONT size=2> </FONT><B><FONT color=#960000
size=2>memberOf</B></FONT><FONT size=2> $allocatedDays)</P>
<P align=left></P>
<P align=left></FONT><B><FONT color=#960000 size=2>then</P></B></FONT><FONT
size=2>
<P align=left>$lesson.setHour($availableHour ) ;</P>
<P align=left>$lesson.setAllocated(</FONT><B><FONT color=#960000
size=2>true</B></FONT><FONT size=2> ) ;</P>
<P align=left></FONT><B><FONT color=#960000 size=2>update</B></FONT><FONT
size=2>($lesson) ;</P>
<P align=left></P>
<P align=left>$availableHour.setSubject($lesson.getSubject() ) ;</P>
<P align=left>$availableHour.setAllocated(</FONT><B><FONT color=#960000
size=2>true</B></FONT><FONT size=2> ) ;</P>
<P align=left></FONT><B><FONT color=#960000 size=2>update</B></FONT><FONT
size=2>($availableHour) ;</P>
<P align=left></P>
<P align=left>$subjectAllocation.addAllocation($availableHour ) ;</P>
<P></FONT><B><FONT color=#960000 size=2>update</B></FONT><FONT
size=2>($subjectAllocation) ;</P></FONT>
<DIV><SPAN class=751431012-15042008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV><FONT size=2></FONT><BR>
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org] <B>On Behalf Of </B>Edson
Tirelli<BR><B>Sent:</B> Monday, April 14, 2008 4:55 PM<BR><B>To:</B> Rules Users
List<BR><B>Subject:</B> Re: [rules-users] newbie: update and
shallowCache<BR></FONT><BR></DIV>
<DIV></DIV><FONT face=Arial color=#0000ff size=2></FONT><BR>
Regis,<BR><BR> You are probably having problems with mutable
predicates, when using "<SPAN><FONT face=Arial
size=2>subject.allocatedDays</FONT></SPAN>". As a first step to understand your
problem, I strongly encourage you to make constraints flat, i.e., avoid using
nested accessors. After you get used to what can and what can't be done, you can
go back to use nested accessors. <BR> Also, I suggest you use
modify() block instead of update():<BR><BR><SPAN><B><FONT color=#960000>
<P align=left><FONT face=Arial size=2>rule <BR></FONT></P></FONT></B><FONT
face=Arial><FONT size=2><FONT color=#008000>"allocate"</FONT></FONT></FONT>
<P align=left><B><FONT color=#960000><FONT face=Arial
size=2>when</FONT></FONT></B></P>
<P align=left><FONT size=2><FONT face=Arial>$lesson : Lesson(allocated ==
</FONT><B><FONT color=#960000><FONT
face=Arial>false</FONT></FONT></B></FONT><FONT face=Arial size=2>, session.type
== Session.DISTINCT )</FONT></P>
<P align=left><FONT face=Arial size=2>$subject : Subject( $allocatedDays :
allocatedDays ) from $lesson.subject<BR></FONT></P>
<P align=left><FONT size=2><FONT face=Arial>$availableHour : Hour(allocated ==
</FONT><B><FONT color=#960000><FONT
face=Arial>false</FONT></FONT></B></FONT><FONT face=Arial><FONT size=2>, day
<B><FONT color=#960000>not</FONT></B></FONT></FONT><FONT face=Arial><FONT
size=2> <B><FONT color=#960000>memberOf</FONT></B></FONT></FONT><FONT face=Arial
size=2> $allocatedDays)</FONT></P>
<P align=left><B><FONT color=#960000><FONT face=Arial
size=2>then</FONT></FONT></B></P>
<P align=left><FONT face=Arial size=2>modify( $lesson) {</FONT></P>
<P align=left><FONT face=Arial size=2> setHour($availableHour
),<BR></FONT></P>
<P align=left><FONT size=2><FONT face=Arial>
setAllocated(</FONT><B><FONT color=#960000><FONT
face=Arial>true</FONT></FONT></B></FONT><FONT face=Arial size=2>)</FONT></P>
<P align=left><FONT face=Arial size=2>}<BR></FONT></P>
<P align=left><FONT face=Arial size=2>modify( $availableHour )</FONT></P>
<P align=left><FONT face=Arial size=2>
setSubject($lesson.getSubject()),<BR></FONT></P>
<P align=left><FONT size=2><FONT face=Arial>
setAllocated(</FONT><B><FONT color=#960000><FONT
face=Arial>true</FONT></FONT></B></FONT><FONT face=Arial size=2> )</FONT></P>
<P align=left><FONT face=Arial size=2>}<BR></FONT></P><FONT color=#960000><FONT
size=2><FONT face=Arial><B></B></FONT></FONT></FONT><FONT color=#960000>
<P><FONT face=Arial size=2><B>end</B></FONT><BR></P>
<DIV><SPAN><SPAN><BR></SPAN></SPAN></DIV></FONT></SPAN>
<DIV class=gmail_quote> Hope it
helps.<BR><BR> []s<BR> Edson<BR>
<BR>2008/4/14 Piccand, Regis <<A
href="mailto:rpiccand@verisign.com">rpiccand@verisign.com</A>>:<BR>
<BLOCKQUOTE class=gmail_quote
style="PADDING-LEFT: 1ex; MARGIN: 0pt 0pt 0pt 0.8ex; BORDER-LEFT: rgb(204,204,204) 1px solid">
<DIV>
<DIV><SPAN><FONT face=Arial size=2>Hi all,</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2>I am evaluating Drools and am stuck
with a simple rule that selects elements which do not correspond to the
condition... Since I am updating objects in the RHD, I guess it has to do with
my wrong understanding (and the cache...?)</FONT></SPAN></DIV>
<DIV><SPAN><SPAN><FONT face=Arial color=#000000
size=2></FONT></SPAN></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2>I am trying to allocate lessons to periods
(hour). My object model can be summarize is as follows :</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2>Lesson </FONT></SPAN></DIV>
<DIV><SPAN> <FONT face=Arial size=2>boolean :
allocated // true if the lesson has been allocated to an
hour</FONT></SPAN></DIV>
<DIV><SPAN> <FONT face=Arial size=2>int :
session
// a session is a bunch of lessons</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2> Subject :
subject // an allocated lesson is assigned a
subject</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2>Subject</FONT></SPAN></DIV>
<DIV><SPAN> <FONT face=Arial size=2>Set<Day> :
allocatedDays // days in which this subject is taught - checked before
allocation, as a subject can only be taught once a day</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2>Hour</FONT></SPAN></DIV>
<DIV><SPAN> <FONT face=Arial size=2>boolean : allocated //
true is this hour has been allocated with a lesson</FONT></SPAN></DIV>
<DIV><SPAN> D<FONT face=Arial size=2>ay : day // the day
this hour belongs to - required to check with
subject.allocatedDays</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2>I put in the workingMemory a bunch of
Lesson objects, which have been set with Subject and Session id. I also
put a bunch of Hour object, set with a Day.</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><FONT face=Arial size=2>My rule is as follows:</FONT></SPAN></DIV>
<DIV><SPAN><FONT face=Arial size=2></FONT></SPAN> </DIV>
<DIV><SPAN><B><FONT color=#960000>
<P align=left><FONT face=Arial size=2>rule</FONT></P></FONT></B><FONT
face=Arial><FONT size=2><FONT color=#008000>"allocate"</FONT></FONT></FONT>
<P align=left><FONT face=Arial size=2></FONT></P>
<P align=left><B><FONT color=#960000><FONT face=Arial
size=2>when</FONT></FONT></B></P>
<P align=left><FONT size=2><FONT face=Arial>$lesson : Lesson(allocated ==
</FONT><B><FONT color=#960000><FONT
face=Arial>false</FONT></FONT></B></FONT><FONT face=Arial size=2>,
session.type == Session.DISTINCT, $allocatedDays :
subject.allocatedDays)</FONT></P>
<P align=left><FONT size=2><FONT face=Arial>$availableHour : Hour(allocated ==
</FONT><B><FONT color=#960000><FONT
face=Arial>false</FONT></FONT></B></FONT><FONT face=Arial><FONT size=2>, day
<B><FONT color=#960000>not</FONT></B></FONT></FONT><FONT face=Arial><FONT
size=2> <B><FONT color=#960000>memberOf</FONT></B></FONT></FONT><FONT
face=Arial size=2> $allocatedDays)</FONT></P>
<P align=left><FONT face=Arial size=2></FONT></P>
<P align=left><B><FONT color=#960000><FONT face=Arial
size=2>then</FONT></FONT></B></P>
<P align=left><FONT face=Arial size=2>$lesson.setHour($availableHour )
;</FONT></P>
<P align=left><FONT size=2><FONT
face=Arial>$lesson.setAllocated(</FONT><B><FONT color=#960000><FONT
face=Arial>true</FONT></FONT></B></FONT><FONT face=Arial size=2>) ;</FONT></P>
<P align=left><B><FONT color=#960000><FONT face=Arial
size=2>update</FONT></FONT></B><FONT face=Arial size=2>($lesson);</FONT></P>
<P align=left><FONT face=Arial size=2></FONT></P>
<P align=left><FONT face=Arial
size=2>$availableHour.setSubject($lesson.getSubject()) ;</FONT></P>
<P align=left><FONT size=2><FONT
face=Arial>$availableHour.setAllocated(</FONT><B><FONT color=#960000><FONT
face=Arial>true</FONT></FONT></B></FONT><FONT face=Arial size=2> );</FONT></P>
<P align=left><B><FONT color=#960000><FONT face=Arial
size=2>update</FONT></FONT></B><FONT face=Arial
size=2>($availableHour);</FONT></P>
<P align=left><FONT face=Arial size=2></FONT></P><FONT color=#960000>
<P><FONT face=Arial size=2><B>end</B></FONT></P>
<DIV><SPAN><SPAN><FONT face=Arial color=#000000 size=2>When I set a debug on
the first line of the THEN section, I can see that sometimes
$availableHour.allocated == true ... sometimes $lesson.allocated == true
(although it's an implicit And statement ...)</FONT></SPAN></SPAN></DIV>
<DIV>
<P><FONT face=Arial><FONT color=#000000><FONT size=2><SPAN>Therefore, I can
see that the update() works, but it seems that the rule does not use the
updated object (due to shallow copy ??)</SPAN></FONT></FONT></FONT></P>
<P><FONT face=Arial><FONT color=#000000><FONT size=2><SPAN></SPAN>A<SPAN>ny
help more than
welcome</SPAN></FONT></FONT></FONT></P></DIV></FONT></SPAN></DIV>
<P><SPAN><FONT face=Arial color=#000000 size=2>Regis</FONT></SPAN></P>
<P><SPAN><FONT face=Arial color=#000000
size=2></FONT></SPAN> </P></DIV><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"
target=_blank>https://lists.jboss.org/mailman/listinfo/rules-users</A><BR><BR></BLOCKQUOTE></DIV><BR><BR
clear=all><BR>-- <BR>Edson Tirelli<BR>JBoss Drools Core Development<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> </BODY></HTML>