[jboss-svn-commits] JBL Code SVN: r8834 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo: builder and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Jan 11 18:40:25 EST 2007
Author: tirelli
Date: 2007-01-11 18:40:19 -0500 (Thu, 11 Jan 2007)
New Revision: 8834
Added:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.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/ReteooRuleBuilder.java
Log:
JBRULES-218: collect and accumulate are now working
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java 2007-01-11 22:21:25 UTC (rev 8833)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java 2007-01-11 23:40:19 UTC (rev 8834)
@@ -162,77 +162,6 @@
return (BaseNode[]) this.rules.remove( rule );
}
-// private void attachAccumulate(final TupleSource tupleSource,
-// final GroupElement parent,
-// final Accumulate accumulate) {
-// // If a tupleSource does not exist then we need to adapt an
-// // InitialFact into a a TupleSource using LeftInputAdapterNode
-// if ( this.tupleSource == null ) {
-// // adjusting offset as all tuples will now contain initial-fact at index 0
-// this.currentOffsetAdjustment = 1;
-//
-// final ObjectSource auxObjectSource = attachNode( new ObjectTypeNode( this.id++,
-// new ClassObjectType( InitialFact.class ),
-// this.rete,
-// this.ruleBase.getConfiguration().getAlphaNodeHashingThreshold()) );
-//
-// this.tupleSource = attachNode( new LeftInputAdapterNode( this.id++,
-// auxObjectSource ) );
-// }
-//
-// final Column sourceColumn = accumulate.getSourceColumn();
-// final BetaConstraints sourceBinder = attachColumn( sourceColumn,
-// parent,
-// true );
-//
-// final Column column = accumulate.getResultColumn();
-// // Adjusting offset in case a previous Initial-Fact was added to the network
-// column.adjustOffset( this.currentOffsetAdjustment );
-//
-// final List constraints = column.getConstraints();
-//
-// // Check if the Column is bound
-// if ( column.getDeclaration() != null ) {
-// final Declaration declaration = column.getDeclaration();
-// // Add the declaration the map of previously bound declarations
-// this.declarations.put( declaration.getIdentifier(),
-// declaration );
-// }
-//
-// final List betaConstraints = new ArrayList();
-// final List alphaConstraints = new ArrayList();
-//
-// for ( final Iterator it = constraints.iterator(); it.hasNext(); ) {
-// final Object object = it.next();
-// // Check if its a declaration
-// if ( object instanceof Declaration ) {
-// final Declaration declaration = (Declaration) object;
-// // Add the declaration the map of previously bound declarations
-// this.declarations.put( declaration.getIdentifier(),
-// declaration );
-// continue;
-// }
-//
-// final AlphaNodeFieldConstraint fieldConstraint = (AlphaNodeFieldConstraint) object;
-// if ( fieldConstraint instanceof LiteralConstraint ) {
-// alphaConstraints.add( fieldConstraint );
-// } else {
-// checkUnboundDeclarations( fieldConstraint.getRequiredDeclarations() );
-// betaConstraints.add( fieldConstraint );
-// }
-// }
-//
-// final BetaConstraints resultsBinder = createBetaNodeConstraint( betaConstraints );
-//
-// this.tupleSource = attachNode( new AccumulateNode( this.id++,
-// this.tupleSource,
-// this.objectSource,
-// (AlphaNodeFieldConstraint[]) alphaConstraints.toArray( new AlphaNodeFieldConstraint[alphaConstraints.size()] ),
-// sourceBinder,
-// resultsBinder,
-// accumulate ) );
-// }
-//
public void removeRule(final Rule rule) {
// reset working memories for potential propagation
Added: 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-01-11 22:21:25 UTC (rev 8833)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java 2007-01-11 23:40:19 UTC (rev 8834)
@@ -0,0 +1,108 @@
+/*
+ * Copyright 2006 JBoss Inc
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.drools.reteoo.builder;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.drools.common.BetaConstraints;
+import org.drools.reteoo.AccumulateNode;
+import org.drools.reteoo.TupleSource;
+import org.drools.rule.Accumulate;
+import org.drools.rule.Column;
+import org.drools.rule.Declaration;
+import org.drools.rule.LiteralConstraint;
+import org.drools.rule.RuleConditionElement;
+import org.drools.spi.AlphaNodeFieldConstraint;
+
+/**
+ * @author etirelli
+ *
+ */
+public class AccumulateBuilder
+ implements
+ ReteooComponentBuilder {
+
+ /**
+ * @inheritDoc
+ */
+ public void build(BuildContext context,
+ BuildUtils utils,
+ RuleConditionElement rce) {
+ Accumulate accumulate = (Accumulate) rce;
+
+ final Column sourceColumn = accumulate.getSourceColumn();
+
+ // get builder for the column
+ ReteooComponentBuilder builder = utils.getBuilderFor( sourceColumn );
+
+ // builds the source column
+ builder.build( context,
+ utils,
+ sourceColumn );
+
+ final Column column = accumulate.getResultColumn();
+ // adjusting target column offset to be the same as the source column
+ column.setOffset( context.getCurrentColumnOffset() - 1 );
+
+ final List constraints = column.getConstraints();
+
+ final List betaConstraints = new ArrayList();
+ final List alphaConstraints = new ArrayList();
+
+ for ( final Iterator it = constraints.iterator(); it.hasNext(); ) {
+ final Object object = it.next();
+ // Check if its a declaration
+ if ( object instanceof Declaration ) {
+ continue;
+ }
+
+ final AlphaNodeFieldConstraint fieldConstraint = (AlphaNodeFieldConstraint) object;
+ if ( fieldConstraint instanceof LiteralConstraint ) {
+ alphaConstraints.add( fieldConstraint );
+ } else {
+ utils.checkUnboundDeclarations( context,
+ fieldConstraint.getRequiredDeclarations() );
+ betaConstraints.add( fieldConstraint );
+ }
+ }
+
+ final BetaConstraints resultsBinder = utils.createBetaNodeConstraint( context,
+ betaConstraints );
+
+ context.setTupleSource( (TupleSource) utils.attachNode( context,
+ new AccumulateNode( context.getNextId(),
+ context.getTupleSource(),
+ context.getObjectSource(),
+ (AlphaNodeFieldConstraint[]) alphaConstraints.toArray( new AlphaNodeFieldConstraint[alphaConstraints.size()] ),
+ context.getBetaconstraints(),
+ resultsBinder,
+ accumulate ) ) );
+ // source column was bound, so nulling context
+ context.setObjectSource( null );
+ }
+
+ /**
+ * @inheritDoc
+ */
+ public boolean requiresLeftActivation(BuildUtils utils,
+ RuleConditionElement rce) {
+ return true;
+ }
+
+}
Property changes on: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/AccumulateBuilder.java
___________________________________________________________________
Name: svn:executable
+ *
Name: svn:keywords
+ id author date revision
Name: svn:eol-style
+ native
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-01-11 22:21:25 UTC (rev 8833)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/CollectBuilder.java 2007-01-11 23:40:19 UTC (rev 8834)
@@ -44,11 +44,11 @@
public void build(BuildContext context,
BuildUtils utils,
RuleConditionElement rce) {
-
+
Collect collect = (Collect) rce;
-
+
final Column sourceColumn = collect.getSourceColumn();
-
+
// get builder for the column
ReteooComponentBuilder builder = utils.getBuilderFor( sourceColumn );
@@ -59,7 +59,7 @@
final Column column = collect.getResultColumn();
// adjusting target column offset to be the same as the source column
- column.setOffset( context.getCurrentColumnOffset()-1 );
+ column.setOffset( context.getCurrentColumnOffset() - 1 );
final List constraints = column.getConstraints();
@@ -88,12 +88,14 @@
context.setTupleSource( (TupleSource) utils.attachNode( context,
new CollectNode( context.getNextId(),
- context.getTupleSource(),
- context.getObjectSource(),
- (AlphaNodeFieldConstraint[]) alphaConstraints.toArray( new AlphaNodeFieldConstraint[alphaConstraints.size()] ),
- context.getBetaconstraints(),
- resultsBinder,
- collect ) ) );
+ context.getTupleSource(),
+ context.getObjectSource(),
+ (AlphaNodeFieldConstraint[]) alphaConstraints.toArray( new AlphaNodeFieldConstraint[alphaConstraints.size()] ),
+ context.getBetaconstraints(),
+ resultsBinder,
+ collect ) ) );
+ // source column was bound, so nulling context
+ context.setObjectSource( null );
}
/**
@@ -104,6 +106,4 @@
return true;
}
-
-
}
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-01-11 22:21:25 UTC (rev 8833)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/builder/ReteooRuleBuilder.java 2007-01-11 23:40:19 UTC (rev 8834)
@@ -34,6 +34,7 @@
import org.drools.reteoo.ReteooRuleBase;
import org.drools.reteoo.RuleTerminalNode;
import org.drools.reteoo.TerminalNode;
+import org.drools.rule.Accumulate;
import org.drools.rule.Collect;
import org.drools.rule.Column;
import org.drools.rule.EvalCondition;
@@ -66,7 +67,8 @@
new FromBuilder() );
utils.addBuilder( Collect.class,
new CollectBuilder() );
- //utils.addBuilder( Accumulate.class, new AccumulateBuilder() );
+ utils.addBuilder( Accumulate.class,
+ new AccumulateBuilder() );
}
/**
More information about the jboss-svn-commits
mailing list