[jboss-svn-commits] JBL Code SVN: r7592 - in labs/jbossrules/trunk: drools-compiler/src/main/java/org/drools/semantics/java drools-compiler/src/main/resources/org/drools/semantics/java drools-compiler/src/test/java/org/drools/integrationtests drools-compiler/src/test/resources/org/drools/integrationtests drools-core/src/main/java/org/drools drools-core/src/main/java/org/drools/reteoo drools-core/src/main/java/org/drools/rule drools-core/src/main/java/org/drools/spi

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Nov 14 11:59:23 EST 2006


Author: tirelli
Date: 2006-11-14 11:58:59 -0500 (Tue, 14 Nov 2006)
New Revision: 7592

Modified:
   labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java
   labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/semantics/java/javaInvokers.stg
   labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/semantics/java/javaRule.stg
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
   labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ReteTest.java
   labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_DeclaringAndUsingBindsInSamePattern.drl
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseFactory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PredicateExpression.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/ReturnValueExpression.java
Log:
JBRULES-515: binding variables in the same pattern and mixing with previously bound variables are now working fine for predicates and return values too.

Modified: labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-compiler/src/main/java/org/drools/semantics/java/RuleBuilder.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -498,7 +498,8 @@
         if ( fieldConstraintDescr.getRestrictions().size() == 1 ) {
             final Object object = fieldConstraintDescr.getRestrictions().get( 0 );
 
-            final Restriction restriction = buildRestriction( extractor,
+            final Restriction restriction = buildRestriction( column, 
+                                                              extractor,
                                                               fieldConstraintDescr,
                                                               (RestrictionDescr) object );
             if ( restriction == null ) {
@@ -552,7 +553,8 @@
                 if ( currentList != null ) {
                     // Are we are at the first operator? if so treat differently
                     if ( previousList == null ) {
-                        restriction = buildRestriction( extractor,
+                        restriction = buildRestriction( column,
+                                                        extractor,
                                                         fieldConstraintDescr,
                                                         previousRestriction );
                         if ( currentList == andList ) {
@@ -561,7 +563,8 @@
                             orList.add( restriction );
                         }
                     } else {
-                        restriction = buildRestriction( extractor,
+                        restriction = buildRestriction( column,
+                                                        extractor,
                                                         fieldConstraintDescr,
                                                         previousRestriction );
 
@@ -589,7 +592,8 @@
             currentRestriction = (RestrictionDescr) object;
         }
 
-        final Restriction restriction = buildRestriction( extractor,
+        final Restriction restriction = buildRestriction( column, 
+                                                          extractor,
                                                           fieldConstraintDescr,
                                                           currentRestriction );
         currentList.add( restriction );
@@ -620,7 +624,8 @@
                                                                    restrictions ) );
     }
 
-    private Restriction buildRestriction(final FieldExtractor extractor,
+    private Restriction buildRestriction(final Column column,
+                                         final FieldExtractor extractor,
                                          final FieldConstraintDescr fieldConstraintDescr,
                                          final RestrictionDescr restrictionDescr) {
         Restriction restriction = null;
@@ -633,7 +638,8 @@
                                             fieldConstraintDescr,
                                             (VariableRestrictionDescr) restrictionDescr );
         } else if ( restrictionDescr instanceof ReturnValueRestrictionDescr ) {
-            restriction = buildRestriction( extractor,
+            restriction = buildRestriction( column,
+                                            extractor,
                                             fieldConstraintDescr,
                                             (ReturnValueRestrictionDescr) restrictionDescr );
 
@@ -754,7 +760,8 @@
                                        extractor );
     }
 
-    private ReturnValueRestriction buildRestriction(final FieldExtractor extractor,
+    private ReturnValueRestriction buildRestriction(final Column column,
+                                                    final FieldExtractor extractor,
                                                     final FieldConstraintDescr fieldConstraintDescr,
                                                     final ReturnValueRestrictionDescr returnValueRestrictionDescr) {
         final String className = "returnValue" + this.counter++;
@@ -763,9 +770,15 @@
         final List[] usedIdentifiers = getUsedIdentifiers( returnValueRestrictionDescr,
                                                            returnValueRestrictionDescr.getText() );
 
-        final Declaration[] declarations = new Declaration[usedIdentifiers[0].size()];
+        final List tupleDeclarations = new ArrayList();
+        final List factDeclarations = new ArrayList();
         for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
-            declarations[i] = (Declaration) this.declarations.get( (String) usedIdentifiers[0].get( i ) );
+            Declaration declaration = (Declaration) this.declarations.get( (String) usedIdentifiers[0].get( i ) );
+            if( declaration.getColumn() == column ) {
+                factDeclarations.add( declaration );
+            } else {
+                tupleDeclarations.add( declaration );
+            }
         }
 
         final Evaluator evaluator = getEvaluator( returnValueRestrictionDescr,
@@ -775,17 +788,31 @@
             return null;
         }
 
+        Declaration[] previousDeclarations = (Declaration[]) tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
+        Declaration[] localDeclarations = (Declaration[]) factDeclarations.toArray( new Declaration[factDeclarations.size()] );
         final ReturnValueRestriction returnValueRestriction = new ReturnValueRestriction( extractor,
-                                                                                          declarations,
+                                                                                          previousDeclarations,
+                                                                                          localDeclarations,
                                                                                           evaluator );
 
         StringTemplate st = RuleBuilder.ruleGroup.getInstanceOf( "returnValueMethod" );
 
         setStringTemplateAttributes( st,
-                                     declarations,
+                                     previousDeclarations,
                                      (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ),
                                      returnValueRestrictionDescr.getText() );
 
+        final String[] localDeclarationTypes = new String[localDeclarations.length];
+        for ( int i = 0, size = localDeclarations.length; i < size; i++ ) {
+            localDeclarationTypes[i] = localDeclarations[i].getExtractor().getExtractToClass().getName().replace( '$',
+                                                                                                        '.' );
+        }
+
+        st.setAttribute( "localDeclarations",
+                         localDeclarations );
+        st.setAttribute( "localDeclarationTypes",
+                         localDeclarationTypes );
+
         st.setAttribute( "methodName",
                          className );
 
@@ -807,10 +834,15 @@
                          className );
 
         setStringTemplateAttributes( st,
-                                     declarations,
+                                     previousDeclarations,
                                      (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ),
                                      returnValueRestrictionDescr.getText() );
 
+        st.setAttribute( "localDeclarations",
+                         localDeclarations );
+        st.setAttribute( "localDeclarationTypes",
+                         localDeclarationTypes );
+
         st.setAttribute( "hashCode",
                          returnValueText.hashCode() );
 
@@ -855,13 +887,22 @@
         // Don't include the focus declaration, that hasn't been merged into the tuple yet.
         usedIdentifiers[0].remove( predicateDescr.getDeclaration() );
 
-        final Declaration[] declarations = new Declaration[usedIdentifiers[0].size()];
+        final List tupleDeclarations = new ArrayList();
+        final List factDeclarations = new ArrayList();
         for ( int i = 0, size = usedIdentifiers[0].size(); i < size; i++ ) {
-            declarations[i] = (Declaration) this.declarations.get( (String) usedIdentifiers[0].get( i ) );
+            Declaration decl = (Declaration) this.declarations.get( (String) usedIdentifiers[0].get( i ) );
+            if( decl.getColumn() == column ) {
+                factDeclarations.add( decl );
+            } else {
+                tupleDeclarations.add( decl );
+            }
         }
+        Declaration[] previousDeclarations = (Declaration[]) tupleDeclarations.toArray( new Declaration[tupleDeclarations.size()] );
+        Declaration[] localDeclarations = (Declaration[]) factDeclarations.toArray( new Declaration[factDeclarations.size()] );
 
         final PredicateConstraint predicateConstraint = new PredicateConstraint( declaration,
-                                                                                 declarations );
+                                                                                 previousDeclarations,
+                                                                                 localDeclarations );
         column.addConstraint( predicateConstraint );
 
         StringTemplate st = RuleBuilder.ruleGroup.getInstanceOf( "predicateMethod" );
@@ -874,10 +915,21 @@
                                                                                            '.' ) );
 
         setStringTemplateAttributes( st,
-                                     declarations,
+                                     previousDeclarations,
                                      (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ),
                                      predicateDescr.getText() );
 
+        final String[] localDeclarationTypes = new String[localDeclarations.length];
+        for ( int i = 0, size = localDeclarations.length; i < size; i++ ) {
+            localDeclarationTypes[i] = localDeclarations[i].getExtractor().getExtractToClass().getName().replace( '$',
+                                                                                                        '.' );
+        }
+
+        st.setAttribute( "localDeclarations",
+                         localDeclarations );
+        st.setAttribute( "localDeclarationTypes",
+                         localDeclarationTypes );
+
         st.setAttribute( "methodName",
                          className );
 
@@ -905,10 +957,15 @@
                                                                                            '.' ) );
 
         setStringTemplateAttributes( st,
-                                     declarations,
+                                     previousDeclarations,
                                      (String[]) usedIdentifiers[1].toArray( new String[usedIdentifiers[1].size()] ),
                                      predicateDescr.getText() );
 
+        st.setAttribute( "localDeclarations",
+                         localDeclarations );
+        st.setAttribute( "localDeclarationTypes",
+                         localDeclarationTypes );
+
         st.setAttribute( "hashCode",
                          predicateText.hashCode() );
 

Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/semantics/java/javaInvokers.stg
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/semantics/java/javaInvokers.stg	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/semantics/java/javaInvokers.stg	2006-11-14 16:58:59 UTC (rev 7592)
@@ -53,22 +53,26 @@
     }
 >>
 
-returnValueInvoker(package, invokerClassName, ruleClassName, methodName, declarations, declarationTypes, globals, globalTypes, hashCode) ::= <<
+returnValueInvoker(package, invokerClassName, ruleClassName, methodName, declarations, declarationTypes, localDeclarations, localDeclarationTypes, globals, globalTypes, hashCode) ::= <<
 package <package>;
 
 public class <invokerClassName> implements org.drools.spi.ReturnValueExpression, org.drools.spi.CompiledInvoker
 {
     private static final long serialVersionUID  = 320L;
     
-    public org.drools.spi.FieldValue evaluate(org.drools.spi.Tuple tuple,
-                            org.drools.rule.Declaration[] declarations, 
+    public org.drools.spi.FieldValue evaluate(java.lang.Object object,
+                            org.drools.spi.Tuple tuple,
+                            org.drools.rule.Declaration[] previousDeclarations, 
+                            org.drools.rule.Declaration[] localDeclarations, 
                             org.drools.WorkingMemory workingMemory) throws Exception {                               
 
-        <declarationTypes, declarations:{ type, declr| <type> <declr.identifier> = ( <type> ) declarations[<i0>].<declr.extractor.nativeReadMethod.name>( ( (org.drools.common.InternalFactHandle) tuple.get( declarations[<i0>] ) ).getObject() );<\n>}>
+        <declarationTypes, declarations:{ type, declr| <type> <declr.identifier> = ( <type> ) previousDeclarations[<i0>].<declr.extractor.nativeReadMethod.name>( ( (org.drools.common.InternalFactHandle) tuple.get( previousDeclarations[<i0>] ) ).getObject() );<\n>}>
+        <localDeclarationTypes, localDeclarations:{ type, declr| <type> <declr.identifier> = ( <type> ) localDeclarations[<i0>].<declr.extractor.nativeReadMethod.name>( object );<\n>}>
         <globalTypes, globals:{ type, identifier | <type> <identifier> = ( <type> ) workingMemory.getGlobal( "<identifier>" );<\n>}>    
         
         return <ruleClassName>.<methodName>( 
-            <declarations:{ declr | <declr.identifier>}; separator=",\n"><if(globals)><if(declarations)>,<endif><endif>
+            <declarations:{ declr | <declr.identifier>}; separator=",\n"><if(localDeclarations)><if(declarations)>,<endif><endif>
+            <localDeclarations:{ declr | <declr.identifier>}; separator=",\n"><if(globals)><if(localDeclarations)>,<endif><if(!localDeclarations)><if(declarations)>,<endif><endif><endif>
 	        <globals:{ identifier | <identifier>}; separator=",\n"> );
     }    
     
@@ -81,7 +85,7 @@
 >>
 
 predicateInvoker(package, invokerClassName, ruleClassName, methodName, declaration, declarationType, 
-                 declarations, declarationTypes, globals, globalTypes, hashCode) ::= <<
+                 declarations, declarationTypes, localDeclarations, localDeclarationTypes, globals, globalTypes, hashCode) ::= <<
 package <package>;
 
 public class <invokerClassName> implements org.drools.spi.PredicateExpression, org.drools.spi.CompiledInvoker
@@ -91,15 +95,18 @@
     public boolean evaluate(Object object,
     						org.drools.spi.Tuple tuple,
                             org.drools.rule.Declaration declaration,
-                            org.drools.rule.Declaration[] declarations, 
+                            org.drools.rule.Declaration[] previousDeclarations, 
+                            org.drools.rule.Declaration[] localDeclarations, 
                             org.drools.WorkingMemory workingMemory) throws Exception {                               
 		<declarationType> <declaration.identifier> = (<declarationType>) declaration.<declaration.extractor.nativeReadMethod.name>( object );
-        <declarationTypes, declarations:{ type, declr| <type> <declr.identifier> = ( <type> ) declarations[<i0>].<declr.extractor.nativeReadMethod.name>( ( (org.drools.common.InternalFactHandle) tuple.get( declarations[<i0>] ) ).getObject() );<\n>}>
+        <declarationTypes, declarations:{ type, declr| <type> <declr.identifier> = ( <type> ) previousDeclarations[<i0>].<declr.extractor.nativeReadMethod.name>( ( (org.drools.common.InternalFactHandle) tuple.get( previousDeclarations[<i0>] ) ).getObject() );<\n>}>
+        <localDeclarationTypes, localDeclarations:{ type, declr| <type> <declr.identifier> = ( <type> ) localDeclarations[<i0>].<declr.extractor.nativeReadMethod.name>( object );<\n>}>
         <globalTypes, globals:{ type, identifier | <type> <identifier> = ( <type> ) workingMemory.getGlobal( "<identifier>" );<\n>}>    
         
         return <ruleClassName>.<methodName>( 
             <declaration.identifier><if(declarations)>,<endif>
-            <declarations:{ declr | <declr.identifier>}; separator=",\n"><if(globals)>,<endif>
+            <declarations:{ declr | <declr.identifier>}; separator=",\n"><if(localDeclarations)>,<endif>
+            <localDeclarations:{ declr | <declr.identifier>}; separator=",\n"><if(globals)>,<endif>
 	        <globals:{ identifier | <identifier>}; separator=",\n"> );
     }
     

Modified: labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/semantics/java/javaRule.stg
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/semantics/java/javaRule.stg	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-compiler/src/main/resources/org/drools/semantics/java/javaRule.stg	2006-11-14 16:58:59 UTC (rev 7592)
@@ -1,13 +1,18 @@
 group javaMethods;
 
-returnValueMethod(declarations, declarationTypes, globals, globalTypes, methodName, text) ::= <<
-public static org.drools.spi.FieldValue <methodName>(<declarationTypes, declarations:{ type, declr | <type> <declr.identifier>}; separator=","><if(globals)><if(declarations)>,<endif><endif> <globalTypes, globals:{ type, identifier | <type> <identifier>}; separator=","> ) throws Exception {
+returnValueMethod(declarations, declarationTypes, localDeclarations, localDeclarationTypes, globals, globalTypes, methodName, text) ::= <<
+public static org.drools.spi.FieldValue <methodName>(<declarationTypes, declarations:{ type, declr | <type> <declr.identifier>}; separator=","><if(localDeclarations)><if(declarations)>,<endif><endif> 
+                                                     <localDeclarationTypes, localDeclarations:{ type, declr | <type> <declr.identifier>}; separator=","><if(globals)><if(localDeclarations)>,<endif><if(!localDeclarations)><if(declarations)>,<endif><endif><endif>
+                                                     <globalTypes, globals:{ type, identifier | <type> <identifier>}; separator=","> ) throws Exception {
     return org.drools.base.FieldFactory.getFieldValue( <text> );
 }
 >>
 
-predicateMethod(declaration, declarationType, declarations, declarationTypes, globals, globalTypes, methodName, text) ::= <<
-public static boolean <methodName>(<declarationType> <declaration.identifier><if(declarations)>,<endif> <declarationTypes, declarations:{ type, declr | <type> <declr.identifier>}; separator=","><if(globals)>,<endif> <globalTypes, globals:{ type, identifier | <type> <identifier>}; separator=","> ) throws Exception {
+predicateMethod(declaration, declarationType, declarations, declarationTypes, localDeclarations, localDeclarationTypes, globals, globalTypes, methodName, text) ::= <<
+public static boolean <methodName>(<declarationType> <declaration.identifier><if(declarations)>,<endif> 
+                                   <declarationTypes, declarations:{ type, declr | <type> <declr.identifier>}; separator=","><if(localDeclarations)>,<endif> 
+                                   <localDeclarationTypes, localDeclarations:{ type, declr | <type> <declr.identifier>}; separator=","><if(globals)>,<endif>
+                                   <globalTypes, globals:{ type, identifier | <type> <identifier>}; separator=","> ) throws Exception {
     return ( <text> );
 }
 >>

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/IntegrationCases.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -49,6 +49,7 @@
 import org.drools.QueryResult;
 import org.drools.QueryResults;
 import org.drools.RuleBase;
+import org.drools.RuleBaseConfiguration;
 import org.drools.Sensor;
 import org.drools.State;
 import org.drools.TestParam;
@@ -86,6 +87,9 @@
     /** Implementation specific subclasses must provide this. */
     protected abstract RuleBase getRuleBase() throws Exception;
 
+    /** Implementation specific subclasses must provide this. */
+    protected abstract RuleBase getRuleBase(RuleBaseConfiguration config) throws Exception;
+
     public void testGlobals() throws Exception {
 
         final PackageBuilder builder = new PackageBuilder();
@@ -3539,11 +3543,14 @@
     }
 
     public void testDeclaringAndUsingBindsInSamePattern() throws Exception {
+        final RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setRemoveIdentities( true );
+        
         final PackageBuilder builder = new PackageBuilder();
         builder.addPackageFromDrl( new InputStreamReader( getClass().getResourceAsStream( "test_DeclaringAndUsingBindsInSamePattern.drl" ) ) );
         final Package pkg = builder.getPackage();
 
-        final RuleBase ruleBase = getRuleBase();
+        final RuleBase ruleBase = getRuleBase(config);
         ruleBase.addPackage( pkg );
         final WorkingMemory workingMemory = ruleBase.newWorkingMemory();
 
@@ -3564,7 +3571,7 @@
                                          150 );
             workingMemory.assertObject( sensor2 );
             workingMemory.fireAllRules();
-            assertEquals( 1,
+            assertEquals( 3,
                           sensors.size() );
 
         } catch ( RuntimeException e ) {

Modified: labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ReteTest.java
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ReteTest.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-compiler/src/test/java/org/drools/integrationtests/ReteTest.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -17,6 +17,7 @@
  */
 
 import org.drools.RuleBase;
+import org.drools.RuleBaseConfiguration;
 import org.drools.RuleBaseFactory;
 
 /** Run all the tests with the ReteOO engine implementation */
@@ -24,7 +25,12 @@
 
     protected RuleBase getRuleBase() throws Exception {
 
-        return RuleBaseFactory.newRuleBase( RuleBase.RETEOO );
+        return RuleBaseFactory.newRuleBase( RuleBase.RETEOO, null );
     }
 
+    protected RuleBase getRuleBase(final RuleBaseConfiguration config ) throws Exception {
+
+        return RuleBaseFactory.newRuleBase( RuleBase.RETEOO, config );
+    }
+
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_DeclaringAndUsingBindsInSamePattern.drl
===================================================================
--- labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_DeclaringAndUsingBindsInSamePattern.drl	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-compiler/src/test/resources/org/drools/integrationtests/test_DeclaringAndUsingBindsInSamePattern.drl	2006-11-14 16:58:59 UTC (rev 7592)
@@ -5,10 +5,28 @@
 
 global java.util.List sensors;
 
-rule "BindsTest"
+rule "BindsTest1_returnValue"
 	when
-		$sensor : Sensor( $temp : temperature, pressure < $temp )
+		$sensor1 : Sensor( $temp1 : temperature, pressure < $temp1 )
+		$sensor2 : Sensor( $temp2 : temperature, pressure < ( $temp1 + $temp2 ) )
 	then 
-	    sensors.add( $sensor );
+	    sensors.add( $sensor1 );
 end
 
+rule "BindsTest2_predicate"
+	when
+		$sensor1 : Sensor( $temp1 : temperature, pressure < $temp1 )
+		$sensor2 : Sensor( $temp2 : temperature, $p : pressure -> ( $p < ($temp1 + $temp2 ) ) )
+	then 
+	    sensors.add( $sensor1 );
+end
+
+rule "BindsTest3_eval"
+	when
+		$sensor1 : Sensor( $temp1 : temperature, pressure < $temp1 )
+		$sensor2 : Sensor( $temp2 : temperature, $p : pressure )
+		eval( $p < $temp1 + $temp2 )
+	then 
+	    sensors.add( $sensor1 );
+end
+

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -17,8 +17,6 @@
 package org.drools;
 
 import java.io.Serializable;
-import java.util.HashMap;
-import java.util.Map;
 
 /**
  * RuleBaseConfiguration

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseFactory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseFactory.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseFactory.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -36,14 +36,14 @@
 
     /** Create a new default rule base (RETEOO type engine) */
     public static RuleBase newRuleBase() {
-        return RuleBaseFactory.newRuleBase( RuleBase.RETEOO );
+        return RuleBaseFactory.newRuleBase( RuleBase.RETEOO, null );
     }
 
     /** Create a new RuleBase of the appropriate type */
-    public static RuleBase newRuleBase(final int type) {
+    public static RuleBase newRuleBase(final int type, final RuleBaseConfiguration config) {
         switch ( type ) {
             case RuleBase.RETEOO :
-                return new org.drools.reteoo.ReteooRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString() );
+                return new org.drools.reteoo.ReteooRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString(), config );
             case RuleBase.LEAPS :
                 //@todo this needs to be reflection based  now, as we do  not know the  module is  in the classpath
                 //return new org.drools.leaps.LeapsRuleBase( UUIDGenerator.getInstance().generateRandomBasedUUID().toString() );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooRuleBase.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -91,6 +91,13 @@
               factHandleFactory );
     }
 
+    public ReteooRuleBase(final String id,
+                          final RuleBaseConfiguration config) {
+        this( id,
+              config,
+              new ReteooFactHandleFactory() );
+    }
+
     /**
      * @param config
      */

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/PredicateConstraint.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -40,41 +40,67 @@
 
     private final Declaration[]        requiredDeclarations;
 
+    private final Declaration[]        previousDeclarations;
+
+    private final Declaration[]        localDeclarations;
+
     private static final Declaration[] EMPTY_DECLARATIONS = new Declaration[0];
 
     public PredicateConstraint(final PredicateExpression evaluator,
                                final Declaration declaration) {
         this( evaluator,
               declaration,
+              null,
               null );
     }
 
     public PredicateConstraint(final Declaration declaration,
-                               final Declaration[] requiredDeclarations) {
+                               final Declaration[] previousDeclarations,
+                               final Declaration[] localDeclarations) {
         this( null,
               declaration,
-              requiredDeclarations );
+              previousDeclarations,
+              localDeclarations );
     }
 
     public PredicateConstraint(final PredicateExpression expression,
                                final Declaration declaration,
-                               final Declaration[] requiredDeclarations) {
+                               final Declaration[] previousDeclarations,
+                               final Declaration[] localDeclarations) {
 
         this.expression = expression;
 
         this.declaration = declaration;
 
-        if ( requiredDeclarations == null ) {
-            this.requiredDeclarations = PredicateConstraint.EMPTY_DECLARATIONS;
+        if ( previousDeclarations == null ) {
+            this.previousDeclarations = PredicateConstraint.EMPTY_DECLARATIONS;
         } else {
-            this.requiredDeclarations = requiredDeclarations;
+            this.previousDeclarations = previousDeclarations;
         }
+        
+        if ( localDeclarations == null ) {
+            this.localDeclarations = PredicateConstraint.EMPTY_DECLARATIONS;
+        } else {
+            this.localDeclarations = localDeclarations;
+        }
+        
+        this.requiredDeclarations = new Declaration[ previousDeclarations.length + localDeclarations.length ];
+        System.arraycopy( this.previousDeclarations, 0, this.requiredDeclarations, 0, this.previousDeclarations.length );
+        System.arraycopy( this.localDeclarations, 0, this.requiredDeclarations, this.previousDeclarations.length, this.localDeclarations.length );
     }
 
     public Declaration[] getRequiredDeclarations() {
         return this.requiredDeclarations;
     }
 
+    public Declaration[] getPreviousDeclarations() {
+        return this.previousDeclarations;
+    }
+
+    public Declaration[] getLocalDeclarations() {
+        return this.localDeclarations;
+    }
+
     public void setPredicateExpression(final PredicateExpression expression) {
         this.expression = expression;
     }
@@ -84,7 +110,7 @@
     }
 
     public String toString() {
-        return "[PredicateConstraint declarations=" + this.requiredDeclarations + "]";
+        return "[PredicateConstraint previousDeclarations=" + this.previousDeclarations + " localDeclarations=" + this.localDeclarations+ "]";
     }
 
     public int hashCode() {
@@ -102,10 +128,14 @@
 
         final PredicateConstraint other = (PredicateConstraint) object;
 
-        if ( this.requiredDeclarations.length != other.requiredDeclarations.length ) {
+        if ( this.previousDeclarations.length != other.previousDeclarations.length ) {
             return false;
         }
 
+        if ( this.localDeclarations.length != other.localDeclarations.length ) {
+            return false;
+        }
+
         if ( this.declaration.getColumn().getFactIndex() != other.declaration.getColumn().getFactIndex() ) {
             return false;
         }
@@ -114,16 +144,26 @@
             return false;
         }
 
-        for ( int i = 0, length = this.requiredDeclarations.length; i < length; i++ ) {
-            if ( this.requiredDeclarations[i].getColumn().getFactIndex() != other.requiredDeclarations[i].getColumn().getFactIndex() ) {
+        for ( int i = 0, length = this.previousDeclarations.length; i < length; i++ ) {
+            if ( this.previousDeclarations[i].getColumn().getFactIndex() != other.previousDeclarations[i].getColumn().getFactIndex() ) {
                 return false;
             }
 
-            if ( !this.requiredDeclarations[i].getExtractor().equals( other.requiredDeclarations[i].getExtractor() ) ) {
+            if ( !this.previousDeclarations[i].getExtractor().equals( other.previousDeclarations[i].getExtractor() ) ) {
                 return false;
             }
         }
 
+        for ( int i = 0, length = this.localDeclarations.length; i < length; i++ ) {
+            if ( this.localDeclarations[i].getColumn().getFactIndex() != other.localDeclarations[i].getColumn().getFactIndex() ) {
+                return false;
+            }
+
+            if ( !this.localDeclarations[i].getExtractor().equals( other.localDeclarations[i].getExtractor() ) ) {
+                return false;
+            }
+        }
+
         return this.expression.equals( other.expression );
     }
 
@@ -137,7 +177,8 @@
             return this.expression.evaluate( object,
                                              null,
                                              declaration,
-                                             requiredDeclarations,
+                                             previousDeclarations,
+                                             localDeclarations,
                                              workingMemory );
         } catch ( Exception e ) {
             throw new RuntimeDroolsException( "Exception executing predicate " + this.expression,
@@ -152,7 +193,8 @@
             return this.expression.evaluate( object,
                                              ctx.leftTuple,
                                              declaration,
-                                             requiredDeclarations,
+                                             previousDeclarations,
+                                             localDeclarations,
                                              ctx.workingMemory );
         } catch ( Exception e ) {
             throw new RuntimeDroolsException( "Exception executing predicate " + this.expression,
@@ -167,7 +209,8 @@
             return this.expression.evaluate( ctx.rightObject,
                                              tuple,
                                              declaration,
-                                             requiredDeclarations,
+                                             previousDeclarations,
+                                             localDeclarations,
                                              ctx.workingMemory );
         } catch ( Exception e ) {
             throw new RuntimeDroolsException( "Exception executing predicate " + this.expression,
@@ -178,6 +221,9 @@
     public static class PredicateContextEntry
         implements
         ContextEntry {
+
+        private static final long serialVersionUID = 4217315252579887635L;
+        
         public ReteTuple             leftTuple;
         public Object                rightObject;
         public InternalWorkingMemory workingMemory;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueConstraint.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -40,26 +40,6 @@
     private final ReturnValueRestriction restriction;
 
     public ReturnValueConstraint(final FieldExtractor fieldExtractor,
-                                 final Declaration[] declarations,
-                                 final Evaluator evaluator) {
-        this.fieldExtractor = fieldExtractor;
-        this.restriction = new ReturnValueRestriction( fieldExtractor,
-                                                       declarations,
-                                                       evaluator );
-    }
-
-    public ReturnValueConstraint(final FieldExtractor fieldExtractor,
-                                 final ReturnValueExpression expression,
-                                 final Declaration[] declarations,
-                                 final Evaluator evaluator) {
-        this.fieldExtractor = fieldExtractor;
-        this.restriction = new ReturnValueRestriction( fieldExtractor,
-                                                       expression,
-                                                       declarations,
-                                                       evaluator );
-    }
-
-    public ReturnValueConstraint(final FieldExtractor fieldExtractor,
                                  final ReturnValueRestriction restriction) {
         this.fieldExtractor = fieldExtractor;
         this.restriction = restriction;

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/rule/ReturnValueRestriction.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -34,47 +34,74 @@
     implements
     Restriction {
 
-    private static final long          serialVersionUID       = 320;
+    private static final long             serialVersionUID       = 320;
 
-    private ReturnValueExpression      expression;
+    private ReturnValueExpression         expression;
 
-    private final Declaration[]        requiredDeclarations;
+    private final Declaration[]           requiredDeclarations;
 
-    private final Evaluator            evaluator;
+    private final Declaration[]           previousDeclarations;
 
-    private static final Declaration[] noRequiredDeclarations = new Declaration[]{};
-    
+    private final Declaration[]           localDeclarations;
+
+    private final Evaluator               evaluator;
+
+    private static final Declaration[]    noRequiredDeclarations = new Declaration[]{};
+
     private final ReturnValueContextEntry contextEntry;
 
     public ReturnValueRestriction(final FieldExtractor fieldExtractor,
-                                  final Declaration[] declarations,
+                                  final Declaration[] previousDeclarations,
+                                  final Declaration[] localDeclarations,
                                   final Evaluator evaluator) {
         this( fieldExtractor,
               null,
-              declarations,
+              previousDeclarations,
+              localDeclarations,
               evaluator );
     }
 
     public ReturnValueRestriction(final FieldExtractor fieldExtractor,
                                   final ReturnValueExpression returnValueExpression,
-                                  final Declaration[] declarations,
+                                  final Declaration[] previousDeclarations,
+                                  final Declaration[] localDeclarations,
                                   final Evaluator evaluator) {
         this.expression = returnValueExpression;
 
-        if ( declarations != null ) {
-            this.requiredDeclarations = declarations;
+        if ( previousDeclarations != null ) {
+            this.previousDeclarations = previousDeclarations;
         } else {
-            this.requiredDeclarations = ReturnValueRestriction.noRequiredDeclarations;
+            this.previousDeclarations = ReturnValueRestriction.noRequiredDeclarations;
         }
 
+        if ( localDeclarations != null ) {
+            this.localDeclarations = localDeclarations;
+        } else {
+            this.localDeclarations = ReturnValueRestriction.noRequiredDeclarations;
+        }
+
         this.evaluator = evaluator;
-        this.contextEntry = new ReturnValueContextEntry(fieldExtractor, requiredDeclarations);
+        this.contextEntry = new ReturnValueContextEntry( fieldExtractor,
+                                                         previousDeclarations,
+                                                         localDeclarations );
+
+        this.requiredDeclarations = new Declaration[ previousDeclarations.length + localDeclarations.length ];
+        System.arraycopy( this.previousDeclarations, 0, this.requiredDeclarations, 0, this.previousDeclarations.length );
+        System.arraycopy( this.localDeclarations, 0, this.requiredDeclarations, this.previousDeclarations.length, this.localDeclarations.length );
     }
 
     public Declaration[] getRequiredDeclarations() {
         return this.requiredDeclarations;
     }
 
+    public Declaration[] getPreviousDeclarations() {
+        return this.previousDeclarations;
+    }
+
+    public Declaration[] getLocalDeclarations() {
+        return this.localDeclarations;
+    }
+
     public void setReturnValueExpression(final ReturnValueExpression expression) {
         this.expression = expression;
     }
@@ -94,8 +121,10 @@
         try {
             return this.evaluator.evaluate( extractor,
                                             object,
-                                            this.expression.evaluate( tuple,
-                                                                      this.requiredDeclarations,
+                                            this.expression.evaluate( object,
+                                                                      tuple,
+                                                                      this.previousDeclarations,
+                                                                      this.localDeclarations,
                                                                       workingMemory ) );
         } catch ( final Exception e ) {
             throw new RuntimeDroolsException( e );
@@ -122,8 +151,9 @@
         final int PRIME = 31;
         int result = 1;
         result = PRIME * result + this.evaluator.hashCode();
-        result = PRIME * result + ( ( this.expression != null ) ? this.expression.hashCode() : 0 );
-        result = PRIME * result + ReturnValueRestriction.hashCode( this.requiredDeclarations );
+        result = PRIME * result + ((this.expression != null) ? this.expression.hashCode() : 0);
+        result = PRIME * result + ReturnValueRestriction.hashCode( this.localDeclarations );
+        result = PRIME * result + ReturnValueRestriction.hashCode( this.previousDeclarations );
         return result;
     }
 
@@ -138,15 +168,24 @@
 
         final ReturnValueRestriction other = (ReturnValueRestriction) object;
 
-        if ( this.requiredDeclarations.length != other.requiredDeclarations.length ) {
+        if ( this.localDeclarations.length != other.localDeclarations.length ) {
             return false;
         }
 
-        if ( !Arrays.equals( this.requiredDeclarations,
-                             other.requiredDeclarations ) ) {
+        if ( this.previousDeclarations.length != other.previousDeclarations.length ) {
             return false;
         }
 
+        if ( !Arrays.equals( this.previousDeclarations,
+                             other.previousDeclarations ) ) {
+            return false;
+        }
+
+        if ( !Arrays.equals( this.previousDeclarations,
+                             other.previousDeclarations ) ) {
+            return false;
+        }
+
         return this.expression.equals( other.expression );
     }
 
@@ -169,17 +208,24 @@
     public static class ReturnValueContextEntry
         implements
         ContextEntry {
+
+        private static final long serialVersionUID = 3563817867979321431L;
+        
         public FieldExtractor        fieldExtractor;
         public Object                object;
         public ReteTuple             leftTuple;
         public InternalWorkingMemory workingMemory;
-        public Declaration[]         requiredDeclarations;
+        public Declaration[]         previousDeclarations;
+        public Declaration[]         localDeclarations;
 
-        private ContextEntry          entry;
+        private ContextEntry         entry;
 
-        public ReturnValueContextEntry(FieldExtractor fieldExtractor, Declaration[] requiredDeclarations) {
+        public ReturnValueContextEntry(FieldExtractor fieldExtractor,
+                                       Declaration[] previousDeclarations,
+                                       Declaration[] localDeclarations) {
             this.fieldExtractor = fieldExtractor;
-            this.requiredDeclarations = requiredDeclarations;
+            this.previousDeclarations = previousDeclarations;
+            this.localDeclarations = localDeclarations;
         }
 
         public ContextEntry getNext() {
@@ -226,10 +272,14 @@
         /* (non-Javadoc)
          * @see org.drools.rule.ReturnValueContextEntry#getRequiredDeclarations()
          */
-        public Declaration[] getRequiredDeclarations() {
-            return this.requiredDeclarations;
+        public Declaration[] getPreviousDeclarations() {
+            return this.previousDeclarations;
         }
 
+        public Declaration[] getLocalDeclarations() {
+            return this.localDeclarations;
+        }
+
         /* (non-Javadoc)
          * @see org.drools.rule.ReturnValueContextEntry#getWorkingMemory()
          */

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PredicateExpression.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PredicateExpression.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/PredicateExpression.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -25,6 +25,7 @@
     public boolean evaluate(Object object,
                             Tuple tuple,
                             Declaration declaration,
-                            Declaration[] requiredDeclarations,
+                            Declaration[] previousDeclarations,
+                            Declaration[] localDeclarations,
                             WorkingMemory workingMemory) throws Exception;
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/ReturnValueExpression.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/ReturnValueExpression.java	2006-11-14 16:16:40 UTC (rev 7591)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/spi/ReturnValueExpression.java	2006-11-14 16:58:59 UTC (rev 7592)
@@ -22,7 +22,9 @@
 public interface ReturnValueExpression
     extends
     Invoker {
-    public FieldValue evaluate(Tuple tuple,
-                               Declaration[] requiredDeclarations,
+    public FieldValue evaluate(Object object,
+                               Tuple tuple,
+                               Declaration[] previousDeclarations,
+                               Declaration[] localDeclarations,
                                WorkingMemory workingMemory) throws Exception;
 }
\ No newline at end of file




More information about the jboss-svn-commits mailing list