[jboss-svn-commits] JBL Code SVN: r14902 - in labs/jbossrules/trunk/drools-core/src: main/java/org/drools/reteoo and 2 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Sep 5 16:03:00 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-09-05 16:03:00 -0400 (Wed, 05 Sep 2007)
New Revision: 14902

Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.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
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/BetaNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ExistsNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java
Log:
JBRULES-1153 Accumulate/Collect can't be used in queries
-like sequential Querries do not use any memory, so added context to BuildContext to provide setting information for memory on nodes.

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -41,6 +41,7 @@
 import org.drools.WorkingMemory;
 import org.drools.RuleBaseConfiguration.AssertBehaviour;
 import org.drools.RuleBaseConfiguration.LogicalOverride;
+import org.drools.base.DroolsQuery;
 import org.drools.base.MapGlobalResolver;
 import org.drools.base.ShadowProxy;
 import org.drools.event.AgendaEventListener;
@@ -834,10 +835,10 @@
         return handle;
     }
 
-    private void insert(InternalFactHandle handle,
-                        Object object,
-                        Rule rule,
-                        Activation activation) {
+    protected void insert(InternalFactHandle handle,
+                          Object object,
+                          Rule rule,
+                          Activation activation) {
         this.ruleBase.executeQueuedActions();
 
         if ( activation != null ) {
@@ -1095,7 +1096,7 @@
         try {
             this.lock.lock();
             this.ruleBase.executeQueuedActions();
-            
+
             final InternalFactHandle handle = (InternalFactHandle) factHandle;
             final Object originalObject = (handle.isShadowFact()) ? ((ShadowProxy) handle.getObject()).getShadowedObject() : handle.getObject();
 
@@ -1170,7 +1171,7 @@
         try {
             this.lock.lock();
             this.ruleBase.executeQueuedActions();
-            
+
             // only needed if we maintain tms, but either way we must get it before we do the retract
             int status = -1;
             if ( this.maintainTms ) {
@@ -1389,33 +1390,33 @@
         }
         return result;
     }
-    
+
     public Entry[] getActivationParameters(long activationId) {
-    	Activation[] activations = getAgenda().getActivations();
-    	for (int i = 0; i < activations.length; i++) {
-    		if (activations[i].getActivationNumber() == activationId) {
-    			Map params = getActivationParameters(activations[i]);
-    			return (Entry[]) params.entrySet().toArray(new Entry[params.size()]);
-    		}
-    	}
-    	return new Entry[0];
+        Activation[] activations = getAgenda().getActivations();
+        for ( int i = 0; i < activations.length; i++ ) {
+            if ( activations[i].getActivationNumber() == activationId ) {
+                Map params = getActivationParameters( activations[i] );
+                return (Entry[]) params.entrySet().toArray( new Entry[params.size()] );
+            }
+        }
+        return new Entry[0];
     }
-    
+
     /**
      * Helper method 
      */
     public Map getActivationParameters(Activation activation) {
-    	Map result = new HashMap();
-    	Declaration[] declarations = activation.getRule().getDeclarations();
-    	for (int i = 0; i < declarations.length; i++) {
-    		FactHandle handle = activation.getTuple().get(declarations[i]);
-    		if (handle instanceof InternalFactHandle) {
-    			result.put(declarations[i].getIdentifier(),
-					declarations[i].getValue(this,
-						((InternalFactHandle) handle).getObject()));
-    		}
-    	}
-    	return result;
+        Map result = new HashMap();
+        Declaration[] declarations = activation.getRule().getDeclarations();
+        for ( int i = 0; i < declarations.length; i++ ) {
+            FactHandle handle = activation.getTuple().get( declarations[i] );
+            if ( handle instanceof InternalFactHandle ) {
+                result.put( declarations[i].getIdentifier(),
+                            declarations[i].getValue( this,
+                                                      ((InternalFactHandle) handle).getObject() ) );
+            }
+        }
+        return result;
     }
 
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -24,6 +24,7 @@
 import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Accumulate;
 import org.drools.spi.AlphaNodeFieldConstraint;
 import org.drools.spi.PropagationContext;
@@ -51,32 +52,6 @@
     private final AlphaNodeFieldConstraint[] resultConstraints;
     private final BetaConstraints            resultBinder;
 
-    /**
-     * Construct.
-     * 
-     * @param id
-     *            The id for the node
-     * @param leftInput
-     *            The left input <code>TupleSource</code>.
-     * @param rightInput
-     *            The right input <code>ObjectSource</code>.
-     * @param accumulate
-     *            The accumulate conditional element
-     */
-    AccumulateNode(final int id,
-                   final TupleSource leftInput,
-                   final ObjectSource rightInput,
-                   final Accumulate accumulate) {
-        this( id,
-              leftInput,
-              rightInput,
-              new AlphaNodeFieldConstraint[0],
-              EmptyBetaConstraints.getInstance(),
-              EmptyBetaConstraints.getInstance(),
-              accumulate,
-              false );
-    }
-
     public AccumulateNode(final int id,
                           final TupleSource leftInput,
                           final ObjectSource rightInput,
@@ -84,7 +59,8 @@
                           final BetaConstraints sourceBinder,
                           final BetaConstraints resultBinder,
                           final Accumulate accumulate,
-                          final boolean unwrapRightObject) {
+                          final boolean unwrapRightObject,
+                          final BuildContext context) {
         super( id,
                leftInput,
                rightInput,
@@ -93,6 +69,7 @@
         this.resultConstraints = resultConstraints;
         this.accumulate = accumulate;
         this.unwrapRightObject = unwrapRightObject;
+        this.hasLeftMemory = context.hasLeftMemory();
     }
 
     /**
@@ -122,7 +99,7 @@
 
         AccumulateResult accresult = new AccumulateResult();
 
-        if ( !workingMemory.isSequential() ) {
+        if ( this.hasLeftMemory ) {
             memory.betaMemory.getTupleMemory().add( leftTuple );
             memory.betaMemory.getCreatedHandles().put( leftTuple,
                                             accresult,
@@ -233,7 +210,7 @@
         final AccumulateMemory memory = (AccumulateMemory) workingMemory.getNodeMemory( this );
         memory.betaMemory.getFactHandleMemory().add( handle );
 
-        if ( workingMemory.isSequential() ) {
+        if ( ! this.hasLeftMemory ) {
             // do nothing here, as we know there are no left tuples at this stage in sequential mode.
             return;
         }

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	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/BetaNode.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -65,29 +65,14 @@
 
     private ObjectSinkNode          previousObjectSinkNode;
     private ObjectSinkNode          nextObjectSinkNode;
+    
+    protected boolean hasLeftMemory = true;
 
     // ------------------------------------------------------------
     // Constructors
     // ------------------------------------------------------------
 
     /**
-     * The constructor defaults to using a BetaNodeBinder with no constraints
-     * 
-     * @param leftInput
-     *            The left input <code>TupleSource</code>.
-     * @param rightInput
-     *            The right input <code>ObjectSource</code>.
-     */
-    BetaNode(final int id,
-             final TupleSource leftInput,
-             final ObjectSource rightInput) {
-        this( id,
-              leftInput,
-              rightInput,
-              EmptyBetaConstraints.getInstance() );
-    }
-
-    /**
      * Constructs a <code>BetaNode</code> using the specified <code>BetaNodeBinder</code>.
      * 
      * @param leftInput
@@ -224,7 +209,7 @@
 
         final BetaNode other = (BetaNode) object;
 
-        return this.getClass() == other.getClass() && this.leftInput.equals( other.leftInput ) && this.rightInput.equals( other.rightInput ) && this.constraints.equals( other.constraints );
+        return this.getClass() == other.getClass() && this.hasLeftMemory == other.hasLeftMemory && this.leftInput.equals( other.leftInput ) && this.rightInput.equals( other.rightInput ) && this.constraints.equals( other.constraints );
     }
 
     /**

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	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -23,6 +23,7 @@
 import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Collect;
 import org.drools.spi.AlphaNodeFieldConstraint;
 import org.drools.spi.PropagationContext;
@@ -57,32 +58,6 @@
      *            The left input <code>TupleSource</code>.
      * @param rightInput
      *            The right input <code>ObjectSource</code>.
-     * @param collect
-     *            The collect conditional element
-     */
-    CollectNode(final int id,
-                final TupleSource leftInput,
-                final ObjectSource rightInput,
-                final Collect collect) {
-        this( id,
-              leftInput,
-              rightInput,
-              new AlphaNodeFieldConstraint[0],
-              EmptyBetaConstraints.getInstance(),
-              EmptyBetaConstraints.getInstance(),
-              collect,
-              false );
-    }
-
-    /**
-     * Constructor.
-     * 
-     * @param id
-     *            The id for the node
-     * @param leftInput
-     *            The left input <code>TupleSource</code>.
-     * @param rightInput
-     *            The right input <code>ObjectSource</code>.
      * @param resultConstraints
      *            The alpha constraints to be applied to the resulting collection
      * @param sourceBinder
@@ -99,7 +74,8 @@
                        final BetaConstraints sourceBinder,
                        final BetaConstraints resultsBinder,
                        final Collect collect,
-                       final boolean unwrapRight ) {
+                       final boolean unwrapRight,
+                       final BuildContext context) {
         super( id,
                leftInput,
                rightInput,
@@ -108,6 +84,7 @@
         this.resultConstraints = resultConstraints;
         this.collect = collect;
         this.unwrapRightObject = unwrapRight;
+        this.hasLeftMemory = context.hasLeftMemory();
     }
 
     /**
@@ -136,7 +113,7 @@
         colresult.propagated = false;
         
         // do not add tuple and result to the memory in sequential mode
-        if( ! workingMemory.isSequential() ) {
+        if ( this.hasLeftMemory ) {
             memory.getTupleMemory().add( leftTuple );
             memory.getCreatedHandles().put( leftTuple,
                                             colresult,
@@ -221,7 +198,7 @@
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
         memory.getFactHandleMemory().add( handle );
         
-        if ( workingMemory.isSequential() ) {
+        if ( !this.hasLeftMemory ) {
             // do nothing here, as we know there are no left tuples at this stage in sequential mode.
             return;
         }        

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -20,6 +20,7 @@
 import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.spi.PropagationContext;
 import org.drools.util.FactEntry;
 import org.drools.util.Iterator;
@@ -51,25 +52,6 @@
     // ------------------------------------------------------------
 
     /**
-     * Constructs a new Exists node with EmptyBetaConstraints.
-     * 
-     * @paran id
-     *            The unique id for this node.
-     * @param leftInput
-     *            The left input <code>TupleSource</code>.
-     * @param rightInput
-     *            The right input <code>ObjectSource</code>.
-     */
-    public ExistsNode(final int id,
-                      final TupleSource leftInput,
-                      final ObjectSource rightInput) {
-        super( id,
-               leftInput,
-               rightInput,
-               EmptyBetaConstraints.getInstance() );
-    }
-
-    /**
      * Construct.
      * 
      * @paran id
@@ -84,11 +66,13 @@
     public ExistsNode(final int id,
                       final TupleSource leftInput,
                       final ObjectSource rightInput,
-                      final BetaConstraints joinNodeBinder) {
+                      final BetaConstraints joinNodeBinder,
+                      final BuildContext context) {
         super( id,
                leftInput,
                rightInput,
                joinNodeBinder );
+        this.hasLeftMemory = context.hasLeftMemory();        
     }
 
     /**
@@ -108,7 +92,7 @@
                             final InternalWorkingMemory workingMemory) {
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
         
-        if ( !workingMemory.isSequential() ) {
+        if ( this.hasLeftMemory ) {
             memory.getTupleMemory().add( leftTuple );
         }
 
@@ -150,7 +134,7 @@
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
         memory.getFactHandleMemory().add( handle );
         
-        if ( workingMemory.isSequential() ) {
+        if ( !this.hasLeftMemory ) {
             // do nothing here, as we know there are no left tuples at this stage in sequential mode.
             return;
         }          

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -19,6 +19,7 @@
 import org.drools.common.BetaConstraints;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.spi.PropagationContext;
 import org.drools.util.FactEntry;
 import org.drools.util.Iterator;
@@ -52,36 +53,22 @@
     // ------------------------------------------------------------
     // Instance methods
     // ------------------------------------------------------------
-
+    
     /**
      * 
      */
     private static final long serialVersionUID = 400L;
 
-    /**
-     * Construct.
-     * 
-     * @param leftInput
-     *            The left input <code>TupleSource</code>.
-     * @param rightInput
-     *            The right input <code>TupleSource</code>.
-     */
     public JoinNode(final int id,
                     final TupleSource leftInput,
-                    final ObjectSource rightInput) {
-        super( id,
-               leftInput,
-               rightInput );
-    }
-
-    public JoinNode(final int id,
-                    final TupleSource leftInput,
                     final ObjectSource rightInput,
-                    final BetaConstraints binder) {
+                    final BetaConstraints binder,
+                    final BuildContext context) {
         super( id,
                leftInput,
                rightInput,
                binder );
+        this.hasLeftMemory = context.hasLeftMemory();
     }
 
     /**
@@ -107,7 +94,7 @@
                             final InternalWorkingMemory workingMemory) {
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
         
-        if ( !workingMemory.isSequential() ) {
+        if ( this.hasLeftMemory ) {
             memory.getTupleMemory().add( leftTuple );
         }
 
@@ -149,7 +136,7 @@
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
 
         memory.getFactHandleMemory().add( handle );
-        if ( workingMemory.isSequential() ) {
+        if ( ! this.hasLeftMemory ) {
             // do nothing here, as we know there are no left tuples at this stage in sequential mode.
             return;
         }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -20,6 +20,7 @@
 import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.spi.PropagationContext;
 import org.drools.util.FactEntry;
 import org.drools.util.Iterator;
@@ -61,29 +62,14 @@
      */
     public NotNode(final int id,
                    final TupleSource leftInput,
-                   final ObjectSource rightInput) {
-        super( id,
-               leftInput,
-               rightInput,
-               EmptyBetaConstraints.getInstance() );
-    }
-
-    /**
-     * Construct.
-     * 
-     * @param leftInput
-     *            The left input <code>TupleSource</code>.
-     * @param rightInput
-     *            The right input <code>TupleSource</code>.
-     */
-    public NotNode(final int id,
-                   final TupleSource leftInput,
                    final ObjectSource rightInput,
-                   final BetaConstraints joinNodeBinder) {
+                   final BetaConstraints joinNodeBinder,
+                   final BuildContext context) {
         super( id,
                leftInput,
                rightInput,
                joinNodeBinder );
+        this.hasLeftMemory = context.hasLeftMemory();        
     }
 
     /**
@@ -103,7 +89,7 @@
                             final InternalWorkingMemory workingMemory) {
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
         
-        if ( !workingMemory.isSequential() ) {
+        if ( this.hasLeftMemory ) {
             memory.getTupleMemory().add( leftTuple );
         }
 
@@ -145,7 +131,7 @@
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( this );
         memory.getFactHandleMemory().add( handle );
         
-        if ( workingMemory.isSequential() ) {
+        if ( !this.hasLeftMemory ) {
             // do nothing here, as we know there are no left tuples at this stage in sequential mode.
             return;
         }        

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -24,6 +24,7 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.NodeMemory;
 import org.drools.common.PropagationContextImpl;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Declaration;
 import org.drools.spi.Constraint;
 import org.drools.spi.ObjectType;
@@ -80,6 +81,18 @@
     // Constructors
     // ------------------------------------------------------------
 
+    public ObjectTypeNode(final int id,
+                          final ObjectType objectType,
+                          final Rete rete,
+                          final int alphaNodeHashingThreshold ) {
+        super( id,
+               null,
+               alphaNodeHashingThreshold );
+        this.rete = rete;
+        this.objectType = objectType;
+        setHasMemory( true );  
+    }
+    
     /**
      * Construct given a semantic <code>ObjectType</code> and the provided
      * unique id. All <code>ObjectTypdeNode</code> have node memory.
@@ -91,14 +104,13 @@
      */
     public ObjectTypeNode(final int id,
                           final ObjectType objectType,
-                          final Rete rete,
-                          final int alphaNodeHashingThreshold) {
+                          final BuildContext context) {
         super( id,
-               null,
-               alphaNodeHashingThreshold );
-        this.rete = rete;
+               context.getRuleBase().getRete(),
+               context.getRuleBase().getConfiguration().getAlphaNodeHashingThreshold() );
+        this.rete = (Rete) this.objectSource;
         this.objectType = objectType;
-        setHasMemory( true );
+        setHasMemory( context.hasObjectTypeMemory() );
     }
 
     // ------------------------------------------------------------

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -43,6 +43,7 @@
 import org.drools.objenesis.Objenesis;
 import org.drools.objenesis.ObjenesisStd;
 import org.drools.objenesis.instantiator.ObjectInstantiator;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.reteoo.builder.PatternBuilder;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
@@ -353,8 +354,10 @@
             ObjectType objectType = new FactTemplateObjectType(factTemplate);
             this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes().get( objectType );
             if ( this.concreteObjectTypeNode == null ) {
+                BuildContext context = new BuildContext(ruleBase, 
+                                                        ((ReteooRuleBase)ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator());                
                 // there must exist an ObjectTypeNode for this concrete class                
-                this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( ruleBase.getRete(),
+                this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
                                                                                    objectType );
             }           
             this.cache = new ObjectTypeNode[] { this.concreteObjectTypeNode };
@@ -414,8 +417,10 @@
             ObjectType objectType =  new ClassObjectType( clazz );
             this.concreteObjectTypeNode = (ObjectTypeNode) ruleBase.getRete().getObjectTypeNodes().get( objectType );
             if ( this.concreteObjectTypeNode == null ) {
+                BuildContext context = new BuildContext(ruleBase, 
+                                                        ((ReteooRuleBase)ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator());
                 // there must exist an ObjectTypeNode for this concrete class
-                this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( ruleBase.getRete(),
+                this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
                                                                                    objectType );
             }
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooWorkingMemory.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -84,13 +84,21 @@
         return getQueryResults( query, null );
     }
     public QueryResults getQueryResults(final String query, final Object[] arguments) {
-        final FactHandle handle = insert( new DroolsQuery( query, arguments ) );
+
+        Object object = new DroolsQuery( query, arguments );
+        InternalFactHandle handle = this.handleFactory.newFactHandle( object );
+        
+        insert( handle,
+                object,
+                null,
+                null );
+        
         final QueryTerminalNode node = (QueryTerminalNode) this.queryResults.remove( query );
         Query queryObj = null;
         List list = null;
 
         if ( node == null ) {
-            // There are no results, first check the query object actually exists and then retract the DroolsQuery object
+            // There are no results, first check the query object actually exists
             final org.drools.rule.Package[] pkgs = this.ruleBase.getPackages();
             for ( int i = 0; i < pkgs.length; i++ ) {
                 final Rule rule = pkgs[i].getRule( query );
@@ -99,20 +107,26 @@
                     break;
                 }
             }
-            retract( handle );
+
+            this.handleFactory.destroyFactHandle( handle );
+            
             if ( queryObj == null ) {
                 throw new IllegalArgumentException( "Query '" + query + "' does not exist" );
             }
             list = Collections.EMPTY_LIST;
         } else {
             list = (List) this.nodeMemories.remove( node.getId() );
-
-            retract( handle );
+            
             if ( list == null ) {
                 list = Collections.EMPTY_LIST;
             }
             queryObj = (Query) node.getRule();
+            
+            this.handleFactory.destroyFactHandle( handle );
         }
+        
+        
+        
 
         return new QueryResults( list,
                                  queryObj,

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/RuleTerminalNode.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -32,6 +32,7 @@
 import org.drools.common.NodeMemory;
 import org.drools.common.PropagationContextImpl;
 import org.drools.common.ScheduledAgendaItem;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.GroupElement;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
@@ -94,11 +95,13 @@
     public RuleTerminalNode(final int id,
                             final TupleSource source,
                             final Rule rule,
-                            final GroupElement subrule) {
+                            final GroupElement subrule,
+                            final BuildContext buildContext) {
         super( id );
         this.rule = rule;
         this.tupleSource = source;
         this.subrule = subrule;
+        this.hasMemory = buildContext.hasTerminalNodeMemory();
     }
 
     // ------------------------------------------------------------
@@ -191,7 +194,7 @@
             agenda.scheduleItem( item );
             tuple.setActivation( item );
             
-            if ( !workingMemory.isSequential() ) {
+            if ( this.hasMemory ) {
                 memory.getTupleMemory().add( tuple );
             }
 
@@ -232,7 +235,7 @@
                                                     this.rule,
                                                     this.subrule );
             
-            if ( workingMemory.isSequential() ) {
+            if ( this.hasMemory ) {
                 item.setSequenence( this.sequence );
             }
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -101,7 +101,8 @@
                                                                                     sourceBinder,
                                                                                     resultsBinder,
                                                                                     accumulate,
-                                                                                    existSubNetwort ) ) );
+                                                                                    existSubNetwort,
+                                                                                    context ) ) );
         // source pattern was bound, so nulling context
         context.setObjectSource( null );
         context.setCurrentPatternOffset( currentPatternIndex );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -67,20 +67,32 @@
 
     // alpha constraints from the last pattern attached
     private List                      alphaConstraints;
+    
+    private boolean                   hasLeftMemory;
+    
+    private boolean                   hasObjectTypeMemory;    
+    
+    private boolean                   hasTerminalNodeMemory;
 
     public BuildContext(final InternalRuleBase rulebase,
                         final ReteooBuilder.IdGenerator idGenerator) {
         this.rulebase = rulebase;
-        this.workingMemories = (InternalWorkingMemory[]) this.rulebase.getWorkingMemories();
+
         this.idGenerator = idGenerator;
+        
+        this.workingMemories = null;
 
-        this.objectType = new LinkedList();
-        this.buildstack = new LinkedList();
+        this.objectType = null;
+        this.buildstack = null;
 
         this.tupleSource = null;
         this.objectSource = null;
 
         this.currentPatternOffset = 0;
+        
+        this.hasLeftMemory = true;
+        
+        this.hasObjectTypeMemory = true;
     }
 
     /**
@@ -99,6 +111,9 @@
     }
 
     public void syncObjectTypesWithPatternOffset() {
+        if (this.objectType == null ) {
+            this.objectType = new LinkedList();
+        }
         while ( this.objectType.size() > this.currentPatternOffset ) {
             this.objectType.removeLast();
         }
@@ -122,6 +137,9 @@
      * @return the objectType
      */
     public LinkedList getObjectType() {
+        if (this.objectType == null ) {
+            this.objectType = new LinkedList();
+        }        
         return this.objectType;
     }
 
@@ -129,6 +147,9 @@
      * @param objectType the objectType to set
      */
     public void setObjectType(final LinkedList objectType) {
+        if (this.objectType == null ) {
+            this.objectType = new LinkedList();
+        }        
         this.objectType = objectType;
     }
 
@@ -170,6 +191,9 @@
      * @return
      */
     public InternalWorkingMemory[] getWorkingMemories() {
+        if ( this.workingMemories == null ) {
+            this.workingMemories = (InternalWorkingMemory[]) this.rulebase.getWorkingMemories();
+        }
         return this.workingMemories;
     }
 
@@ -193,6 +217,9 @@
      * @param rce
      */
     public void push(final RuleConditionElement rce) {
+        if ( this.buildstack == null ) {
+            this.buildstack = new LinkedList();            
+        }        
         this.buildstack.addLast( rce );
     }
 
@@ -201,6 +228,9 @@
      * @return
      */
     public RuleConditionElement pop() {
+        if ( this.buildstack == null ) {
+            this.buildstack = new LinkedList();            
+        }
         return (RuleConditionElement) this.buildstack.removeLast();
     }
 
@@ -209,6 +239,9 @@
      * @return
      */
     public RuleConditionElement peek() {
+        if ( this.buildstack == null ) {
+            this.buildstack = new LinkedList();            
+        }        
         return (RuleConditionElement) this.buildstack.getLast();
     }
 
@@ -217,6 +250,9 @@
      * @return
      */
     public ListIterator stackIterator() {
+        if ( this.buildstack == null ) {
+            this.buildstack = new LinkedList();            
+        }        
         return this.buildstack.listIterator();
     }
 
@@ -258,4 +294,28 @@
         this.alphaConstraints = alphaConstraints;
     }
 
+    public boolean hasLeftMemory() {
+        return this.hasLeftMemory;
+    }
+
+    public void setHasLeftMemory(boolean hasLeftMemory) {
+        this.hasLeftMemory = hasLeftMemory;
+    }
+
+    public boolean hasObjectTypeMemory() {
+        return hasObjectTypeMemory;
+    }
+
+    public void setHasObjectTypeMemory(boolean hasObjectTypeMemory) {
+        this.hasObjectTypeMemory = hasObjectTypeMemory;
+    }
+
+    public boolean hasTerminalNodeMemory() {
+        return hasTerminalNodeMemory;
+    }
+
+    public void setHasTerminalNodeMemory(boolean hasTerminalNodeMemory) {
+        this.hasTerminalNodeMemory = hasTerminalNodeMemory;
+    }        
+        
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -95,7 +95,8 @@
                                                                                  binder, // source binder
                                                                                  resultBinder,
                                                                                  collect,
-                                                                                 existSubNetwort ) ) );
+                                                                                 existSubNetwort,
+                                                                                 context ) ) );
         // source pattern was bound, so nulling context
         context.setObjectSource( null );
         context.setCurrentPatternOffset( currentPatternIndex );

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/GroupElementBuilder.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -22,6 +22,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.drools.RuleBaseFactory;
 import org.drools.RuntimeDroolsException;
 import org.drools.common.BetaConstraints;
 import org.drools.common.TupleStartEqualsConstraint;
@@ -30,6 +31,7 @@
 import org.drools.reteoo.LeftInputAdapterNode;
 import org.drools.reteoo.NotNode;
 import org.drools.reteoo.ObjectSource;
+import org.drools.reteoo.ReteooRuleBase;
 import org.drools.reteoo.RightInputAdapterNode;
 import org.drools.reteoo.TupleSource;
 import org.drools.rule.GroupElement;
@@ -128,11 +130,13 @@
                     final BetaConstraints betaConstraints = utils.createBetaNodeConstraint( context,
                                                                                             context.getBetaconstraints(),
                                                                                             false );
+                    
                     context.setTupleSource( (TupleSource) utils.attachNode( context,
                                                                             new JoinNode( context.getNextId(),
                                                                                           context.getTupleSource(),
                                                                                           context.getObjectSource(),
-                                                                                          betaConstraints ) ) );
+                                                                                          betaConstraints,
+                                                                                          context ) ) );
                     context.setBetaconstraints( null );
                     context.setObjectSource( null );
                 }
@@ -237,7 +241,8 @@
                                                                     new NotNode( context.getNextId(),
                                                                                  context.getTupleSource(),
                                                                                  context.getObjectSource(),
-                                                                                 betaConstraints ) ) );
+                                                                                 betaConstraints,
+                                                                                 context ) ) );
             context.setBetaconstraints( null );
             context.setObjectSource( null );
 
@@ -313,7 +318,8 @@
                                                                     new ExistsNode( context.getNextId(),
                                                                                     context.getTupleSource(),
                                                                                     context.getObjectSource(),
-                                                                                    betaConstraints ) ) );
+                                                                                    betaConstraints,
+                                                                                    context ) ) );
             context.setBetaconstraints( null );
             context.setObjectSource( null );
 

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -21,6 +21,7 @@
 import java.util.List;
 
 import org.drools.base.ClassObjectType;
+import org.drools.base.DroolsQuery;
 import org.drools.common.InstanceNotEqualsConstraint;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.reteoo.AlphaNode;
@@ -145,17 +146,17 @@
         }
     }
     
-    public static ObjectTypeNode attachObjectTypeNode(Rete rete, ObjectType objectType) {
-        ReteooRuleBase ruleBase = ( ReteooRuleBase ) rete.getRuleBase();
-        ReteooBuilder builder = ruleBase.getReteooBuilder();
-                
-        ObjectTypeNode otn = new ObjectTypeNode( builder.getIdGenerator().getNextId(),
+    public static ObjectTypeNode attachObjectTypeNode(BuildContext context, ObjectType objectType) {                
+        ObjectTypeNode otn = new ObjectTypeNode( context.getNextId(),
                             objectType,
-                            rete,
-                            ruleBase.getConfiguration().getAlphaNodeHashingThreshold() );
+                            context );
                 
-        InternalWorkingMemory[] wms = ruleBase.getWorkingMemories();
-        otn.attach( wms );      
+        InternalWorkingMemory[] wms = context.getWorkingMemories();
+        if ( wms.length > 0 ) {
+            otn.attach( wms );
+        } else {
+            otn.attach();
+        }
         
         return otn;
     }
@@ -165,11 +166,18 @@
                                  final Pattern pattern,
                                  List alphaConstraints) throws InvalidPatternException {
 
+        if ( pattern.getObjectType() instanceof ClassObjectType ) {
+            if ( DroolsQuery.class ==((ClassObjectType)pattern.getObjectType()).getClassType() ) {
+                context.setHasLeftMemory( false );
+                context.setHasObjectTypeMemory( false );
+                context.setHasTerminalNodeMemory( false );
+            }
+        }
+        
         context.setObjectSource( (ObjectSource) utils.attachNode( context,
                                                                   new ObjectTypeNode( context.getNextId(),
                                                                                       pattern.getObjectType(),
-                                                                                      context.getRuleBase().getRete(),
-                                                                                      context.getRuleBase().getConfiguration().getAlphaNodeHashingThreshold() ) ) );
+                                                                                      context) ) );
 
         for ( final Iterator it = alphaConstraints.iterator(); it.hasNext(); ) {
             final AlphaNodeFieldConstraint constraint = (AlphaNodeFieldConstraint) it.next();

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -105,6 +105,11 @@
             // creates a clean build context for each subrule
             final BuildContext context = new BuildContext( rulebase,
                                                            idGenerator );
+            if ( rulebase.getConfiguration().isSequential() ) {
+                context.setHasLeftMemory( false );
+                context.setHasObjectTypeMemory( false );
+                context.setHasTerminalNodeMemory( false );
+            }
             // adds subrule
             final TerminalNode node = this.addSubRule( context,
                                                        subrules[i],
@@ -147,7 +152,8 @@
             terminal = new RuleTerminalNode( context.getNextId(),
                                              context.getTupleSource(),
                                              rule,
-                                             subrule );
+                                             subrule,
+                                             context );
         } else {
             // Check there is no consequence
             if ( rule.getConsequence() != null ) {

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AccumulateNodeTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -22,14 +22,17 @@
 import org.drools.RuleBaseFactory;
 import org.drools.base.ClassObjectType;
 import org.drools.common.DefaultFactHandle;
+import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.AccumulateNode.AccumulateMemory;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Accumulate;
 import org.drools.rule.Declaration;
 import org.drools.rule.Pattern;
 import org.drools.rule.Rule;
+import org.drools.spi.AlphaNodeFieldConstraint;
 import org.drools.spi.MockConstraint;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
@@ -63,8 +66,12 @@
                                                    PropagationContext.ASSERTION,
                                                    null,
                                                    null );
-        this.workingMemory = new ReteooWorkingMemory( 1,
-                                                      (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase,
+                                                      ruleBase.getReteooBuilder().getIdGenerator() );
+        
+        this.workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         this.tupleSource = new MockTupleSource( 4 );
         this.objectSource = new MockObjectSource( 4 );
@@ -79,11 +86,18 @@
                                           new Declaration[0],
                                           new Declaration[0],
                                           this.accumulator );
+        
+        
 
         this.node = new AccumulateNode( 15,
                                         this.tupleSource,
                                         this.objectSource,
-                                        this.accumulate );
+                                        new AlphaNodeFieldConstraint[0],
+                                        EmptyBetaConstraints.getInstance(),
+                                        EmptyBetaConstraints.getInstance(),
+                                        this.accumulate,
+                                        false,
+                                        buildContext );
 
         this.node.addTupleSink( this.sink );
 
@@ -362,8 +376,11 @@
     }
 
     public void testMemory() {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase,
+                                                      ruleBase.getReteooBuilder().getIdGenerator() );
+        
+        this.workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final MockObjectSource objectSource = new MockObjectSource( 1 );
         final MockTupleSource tupleSource = new MockTupleSource( 1 );
@@ -371,9 +388,14 @@
         final AccumulateNode accumulateNode = new AccumulateNode( 2,
                                                                   tupleSource,
                                                                   objectSource,
-                                                                  this.accumulate );
+                                                                  new AlphaNodeFieldConstraint[0],
+                                                                  EmptyBetaConstraints.getInstance(),
+                                                                  EmptyBetaConstraints.getInstance(),
+                                                                  this.accumulate,
+                                                                  false,
+                                                                  buildContext  );
 
-        final BetaMemory memory = ((AccumulateMemory) this.workingMemory.getNodeMemory( this.node )).betaMemory;
+        final BetaMemory memory = ((AccumulateMemory) this.workingMemory.getNodeMemory( accumulateNode )).betaMemory;
 
         assertNotNull( memory );
     }

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AgendaTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -39,6 +39,7 @@
 import org.drools.common.RuleFlowGroupImpl;
 import org.drools.conflict.DepthConflictResolver;
 import org.drools.reteoo.ReteooBuilder.IdGenerator;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Rule;
 import org.drools.spi.Activation;
 import org.drools.spi.ActivationGroup;
@@ -55,9 +56,15 @@
  */
 
 public class AgendaTest extends DroolsTestCase {
+    private InternalRuleBase ruleBase;
+    private BuildContext buildContext;
+    
+    protected void setUp() throws Exception {
+        ruleBase = ( InternalRuleBase ) RuleBaseFactory.newRuleBase();
+        buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+    }
+    
     public void testClearAgenda() {
-        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
@@ -68,12 +75,14 @@
         final RuleTerminalNode node1 = new RuleTerminalNode( 3,
                                                              new MockTupleSource( 2 ),
                                                              rule1,
-                                                             rule1.getLhs() );
+                                                             rule1.getLhs(),
+                                                             buildContext );
         
         final RuleTerminalNode node2 = new RuleTerminalNode( 5,
                                                              new MockTupleSource( 4 ),
                                                              rule2,
-                                                             rule2.getLhs() );        
+                                                             rule2.getLhs(),
+                                                             buildContext );        
 
         final ReteTuple tuple = new ReteTuple( new DefaultFactHandle( 1,
                                                                       "cheese" ) );
@@ -143,16 +152,16 @@
     }
 
     public void testFilters() throws Exception {
-        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
         final Rule rule = new Rule( "test-rule" );
         final RuleTerminalNode node = new RuleTerminalNode( 3,
                                                             new MockTupleSource( 2 ),
                                                             rule,
-                                                            rule.getLhs() );
+                                                            rule.getLhs(),
+                                                            buildContext );
 
         final Map results = new HashMap();
         // add consequence
@@ -235,8 +244,6 @@
     }
 
     public void testFocusStack() throws ConsequenceException {
-        final InternalRuleBase ruleBase = ( InternalRuleBase ) RuleBaseFactory.newRuleBase();
-
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         // create the consequence
@@ -257,7 +264,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                              new MockTupleSource( 2 ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext );
         rule0.setConsequence( consequence );
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -269,7 +277,8 @@
         final RuleTerminalNode node1 = new RuleTerminalNode( 5,
                                                              new MockTupleSource( 4 ),
                                                              rule1,
-                                                             rule1.getLhs() );
+                                                             rule1.getLhs(),
+                                                             buildContext );
         rule1.setConsequence( consequence );
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -281,7 +290,8 @@
         final RuleTerminalNode node2 = new RuleTerminalNode( 7,
                                                              new MockTupleSource( 6 ),
                                                              rule2,
-                                                             rule2.getLhs() );
+                                                             rule2.getLhs(),
+                                                             buildContext );
         rule2.setConsequence( consequence );
         final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -293,7 +303,8 @@
         final RuleTerminalNode node3 = new RuleTerminalNode( 9,
                                                              new MockTupleSource( 8 ),
                                                              rule3,
-                                                             rule3.getLhs() );
+                                                             rule3.getLhs(),
+                                                             buildContext );
         rule3.setConsequence( consequence );
         final PropagationContext context3 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -454,8 +465,6 @@
 
     //
     public void testAutoFocus() throws ConsequenceException {
-        final InternalRuleBase ruleBase = ( InternalRuleBase ) RuleBaseFactory.newRuleBase();
-
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
 
@@ -485,7 +494,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( 2,
                                                             new MockTupleSource( 2 ),
                                                             rule,
-                                                            rule.getLhs() );
+                                                            rule.getLhs(),
+                                                            buildContext );
         rule.setConsequence( consequence );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
@@ -549,7 +559,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( 2,
                                                             new MockTupleSource( 2 ),
                                                             rule,
-                                                            rule.getLhs() );
+                                                            rule.getLhs(),
+                                                            buildContext );
 
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
@@ -615,7 +626,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                              new MockTupleSource( 2 ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext );
         rule0.setConsequence( consequence );
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -627,7 +639,8 @@
         final RuleTerminalNode node1 = new RuleTerminalNode( 5,
                                                              new MockTupleSource( 4 ),
                                                              rule1,
-                                                             rule1.getLhs() );
+                                                             rule1.getLhs(),
+                                                             buildContext );
         rule1.setConsequence( consequence );
         final PropagationContext context1 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -638,7 +651,8 @@
         final RuleTerminalNode node2 = new RuleTerminalNode( 7,
                                                              new MockTupleSource( 6 ),
                                                              rule2,
-                                                             rule2.getLhs() );
+                                                             rule2.getLhs(),
+                                                             buildContext );
         rule2.setConsequence( consequence );
         final PropagationContext context2 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -651,7 +665,8 @@
         final RuleTerminalNode node3 = new RuleTerminalNode( 9,
                                                              new MockTupleSource( 8 ),
                                                              rule3,
-                                                             rule3.getLhs() );
+                                                             rule3.getLhs(),
+                                                             buildContext );
         rule3.setConsequence( consequence );
         final PropagationContext context3 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -800,7 +815,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                              new MockTupleSource( 2 ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext );
 
         final Rule rule1 = new Rule( "test-rule1" );
         rule1.setRuleFlowGroup( "rule-flow-group-1" );
@@ -809,7 +825,8 @@
         final RuleTerminalNode node1 = new RuleTerminalNode( 4,
                                                              new MockTupleSource( 2 ),
                                                              rule1,
-                                                             rule1.getLhs() );
+                                                             rule1.getLhs(),
+                                                             buildContext );
 
         final Rule rule2 = new Rule( "test-rule2" );
         rule2.setRuleFlowGroup( "rule-flow-group-2" );
@@ -819,7 +836,8 @@
         final RuleTerminalNode node2 = new RuleTerminalNode( 5,
                                                              new MockTupleSource( 2 ),
                                                              rule2,
-                                                             rule2.getLhs() );
+                                                             rule2.getLhs(),
+                                                             buildContext );
 
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -946,7 +964,8 @@
         final RuleTerminalNode node1 = new RuleTerminalNode( 4,
                                                              new MockTupleSource( 2 ),
                                                              rule1,
-                                                             rule1.getLhs() );
+                                                             rule1.getLhs(),
+                                                             buildContext );
 
         // create context
         final PropagationContext context0 = new PropagationContextImpl( 0,
@@ -976,7 +995,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                              new MockTupleSource( 2 ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext );
 
         final RuleFlowGroup ruleFlowGroup0 = agenda.getRuleFlowGroup( "rule-flow-group-0" );
 
@@ -1043,7 +1063,8 @@
         final RuleTerminalNode node1 = new RuleTerminalNode( 4,
                                                              new MockTupleSource( 2 ),
                                                              rule1,
-                                                             rule1.getLhs() );
+                                                             rule1.getLhs(),
+                                                             buildContext );
 
         // create context
         final PropagationContext context0 = new PropagationContextImpl( 0,
@@ -1075,7 +1096,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                              new MockTupleSource( 2 ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext );
 
         final RuleFlowGroup ruleFlowGroup0 = agenda.getRuleFlowGroup( "rule-flow-group-0" );
 
@@ -1142,7 +1164,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( 1,
                                                              new MockTupleSource( 2 ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext );
 
         final RuleFlowGroup ruleFlowGroup0 = agenda.getRuleFlowGroup( "rule-flow-group-0" );
 
@@ -1230,7 +1253,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( idGenerator.getNextId(),
                                                              new MockTupleSource( idGenerator.getNextId() ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext );
 
         final RuleFlowGroup ruleFlowGroup0 = agenda.getRuleFlowGroup( "rule-flow-group-0" );
         assertTrue( ruleFlowGroup0.isAutoDeactivate() );
@@ -1377,7 +1401,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( 2,
                                                             new MockTupleSource( 2 ),
                                                             rule,
-                                                            rule.getLhs() );
+                                                            rule.getLhs(),
+                                                            buildContext );
 
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
@@ -1440,7 +1465,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                              new MockTupleSource( 2 ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext );
         node0.setSequence( 72 );
         rule0.setConsequence( consequence );
         final PropagationContext context0 = new PropagationContextImpl( 0,
@@ -1453,7 +1479,8 @@
         final RuleTerminalNode node1 = new RuleTerminalNode( 5,
                                                              new MockTupleSource( 4 ),
                                                              rule1,
-                                                             rule1.getLhs() );
+                                                             rule1.getLhs(),
+                                                             buildContext );
         node1.setSequence( 10 );
         rule1.setConsequence( consequence );
         final PropagationContext context1 = new PropagationContextImpl( 0,
@@ -1466,7 +1493,8 @@
         final RuleTerminalNode node2 = new RuleTerminalNode( 7,
                                                              new MockTupleSource( 6 ),
                                                              rule2,
-                                                             rule2.getLhs() );
+                                                             rule2.getLhs(),
+                                                             buildContext );
         node2.setSequence( 7 );
         rule2.setConsequence( consequence );
         final PropagationContext context2 = new PropagationContextImpl( 0,
@@ -1479,7 +1507,8 @@
         final RuleTerminalNode node3 = new RuleTerminalNode( 9,
                                                              new MockTupleSource( 8 ),
                                                              rule3,
-                                                             rule3.getLhs() );
+                                                             rule3.getLhs(),
+                                                             buildContext );
         node3.setSequence( 0 );
         rule3.setConsequence( consequence );
         final PropagationContext context3 = new PropagationContextImpl( 0,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/BetaNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/BetaNodeTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/BetaNodeTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -16,6 +16,10 @@
 
 package org.drools.reteoo;
 
+import org.drools.RuleBaseFactory;
+import org.drools.common.EmptyBetaConstraints;
+import org.drools.reteoo.builder.BuildContext;
+
 import junit.framework.TestCase;
 
 /**
@@ -45,18 +49,29 @@
         final TupleSource ts = new MockTupleSource( 1 );
         final ObjectSource os = new MockObjectSource( 2 );
 
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );        
+        
         final BetaNode j1 = new JoinNode( 1,
-                                    ts,
-                                    os );
+                                          ts,
+                                          os,
+                                          EmptyBetaConstraints.getInstance(),
+                                          buildContext );
         final BetaNode j2 = new JoinNode( 2,
-                                    ts,
-                                    os );
+                                          ts,
+                                          os,
+                                          EmptyBetaConstraints.getInstance(),
+                                          buildContext );
         final BetaNode n1 = new NotNode( 3,
-                                   ts,
-                                   os );
+                                         ts,
+                                         os,
+                                         EmptyBetaConstraints.getInstance(),
+                                         buildContext );
         final BetaNode n2 = new NotNode( 4,
-                                   ts,
-                                   os );
+                                         ts,
+                                         os,
+                                         EmptyBetaConstraints.getInstance(),
+                                         buildContext );
 
         assertEquals( j1,
                       j1 );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CollectNodeTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -26,10 +26,13 @@
 import org.drools.RuleBaseFactory;
 import org.drools.base.ClassObjectType;
 import org.drools.common.DefaultFactHandle;
+import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.PropagationContextImpl;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Collect;
 import org.drools.rule.Pattern;
 import org.drools.rule.Rule;
+import org.drools.spi.AlphaNodeFieldConstraint;
 import org.drools.spi.MockConstraint;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
@@ -66,9 +69,13 @@
                                                          PropagationContext.RETRACTION,
                                                          null,
                                                          null );
-        this.workingMemory = new ReteooWorkingMemory( 1,
-                                                      (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
 
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase,
+                                                      ruleBase.getReteooBuilder().getIdGenerator() );
+        
+        this.workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+
         this.tupleSource = new MockTupleSource( 4 );
         this.objectSource = new MockObjectSource( 4 );
         this.sink = new MockTupleSink();
@@ -85,7 +92,12 @@
         this.node = new CollectNode( 15,
                                      this.tupleSource,
                                      this.objectSource,
-                                     this.collect );
+                                     new AlphaNodeFieldConstraint[0],
+                                     EmptyBetaConstraints.getInstance(),
+                                     EmptyBetaConstraints.getInstance(),
+                                     this.collect,
+                                     false,
+                                     buildContext );
 
         this.node.addTupleSink( this.sink );
 
@@ -349,8 +361,11 @@
     }
 
     public void testMemory() {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase,
+                                                      ruleBase.getReteooBuilder().getIdGenerator() );
+        
+        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) ruleBase.newStatefulSession();
 
         final MockObjectSource objectSource = new MockObjectSource( 1 );
         final MockTupleSource tupleSource = new MockTupleSource( 1 );
@@ -358,7 +373,12 @@
         final CollectNode collectNode = new CollectNode( 2,
                                                          tupleSource,
                                                          objectSource,
-                                                         this.collect );
+                                                         new AlphaNodeFieldConstraint[0],
+                                                         EmptyBetaConstraints.getInstance(),
+                                                         EmptyBetaConstraints.getInstance(),
+                                                         this.collect,
+                                                         false,
+                                                         buildContext  );
 
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( collectNode );
 
@@ -373,6 +393,7 @@
                                                       (ReteooRuleBase) RuleBaseFactory.newRuleBase( conf ) );
         
         this.memory = (BetaMemory) this.workingMemory.getNodeMemory( this.node );
+        this.node.hasLeftMemory = false;
 
         final DefaultFactHandle f0 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "cheese" );
         final DefaultFactHandle f1 = (DefaultFactHandle) this.workingMemory.getFactHandleFactory().newFactHandle( "other cheese" );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -10,6 +10,7 @@
 import org.drools.base.evaluators.Operator;
 import org.drools.base.evaluators.StringFactory;
 import org.drools.base.field.ObjectFieldImpl;
+import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.InternalWorkingMemory;
 import org.drools.rule.LiteralConstraint;
@@ -380,7 +381,8 @@
                      final ObjectSource rightInput) {
             super( id,
                    leftInput,
-                   rightInput );
+                   rightInput,
+                   EmptyBetaConstraints.getInstance() );
             //  Auto-generated constructor stub
         }
 

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ExistsNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ExistsNodeTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ExistsNodeTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -28,6 +28,7 @@
 import org.drools.common.DefaultBetaConstraints;
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.PropagationContextImpl;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Rule;
 import org.drools.spi.BetaNodeFieldConstraint;
 import org.drools.spi.MockConstraint;
@@ -59,9 +60,13 @@
                                                    PropagationContext.ASSERTION,
                                                    null,
                                                    null );
-        this.workingMemory = new ReteooWorkingMemory( 1,
-                                                      (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
 
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase,
+                                                      ruleBase.getReteooBuilder().getIdGenerator() );
+
+        this.workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+
         final RuleBaseConfiguration configuration = new RuleBaseConfiguration();
 
         // string1Declaration is bound to pattern 3 
@@ -69,7 +74,8 @@
                                     new MockTupleSource( 5 ),
                                     new MockObjectSource( 8 ),
                                     new DefaultBetaConstraints( new BetaNodeFieldConstraint[]{this.constraint},
-                                                                configuration ) );
+                                                                configuration ),
+                                    buildContext );
 
         this.sink = new MockTupleSink();
         this.node.addTupleSink( this.sink );
@@ -122,7 +128,7 @@
 
         // assert tuple, will have matches, so propagate
         final DefaultFactHandle f2 = (DefaultFactHandle) this.workingMemory.insert( new Cheese( "gouda",
-                                                                                                      10 ) );
+                                                                                                10 ) );
         final ReteTuple tuple2 = new ReteTuple( f2 );
         this.node.assertTuple( tuple2,
                                this.context,
@@ -198,7 +204,7 @@
 
         // assert tuple, will have matches, so do assert propagation
         final DefaultFactHandle f2 = (DefaultFactHandle) this.workingMemory.insert( new Cheese( "gouda",
-                                                                                                      10 ) );
+                                                                                                10 ) );
         final ReteTuple tuple2 = new ReteTuple( f2 );
         this.node.assertTuple( tuple2,
                                this.context,

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/JoinNodeTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -21,12 +21,15 @@
 import java.util.List;
 
 import org.drools.DroolsTestCase;
+import org.drools.RuleBase;
 import org.drools.RuleBaseConfiguration;
 import org.drools.RuleBaseFactory;
 import org.drools.common.DefaultBetaConstraints;
 import org.drools.common.DefaultFactHandle;
+import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.InternalFactHandle;
 import org.drools.common.PropagationContextImpl;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Rule;
 import org.drools.spi.BetaNodeFieldConstraint;
 import org.drools.spi.MockConstraint;
@@ -62,12 +65,16 @@
         this.sink = new MockTupleSink();
 
         final RuleBaseConfiguration configuration = new RuleBaseConfiguration();
+        
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
 
         this.node = new JoinNode( 15,
                                   this.tupleSource,
                                   this.objectSource,
                                   new DefaultBetaConstraints( new BetaNodeFieldConstraint[]{this.constraint},
-                                                              configuration ) );
+                                                              configuration ),
+                                  buildContext );
 
         this.node.addTupleSink( this.sink );
 
@@ -121,9 +128,13 @@
         final MockObjectSource objectSource = new MockObjectSource( 1 );
         final MockTupleSource tupleSource = new MockTupleSource( 1 );
 
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );        
         final JoinNode joinNode = new JoinNode( 2,
                                                 tupleSource,
-                                                objectSource );
+                                                objectSource,
+                                                EmptyBetaConstraints.getInstance(),
+                                                buildContext );
 
         final BetaMemory memory = (BetaMemory) workingMemory.getNodeMemory( joinNode );
 
@@ -179,12 +190,18 @@
         this.workingMemory = new ReteooWorkingMemory( 1,
                                                       (ReteooRuleBase) RuleBaseFactory.newRuleBase( conf ) );
 
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
+        buildContext.setHasLeftMemory( false );
+        buildContext.setHasObjectTypeMemory( false );
+        
         // override setup, so its working in sequential mode
         this.node = new JoinNode( 15,
                                   this.tupleSource,
                                   this.objectSource,
                                   new DefaultBetaConstraints( new BetaNodeFieldConstraint[]{this.constraint},
-                                                              conf ) );
+                                                              conf ),
+                                  buildContext);
 
         this.node.addTupleSink( this.sink );
 
@@ -418,9 +435,14 @@
         final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
                                                                            (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
 
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
+        
         final JoinNode joinNode = new JoinNode( 1,
                                                 this.tupleSource,
-                                                this.objectSource );
+                                                this.objectSource,
+                                                EmptyBetaConstraints.getInstance(),
+                                                buildContext );
 
         // Add the first tuple sink and assert a tuple and object
         // The sink has no memory

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -34,15 +34,22 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.ReteooBuilder.IdGenerator;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Rule;
 import org.drools.spi.Consequence;
 import org.drools.spi.KnowledgeHelper;
 import org.drools.spi.PropagationContext;
 
 public class LogicalAssertionTest extends DroolsTestCase {
-
+    private ReteooRuleBase ruleBase;
+    private BuildContext buildContext;
+    
+    protected void setUp() throws Exception {
+        ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+    }
+    
     public void testSingleLogicalRelationship() throws Exception {
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final Rete rete = ruleBase.getRete();
@@ -60,7 +67,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule1,
-                                                            rule1.getLhs() );
+                                                            rule1.getLhs(),
+                                                            buildContext );
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
@@ -147,7 +155,6 @@
         // MockObjectSink so w can detect assertions and retractions
         final Rule rule1 = new Rule( "test-rule1" );
 
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final Rete rete = ruleBase.getRete();
@@ -162,7 +169,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule1,
-                                                            rule1.getLhs() );
+                                                            rule1.getLhs(),
+                                                            buildContext );
 
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
@@ -238,7 +246,6 @@
         // create a RuleBase with a single ObjectTypeNode we attach a
         // MockObjectSink so we can detect assertions and retractions
         final Rule rule1 = new Rule( "test-rule1" );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final Rete rete = ruleBase.getRete();
@@ -252,7 +259,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule1,
-                                                            rule1.getLhs() );
+                                                            rule1.getLhs(),
+                                                            buildContext  );
 
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
@@ -378,6 +386,9 @@
         RuleBaseConfiguration conf = new RuleBaseConfiguration();
         conf.setLogicalOverride( LogicalOverride.PRESERVE );
         ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase(conf);
+        
+        BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
+        
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final Rete rete = ruleBase.getRete();
@@ -391,7 +402,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule1,
-                                                            rule1.getLhs() );
+                                                            rule1.getLhs(),
+                                                            buildContext  );
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
@@ -466,7 +478,6 @@
         // create a RuleBase with a single ObjectTypeNode we attach a
         // MockObjectSink so we can detect assertions and retractions
         final Rule rule1 = new Rule( "test-rule1" );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final Rete rete = ruleBase.getRete();
@@ -480,7 +491,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule1,
-                                                            rule1.getLhs() );
+                                                            rule1.getLhs(),
+                                                            buildContext  );
 
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
@@ -525,7 +537,8 @@
         final RuleTerminalNode node2 = new RuleTerminalNode( idGenerator.getNextId(),
                                                              new MockTupleSource( 3 ),
                                                              rule2,
-                                                             rule2.getLhs() );
+                                                             rule2.getLhs(),
+                                                             buildContext  );
         rule2.setConsequence( consequence );
 
         final DefaultFactHandle handle2 = new DefaultFactHandle( 2,
@@ -563,7 +576,6 @@
 
     public void testMultipleLogicalRelationships() throws FactException {
         final Rule rule1 = new Rule( "test-rule1" );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final Rete rete = ruleBase.getRete();
@@ -580,7 +592,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource(  idGenerator.getNextId() ),
                                                             rule1,
-                                                            rule1.getLhs() );
+                                                            rule1.getLhs(),
+                                                            buildContext  );
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();
@@ -618,7 +631,8 @@
         final RuleTerminalNode node2 = new RuleTerminalNode(  idGenerator.getNextId(),
                                                              new MockTupleSource(  idGenerator.getNextId() ),
                                                              rule2,
-                                                             rule2.getLhs() );
+                                                             rule2.getLhs(),
+                                                             buildContext  );
         rule2.setConsequence( consequence );
 
         final DefaultFactHandle handle2 = new DefaultFactHandle( 2,
@@ -696,7 +710,6 @@
         // create a RuleBase with a single ObjectTypeNode we attach a
         // MockObjectSink so we can detect assertions and retractions
         final Rule rule1 = new Rule( "test-rule1" );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final Rete rete = ruleBase.getRete();
@@ -710,7 +723,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule1,
-                                                            rule1.getLhs() );
+                                                            rule1.getLhs(),
+                                                            buildContext  );
 
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
@@ -798,7 +812,6 @@
         // create a RuleBase with a single ObjectTypeNode we attach a
         // MockObjectSink so we can detect assertions and retractions
         final Rule rule1 = new Rule( "test-rule1" );
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final Rete rete = ruleBase.getRete();
@@ -812,7 +825,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule1,
-                                                            rule1.getLhs() );
+                                                            rule1.getLhs(),
+                                                            buildContext  );
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final Agenda agenda = workingMemory.getAgenda();

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/NotNodeTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -30,6 +30,7 @@
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.EmptyBetaConstraints;
 import org.drools.common.PropagationContextImpl;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Rule;
 import org.drools.spi.BetaNodeFieldConstraint;
 import org.drools.spi.MockConstraint;
@@ -62,12 +63,17 @@
 
         final RuleBaseConfiguration configuration = new RuleBaseConfiguration();
 
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase,
+                                                      ruleBase.getReteooBuilder().getIdGenerator() );
+
         // string1Declaration is bound to pattern 3 
         this.node = new NotNode( 15,
                                  new MockTupleSource( 5 ),
                                  new MockObjectSource( 8 ),
                                  new DefaultBetaConstraints( new BetaNodeFieldConstraint[]{this.constraint},
-                                                             configuration ) );
+                                                             configuration ),
+                                 buildContext );
 
         this.sink = new MockTupleSink();
         this.node.addTupleSink( this.sink );
@@ -131,7 +137,7 @@
 
         // assert tuple, will have matches, so no propagation
         final DefaultFactHandle f2 = (DefaultFactHandle) this.workingMemory.insert( new Cheese( "gouda",
-                                                                                                      10 ) );
+                                                                                                10 ) );
         final ReteTuple tuple2 = new ReteTuple( f2 );
         this.node.assertTuple( tuple2,
                                this.context,
@@ -210,7 +216,7 @@
 
         // assert tuple, will have no matches, so do assert propagation
         final DefaultFactHandle f2 = (DefaultFactHandle) this.workingMemory.insert( new Cheese( "gouda",
-                                                                                                      10 ) );
+                                                                                                10 ) );
         final ReteTuple tuple2 = new ReteTuple( f2 );
         this.node.assertTuple( tuple2,
                                this.context,
@@ -300,15 +306,20 @@
 
     public void testGetConstraints_ReturnsNullEvenWithEmptyBinder() {
         final BetaConstraints nullConstraints = EmptyBetaConstraints.getInstance();
+        
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
+        
         final NotNode notNode = new NotNode( 1,
-                                       this.tupleSource,
-                                       this.objectSource,
-                                       nullConstraints );
+                                             this.tupleSource,
+                                             this.objectSource,
+                                             nullConstraints,
+                                             buildContext );
         final BetaNodeFieldConstraint[] constraints = notNode.getConstraints();
         assertEquals( 0,
                       constraints.length );
     }
-    
+
     /**
      * Test just tuple assertions
      * 
@@ -318,15 +329,25 @@
         RuleBaseConfiguration conf = new RuleBaseConfiguration();
         conf.setSequential( true );
 
+        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( conf );
+        
         this.workingMemory = new ReteooWorkingMemory( 1,
-                                                      (ReteooRuleBase) RuleBaseFactory.newRuleBase( conf ) );
+                                                      ruleBase );
 
+        BuildContext buildContext = new BuildContext( ruleBase,
+                                                      ruleBase.getReteooBuilder().getIdGenerator() );
+        
+        buildContext.setHasLeftMemory( false );
+        buildContext.setHasObjectTypeMemory( false );
+        buildContext.setHasTerminalNodeMemory( false );
+
         // override setup, so its working in sequential mode
         this.node = new NotNode( 15,
-                                  this.tupleSource,
-                                  this.objectSource,
-                                  new DefaultBetaConstraints( new BetaNodeFieldConstraint[]{this.constraint},
-                                                              conf ) );
+                                 this.tupleSource,
+                                 this.objectSource,
+                                 new DefaultBetaConstraints( new BetaNodeFieldConstraint[]{this.constraint},
+                                                             conf ),
+                                 buildContext );
 
         this.node.addTupleSink( this.sink );
 
@@ -355,6 +376,4 @@
 
     }
 
-    
-
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -35,6 +35,8 @@
 import org.drools.base.FieldFactory;
 import org.drools.base.ValueType;
 import org.drools.base.evaluators.Operator;
+import org.drools.common.EmptyBetaConstraints;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.LiteralConstraint;
 import org.drools.rule.Query;
 import org.drools.spi.Evaluator;
@@ -99,9 +101,13 @@
                                    3  );
         alphaNode.attach();
 
+        BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
+        
         final JoinNode joinNode = new JoinNode( 6,
                                                 liaNode,
-                                                alphaNode );
+                                                alphaNode,
+                                                EmptyBetaConstraints.getInstance(),
+                                                buildContext );
         joinNode.attach();
 
         final Query query = new Query( "query-1" );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/RuleFlowGroupTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -28,6 +28,7 @@
 import org.drools.common.InternalAgenda;
 import org.drools.common.PropagationContextImpl;
 import org.drools.common.RuleFlowGroupImpl;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Rule;
 import org.drools.ruleflow.common.instance.ProcessInstance;
 import org.drools.ruleflow.core.Connection;
@@ -56,10 +57,15 @@
  */
 
 public class RuleFlowGroupTest extends DroolsTestCase {
-
+    private ReteooRuleBase ruleBase;
+    private BuildContext buildContext;
+    
+    protected void setUp() throws Exception {
+        ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+    }
+    
     public void testRuleFlowGroup() {
-        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
@@ -87,7 +93,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                              new MockTupleSource( 2 ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext);
 
         final Rule rule1 = new Rule( "test-rule1" );
         rule1.setRuleFlowGroup( "rule-flow-group-1" );
@@ -96,7 +103,8 @@
         final RuleTerminalNode node1 = new RuleTerminalNode( 4,
                                                              new MockTupleSource( 2 ),
                                                              rule1,
-                                                             rule1.getLhs() );
+                                                             rule1.getLhs(),
+                                                             buildContext );
 
         final Rule rule2 = new Rule( "test-rule2" );
         rule2.setRuleFlowGroup( "rule-flow-group-2" );
@@ -106,7 +114,8 @@
         final RuleTerminalNode node2 = new RuleTerminalNode( 5,
                                                              new MockTupleSource( 2 ),
                                                              rule2,
-                                                             rule2.getLhs() );
+                                                             rule2.getLhs(),
+                                                             buildContext );
 
         final Rule rule3 = new Rule( "test-rule3" );
         rule3.setRuleFlowGroup( "rule-flow-group-3" );
@@ -115,7 +124,8 @@
         final RuleTerminalNode node3 = new RuleTerminalNode( 6,
                                                              new MockTupleSource( 2 ),
                                                              rule3,
-                                                             rule3.getLhs() );
+                                                             rule3.getLhs(),
+                                                             buildContext );
 
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -300,8 +310,6 @@
     
     /** XOR split and join */
     public void testRuleFlowGroup2() {
-        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
         final InternalAgenda agenda = (InternalAgenda) workingMemory.getAgenda();
@@ -329,7 +337,8 @@
         final RuleTerminalNode node0 = new RuleTerminalNode( 3,
                                                              new MockTupleSource( 2 ),
                                                              rule0,
-                                                             rule0.getLhs() );
+                                                             rule0.getLhs(),
+                                                             buildContext );
 
         final Rule rule1 = new Rule( "test-rule1" );
         rule1.setRuleFlowGroup( "rule-flow-group-1" );
@@ -338,7 +347,8 @@
         final RuleTerminalNode node1 = new RuleTerminalNode( 4,
                                                              new MockTupleSource( 2 ),
                                                              rule1,
-                                                             rule1.getLhs() );
+                                                             rule1.getLhs(),
+                                                             buildContext );
 
         final Rule rule2 = new Rule( "test-rule2" );
         rule2.setRuleFlowGroup( "rule-flow-group-2" );
@@ -348,7 +358,8 @@
         final RuleTerminalNode node2 = new RuleTerminalNode( 5,
                                                              new MockTupleSource( 2 ),
                                                              rule2,
-                                                             rule2.getLhs() );
+                                                             rule2.getLhs(),
+                                                             buildContext );
 
         final Rule rule3 = new Rule( "test-rule3" );
         rule3.setRuleFlowGroup( "rule-flow-group-3" );
@@ -357,7 +368,8 @@
         final RuleTerminalNode node3 = new RuleTerminalNode( 6,
                                                              new MockTupleSource( 2 ),
                                                              rule3,
-                                                             rule3.getLhs() );
+                                                             rule3.getLhs(),
+                                                             buildContext );
 
         final PropagationContext context0 = new PropagationContextImpl( 0,
                                                                         PropagationContext.ASSERTION,
@@ -431,7 +443,8 @@
         final RuleTerminalNode splitNode1 = new RuleTerminalNode( 7,
                                                              	  new MockTupleSource( 2 ),
                                                              	  splitRule1,
-                                                             	  splitRule1.getLhs() );
+                                                             	  splitRule1.getLhs(),
+                                                                  buildContext );
 
         final Rule splitRule2 = new Rule( "RuleFlow-1-" + split.getId() + "-" + ruleSet2.getId());
         splitRule2.setRuleFlowGroup( "DROOLS_SYSTEM" );
@@ -440,7 +453,8 @@
         final RuleTerminalNode splitNode2 = new RuleTerminalNode( 8,
                                                              	  new MockTupleSource( 2 ),
                                                              	  splitRule2,
-                                                             	  splitRule2.getLhs() );
+                                                             	  splitRule2.getLhs(),
+                                                                  buildContext );
 
         // proces instance
         final RuleFlowProcessInstance processInstance = new RuleFlowProcessInstanceImpl();

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java	2007-09-05 19:22:40 UTC (rev 14901)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/SchedulerTest.java	2007-09-05 20:03:00 UTC (rev 14902)
@@ -28,6 +28,7 @@
 import org.drools.common.InternalWorkingMemory;
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.ReteooBuilder.IdGenerator;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.Rule;
 import org.drools.spi.Duration;
 import org.drools.spi.KnowledgeHelper;
@@ -39,8 +40,16 @@
  */
 
 public class SchedulerTest extends DroolsTestCase {
+    private ReteooRuleBase ruleBase;
+    private BuildContext buildContext;
+    
+    protected void setUp() throws Exception {
+        ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+    }
+    
+    
     public void testScheduledActivation() throws Exception {
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
         InternalWorkingMemory workingMemory = ( InternalWorkingMemory ) ruleBase.newStatefulSession();
 
@@ -48,7 +57,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule,
-                                                            rule.getLhs() );
+                                                            rule.getLhs(),
+                                                            buildContext );
         final List data = new ArrayList();
 
         // add consequence
@@ -102,7 +112,6 @@
     }
 
     public void testDoLoopScheduledActivation() throws Exception {
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
@@ -112,7 +121,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule,
-                                                            rule.getLhs() );
+                                                            rule.getLhs(),
+                                                            buildContext );
         final List data = new ArrayList();
 
         /* 1/10th of a second */
@@ -192,7 +202,8 @@
         final RuleTerminalNode node = new RuleTerminalNode( idGenerator.getNextId(),
                                                             new MockTupleSource( idGenerator.getNextId() ),
                                                             rule,
-                                                            rule.getLhs() );
+                                                            rule.getLhs(),
+                                                            buildContext );
 
         /* 1/10th of a second */
         final Duration duration = new Duration() {




More information about the jboss-svn-commits mailing list