<br> Nope. You must use the update method. You can get the previous fact handle using the get method in working memory if you still have the original non-modified object, or if behavior is equals based, using an equals object.<br>
<br> []<br> Edson<br><br><div class="gmail_quote">2008/5/30 Fenderbosch, Eric <<a href="mailto:Eric.Fenderbosch@fedex.com">Eric.Fenderbosch@fedex.com</a>>:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Is it required to use WorkingMemory.update to update an existing fact?<br>
I thought if assert behavior was set to equality and you implemented the<br>
equals method properly, then you could simply use WorkingMemory.insert<br>
to overwrite a fact in working memory with a new version. If this isn't<br>
the case, then are there other settings that will give this behavior?<br>
<br>
I'm using <a href="http://4.0.7." target="_blank">4.0.7.</a><br>
<br>
Thanks for any help.<br>
<br>
Eric<br>
<br>
Here's my RuleBaseConfiguration:<br>
AlphaNodeHashingThreshold : 3<br>
CompositeKeyDepth : 3<br>
ExecutorServiceorg.drools.concurrent.DefaultExecutorService<br>
RuleBaseUpdateHandler :<br>
org.drools.base.FireAllRulesRuleBaseUpdateListener<br>
AgendaGroupFactory :<br>
org.drools.common.PriorityQueueAgendaGroupFactory@17653ae<br>
AssertBehaviour : equality<br>
ConflictResolver : org.drools.conflict.DepthConflictResolver@16fe0f4<br>
ConsequenceExceptionHandler :<br>
org.drools.base.DefaultConsequenceExceptionHandler@19d0a1<br>
LogicalOverride : discard<br>
SequentialAgenda : sequential<br>
AlphaMemory : false<br>
IndexLeftBetaMemory : true<br>
IndexRightBetaMemory : true<br>
MaintainTms : true<br>
RemoveIdenities : true<br>
Sequential : false<br>
ShadowProxy : true<br>
ShareAlphaNodes : true<br>
ShareBetaNodes : true<br>
UseStaticObjensis : false<br>
<br>
<br>
My TestFact class:<br>
<br>
public class TestFact {<br>
<br>
private String id;<br>
private String value;<br>
<br>
public String getId() {<br>
return id;<br>
}<br>
<br>
public void setId(String id) {<br>
<a href="http://this.id" target="_blank">this.id</a> = id;<br>
}<br>
<br>
public String getValue() {<br>
return value;<br>
}<br>
<br>
public void setValue(String value) {<br>
this.value = value;<br>
}<br>
<br>
@Override<br>
public int hashCode() {<br>
return id.hashCode();<br>
}<br>
<br>
@Override<br>
public boolean equals(Object obj) {<br>
if (this == obj) return true;<br>
if (!(obj instanceof TestFact)) return false;<br>
TestFact other = (TestFact) obj;<br>
// not null safe, i know<br>
return this.id.equals(<a href="http://other.id" target="_blank">other.id</a>);<br>
}<br>
}<br>
<br>
And the JUnit Test Case that fails:<br>
public void testFactUpdate() throws Exception {<br>
TestFact testFact = new TestFact();<br>
testFact.setId("1234");<br>
testFact.setValue("old");<br>
<br>
FactHandle testFactHandle =<br>
workingMemory.insert(testFact);<br>
<br>
TestFact updatedFact = new TestFact();<br>
updatedFact.setId("1234");<br>
updatedFact.setValue("new");<br>
<br>
FactHandle updatedFactHandle =<br>
workingMemory.insert(updatedFact);<br>
// using workingMemory.update here works<br>
<br>
// passes<br>
assertTrue(testFactHandle == updatedFactHandle);<br>
<br>
TestFact retrievedTestFact = (TestFact)<br>
workingMemory.getObject(testFactHandle);<br>
// fails<br>
assertEquals("new", retrievedTestFact.getValue());<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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><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>