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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Aug 12 14:25:47 EDT 2006


Author: tirelli
Date: 2006-08-12 14:25:42 -0400 (Sat, 12 Aug 2006)
New Revision: 5831

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
Log:
JBRULES-387:

 * Fixing NOT and JOIN node problems on modify tuple 



Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java	2006-08-12 17:59:41 UTC (rev 5830)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java	2006-08-12 18:25:42 UTC (rev 5831)
@@ -17,6 +17,7 @@
  */
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -249,9 +250,13 @@
         memory.add( workingMemory,
                     leftTuple );
 
-        final Map matches = leftTuple.getTupleMatches();
+        // TIRELLI's NOTE: the following is necessary because in case memory  
+        // indexing is enabled, the loop over right objects may skip some of the
+        // previously matched objects
+        final Map oldMatches = new HashMap(leftTuple.getTupleMatches());
+        leftTuple.getTupleMatches().clear();
 
-        final int previous = matches.size();
+        final int previous = oldMatches.size();
         final BetaNodeBinder binder = getJoinNodeBinder();
 
         for ( final Iterator rightIterator = memory.rightObjectIterator( workingMemory,
@@ -263,21 +268,30 @@
                                    leftTuple,
                                    workingMemory ) ) {
                 // test passes
-                TupleMatch tupleMatch = (TupleMatch) leftTuple.getTupleMatches().get( handle );
+                TupleMatch tupleMatch = (TupleMatch) oldMatches.remove( handle );
                 if ( tupleMatch == null ) {
                     // no previous matches so add a match now
                     tupleMatch = objectMatches.add( leftTuple );
-                    leftTuple.addTupleMatch( handle,
-                                             tupleMatch );
                 }
+                leftTuple.addTupleMatch( handle,
+                                         tupleMatch );
             } else {
-                final TupleMatch tupleMatch = leftTuple.removeMatch( handle );
+                final TupleMatch tupleMatch = (TupleMatch) oldMatches.remove( handle );
                 if ( tupleMatch != null ) {
                     // use to match and doesn't any more, so remove match
                     objectMatches.remove( tupleMatch );
                 }
             }
         }
+
+        // TIRELLI's NOTE: the following is necessary because in case memory  
+        // indexing is enabled, the loop over right objects may skip some of the
+        // previously matched objects
+        for ( final Iterator oldMatchesIt = oldMatches.values().iterator(); oldMatchesIt.hasNext(); ) {
+            final TupleMatch tupleMatch = (TupleMatch) oldMatchesIt.next();
+            tupleMatch.getObjectMatches().remove( tupleMatch );
+        }
+        
         if ( previous == 0 && leftTuple.matchesSize() == 0 ) {
             propagateModifyTuple( leftTuple,
                                   context,
@@ -306,20 +320,22 @@
 
         TupleMatch tupleMatch = objectMatches.getFirstTupleMatch();
         final BetaNodeBinder binder = getJoinNodeBinder();
-
+        
         for ( final Iterator it = memory.leftTupleIterator( workingMemory,
                                                             handle ); it.hasNext(); ) {
             final ReteTuple leftTuple = (ReteTuple) it.next();
+            
             if ( tupleMatch != null && tupleMatch.getTuple() == leftTuple ) {
                 // has previous match so need to decide whether to continue
                 // modify or retract
                 final int previous = leftTuple.getTupleMatches().size();
+                TupleMatch nextTupleMatch = (TupleMatch) tupleMatch.getNext();
                 if ( !binder.isAllowed( handle,
                                         leftTuple,
                                         workingMemory ) ) {
                     leftTuple.removeMatch( handle );
                     objectMatches.remove( tupleMatch );
-                }
+                } 
                 if ( previous == 0 && leftTuple.matchesSize() == 0 ) {
                     propagateModifyTuple( leftTuple,
                                           context,
@@ -334,7 +350,7 @@
                                            workingMemory );
                 }
 
-                tupleMatch = (TupleMatch) tupleMatch.getNext();
+                tupleMatch = (TupleMatch) nextTupleMatch;
             } else {
                 // no previous join, so attempt join now
                 final int previousSize = leftTuple.matchesSize();




More information about the jboss-svn-commits mailing list