[jboss-svn-commits] JBL Code SVN: r13171 - labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Jul 6 13:45:51 EDT 2007


Author: tirelli
Date: 2007-07-06 13:45:50 -0400 (Fri, 06 Jul 2007)
New Revision: 13171

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
Log:
JBRULES-926: fixing update for equality assert behavior

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-07-06 17:24:55 UTC (rev 13170)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-07-06 17:45:50 UTC (rev 13171)
@@ -704,14 +704,7 @@
 
         if ( isSequential() ) {
             handle = this.handleFactory.newFactHandle( object );
-            this.assertMap.put( handle,
-                                handle,
-                                false );
-            if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
-                this.identityMap.put( handle,
-                                      handle,
-                                      false );
-            }
+            addHandleToMaps( handle );
             insert( handle,
                     object,
                     rule,
@@ -763,14 +756,7 @@
                     // key is also null, so treat as a totally new stated/logical
                     // assert
                     handle = this.handleFactory.newFactHandle( object );
-                    this.assertMap.put( handle,
-                                        handle,
-                                        false );
-                    if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
-                        this.identityMap.put( handle,
-                                              handle,
-                                              false );
-                    }
+                    addHandleToMaps( handle );
                     
                     key = new EqualityKey( handle );
                     handle.setEqualityKey( key );
@@ -816,30 +802,15 @@
                             handle = this.handleFactory.newFactHandle( object );
                             handle.setEqualityKey( key );
                             key.addFactHandle( handle );
-                            this.assertMap.put( handle,
-                                                handle,
-                                                false );
+                            addHandleToMaps( handle );
                             
-                            if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
-                                this.identityMap.put( handle,
-                                                      handle,
-                                                      false );
-                            }
-                            
                         }
 
                     } else {
                         handle = this.handleFactory.newFactHandle( object );
-                        this.assertMap.put( handle,
-                                            handle,
-                                            false );
+                        addHandleToMaps( handle );
                         key.addFactHandle( handle );
                         handle.setEqualityKey( key );
-                        if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
-                            this.identityMap.put( handle,
-                                                  handle,
-                                                  false );
-                        }
                         
                     }
 
@@ -864,14 +835,7 @@
                     return handle;
                 }
                 handle = this.handleFactory.newFactHandle( object );
-                this.assertMap.put( handle,
-                                    handle,
-                                    false );
-                if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
-                    this.identityMap.put( handle,
-                                          handle,
-                                          false );
-                }
+                addHandleToMaps( handle );
                 
             }
 
@@ -1038,10 +1002,7 @@
                                                                 object,
                                                                 this );
 
-            this.assertMap.remove( handle );
-            if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
-                this.identityMap.remove( handle );
-            }
+            removeHandleFromMaps( handle );
 
 
             this.handleFactory.destroyFactHandle( handle );
@@ -1054,6 +1015,24 @@
         }
     }
 
+    private void addHandleToMaps(InternalFactHandle handle) {
+        this.assertMap.put( handle,
+                            handle,
+                            false );
+        if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
+            this.identityMap.put( handle,
+                                  handle,
+                                  false );
+        }
+    }
+
+    private void removeHandleFromMaps(final InternalFactHandle handle) {
+        this.assertMap.remove( handle );
+        if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
+            this.identityMap.remove( handle );
+        }
+    }
+
     public void modifyRetract(final FactHandle factHandle) {
         modifyRetract( factHandle,
                        null,
@@ -1207,24 +1186,11 @@
                        propagationContext );
 
             if ( (originalObject != object) || (this.ruleBase.getConfiguration().getAssertBehaviour() != AssertBehaviour.IDENTITY) ) {
-                // as assertMap may be using an "identity" equality comparator,
-                // we need to remove the handle from the map, before replacing the object
-                // and then re-add the handle. Otherwise we may end up with a leak.
-                this.assertMap.remove( handle );
-                if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
-                    this.identityMap.remove( handle );
-                }
+                removeHandleFromMaps( handle );
 
                 // set anyway, so that it updates the hashCodes
                 handle.setObject( object );
-                this.assertMap.put( handle,
-                                    handle,
-                                    false );
-                if ( this.ruleBase.getConfiguration().getAssertBehaviour() == AssertBehaviour.EQUALITY ) {
-                    this.identityMap.put( handle,
-                                          handle,
-                                          false );
-                }
+                addHandleToMaps( handle );
             }
 
             if ( this.maintainTms ) {




More information about the jboss-svn-commits mailing list