<br> Yes, your implementation looks fine. It is a hashmap lookup with a few additional checks, but I don't think it has noticeable perf difference, since keeping an external map would also require object creation (Map.Entry, etc) and would duplicate something that already exists internally.<br>
<br> []s<br> Edson<br><br><br><div class="gmail_quote">2008/6/2 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;">
Thanks.<br>
<br>
What I've done is add an insertOrUpdate method on a util class we use.<br>
How efficient is getFactHandle? Is it a simple HashMap lookup? Or<br>
would we be better off keeping our own map of handles->facts?<br>
<br>
public static FactHandle insertOrUpdate(Object fact, boolean dynamic) {<br>
FactHandle factHandle = workingMemory.getFactHandle(fact);<br>
if (factHandle == null) {<br>
return workingMemory.insert(fact, dynamic);<br>
}<br>
workingMemory.update(factHandle, fact);<br>
return factHandle;<br>
}<br>
<br>
________________________________<br>
<br>
From: <a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a><br>
[mailto:<a href="mailto:rules-users-bounces@lists.jboss.org">rules-users-bounces@lists.jboss.org</a>] On Behalf Of Edson Tirelli<br>
Sent: Saturday, May 31, 2008 9:12 AM<br>
To: Rules Users List<br>
Subject: Re: [rules-users] Updating an existing fact w/o using fact<br>
handle<br>
<div><div></div><div class="Wj3C7c"><br>
<br>
<br>
Nope. You must use the update method. You can get the previous fact<br>
handle using the get method in working memory if you still have the<br>
original non-modified object, or if behavior is equals based, using an<br>
equals object.<br>
<br>
[]<br>
Edson<br>
<br>
<br>
2008/5/30 Fenderbosch, Eric <<a href="mailto:Eric.Fenderbosch@fedex.com">Eric.Fenderbosch@fedex.com</a>>:<br>
<br>
<br>
Is it required to use WorkingMemory.update to update an existing<br>
fact?<br>
I thought if assert behavior was set to equality and you<br>
implemented the<br>
equals method properly, then you could simply use<br>
WorkingMemory.insert<br>
to overwrite a fact in working memory with a new version. If<br>
this isn't<br>
the case, then are there other settings that will give this<br>
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 :<br>
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",<br>
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>
<br>
<br>
<br>
<br>
<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" target="_blank">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" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</div></div></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>