[rules-users] Updating an existing fact w/o using fact handle
Edson Tirelli
tirelli at post.com
Sat May 31 09:11:52 EDT 2008
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.
[]
Edson
2008/5/30 Fenderbosch, Eric <Eric.Fenderbosch at fedex.com>:
> Is it required to use WorkingMemory.update to update an existing fact?
> I thought if assert behavior was set to equality and you implemented the
> equals method properly, then you could simply use WorkingMemory.insert
> to overwrite a fact in working memory with a new version. If this isn't
> the case, then are there other settings that will give this behavior?
>
> I'm using 4.0.7.
>
> Thanks for any help.
>
> Eric
>
> Here's my RuleBaseConfiguration:
> AlphaNodeHashingThreshold : 3
> CompositeKeyDepth : 3
> ExecutorServiceorg.drools.concurrent.DefaultExecutorService
> RuleBaseUpdateHandler :
> org.drools.base.FireAllRulesRuleBaseUpdateListener
> AgendaGroupFactory :
> org.drools.common.PriorityQueueAgendaGroupFactory at 17653ae
> AssertBehaviour : equality
> ConflictResolver : org.drools.conflict.DepthConflictResolver at 16fe0f4
> ConsequenceExceptionHandler :
> org.drools.base.DefaultConsequenceExceptionHandler at 19d0a1
> LogicalOverride : discard
> SequentialAgenda : sequential
> AlphaMemory : false
> IndexLeftBetaMemory : true
> IndexRightBetaMemory : true
> MaintainTms : true
> RemoveIdenities : true
> Sequential : false
> ShadowProxy : true
> ShareAlphaNodes : true
> ShareBetaNodes : true
> UseStaticObjensis : false
>
>
> My TestFact class:
>
> public class TestFact {
>
> private String id;
> private String value;
>
> public String getId() {
> return id;
> }
>
> public void setId(String id) {
> this.id = id;
> }
>
> public String getValue() {
> return value;
> }
>
> public void setValue(String value) {
> this.value = value;
> }
>
> @Override
> public int hashCode() {
> return id.hashCode();
> }
>
> @Override
> public boolean equals(Object obj) {
> if (this == obj) return true;
> if (!(obj instanceof TestFact)) return false;
> TestFact other = (TestFact) obj;
> // not null safe, i know
> return this.id.equals(other.id);
> }
> }
>
> And the JUnit Test Case that fails:
> public void testFactUpdate() throws Exception {
> TestFact testFact = new TestFact();
> testFact.setId("1234");
> testFact.setValue("old");
>
> FactHandle testFactHandle =
> workingMemory.insert(testFact);
>
> TestFact updatedFact = new TestFact();
> updatedFact.setId("1234");
> updatedFact.setValue("new");
>
> FactHandle updatedFactHandle =
> workingMemory.insert(updatedFact);
> // using workingMemory.update here works
>
> // passes
> assertTrue(testFactHandle == updatedFactHandle);
>
> TestFact retrievedTestFact = (TestFact)
> workingMemory.getObject(testFactHandle);
> // fails
> assertEquals("new", retrievedTestFact.getValue());
> }
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
--
Edson Tirelli
JBoss Drools Core Development
Office: +55 11 3529-6000
Mobile: +55 11 9287-5646
JBoss, a division of Red Hat @ www.jboss.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20080531/9e279f94/attachment.html
More information about the rules-users
mailing list