[jboss-svn-commits] JBL Code SVN: r6992 - 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
Fri Oct 20 18:43:22 EDT 2006


Author: tirelli
Date: 2006-10-20 18:43:16 -0400 (Fri, 20 Oct 2006)
New Revision: 6992

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
Log:
JBRULES-527: fixing compilation problems

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaMemory.java	2006-10-20 21:53:32 UTC (rev 6991)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaMemory.java	2006-10-20 22:43:16 UTC (rev 6992)
@@ -1,10 +1,14 @@
 package org.drools.reteoo;
 
+import java.util.HashMap;
+import java.util.Map;
+
 import org.drools.util.TupleHashTable;
 
 public class BetaMemory {
     private TupleHashTable  tupleMemory;
     private ObjectHashTable objectMemory;
+    private Map         createdHandles;
 
     public BetaMemory(final TupleHashTable tupleMemory,
                       final ObjectHashTable objectMemory) {
@@ -19,4 +23,11 @@
     public TupleHashTable getTupleMemory() {
         return this.tupleMemory;
     }
+    
+    public Map getCreatedHandles() {
+        if(createdHandles == null) {
+            createdHandles = new HashMap();
+        }
+        return createdHandles;
+    }
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2006-10-20 21:53:32 UTC (rev 6991)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2006-10-20 22:43:16 UTC (rev 6992)
@@ -227,42 +227,6 @@
      */
     public Object createMemory(final RuleBaseConfiguration config) {
         return this.constraints.createBetaMemory();
-        //        // iterate over all the constraints untill we find one that is indexeable. When we find it we remove it from the list and create the 
-        //        // BetaMemory for it. If we don't find one, we create a normal beta memory. We don't need the constraint as we can assume that 
-        //        // anything  returned by the memory already passes that test.
-        //        LinkedList constraints = this.constraints.getConstraints();
-        //        BetaMemory memory = null;
-        //
-        //        if ( constraints != null ) {
-        //            for ( LinkedListEntry entry = (LinkedListEntry) constraints.getFirst(); entry != null; entry = (LinkedListEntry) entry.getNext() ) {
-        //                BetaNodeFieldConstraint constraint = (BetaNodeFieldConstraint) entry.getObject();
-        //                if ( constraint.getClass() == VariableConstraint.class ) {
-        //                    VariableConstraint variableConstraint = (VariableConstraint) constraint;
-        //                    FieldExtractor extractor = variableConstraint.getFieldExtractor();
-        //                    Evaluator evaluator = variableConstraint.getEvaluator();
-        //                    if ( evaluator.getOperator() == Operator.EQUAL ) {
-        //                        // make suret the indexed constraint is first
-        //                        if ( constraints.getFirst() != entry ) {
-        //                            constraints.remove( entry );
-        //                            constraints.insertAfter( null,
-        //                                                     entry );
-        //                        }
-        //                        memory = new BetaMemory( new TupleHashTable(),
-        //                                                 new FieldIndexHashTable( extractor,
-        //                                                                          variableConstraint.getRequiredDeclarations()[0] ) );
-        //                        break;
-        //
-        //                    }
-        //                }
-        //            }
-        //        }
-        //
-        //        if ( memory == null ) {
-        //            memory = new BetaMemory( new TupleHashTable(),
-        //                                     new FactHashTable() );
-        //        }
-        //
-        //        return memory;
     }
 
     /**

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2006-10-20 21:53:32 UTC (rev 6991)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2006-10-20 22:43:16 UTC (rev 6992)
@@ -125,8 +125,9 @@
 
         final Collection result = this.collect.instantiateResultObject();
         final Iterator it = memory.getObjectMemory().iterator( leftTuple );
-        this.constraints.updateFromTuple( workingMemory, leftTuple );
-        
+        this.constraints.updateFromTuple( workingMemory,
+                                          leftTuple );
+
         for ( FactEntry entry = (FactEntry) it.next(); entry != null; entry = (FactEntry) it.next() ) {
             final InternalFactHandle handle = entry.getFactHandle();
             if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
@@ -144,13 +145,15 @@
             }
         }
         if ( isAllowed ) {
-            final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result );
+            if ( this.resultsBinder.isAllowedCachedLeft( result ) ) {
+                final InternalFactHandle handle = workingMemory.getFactHandleFactory().newFactHandle( result );
+                memory.getCreatedHandles().put( leftTuple,
+                                                handle );
 
-            if ( this.resultsBinder.isAllowedCachedLeft( result ) ) {
-                this.sink.propagateAssertTuple( leftTuple,
-                                                handle,
-                                                context,
-                                                workingMemory );
+                sink.propagateAssertTuple( leftTuple,
+                                           handle,
+                                           context,
+                                           workingMemory );
             }
         }
     }
@@ -161,31 +164,22 @@
     public void retractTuple(final ReteTuple leftTuple,
                              final PropagationContext context,
                              final InternalWorkingMemory workingMemory) {
-        // FIXME
-//        final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
-//        memory.getTupleMemory().remove( leftTuple );
-//        
-//        final Map matches = leftTuple.getTupleMatches();
-//
-//        if ( !matches.isEmpty() ) {
-//            for ( final Iterator it = matches.values().iterator(); it.hasNext(); ) {
-//                final CompositeTupleMatch compositeTupleMatch = (CompositeTupleMatch) it.next();
-//                compositeTupleMatch.getObjectMatches().remove( compositeTupleMatch );
-//                it.remove();
-//            }
-//        }
-//
-//        // if tuple was propagated
-//        if ( (leftTuple.getChildEntries() != null) && (leftTuple.getChildEntries().size() > 0) ) {
-//            // Need to store the collection result object for later disposal
-//            final InternalFactHandle lastHandle = ((ReteTuple) ((LinkedListEntry) leftTuple.getChildEntries().getFirst()).getObject()).getLastHandle();
-//
-//            leftTuple.retractChildEntries( context,
-//                                           workingMemory );
-//
-//            // Destroying the acumulate result object 
-//            workingMemory.getFactHandleFactory().destroyFactHandle( lastHandle );
-//        }
+
+        final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+        memory.getTupleMemory().remove( leftTuple );
+        final InternalFactHandle handle = (InternalFactHandle) memory.getCreatedHandles().remove( leftTuple );
+
+        // if tuple was propagated
+        if ( handle != null ) {
+
+            this.sink.propagateRetractTuple( leftTuple,
+                                             handle,
+                                             context,
+                                             workingMemory );
+
+            // Destroying the acumulate result object 
+            workingMemory.getFactHandleFactory().destroyFactHandle( handle );
+        }
     }
 
     /**
@@ -205,11 +199,16 @@
         memory.getObjectMemory().add( handle );
 
         final Iterator it = memory.getTupleMemory().iterator();
-        this.constraints.updateFromFactHandle( workingMemory, handle );
+        this.constraints.updateFromFactHandle( workingMemory,
+                                               handle );
         for ( ReteTuple tuple = (ReteTuple) it.next(); tuple != null; tuple = (ReteTuple) it.next() ) {
             if ( this.constraints.isAllowedCachedRight( tuple ) ) {
-                this.retractTuple( tuple, context, workingMemory );
-                this.assertTuple( tuple, context, workingMemory );
+                this.retractTuple( tuple,
+                                   context,
+                                   workingMemory );
+                this.assertTuple( tuple,
+                                  context,
+                                  workingMemory );
             }
         }
     }
@@ -223,9 +222,25 @@
     public void retractObject(final InternalFactHandle handle,
                               final PropagationContext context,
                               final InternalWorkingMemory workingMemory) {
+
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
+        if ( !memory.getObjectMemory().remove( handle ) ) {
+            return;
+        }
 
-        // FIXME
+        final Iterator it = memory.getTupleMemory().iterator();
+        this.constraints.updateFromFactHandle( workingMemory,
+                                               handle );
+        for ( ReteTuple tuple = (ReteTuple) it.next(); tuple != null; tuple = (ReteTuple) it.next() ) {
+            if ( this.constraints.isAllowedCachedRight( tuple ) ) {
+                this.retractTuple( tuple,
+                                   context,
+                                   workingMemory );
+                this.assertTuple( tuple,
+                                  context,
+                                  workingMemory );
+            }
+        }
     }
 
     public String toString() {
@@ -237,19 +252,12 @@
                            InternalWorkingMemory workingMemory) {
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
 
-        final Iterator tupleIter = memory.getTupleMemory().iterator();
-        for ( ReteTuple tuple = (ReteTuple) tupleIter.next(); tuple != null; tuple = (ReteTuple) tupleIter.next() ) {
-            final Iterator objectIter = memory.getObjectMemory().iterator( tuple );
-            this.constraints.updateFromTuple( workingMemory, tuple );
-            for ( FactEntry entry = (FactEntry) objectIter.next(); entry != null; entry = (FactEntry) objectIter.next() ) {
-                final InternalFactHandle handle = entry.getFactHandle();
-                if ( this.constraints.isAllowedCachedLeft( handle.getObject() ) ) {
-                    sink.assertTuple( new ReteTuple( tuple,
-                                                     handle ),
-                                      context,
-                                      workingMemory );
-                }
-            }
+        for ( java.util.Iterator it = memory.getCreatedHandles().entrySet().iterator(); it.hasNext(); ) {
+            Map.Entry entry = (Map.Entry) it.next();
+            sink.assertTuple( new ReteTuple( (ReteTuple)entry.getKey(),
+                                             (InternalFactHandle) entry.getValue()),
+                              context,
+                              workingMemory );
         }
     }
 




More information about the jboss-svn-commits mailing list