[jboss-svn-commits] JBL Code SVN: r20280 - in labs/jbossrules/trunk: drools-compiler/src/test/java/org/drools/integrationtests and 4 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jun 3 19:26:37 EDT 2008


Author: tirelli
Date: 2008-06-03 19:26:37 -0400 (Tue, 03 Jun 2008)
New Revision: 20280

Added:
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModify2.drl
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModifyMVEL2.drl
Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel
   labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaRule.mvel
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/FactHandle.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/JavaAccumulatorFunctionExecutor.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MVELAccumulatorFunctionExecutor.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELAccumulator.java
Log:
Fixing accumulate problems after removing shadow proxies

Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel	2008-06-03 22:50:35 UTC (rev 20279)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaInvokers.mvel	2008-06-03 23:26:37 UTC (rev 20280)
@@ -252,6 +252,7 @@
         @end{}
         ((@{ruleClassName}.@{className})context).accumulate(
             workingMemory,
+            handle,
             innerDeclarations,
             handle.getObject()@if{declarations != empty}, at end{}
             @foreach{declr : declarations} @{declr.identifier}@end{","}@if{globals != empty}, at end{}
@@ -283,11 +284,9 @@
 
         ((@{ruleClassName}.@{className})context).reverse(
             workingMemory,
-            innerDeclarations,
-            handle.getObject()@if{declarations != empty}, at end{}
-            @foreach{declr : declarations} @{declr.identifier}@end{","}@if{globals != empty}, at end{}
-	        @foreach{identifier : globals} @{identifier}@end{","}@if{innerDeclarations != empty}, at end{}
-            @foreach{declr : innerDeclarations} @{declr.identifier}@end{","});
+            handle,
+            handle.getObject()@if{globals != empty}, at end{}
+	        @foreach{identifier : globals} @{identifier}@end{","});
     }
 
     public Object getResult(java.lang.Object workingMemoryContext,

Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaRule.mvel
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaRule.mvel	2008-06-03 22:50:35 UTC (rev 20279)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/rule/builder/dialect/java/javaRule.mvel	2008-06-03 23:26:37 UTC (rev 20280)
@@ -26,6 +26,10 @@
 
     private static final long    serialVersionUID = 400L;
 
+    @if{supportsReverse == "true"}
+    private java.util.Map reverseMap = new java.util.HashMap<org.drools.common.InternalFactHandle, ReverseSnapshot>(); 
+    @end{}
+    
     @foreach{type : attributesTypes, attr : attributes} private @{type} @{attr};
     @end{}    
     
@@ -39,22 +43,33 @@
     }
     
     public void accumulate(org.drools.WorkingMemory workingMemory,
+                           org.drools.common.InternalFactHandle handle,
                            org.drools.rule.Declaration[] innerDeclarations, 
                            Object object @if{declarations != empty}, @end{}
                            @foreach{type : declarationTypes, declr : declarations} @{type} @{declr.identifier}@end{","}@if{globals != empty}, at end{}
                            @foreach{type : globalTypes, identifier : globals} @{type} @{identifier} @end{","}@if{innerDeclarations != empty}, at end{}
                            @foreach{declr : innerDeclarations}@{declr.extractor.extractToClassName} @{declr.identifier}@end{","}
                            ) throws Exception {
+        @if{supportsReverse == "true"}
+        this.reverseMap.put( handle,
+                             new ReverseSnapshot(
+                               @foreach{declr : declarations}@{declr.identifier}@end{","}@if{innerDeclarations != empty && declarations != empty}, at end{}
+                               @foreach{declr : innerDeclarations}@{declr.identifier}@end{","}
+                              ) );
+        @end{}
         @{actionCode}
     }
     
     public void reverse(org.drools.WorkingMemory workingMemory,
-                           org.drools.rule.Declaration[] innerDeclarations, 
-                           Object object @if{declarations != empty}, @end{}
-                           @foreach{type : declarationTypes, declr : declarations} @{type} @{declr.identifier}@end{","}@if{globals != empty}, at end{}
-                           @foreach{type : globalTypes, identifier : globals} @{type} @{identifier} @end{","}@if{innerDeclarations != empty}, at end{}
-                           @foreach{declr : innerDeclarations}@{declr.extractor.extractToClassName} @{declr.identifier}@end{","}
+                           org.drools.common.InternalFactHandle handle,
+                           Object object at if{globals != empty}, at end{}
+                           @foreach{type : globalTypes, identifier : globals} @{type} @{identifier} @end{","}
                            ) throws Exception {
+        @if{supportsReverse == "true"}
+        ReverseSnapshot snapshot = (ReverseSnapshot) this.reverseMap.remove( handle );
+        @foreach{type : declarationTypes, declr : declarations}@{type} @{declr.identifier} = snapshot.@{declr.identifier};@end{}
+        @foreach{declr : innerDeclarations}@{declr.extractor.extractToClassName} @{declr.identifier} = snapshot.@{declr.identifier};@end{}
+        @end{}
         @{reverseCode}
     }
     
@@ -68,6 +83,19 @@
         return @{supportsReverse};
     }
     
+    @if{supportsReverse == "true"}
+    private static class ReverseSnapshot implements java.io.Serializable {
+		@foreach{type : declarationTypes, declr : declarations} public final @{type} @{declr.identifier};@end{}
+        @foreach{declr : innerDeclarations}public final @{declr.extractor.extractToClassName} @{declr.identifier};@end{}
+        
+        public ReverseSnapshot(@foreach{type : declarationTypes, declr : declarations}final @{type} @{declr.identifier}@end{","}@if{innerDeclarations != empty && declarations != empty}, at end{}
+                               @foreach{declr : innerDeclarations}final @{declr.extractor.extractToClassName} @{declr.identifier}@end{","}
+                              ) {
+			@foreach{type : declarationTypes, declr : declarations}this.@{declr.identifier} = @{declr.identifier};@end{}
+    	    @foreach{declr : innerDeclarations}this.@{declr.identifier} = @{declr.identifier};@end{}
+        }
+    } 
+    @end{}
 }
 @end{}
 

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java	2008-06-03 22:50:35 UTC (rev 20279)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/AccumulateTest.java	2008-06-03 23:26:37 UTC (rev 20280)
@@ -331,12 +331,15 @@
         bob.setLikes( "brie" );
         wm.update( bobHandle,
                    bob );
+        cheese[3].setPrice( 20 );
+        wm.update( cheeseHandles[3],
+                   cheese[3] );
         wm.fireAllRules();
 
         // 2 fires
         Assert.assertEquals( 2,
                              results.size() );
-        Assert.assertEquals( 31,
+        Assert.assertEquals( 36,
                              ((Cheesery) results.get( results.size() - 1 )).getTotalAmount() );
 
         // ---------------- 4th scenario
@@ -349,6 +352,77 @@
 
     }
 
+    public void testAccumulateReverseModify2() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateReverseModify2.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         10 ), new Cheese( "stilton",
+                                                                           2 ), new Cheese( "stilton",
+                                                                                            5 ), new Cheese( "brie",
+                                                                                                             15 ), new Cheese( "brie",
+                                                                                                                               16 ), new Cheese( "provolone",
+                                                                                                                                                 8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 0,
+                             results.size() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 9 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 24,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        cheese[3].setPrice( 20 );
+        wm.update( cheeseHandles[3],
+                   cheese[3] );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 36,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 2,
+                             results.size() );
+
+    }
+
     public void testAccumulateReverseModifyMVEL() throws Exception {
         // read in the source
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateReverseModifyMVEL.drl" ) );
@@ -417,6 +491,74 @@
 
     }
 
+    public void FIXME_testAccumulateReverseModifyMVEL2() throws Exception {
+        // read in the source
+        final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateReverseModifyMVEL2.drl" ) );
+        final RuleBase ruleBase = loadRuleBase( reader );
+
+        final WorkingMemory wm = ruleBase.newStatefulSession();
+        final List results = new ArrayList();
+
+        wm.setGlobal( "results",
+                      results );
+
+        final Cheese[] cheese = new Cheese[]{new Cheese( "stilton",
+                                                         10 ), new Cheese( "stilton",
+                                                                           2 ), new Cheese( "stilton",
+                                                                                            5 ), new Cheese( "brie",
+                                                                                                             15 ), new Cheese( "brie",
+                                                                                                                               16 ), new Cheese( "provolone",
+                                                                                                                                                 8 )};
+        final Person bob = new Person( "Bob",
+                                       "stilton" );
+
+        final FactHandle[] cheeseHandles = new FactHandle[cheese.length];
+        for ( int i = 0; i < cheese.length; i++ ) {
+            cheeseHandles[i] = wm.insert( cheese[i] );
+        }
+        final FactHandle bobHandle = wm.insert( bob );
+
+        // ---------------- 1st scenario
+        wm.fireAllRules();
+        // no fire, as per rule constraints
+        Assert.assertEquals( 0,
+                             results.size() );
+
+        // ---------------- 2nd scenario
+        final int index = 1;
+        cheese[index].setPrice( 9 );
+        wm.update( cheeseHandles[index],
+                   cheese[index] );
+        wm.fireAllRules();
+
+        // 1 fire
+        Assert.assertEquals( 1,
+                             results.size() );
+        Assert.assertEquals( 24,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 3rd scenario
+        bob.setLikes( "brie" );
+        wm.update( bobHandle,
+                   bob );
+        wm.fireAllRules();
+
+        // 2 fires
+        Assert.assertEquals( 2,
+                             results.size() );
+        Assert.assertEquals( 31,
+                             ((Number) results.get( results.size() - 1 )).intValue() );
+
+        // ---------------- 4th scenario
+        wm.retract( cheeseHandles[3] );
+        wm.fireAllRules();
+
+        // should not have fired as per constraint
+        Assert.assertEquals( 2,
+                             results.size() );
+
+    }
+
     public void testAccumulateWithFromChaining() throws Exception {
         // read in the source
         final Reader reader = new InputStreamReader( getClass().getResourceAsStream( "test_AccumulateWithFromChaining.drl" ) );

Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModify2.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModify2.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModify2.drl	2008-06-03 23:26:37 UTC (rev 20280)
@@ -0,0 +1,20 @@
+package org.drools.test;
+
+import org.drools.Cheese;
+import org.drools.Cheesery;
+import org.drools.Person;
+
+global java.util.List results;
+
+rule "Constraints everywhere" salience 80
+    when
+        $person      : Person( $likes : likes )
+    	$total       : Number( intValue > 20 ) 
+    	                       from accumulate( Cheese( type == $likes, $p : price ),
+                                                init( int total = 0; ),
+    	                                        action( total += $p; ),
+    	                                        reverse( total -= $p; ),
+                                                result( new Integer( total ) ) )
+    then
+        results.add( $total );
+end  


Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModify2.drl
___________________________________________________________________
Name: svn:executable
   + *

Added: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModifyMVEL2.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModifyMVEL2.drl	                        (rev 0)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModifyMVEL2.drl	2008-06-03 23:26:37 UTC (rev 20280)
@@ -0,0 +1,21 @@
+package org.drools.test;
+
+import org.drools.Cheese;
+import org.drools.Cheesery;
+import org.drools.Person;
+
+global java.util.List results;
+
+rule "Constraints everywhere" salience 80
+    dialect "mvel"
+    when
+        $person      : Person( $likes : likes )
+    	$total       : Number( intValue > 20 ) 
+    	                       from accumulate( $cheese : Cheese( type == $likes, $p : price ),
+                                                init( int total = 0; ),
+    	                                        action( total += $p; ),
+    	                                        reverse( total -= $p; ),
+                                                result( new Integer( total ) ) )
+    then
+        results.add( $total );
+end  


Property changes on: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_AccumulateReverseModifyMVEL2.drl
___________________________________________________________________
Name: svn:executable
   + *

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/FactHandle.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/FactHandle.java	2008-06-03 22:50:35 UTC (rev 20279)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/FactHandle.java	2008-06-03 23:26:37 UTC (rev 20280)
@@ -24,7 +24,6 @@
  * @author <a href="mailto:bob at werken.com">bob mcwhirter </a>
  */
 
-import java.io.Externalizable;
 
 public interface FactHandle {
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/JavaAccumulatorFunctionExecutor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/JavaAccumulatorFunctionExecutor.java	2008-06-03 22:50:35 UTC (rev 20279)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/JavaAccumulatorFunctionExecutor.java	2008-06-03 23:26:37 UTC (rev 20280)
@@ -17,6 +17,12 @@
  */
 package org.drools.base.accumulators;
 
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.util.HashMap;
+import java.util.Map;
+
 import org.drools.FactHandle;
 import org.drools.WorkingMemory;
 import org.drools.common.InternalFactHandle;
@@ -25,13 +31,6 @@
 import org.drools.spi.ReturnValueExpression;
 import org.drools.spi.Tuple;
 
-import java.io.ObjectOutput;
-import java.io.IOException;
-import java.io.ObjectInput;
-import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
-
 /**
  * An MVEL accumulator function executor implementation
  *
@@ -41,10 +40,10 @@
     implements
     Accumulator {
 
-    private static final long           serialVersionUID = 400L;
+    private static final long     serialVersionUID = 400L;
 
     private ReturnValueExpression expression;
-    private AccumulateFunction   function;
+    private AccumulateFunction    function;
 
     public JavaAccumulatorFunctionExecutor() {
 
@@ -55,14 +54,15 @@
         this.function = function;
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        expression  = (ReturnValueExpression)in.readObject();
-        function    = (AccumulateFunction)in.readObject();
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        expression = (ReturnValueExpression) in.readObject();
+        function = (AccumulateFunction) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(expression);
-        out.writeObject(function);
+        out.writeObject( expression );
+        out.writeObject( function );
     }
 
     /* (non-Javadoc)
@@ -70,9 +70,9 @@
      */
     public Object createContext() {
         JavaAccumulatorFunctionContext context = new JavaAccumulatorFunctionContext();
-        context.context = this.function.createContext(); 
-        if( this.function.supportsReverse() ) {
-            context.reverseSupport = new HashMap<ReverseSupportKey, Object>();
+        context.context = this.function.createContext();
+        if ( this.function.supportsReverse() ) {
+            context.reverseSupport = new HashMap<FactHandle, Object>();
         }
         return context;
     }
@@ -104,8 +104,9 @@
                                                        innerDeclarations,
                                                        workingMemory,
                                                        workingMemoryContext ).getValue();
-        if( this.function.supportsReverse() ) {
-            ((JavaAccumulatorFunctionContext) context).reverseSupport.put( new ReverseSupportKey(leftTuple, handle), value );
+        if ( this.function.supportsReverse() ) {
+            ((JavaAccumulatorFunctionContext) context).reverseSupport.put( handle,
+                                                                           value );
         }
         this.function.accumulate( ((JavaAccumulatorFunctionContext) context).context,
                                   value );
@@ -118,10 +119,10 @@
                         Declaration[] declarations,
                         Declaration[] innerDeclarations,
                         WorkingMemory workingMemory) throws Exception {
-        
-        final Object value = ((JavaAccumulatorFunctionContext) context).reverseSupport.remove( new ReverseSupportKey(leftTuple, handle) );
+
+        final Object value = ((JavaAccumulatorFunctionContext) context).reverseSupport.remove( handle );
         this.function.reverse( ((JavaAccumulatorFunctionContext) context).context,
-                                  value );
+                               value );
     }
 
     /* (non-Javadoc)
@@ -151,42 +152,10 @@
         // no working memory context needed
         return null;
     }
-    
+
     private static class JavaAccumulatorFunctionContext {
-        public Object context;
-        public Map<ReverseSupportKey, Object> reverseSupport;
+        public Object                  context;
+        public Map<FactHandle, Object> reverseSupport;
     }
-    
-    private static class ReverseSupportKey implements Serializable {
-        private static final long serialVersionUID = 1473894397336046369L;
-        public final Tuple leftTuple;
-        public final FactHandle factHandle;
-        public ReverseSupportKey( final Tuple leftTuple, final FactHandle handle ) {
-            this.leftTuple = leftTuple;
-            this.factHandle = handle;
-        }
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ((factHandle == null) ? 0 : factHandle.hashCode());
-            result = prime * result + ((leftTuple == null) ? 0 : leftTuple.hashCode());
-            return result;
-        }
-        @Override
-        public boolean equals(Object obj) {
-            if ( this == obj ) return true;
-            if ( obj == null ) return false;
-            if ( getClass() != obj.getClass() ) return false;
-            final ReverseSupportKey other = (ReverseSupportKey) obj;
-            if ( factHandle == null ) {
-                if ( other.factHandle != null ) return false;
-            } else if ( !factHandle.equals( other.factHandle ) ) return false;
-            if ( leftTuple == null ) {
-                if ( other.leftTuple != null ) return false;
-            } else if ( !leftTuple.equals( other.leftTuple ) ) return false;
-            return true;
-        }
-        
-    }
+
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MVELAccumulatorFunctionExecutor.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MVELAccumulatorFunctionExecutor.java	2008-06-03 22:50:35 UTC (rev 20279)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/accumulators/MVELAccumulatorFunctionExecutor.java	2008-06-03 23:26:37 UTC (rev 20280)
@@ -42,9 +42,9 @@
     implements
     Accumulator {
 
-    private static final long        serialVersionUID = 400L;
+    private static final long  serialVersionUID = 400L;
 
-    private final Object             dummy            = new Object();
+    private final Object       dummy            = new Object();
     private DroolsMVELFactory  model;
     private Serializable       expression;
     private AccumulateFunction function;
@@ -62,16 +62,17 @@
         this.function = function;
     }
 
-    public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
-        model       = (DroolsMVELFactory)in.readObject();
-        expression  = (Serializable)in.readObject();
-        function    = (AccumulateFunction)in.readObject();
+    public void readExternal(ObjectInput in) throws IOException,
+                                            ClassNotFoundException {
+        model = (DroolsMVELFactory) in.readObject();
+        expression = (Serializable) in.readObject();
+        function = (AccumulateFunction) in.readObject();
     }
 
     public void writeExternal(ObjectOutput out) throws IOException {
-        out.writeObject(model);
-        out.writeObject(expression);
-        out.writeObject(function);
+        out.writeObject( model );
+        out.writeObject( expression );
+        out.writeObject( function );
     }
 
     /* (non-Javadoc)
@@ -79,9 +80,9 @@
      */
     public Object createContext() {
         MVELAccumulatorFunctionContext context = new MVELAccumulatorFunctionContext();
-        context.context = this.function.createContext(); 
-        if( this.function.supportsReverse() ) {
-            context.reverseSupport = new HashMap<ReverseSupportKey, Object>();
+        context.context = this.function.createContext();
+        if ( this.function.supportsReverse() ) {
+            context.reverseSupport = new HashMap<FactHandle, Object>();
         }
         return context;
     }
@@ -116,8 +117,9 @@
         final Object value = MVEL.executeExpression( this.expression,
                                                      this.dummy,
                                                      factory );
-        if( this.function.supportsReverse() ) {
-            ((MVELAccumulatorFunctionContext) context).reverseSupport.put( new ReverseSupportKey(leftTuple, handle), value );
+        if ( this.function.supportsReverse() ) {
+            ((MVELAccumulatorFunctionContext) context).reverseSupport.put( handle,
+                                                                           value );
         }
         this.function.accumulate( ((MVELAccumulatorFunctionContext) context).context,
                                   value );
@@ -130,7 +132,7 @@
                         Declaration[] declarations,
                         Declaration[] innerDeclarations,
                         WorkingMemory workingMemory) throws Exception {
-        final Object value = ((MVELAccumulatorFunctionContext) context).reverseSupport.remove( new ReverseSupportKey(leftTuple, handle) );
+        final Object value = ((MVELAccumulatorFunctionContext) context).reverseSupport.remove( handle );
         this.function.reverse( ((MVELAccumulatorFunctionContext) context).context,
                                value );
     }
@@ -153,42 +155,10 @@
     public Object createWorkingMemoryContext() {
         return this.model.clone();
     }
-    
+
     private static class MVELAccumulatorFunctionContext {
-        public Object context;
-        public Map<ReverseSupportKey, Object> reverseSupport;
+        public Object                         context;
+        public Map<FactHandle, Object>        reverseSupport;
     }
-    
-    private static class ReverseSupportKey implements Serializable {
-        private static final long serialVersionUID = 1473894397336046369L;
-        public final Tuple leftTuple;
-        public final FactHandle factHandle;
-        public ReverseSupportKey( final Tuple leftTuple, final FactHandle handle ) {
-            this.leftTuple = leftTuple;
-            this.factHandle = handle;
-        }
-        @Override
-        public int hashCode() {
-            final int prime = 31;
-            int result = 1;
-            result = prime * result + ((factHandle == null) ? 0 : factHandle.hashCode());
-            result = prime * result + ((leftTuple == null) ? 0 : leftTuple.hashCode());
-            return result;
-        }
-        @Override
-        public boolean equals(Object obj) {
-            if ( this == obj ) return true;
-            if ( obj == null ) return false;
-            if ( getClass() != obj.getClass() ) return false;
-            final ReverseSupportKey other = (ReverseSupportKey) obj;
-            if ( factHandle == null ) {
-                if ( other.factHandle != null ) return false;
-            } else if ( !factHandle.equals( other.factHandle ) ) return false;
-            if ( leftTuple == null ) {
-                if ( other.leftTuple != null ) return false;
-            } else if ( !leftTuple.equals( other.leftTuple ) ) return false;
-            return true;
-        }
-        
-    }
+
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELAccumulator.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELAccumulator.java	2008-06-03 22:50:35 UTC (rev 20279)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/base/mvel/MVELAccumulator.java	2008-06-03 23:26:37 UTC (rev 20280)
@@ -149,7 +149,7 @@
                             handle.getObject(),
                             workingMemory,
                             (Map) context );
-
+        
         Package pkg = workingMemory.getRuleBase().getPackage( "MAIN" );
         if ( pkg != null ) {
             MVELDialectData data = ( MVELDialectData ) pkg.getDialectDatas().getDialectData( "mvel" );




More information about the jboss-svn-commits mailing list