<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 6.00.2800.1491" name=GENERATOR></HEAD>
<BODY>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff
size=2>Hello,</FONT></SPAN></DIV>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff size=2>If you
can change the code for CreatedFact and let it have a reference to UserFact and
change the rule to:</FONT></SPAN></DIV>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff size=2><FONT
face="Times New Roman" color=#000000 size=3>rule "fact =
1"<BR> when<BR> $f :
UserFact(fact1 == 1);<BR> then
<BR> insertLogical(new
CreatedFact($f));
<BR>end</FONT><BR></FONT></SPAN></DIV>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff size=2>you
will also have to overide equals and hashcode for CreatedFact so that several
CreatedFacts referencing the same UserFact are considered
equal...</FONT></SPAN></DIV>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff size=2>But
with this solution CreatedFact will always be up to date with the value of
UserFact even without firing the rules and maybe it's not what you
want...</FONT></SPAN></DIV>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff
size=2></FONT></SPAN> </DIV>
<DIV><SPAN class=486405115-07102008><FONT face=Arial color=#0000ff
size=2>-Patrick</DIV></FONT></SPAN>
<BLOCKQUOTE dir=ltr style="MARGIN-RIGHT: 0px">
<DIV class=OutlookMessageHeader dir=ltr align=left><FONT face=Tahoma
size=2>-----Message d'origine-----<BR><B>De :</B>
rules-users-bounces@lists.jboss.org
[mailto:rules-users-bounces@lists.jboss.org]<B>De la part de</B> tim
tim<BR><B>Envoyé :</B> mardi, 7. octobre 2008 16:53<BR><B>À :</B>
rules-users@lists.jboss.org<BR><B>Objet :</B> [rules-users] insertLogical
and modifyRetract<BR><BR></FONT></DIV>
<DIV dir=ltr>Hello,<BR><BR>I am a bit confused about how insertLogical()
supposed to work in drools 5.<BR><BR>when i have a rule such as:<BR><BR>rule
"fact = 1"<BR> when<BR>
$f : UserFact(fact1 == 1);<BR> then
<BR> insertLogical(new
CreatedFact($f.getFact2()));
<BR>end<BR><BR>now i change $f in such a way, that the rule will fire
again.<BR>via <BR><BR>// build first version<BR>UserFact f = new
UserFact();<BR>f.setFact1(1);<BR>f.setFact2(1);<BR><BR>memory.insert(f);<BR>memory.fireAllRules();
// <- Rule fires once<BR><BR>// now i change the memory and fire the rules
again<BR><BR>memory.modifyRetract(f) ;<BR>f.setFact2(100); // <- changing
$f, but leaving fact1 as it
is.<BR>memory.modifyInsert(f);<BR><BR>memory.fireAllRules(); // <-
Rule fires again<BR><BR>now the rule should fire again, which it does.<BR>but
i end up with two CreatedFact instances in the workingMemory..<BR>one with the
old OtherFact value 1, and one with the new value, 100<BR><BR>but i want only
the second instance. the one created first is not valid any more.<BR>i could
write an extra rule for retracting the first CreatedFact-fact, but then i
would have<BR>a very tight coupling of the two rules.<BR> <BR>is there a
better way?<BR>it seems odd to me, that a consequence of a rule stays in
memory, when there is<BR>a more current version of the rule evocation with the
_same_ facts in the precondition<BR>and a different consequence.<BR><BR>thanks
in advance, tim<BR><BR></DIV></BLOCKQUOTE></BODY></HTML>