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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Sat Sep 8 13:31:02 EDT 2007


Author: mark.proctor at jboss.com
Date: 2007-09-08 13:31:01 -0400 (Sat, 08 Sep 2007)
New Revision: 14946

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/AlphaNode.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/LeftInputAdapterNode.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/ObjectSink.java
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.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/builder/BuildContext.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/AddRemoveTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.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/LogicalAssertionTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSink.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.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/ReteTest.java
Log:
JBRULES-1153 Accumulate/Collect can't be used in queries
-Updated the memory control some more. It now works and seems robust. But I'm still not happy, as it isn't orthogonal yet.

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AccumulateNode.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -452,13 +452,5 @@
         // keeping attributes public just for performance
         public InternalFactHandle handle;
         public Object             context;
-    }
-
-    public void setIsMemoryAllowed(boolean memoryAllowed) {
-        // TODO Auto-generated method stub
-        
-    }
-    
-    
-
+    }      
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/AlphaNode.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -22,6 +22,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.spi.AlphaNodeFieldConstraint;
 import org.drools.spi.PropagationContext;
 import org.drools.util.FactEntry;
@@ -55,6 +56,8 @@
 
     private ObjectSinkNode                 previousObjectSinkNode;
     private ObjectSinkNode                 nextObjectSinkNode;
+    
+    private boolean                        memoryAllowed;
 
     /**
      * Construct an <code>AlphaNode</code> with a unique id using the provided
@@ -71,13 +74,13 @@
     public AlphaNode(final int id,
                      final AlphaNodeFieldConstraint constraint,
                      final ObjectSource objectSource,
-                     final boolean hasMemory,
-                     final int alphaNodeHashingThreshold) {
+                     final BuildContext context) {
         super( id,
                objectSource,
-               alphaNodeHashingThreshold );
+               context.getRuleBase().getConfiguration().getAlphaNodeHashingThreshold() );
         this.constraint = constraint;
-        setHasMemory( hasMemory );
+        setHasMemory( context.getRuleBase().getConfiguration().isAlphaMemory() );
+        this.memoryAllowed = context.isAlphaMemoryAllowed();
     }
 
     /**
@@ -102,8 +105,10 @@
         attach();
 
         // we are attaching this node with existing working memories
-        // so this  node must also have memory
-        setHasMemory( true );
+        // indicating that we are in a dynamic environment, that might benefit from alpha node memory, if allowed
+        if ( this.memoryAllowed ) {
+            setHasMemory( true );
+        }
         for ( int i = 0, length = workingMemories.length; i < length; i++ ) {
             final InternalWorkingMemory workingMemory = workingMemories[i];
             final PropagationContext propagationContext = new PropagationContextImpl( workingMemory.getNextPropagationIdCounter(),
@@ -189,6 +194,10 @@
         this.objectSource.remove( this,
                                   workingMemories );
     }
+    
+    public void setMemoryAllowed(boolean memoryAllowed) {
+        this.memoryAllowed = memoryAllowed;
+    }
 
     /**
      * Creates a HashSet for the AlphaNode's memory.
@@ -196,6 +205,13 @@
     public Object createMemory(final RuleBaseConfiguration config) {
         return new FactHashTable();
     }
+    
+    /** 
+     * @inheritDoc
+     */
+    protected void addObjectSink(final ObjectSink objectSink) {
+        super.addObjectSink( objectSink );
+    }    
 
     public String toString() {
         return "[AlphaNode(" + this.id + ") constraint=" + this.constraint + "]";

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/CollectNode.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -374,9 +374,4 @@
         public InternalFactHandle handle;
         public boolean            propagated;
     }
-
-    public void setIsMemoryAllowed(boolean memoryAllowed) {
-        // TODO Auto-generated method stub
-        
-    }
 }

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ExistsNode.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -249,9 +249,4 @@
         return "[ExistsNode - " + ((ObjectTypeNode) source).getObjectType() + "]";
     }
 
-    public void setIsMemoryAllowed(boolean memoryAllowed) {
-        // TODO Auto-generated method stub
-        
-    }
-
 }

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/JoinNode.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -255,9 +255,4 @@
 
         return "[JoinNode - " + ((ObjectTypeNode) source).getObjectType() + "]";
     }
-
-    public void setIsMemoryAllowed(boolean memoryAllowed) {
-        // TODO Auto-generated method stub
-        
-    }
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/LeftInputAdapterNode.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -52,24 +52,6 @@
     private ObjectSinkNode     previousObjectSinkNode;
     private ObjectSinkNode     nextObjectSinkNode;
 
-    //    private final AlphaNodeFieldConstraint    constraints;
-
-    //    /**
-    //     * Constructus a LeftInputAdapterNode with a unique id that receives <code>FactHandle</code> from a 
-    //     * parent <code>ObjectSource</code> and adds it to a given pattern in the resulting Tuples.
-    //     * 
-    //     * @param id
-    //     *      The unique id of this node in the current Rete network
-    //     * @param source
-    //     *      The parent node, where Facts are propagated from
-    //     */
-    //    public LeftInputAdapterNode(final int id,
-    //                                final ObjectSource source) {
-    //        this( id,
-    //              source,
-    //              null );
-    //    }
-
     /**
      * Constructus a LeftInputAdapterNode with a unique id that receives <code>FactHandle</code> from a 
      * parent <code>ObjectSource</code> and adds it to a given pattern in the resulting Tuples.
@@ -203,7 +185,7 @@
         }
         this.objectSource.remove( this,
                                   workingMemories );
-    }
+    }    
 
     /**
      * Returns the next node
@@ -301,16 +283,6 @@
                                   final InternalWorkingMemory workingMemory) {
             throw new UnsupportedOperationException( "ObjectSinkAdapter onlys supports assertObject method calls" );
         }
-
-        public void setIsMemoryAllowed(boolean memoryAllowed) {
-            // TODO Auto-generated method stub
-            
-        }
     }
 
-    public void setIsMemoryAllowed(boolean memoryAllowed) {
-        // TODO Auto-generated method stub
-        
-    }
-
 }

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/NotNode.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -243,9 +243,4 @@
 
         return "[NotNode - " + ((ObjectTypeNode) source).getObjectType() + "]";
     }
-
-    public void setIsMemoryAllowed(boolean memoryAllowed) {
-        // TODO Auto-generated method stub
-        
-    }
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSink.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSink.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -60,7 +60,5 @@
      */
     void retractObject(InternalFactHandle handle,
                        PropagationContext context,
-                       InternalWorkingMemory workingMemory);
-    
-    public void setIsMemoryAllowed(boolean memoryAllowed);
+                       InternalWorkingMemory workingMemory);   
 }

Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectSource.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -49,8 +49,6 @@
     protected ObjectSource         objectSource;
 
     private int                    alphaNodeHashingThreshold;
-    
-    private boolean                memoryAllowed;
 
     // ------------------------------------------------------------
     // Constructors
@@ -136,9 +134,5 @@
     public ObjectSinkPropagator getSinkPropagator() {
         return this.sink;
     }
-    
-    public void setIsMemoryAllowed(boolean memoryAllowed) {
-        this.memoryAllowed = memoryAllowed;
-    }
 
 }

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ObjectTypeNode.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -82,18 +82,6 @@
     // ------------------------------------------------------------
     // 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
@@ -303,9 +291,6 @@
     protected void addObjectSink(final ObjectSink objectSink) {
         super.addObjectSink( objectSink );
         this.skipOnModify = canSkipOnModify( this.sink.getSinks() );
-        if ( objectType instanceof ClassObjectType && ((ClassObjectType)this.objectType).getClassType() == DroolsQuery.class ) {
-            objectSink.setIsMemoryAllowed( false );
-        }        
     }
     
     

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/Rete.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -28,6 +28,7 @@
 import org.drools.RuleBaseConfiguration;
 import org.drools.RuntimeDroolsException;
 import org.drools.base.ClassObjectType;
+import org.drools.base.DroolsQuery;
 import org.drools.base.ShadowProxy;
 import org.drools.base.ShadowProxyFactory;
 import org.drools.common.BaseNode;
@@ -135,7 +136,7 @@
             ojectTypeConf = (ObjectTypeConf) memory.get( key );
             if ( ojectTypeConf == null ) {
                 ojectTypeConf = new FactTemplateTypeConf( ((Fact) object).getFactTemplate(),
-                                                                 this.ruleBase );
+                                                          this.ruleBase );
                 memory.put( key,
                             ojectTypeConf,
                             false );
@@ -203,7 +204,7 @@
             objectTypeConf = (ObjectTypeConf) memory.get( object.getClass() );
         }
 
-        ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes( );
+        ObjectTypeNode[] cachedNodes = objectTypeConf.getObjectTypeNodes();
 
         if ( cachedNodes == null ) {
             // it is  possible that there are no ObjectTypeNodes for an  object being retracted
@@ -233,7 +234,7 @@
     }
 
     protected void removeObjectSink(final ObjectSink objectSink) {
-        final ObjectTypeNode node = (ObjectTypeNode) objectSink;        
+        final ObjectTypeNode node = (ObjectTypeNode) objectSink;
         this.objectTypeNodes.remove( node.getObjectType() );
     }
 
@@ -291,12 +292,12 @@
         final ObjectHashMap memory = (ObjectHashMap) workingMemory.getNodeMemory( this );
         Iterator it = memory.iterator();
         final ObjectTypeNode node = (ObjectTypeNode) sink;
-        
+
         ObjectType newObjectType = node.getObjectType();
 
         for ( ObjectEntry entry = (ObjectEntry) it.next(); entry != null; entry = (ObjectEntry) it.next() ) {
             ObjectTypeConf objectTypeConf = (ObjectTypeConf) entry.getValue();
-            if ( newObjectType.isAssignableFrom( objectTypeConf.getConcreteObjectTypeNode().getObjectType() ) ) {                
+            if ( newObjectType.isAssignableFrom( objectTypeConf.getConcreteObjectTypeNode().getObjectType() ) ) {
                 objectTypeConf.resetCache();
                 ObjectTypeNode sourceNode = objectTypeConf.getConcreteObjectTypeNode();
                 FactHashTable table = (FactHashTable) workingMemory.getNodeMemory( sourceNode );
@@ -342,25 +343,35 @@
         implements
         ObjectTypeConf,
         Serializable {
-        private InternalRuleBase               ruleBase;
-        private FactTemplate                   factTemplate;
-        private ObjectTypeNode                 concreteObjectTypeNode;
-        private ObjectTypeNode[]               cache;
-        
-        public FactTemplateTypeConf(FactTemplate  factTemplate,
+        private InternalRuleBase ruleBase;
+        private FactTemplate     factTemplate;
+        private ObjectTypeNode   concreteObjectTypeNode;
+        private ObjectTypeNode[] cache;
+
+        public FactTemplateTypeConf(FactTemplate factTemplate,
                                     InternalRuleBase ruleBase) {
             this.ruleBase = ruleBase;
             this.factTemplate = factTemplate;
-            ObjectType objectType = new FactTemplateObjectType(factTemplate);
+            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());                
+                BuildContext context = new BuildContext( ruleBase,
+                                                         ((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() );
+                if ( context.getRuleBase().getConfiguration().isSequential() ) {
+                    // We are in sequential mode, so no nodes should have memory
+                    context.setHasLeftMemory( false );
+                    context.setHasObjectTypeMemory( false );
+                    context.setHasTerminalNodeMemory( false );
+                } else {
+                    context.setHasLeftMemory( true );
+                    context.setHasObjectTypeMemory( true );
+                    context.setHasTerminalNodeMemory( true );
+                }
                 // there must exist an ObjectTypeNode for this concrete class                
                 this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
                                                                                    objectType );
-            }           
-            this.cache = new ObjectTypeNode[] { this.concreteObjectTypeNode };
+            }
+            this.cache = new ObjectTypeNode[]{this.concreteObjectTypeNode};
         }
 
         public ObjectTypeNode getConcreteObjectTypeNode() {
@@ -369,7 +380,7 @@
 
         public ObjectTypeNode[] getObjectTypeNodes() {
             if ( this.cache == null ) {
-                this.cache = new ObjectTypeNode[] { this.concreteObjectTypeNode };
+                this.cache = new ObjectTypeNode[]{this.concreteObjectTypeNode};
             }
             return this.cache;
         }
@@ -380,7 +391,7 @@
 
         public boolean isShadowEnabled() {
             return false;
-        }        
+        }
 
         public boolean isAssignableFrom(Object object) {
             return this.factTemplate.equals( object );
@@ -414,11 +425,25 @@
             this.cls = clazz;
             this.ruleBase = ruleBase;
 
-            ObjectType objectType =  new ClassObjectType( clazz );
+            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());
+                BuildContext context = new BuildContext( ruleBase,
+                                                         ((ReteooRuleBase) ruleBase.getRete().getRuleBase()).getReteooBuilder().getIdGenerator() );
+                if ( DroolsQuery.class == clazz ) {
+                    context.setHasLeftMemory( false );
+                    context.setHasObjectTypeMemory( false );
+                    context.setHasTerminalNodeMemory( false );
+                } else if ( context.getRuleBase().getConfiguration().isSequential() ) {
+                    // We are in sequential mode, so no nodes should have memory
+                    context.setHasLeftMemory( false );
+                    context.setHasObjectTypeMemory( false );
+                    context.setHasTerminalNodeMemory( false );
+                } else {
+                    context.setHasLeftMemory( true );
+                    context.setHasObjectTypeMemory( true );
+                    context.setHasTerminalNodeMemory( true );
+                }
                 // there must exist an ObjectTypeNode for this concrete class
                 this.concreteObjectTypeNode = PatternBuilder.attachObjectTypeNode( context,
                                                                                    objectType );
@@ -429,7 +454,7 @@
 
         public boolean isAssignableFrom(Object object) {
             return this.cls.isAssignableFrom( (Class) object );
-        }       
+        }
 
         public ObjectTypeNode getConcreteObjectTypeNode() {
             return this.concreteObjectTypeNode;
@@ -483,7 +508,7 @@
          * work it out from the class name (this is in cases where funky classloading is used).
          */
         public static String getPackageName(Class clazz,
-                                             Package pkg) {
+                                            Package pkg) {
             String pkgName = "";
             if ( pkg == null ) {
                 int index = clazz.getName().lastIndexOf( '.' );

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/BuildContext.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -73,6 +73,9 @@
     private boolean                   hasObjectTypeMemory;    
     
     private boolean                   hasTerminalNodeMemory;
+    
+    /** This one is slightly different as alphaMemory can be adaptive, only turning on for new rule attachments */
+    private boolean                   alphaMemoryAllowed;
 
     public BuildContext(final InternalRuleBase rulebase,
                         final ReteooBuilder.IdGenerator idGenerator) {
@@ -316,6 +319,14 @@
 
     public void setHasTerminalNodeMemory(boolean hasTerminalNodeMemory) {
         this.hasTerminalNodeMemory = hasTerminalNodeMemory;
-    }        
+    }     
+    
+    public void setAlphaMemoryAllowed(boolean alphaMemoryAllowed) {
+        this.alphaMemoryAllowed = alphaMemoryAllowed;
+    }
+    
+    public boolean isAlphaMemoryAllowed() {
+        return this.alphaMemoryAllowed;
+    }
         
 }

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/PatternBuilder.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -169,11 +169,19 @@
                                  final Pattern pattern,
                                  List alphaConstraints) throws InvalidPatternException {
 
+        // Drools Query ObjectTypeNode never has memory, but other ObjectTypeNode/AlphaNoesNodes may (if not in sequential), 
+        //so need to preserve, so we can resotre after this node is added. LeftMemory  and Terminal remain the same once set.
+        
+        boolean objectMemory = context.hasObjectTypeMemory(); 
+        boolean alphaMemory = context.isAlphaMemoryAllowed();
+                
         if ( pattern.getObjectType() instanceof ClassObjectType ) {
+            // Is this the query node, if so we don't want any memory
             if ( DroolsQuery.class == ((ClassObjectType) pattern.getObjectType()).getClassType() ) {
                 context.setHasLeftMemory( false );
                 context.setHasObjectTypeMemory( false );
                 context.setHasTerminalNodeMemory( false );
+                context.setAlphaMemoryAllowed( false );
             }
         }
 
@@ -189,9 +197,12 @@
                                                                       new AlphaNode( context.getNextId(),
                                                                                      (AlphaNodeFieldConstraint) constraint,
                                                                                      context.getObjectSource(),
-                                                                                     context.getRuleBase().getConfiguration().isAlphaMemory(),
-                                                                                     context.getRuleBase().getConfiguration().getAlphaNodeHashingThreshold() ) ) );
+                                                                                     context ) ) );
         }
+        
+        // now restore back to original values
+        context.setHasObjectTypeMemory( objectMemory );
+        context.setAlphaMemoryAllowed( alphaMemory );
 
     }
 

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -105,11 +105,19 @@
             // 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 );
+                context.setAlphaMemoryAllowed( false );
+            } else {
+                context.setHasLeftMemory( true );
+                context.setHasObjectTypeMemory( true );
+                context.setHasTerminalNodeMemory( true );
+                context.setAlphaMemoryAllowed( true );                
             }
+            
             // adds subrule
             final TerminalNode node = this.addSubRule( context,
                                                        subrules[i],

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AddRemoveTest.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -21,6 +21,7 @@
 import org.drools.RuleBaseFactory;
 import org.drools.base.ClassObjectType;
 import org.drools.common.InternalRuleBase;
+import org.drools.reteoo.builder.BuildContext;
 
 public class AddRemoveTest extends DroolsTestCase {
     public void testAdd() {
@@ -28,12 +29,12 @@
          * create a RuleBase with a single ObjectTypeNode we attach a
          * MockObjectSink so we can detect assertions and retractions
          */
-        final RuleBase ruleBase = RuleBaseFactory.newRuleBase();
-        final Rete rete = new Rete( (InternalRuleBase) ruleBase);
+        final ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();        
+        BuildContext context = new BuildContext(ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );
+                        
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 0,
                                                                   new ClassObjectType( Object.class ),
-                                                                  rete,
-                                                                  1 );
+                                                                  context );
         objectTypeNode.attach();
 
         final MockObjectSink sink = new MockObjectSink();

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/AlphaNodeTest.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -30,6 +30,7 @@
 import org.drools.base.evaluators.Operator;
 import org.drools.common.DefaultFactHandle;
 import org.drools.common.PropagationContextImpl;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.rule.LiteralConstraint;
 import org.drools.rule.Rule;
 import org.drools.spi.Evaluator;
@@ -39,16 +40,18 @@
 import org.drools.util.FactHashTable;
 
 public class AlphaNodeTest extends DroolsTestCase {
-
+    
     public void testMemory() {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
-
-        final AlphaNode alphaNode = new AlphaNode( 2,
+        RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setAlphaMemory( false );
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+        BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        
+        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
                                                    null,
                                                    null,
-                                                   true,
-                                                   3);
+                                                   buildContext);
 
         final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( alphaNode );
 
@@ -56,15 +59,19 @@
     }
 
     public void testLiteralConstraintAssertObjectWithMemory() throws Exception {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setAlphaMemory( true );
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+        BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );        
+        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
 
-        final MockObjectSource source = new MockObjectSource( 15 );
+        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
 
         final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
                                                                                      "type",
@@ -78,11 +85,10 @@
                                                                     field );
 
         // With Memory
-        final AlphaNode alphaNode = new AlphaNode( 2,
+        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
                                                    constraint,
                                                    source,
-                                                   true,
-                                                   3 ); // has memory
+                                                   buildContext ); // has memory
 
         final MockObjectSink sink = new MockObjectSink();
         alphaNode.addObjectSink( sink );
@@ -138,15 +144,19 @@
     }
 
     public void testLiteralConstraintAssertObjectWithoutMemory() throws Exception {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setAlphaMemory( false );
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+        BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );        
+        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
 
-        final MockObjectSource source = new MockObjectSource( 15 );
+        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
 
         final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
                                                                                       "type",
@@ -160,11 +170,10 @@
                                                                     field );
 
         // With Memory
-        final AlphaNode alphaNode = new AlphaNode( 2,
+        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
                                                    constraint,
                                                    source,
-                                                   false,
-                                                   3 ); // no memory
+                                                   buildContext ); // no memory
 
         final MockObjectSink sink = new MockObjectSink();
         alphaNode.addObjectSink( sink );
@@ -220,17 +229,19 @@
     }
     
     public void testLiteralConstraintAssertSequentialMode() throws Exception {
-        RuleBaseConfiguration conf = new RuleBaseConfiguration();
-        conf.setSequential( true );
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase( conf ) );
+        RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setSequential( true );
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+        BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );        
+        ReteooWorkingMemory workingMemory = new ReteooWorkingMemory(buildContext.getNextId(), ruleBase);       
+        
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
 
-        final MockObjectSource source = new MockObjectSource( 15 );
+        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
 
         final ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
                                                                                      "type",
@@ -244,11 +255,10 @@
                                                                     field );
 
         // With Memory
-        final AlphaNode alphaNode = new AlphaNode( 2,
+        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
                                                    constraint,
                                                    source,
-                                                   true,
-                                                   3 ); // has memory
+                                                   buildContext ); // has memory
 
         final MockObjectSink sink = new MockObjectSink();
         alphaNode.addObjectSink( sink );
@@ -307,15 +317,19 @@
      * Constraint type.
      */
     public void testReturnValueConstraintAssertObject() throws Exception {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setAlphaMemory( false );
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+        BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );        
+        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
 
-        final MockObjectSource source = new MockObjectSource( 15 );
+        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
 
         final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
                                                                                 "type",
@@ -328,11 +342,10 @@
                                                                     evaluator,
                                                                     field );
 
-        final AlphaNode alphaNode = new AlphaNode( 2,
+        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
                                                    constraint,
                                                    source,
-                                                   true,
-                                                   3 );
+                                                   buildContext );
         final MockObjectSink sink = new MockObjectSink();
         alphaNode.addObjectSink( sink );
 
@@ -371,15 +384,19 @@
     }
 
     public void testRetractObjectWithMemory() throws Exception {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setAlphaMemory( true );
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+        BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );        
+        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
 
-        final MockObjectSource source = new MockObjectSource( 15 );
+        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
 
         final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
                                                                                 "type",
@@ -392,11 +409,10 @@
                                                                     evaluator,
                                                                     field );
 
-        final AlphaNode alphaNode = new AlphaNode( 2,
+        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
                                                    constraint,
                                                    source,
-                                                   true,
-                                                   3 ); // has memory
+                                                   buildContext ); // has memory
         final MockObjectSink sink = new MockObjectSink();
         alphaNode.addObjectSink( sink );
 
@@ -450,15 +466,19 @@
     }
 
     public void testRetractObjectWithoutMemory() throws Exception {
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setAlphaMemory( false );
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+        BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );        
+        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
 
-        final MockObjectSource source = new MockObjectSource( 15 );
+        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
 
         final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
                                                                                  "type",
@@ -471,11 +491,10 @@
                                                                     evaluator,
                                                                     field );
 
-        final AlphaNode alphaNode = new AlphaNode( 2,
+        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
                                                    constraint,
                                                    source,
-                                                   false,
-                                                   3 ); // no memory
+                                                   buildContext ); // no memory
         final MockObjectSink sink = new MockObjectSink();
         alphaNode.addObjectSink( sink );
 
@@ -533,16 +552,19 @@
                                           IntrospectionException {
         // An AlphaNode with memory should not try and repropagate from its source
         // Also it should only update the latest tuple sinky
-
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setAlphaMemory( true );
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+        BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );        
+        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
 
-        final MockObjectSource source = new MockObjectSource( 1 );
+        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
 
         final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
                                                                                 "type",
@@ -555,11 +577,10 @@
                                                                     evaluator,
                                                                     field );
 
-        final AlphaNode alphaNode = new AlphaNode( 2,
+        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
                                                    constraint,
                                                    source,
-                                                   true,
-                                                   3 ); // has memory
+                                                   buildContext ); // has memory
 
         alphaNode.attach();
 
@@ -602,15 +623,19 @@
     public void testUpdateSinkWithoutMemory() throws FactException,
                                              IntrospectionException {
         // An AlphaNode without memory should try and repropagate from its source
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           (ReteooRuleBase) RuleBaseFactory.newRuleBase() );
+        RuleBaseConfiguration config = new RuleBaseConfiguration();
+        config.setAlphaMemory( false );
+        ReteooRuleBase ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase( config );
+        BuildContext buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );        
+        ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        
         final Rule rule = new Rule( "test-rule" );
         final PropagationContext context = new PropagationContextImpl( 0,
                                                                        PropagationContext.ASSERTION,
                                                                        null,
                                                                        null );
 
-        final MockObjectSource source = new MockObjectSource( 1 );
+        final MockObjectSource source = new MockObjectSource( buildContext.getNextId() );
 
         final FieldExtractor extractor = ClassFieldExtractorCache.getExtractor(Cheese.class,
                                                                                "type",
@@ -623,11 +648,10 @@
                                                                     evaluator,
                                                                     field );
 
-        final AlphaNode alphaNode = new AlphaNode( 2,
+        final AlphaNode alphaNode = new AlphaNode( buildContext.getNextId(),
                                                    constraint,
                                                    source,
-                                                   false,
-                                                   3 ); // no memory
+                                                   buildContext ); // no memory
 
         alphaNode.attach();
 

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/CompositeObjectSinkAdapterTest.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -5,6 +5,7 @@
 import junit.framework.TestCase;
 
 import org.drools.Cheese;
+import org.drools.RuleBaseFactory;
 import org.drools.base.ClassFieldExtractorCache;
 import org.drools.base.ValueType;
 import org.drools.base.evaluators.Operator;
@@ -13,12 +14,20 @@
 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.LiteralConstraint;
 import org.drools.rule.PredicateConstraint;
 import org.drools.spi.FieldExtractor;
 import org.drools.spi.PropagationContext;
 
 public class CompositeObjectSinkAdapterTest extends TestCase {
+    private ReteooRuleBase ruleBase;
+    private BuildContext buildContext;
+    
+    protected void setUp() throws Exception {
+        this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+    }    
 
     public int    la;
     public int    blah;
@@ -26,7 +35,7 @@
 
     public void testBeta() {
         final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
-        final MockBetaNode beta = new MockBetaNode( 0,
+        final MockBetaNode beta = new MockBetaNode( buildContext.getNextId(),
                                                     null,
                                                     null );
         ad.addObjectSink( beta );
@@ -52,12 +61,11 @@
 
     public void testAlphaWithPredicate() {
         final CompositeObjectSinkAdapter ad = new CompositeObjectSinkAdapter();
-        final AlphaNode al = new AlphaNode( 0,
+        final AlphaNode al = new AlphaNode( buildContext.getNextId(),
                                             new PredicateConstraint( null,
                                                                      null ),
                                             null,
-                                            true,
-                                            3 );
+                                            buildContext );
         ad.addObjectSink( al );
 
         assertEquals( 1,
@@ -80,11 +88,10 @@
         final LiteralConstraint lit = new LiteralConstraint( new MockExtractor(),
                                                              StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
                                                              new ObjectFieldImpl( "stilton" ) );
-        final AlphaNode al = new AlphaNode( 0,
+        final AlphaNode al = new AlphaNode( buildContext.getNextId(),
                                             lit,
                                             new MockObjectSource( 0 ),
-                                            true,
-                                            3 );
+                                            buildContext );
 
         ad.addObjectSink( al );
 
@@ -107,11 +114,10 @@
         final LiteralConstraint lit = new LiteralConstraint( new MockExtractor(),
                                                              StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
                                                              new ObjectFieldImpl( "stilton" ) );
-        final AlphaNode al = new AlphaNode( 0,
+        final AlphaNode al = new AlphaNode( buildContext.getNextId(),
                                             lit,
                                             new MockObjectSource( 0 ),
-                                            true,
-                                            3 );
+                                            buildContext );
 
         ad.addObjectSink( al );
 
@@ -125,11 +131,10 @@
         final LiteralConstraint lit2 = new LiteralConstraint( new MockExtractor(),
                                                               StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
                                                               new ObjectFieldImpl( "cheddar" ) );
-        final AlphaNode al2 = new AlphaNode( 1,
+        final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
                                              lit2,
-                                             new MockObjectSource( 0 ),
-                                             true,
-                                             3 );
+                                             new MockObjectSource( buildContext.getNextId() ),
+                                             buildContext );
 
         ad.addObjectSink( al2 );
 
@@ -142,7 +147,7 @@
                       ad.getSinks()[1] );
 
         //add a beta, just for good measure, make sure it leaves others alone
-        final MockBetaNode beta = new MockBetaNode( 0,
+        final MockBetaNode beta = new MockBetaNode( buildContext.getNextId(),
                                                     null,
                                                     null );
         ad.addObjectSink( beta );
@@ -167,11 +172,10 @@
         final LiteralConstraint lit = new LiteralConstraint( new MockExtractor(),
                                                              StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
                                                              new ObjectFieldImpl( "stilton" ) );
-        final AlphaNode al = new AlphaNode( 0,
+        final AlphaNode al = new AlphaNode( buildContext.getNextId(),
                                             lit,
-                                            new MockObjectSource( 0 ),
-                                            true,
-                                            3 );
+                                            new MockObjectSource( buildContext.getNextId() ),
+                                            buildContext );
 
         ad.addObjectSink( al );
 
@@ -185,11 +189,10 @@
         final LiteralConstraint lit2 = new LiteralConstraint( new MockExtractor(),
                                                               StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
                                                               new ObjectFieldImpl( "cheddar" ) );
-        final AlphaNode al2 = new AlphaNode( 1,
+        final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
                                              lit2,
-                                             new MockObjectSource( 1 ),
-                                             true,
-                                             3 );
+                                             new MockObjectSource( buildContext.getNextId() ),
+                                             buildContext );
 
         ad.addObjectSink( al2 );
 
@@ -200,11 +203,10 @@
         final LiteralConstraint lit3 = new LiteralConstraint( new MockExtractor(),
                                                               StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
                                                               new ObjectFieldImpl( "stinky" ) );
-        final AlphaNode al3 = new AlphaNode( 1,
+        final AlphaNode al3 = new AlphaNode( buildContext.getNextId(),
                                              lit3,
-                                             new MockObjectSource( 2 ),
-                                             true,
-                                             3 );
+                                             new MockObjectSource( buildContext.getNextId() ),
+                                             buildContext );
         ad.addObjectSink( al3 );
 
         //this should now be nicely hashed.
@@ -229,29 +231,26 @@
         final LiteralConstraint lit1 = new LiteralConstraint( extractor,
                                                               StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
                                                               new ObjectFieldImpl( "stilton" ) );
-        final AlphaNode al1 = new AlphaNode( 0,
+        final AlphaNode al1 = new AlphaNode( buildContext.getNextId(),
                                              lit1,
-                                             new MockObjectSource( 0 ),
-                                             true,
-                                             3 );
+                                             new MockObjectSource( buildContext.getNextId() ),
+                                             buildContext );
 
         final LiteralConstraint lit2 = new LiteralConstraint( extractor,
                                                               StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
                                                               new ObjectFieldImpl( "brie" ) );
-        final AlphaNode al2 = new AlphaNode( 0,
+        final AlphaNode al2 = new AlphaNode( buildContext.getNextId(),
                                              lit2,
-                                             new MockObjectSource( 0 ),
-                                             true,
-                                             3 );
+                                             new MockObjectSource( buildContext.getNextId() ),
+                                             buildContext );
 
         final LiteralConstraint lit3 = new LiteralConstraint( extractor,
                                                               StringFactory.getInstance().getEvaluator( Operator.EQUAL ),
                                                               new ObjectFieldImpl( "muzzarela" ) );
-        final AlphaNode al3 = new AlphaNode( 0,
+        final AlphaNode al3 = new AlphaNode( buildContext.getNextId(),
                                              lit3,
-                                             new MockObjectSource( 0 ),
-                                             true,
-                                             3 );
+                                             new MockObjectSource( buildContext.getNextId() ),
+                                             buildContext );
 
         ad.addObjectSink( al1 );
         ad.addObjectSink( al2 );
@@ -420,11 +419,5 @@
             //  Auto-generated method stub
 
         }
-
-        public void setIsMemoryAllowed(boolean memoryAllowed) {
-            // TODO Auto-generated method stub
-            
-        }
-
     }
 }

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/LogicalAssertionTest.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -57,8 +57,7 @@
         // MockObjectSink so we can detect assertions and retractions
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -160,8 +159,7 @@
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -251,8 +249,7 @@
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -394,8 +391,7 @@
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -483,8 +479,7 @@
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -584,8 +579,7 @@
         // MockObjectSink so we can detect assertions and retractions
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -715,8 +709,7 @@
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -817,8 +810,7 @@
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSink.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSink.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/MockObjectSink.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -87,10 +87,4 @@
     public void setPreviousObjectSinkNode(final ObjectSinkNode previous) {
         this.previousObjectSinkNode = previous;
     }
-
-    public void setIsMemoryAllowed(boolean memoryAllowed) {
-        // TODO Auto-generated method stub
-        
-    }
-
 }
\ No newline at end of file

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ObjectTypeNodeTest.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -34,26 +34,32 @@
 import org.drools.common.InternalRuleBase;
 import org.drools.common.PropagationContextImpl;
 import org.drools.reteoo.ReteooBuilder.IdGenerator;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.spi.ObjectType;
 import org.drools.spi.PropagationContext;
 import org.drools.util.FactHashTable;
 import org.drools.util.ObjectHashMap;
 
 public class ObjectTypeNodeTest extends DroolsTestCase {
-
+    private ReteooRuleBase ruleBase;
+    private BuildContext buildContext;
+    
+    protected void setUp() throws Exception {
+        this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+    }
+    
     public void testAttach() throws Exception {
-        ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
         IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
 
-        final Rete source = new Rete( (InternalRuleBase)ruleBase);        
+        final Rete source = this.ruleBase.getRete();    
 
         final ObjectType objectType = new ClassObjectType( String.class );
 
         int id = idGenerator.getNextId();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( id,
                                                                   objectType,
-                                                                  source,
-                                                                  3 );
+                                                                  buildContext );
 
         assertEquals( id,
                       objectTypeNode.getId() );
@@ -89,8 +95,7 @@
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  source,
-                                                                  3 );
+                                                                  buildContext );
 
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -127,6 +132,8 @@
         RuleBaseConfiguration conf = new RuleBaseConfiguration();
         conf.setSequential( true );
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( conf );
+        buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+        
         final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
                                                                            ruleBase );
 
@@ -134,8 +141,7 @@
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( String.class ),
-                                                                  source,
-                                                                  3 );
+                                                                  buildContext );
 
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -170,8 +176,7 @@
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  new Rete( (InternalRuleBase) ruleBase),
-                                                                  3 );
+                                                                  buildContext );
 
         final FactHashTable memory = (FactHashTable) workingMemory.getNodeMemory( objectTypeNode );
 
@@ -185,8 +190,7 @@
 
         ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                             new ClassObjectType( String.class ),
-                                                            source,
-                                                            3 );
+                                                            buildContext );
 
         assertFalse( objectTypeNode.matches( new Object() ) );
         assertFalse( objectTypeNode.matches( new Integer( 5 ) ) );
@@ -194,8 +198,7 @@
 
         objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                              new ClassObjectType( Object.class ),
-                                             source,
-                                             3 );
+                                             buildContext );
 
         assertTrue( objectTypeNode.matches( new Object() ) );
         assertTrue( objectTypeNode.matches( new Integer( 5 ) ) );
@@ -217,8 +220,7 @@
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( String.class ),
-                                                                  source,
-                                                                  3 );
+                                                                  buildContext );
 
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -269,8 +271,7 @@
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( String.class ),
-                                                                  source,
-                                                                  3 );
+                                                                  buildContext );
 
         final MockObjectSink sink1 = new MockObjectSink();
         objectTypeNode.addObjectSink( sink1 );
@@ -335,8 +336,7 @@
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( Cheese.class  ),
-                                                                  source,
-                                                                  3 );
+                                                                  buildContext );
 
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -377,8 +377,7 @@
         final Class shadowClass = ShadowProxyFactory.getProxy( Person.class );
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( idGenerator.getNextId(),
                                                                   new ClassObjectType( Person.class ),
-                                                                  source,
-                                                                  3 );
+                                                                  buildContext );
 
         final MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/PropertyChangeListenerTest.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -7,19 +7,23 @@
 
 import org.drools.RuleBaseFactory;
 import org.drools.base.ClassObjectType;
+import org.drools.reteoo.builder.BuildContext;
 
 public class PropertyChangeListenerTest extends TestCase {
+    private ReteooRuleBase ruleBase;
+    private BuildContext buildContext;
+    
+    protected void setUp() throws Exception {
+        this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+    }
+    
     public void test1() {
-        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-
         final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
 
-        final Rete rete = ruleBase.getRete();
-
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( State.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
 
         objectTypeNode.attach();
 

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-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/QueryTerminalNodeTest.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -43,16 +43,19 @@
 import org.drools.spi.FieldValue;
 
 public class QueryTerminalNodeTest extends TestCase {
+    private ReteooRuleBase ruleBase;
+    private BuildContext buildContext;
+    
+    protected void setUp() throws Exception {
+        this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+    }
+    
     public void testQueryTerminalNode() {
-        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-
-        final Rete rete = ruleBase.getRete();
-
         final ClassObjectType queryObjectType = new ClassObjectType( DroolsQuery.class );
         final ObjectTypeNode queryObjectTypeNode = new ObjectTypeNode( 1,
                                                                        queryObjectType,
-                                                                       rete,
-                                                                       3 );
+                                                                       buildContext );
         queryObjectTypeNode.attach();
 
         ClassFieldExtractor extractor = ClassFieldExtractorCache.getExtractor( DroolsQuery.class,
@@ -69,8 +72,7 @@
         AlphaNode alphaNode = new AlphaNode( 2,
                                              constraint,
                                              queryObjectTypeNode,
-                                             true,
-                                             3  );
+                                             buildContext  );
         alphaNode.attach();
 
         final LeftInputAdapterNode liaNode = new LeftInputAdapterNode( 3,
@@ -80,8 +82,7 @@
         final ClassObjectType cheeseObjectType = new ClassObjectType( Cheese.class );
         final ObjectTypeNode cheeseObjectTypeNode = new ObjectTypeNode( 4,
                                                                         cheeseObjectType,
-                                                                        rete,
-                                                                        3 );
+                                                                        buildContext );
         cheeseObjectTypeNode.attach();
 
         extractor = ClassFieldExtractorCache.getExtractor( Cheese.class,
@@ -97,8 +98,7 @@
         alphaNode = new AlphaNode( 5,
                                    constraint,
                                    cheeseObjectTypeNode,
-                                   true,
-                                   3  );
+                                   buildContext  );
         alphaNode.attach();
 
         BuildContext buildContext = new BuildContext( ruleBase, ruleBase.getReteooBuilder().getIdGenerator() );

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2007-09-08 15:24:21 UTC (rev 14945)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/reteoo/ReteTest.java	2007-09-08 17:31:01 UTC (rev 14946)
@@ -38,6 +38,7 @@
 import org.drools.reteoo.Rete.ClassObjectTypeConf;
 import org.drools.reteoo.Rete.ObjectTypeConf;
 import org.drools.reteoo.ReteooBuilder.IdGenerator;
+import org.drools.reteoo.builder.BuildContext;
 import org.drools.spi.PropagationContext;
 import org.drools.util.ObjectHashMap;
 
@@ -46,27 +47,30 @@
  *
  */
 public class ReteTest extends DroolsTestCase {
-
+    private ReteooRuleBase ruleBase;
+    private BuildContext buildContext;
+    
+    protected void setUp() throws Exception {
+        this.ruleBase = ( ReteooRuleBase ) RuleBaseFactory.newRuleBase();
+        this.buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
+    }
+    
     /**
      * Tests ObjectTypeNodes are correctly added to the Rete object
      * 
      * @throws Exception
      */
     public void testObjectTypeNodes() throws Exception {
-        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-
         final Rete rete = ruleBase.getRete();
 
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( Object.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
 
         final ObjectTypeNode stringTypeNode = new ObjectTypeNode( 2,
                                                                   new ClassObjectType( String.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         stringTypeNode.attach();
 
         final Field field = Rete.class.getDeclaredField( "objectTypeNodes" );
@@ -87,32 +91,27 @@
      * @throws FactException
      */
     public void testCache() throws FactException {
-        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           ruleBase );
+        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
         ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                             new ClassObjectType( List.class ),
-                                                            rete,
-                                                            3 );
+                                                            buildContext );
         objectTypeNode.attach();
         MockObjectSink sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
 
         objectTypeNode = new ObjectTypeNode( 1,
                                              new ClassObjectType( Collection.class ),
-                                             rete,
-                                             3 );
+                                             buildContext );
         objectTypeNode.attach();
         sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
 
         objectTypeNode = new ObjectTypeNode( 1,
                                              new ClassObjectType( ArrayList.class ),
-                                             rete,
-                                             3 );
+                                             buildContext );
         objectTypeNode.attach();
         sink = new MockObjectSink();
         objectTypeNode.addObjectSink( sink );
@@ -153,16 +152,13 @@
      * @throws Exception
      */
     public void testAssertObject() throws Exception {
-        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           ruleBase );
+        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( List.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink1 = new MockObjectSink();
         objectTypeNode.addObjectSink( sink1 );
@@ -205,8 +201,7 @@
     }
 
     public void testAssertObjectWithNoMatchingObjectTypeNode() {
-        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
 
         final Rete rete = ruleBase.getRete();
         assertEquals( 0,
@@ -221,8 +216,7 @@
     }
 
     public void testHierarchy() {
-        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = (ReteooWorkingMemory) ruleBase.newStatefulSession();
+        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
 
         final Rete rete = ruleBase.getRete();
         final IdGenerator idGenerator = ruleBase.getReteooBuilder().getIdGenerator();
@@ -230,8 +224,7 @@
         // Attach a List ObjectTypeNode
         final ObjectTypeNode listOtn = new ObjectTypeNode( idGenerator.getNextId(),
                                                            new ClassObjectType( List.class ),
-                                                           rete,
-                                                           3 );
+                                                           buildContext );
         listOtn.attach();
 
         // Will automatically create an ArrayList ObjectTypeNode
@@ -277,8 +270,7 @@
         // Add a Collection ObjectTypeNode, so that we can check that the data from ArrayList is sent to it
         final ObjectTypeNode collectionOtn = new ObjectTypeNode( idGenerator.getNextId(),
                                                                  new ClassObjectType( Collection.class ),
-                                                                 rete,
-                                                                 3 );
+                                                                 buildContext );
         final MockObjectSink collectionSink = new MockObjectSink();
         collectionOtn.addObjectSink( collectionSink );
         collectionOtn.attach( new InternalWorkingMemory[]{workingMemory} );
@@ -299,16 +291,13 @@
      * ObjectTypeNodes.
      */
     public void testRetractObject() throws Exception {
-        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           ruleBase );
+        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( List.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink1 = new MockObjectSink();
         objectTypeNode.addObjectSink( sink1 );
@@ -359,16 +348,13 @@
     }
 
     public void testIsShadowed() {
-        final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase();
-        final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
-                                                                           ruleBase );
+        final ReteooWorkingMemory workingMemory = ( ReteooWorkingMemory ) this.ruleBase.newStatefulSession();
 
         // Create a Rete network with ObjectTypeNodes for List, Collection and ArrayList
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( Cheese.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink1 = new MockObjectSink();
         objectTypeNode.addObjectSink( sink1 );
@@ -400,6 +386,7 @@
                                 "org.drools.Cheese" );
         RuleBaseConfiguration conf = new RuleBaseConfiguration( properties );
         final ReteooRuleBase ruleBase = (ReteooRuleBase) RuleBaseFactory.newRuleBase( conf );
+        buildContext = new BuildContext( ruleBase, ((ReteooRuleBase)ruleBase).getReteooBuilder().getIdGenerator() );
         final ReteooWorkingMemory workingMemory = new ReteooWorkingMemory( 1,
                                                                            ruleBase );
 
@@ -407,8 +394,7 @@
         final Rete rete = ruleBase.getRete();
         final ObjectTypeNode objectTypeNode = new ObjectTypeNode( 1,
                                                                   new ClassObjectType( Cheese.class ),
-                                                                  rete,
-                                                                  3 );
+                                                                  buildContext );
         objectTypeNode.attach();
         final MockObjectSink sink1 = new MockObjectSink();
         objectTypeNode.addObjectSink( sink1 );




More information about the jboss-svn-commits mailing list