[jboss-svn-commits] JBL Code SVN: r7163 - in labs/jbossrules/trunk/drools-core/src/main/java/org/drools: . common reteoo util
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Thu Oct 26 21:19:15 EDT 2006
Author: mark.proctor at jboss.com
Date: 2006-10-26 21:19:10 -0400 (Thu, 26 Oct 2006)
New Revision: 7163
Modified:
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java
labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java
Log:
-Update RuleBaseConfiguration and make indexing configurable
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2006-10-27 01:17:40 UTC (rev 7162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/RuleBaseConfiguration.java 2006-10-27 01:19:10 UTC (rev 7163)
@@ -42,127 +42,231 @@
public class RuleBaseConfiguration
implements
Serializable {
- private Map properties;
+ private static final long serialVersionUID = 320L;
- private boolean immutable;
+ private boolean immutable;
- /**
- * Property to enable/disable left beta memory indexing
- * Defaults to false
- */
- public static final String PROPERTY_INDEX_LEFT_BETA_MEMORY = "org.drools.reteoo.beta.index-left";
+ private boolean shareAlphaNodes;
+ private boolean shareBetaNodes;
+ private int alphaNodeHashingThreshold;
+ private int compositeKeyDepth;
+ private boolean indexLeftBetaMemory;
+ private boolean indexRightBetaMemory;
+ private AssertBehaviour assertBehaviour;
+ private LogicalOverride logicalOverride;
- /**
- * Property to enable/disable right beta memory indexing
- * Defaults to true
- */
- public static final String PROPERTY_INDEX_RIGHT_BETA_MEMORY = "org.drools.reteoo.beta.index-right";
+ public RuleBaseConfiguration() {
+ this.immutable = false;
- /**
- * Property to enable/disable alpha node hashing inside object type nodes
- * Defaults to true
- */
- public static final String PROPERTY_HASH_OBJECT_TYPE_NODES = "org.drools.reteoo.alpha.hash-type-node";
+ setShareAlphaNodes( Boolean.valueOf( System.getProperty( "drools.shareAlphaNodes",
+ "true" ) ).booleanValue() );
+ setShareBetaNodes( Boolean.valueOf( System.getProperty( "drools.shareBetaNodes",
+ "true" ) ).booleanValue() );
+
+ setAlphaNodeHashingThreshold( Integer.parseInt( System.getProperty( "drools.alphaNodeHashingThreshold",
+ "3" ) ) );
+
+ setCompositeKeyDepth( Integer.parseInt( System.getProperty( "drools.compositeKeyDepth",
+ "3" ) ) );
+
+ setIndexLeftBetaMemory( Boolean.valueOf( System.getProperty( "drools.indexLeftBetaMemory",
+ "true" ) ).booleanValue() );
+ setIndexRightBetaMemory( Boolean.valueOf( System.getProperty( "drools.indexRightBetaMemory",
+ "true" ) ).booleanValue() );
+
+ setAssertBehaviour( AssertBehaviour.determineAssertBehaviour( System.getProperty( "drools.iassertBehaviour",
+ "IDENTITY" ) ) );
+ setLogicalOverride( LogicalOverride.determineLogicalOverride( System.getProperty( "drools.logicalOverride",
+ "DISCARD" ) ) );
+ }
+
/**
- * Property to enable/disable alpha node hashing inside alpha nodes
- * Defaults to false
+ * Makes the configuration object immutable. Once it becomes immutable,
+ * there is no way to make it mutable again.
+ * This is done to keep consistency.
*/
- public static final String PROPERTY_HASH_ALPHA_NODES = "org.drools.reteoo.alpha.hash-alpha-node";
+ public void makeImmutable() {
+ this.immutable = true;
+ }
/**
- * Property to define working memory assert behavior. Valid values are "identity" or "equality".
- * Defaults to identity
+ * Returns true if this configuration object is immutable or false otherwise.
+ * @return
*/
- public static final String PROPERTY_ASSERT_BEHAVIOR = "org.drools.wm.assert-behavior";
+ public boolean isImmutable() {
+ return this.immutable;
+ }
- public static final String PROPERTY_LOGICAL_OVERRIDE_BEHAVIOR = "org.drools.wm.logical-override-behavior";
+ public boolean isShareAlphaNodes() {
+ return shareAlphaNodes;
+ }
- public static final String WM_BEHAVIOR_IDENTITY = "identity";
- public static final String WM_BEHAVIOR_EQUALITY = "equality";
+ public void setShareAlphaNodes(boolean shareAlphaNodes) {
+ if ( !this.immutable ) {
+ this.shareAlphaNodes = shareAlphaNodes;
+ } else {
+ throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
+ }
+ }
- public static final String WM_BEHAVIOR_PRESERVE = "preserve";
- public static final String WM_BEHAVIOR_DISCARD = "discard";
+ public boolean isShareBetaNodes() {
+ return shareBetaNodes;
+ }
- // a generated serial version id
- private static final long serialVersionUID = 2989084670778336973L;
+ public void setShareBetaNodes(boolean shareBetaNodes) {
+ if ( !this.immutable ) {
+ this.shareBetaNodes = shareBetaNodes;
+ } else {
+ throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
+ }
+ }
- public RuleBaseConfiguration() {
- this.properties = new HashMap();
- this.immutable = false;
+ public int getAlphaNodeHashingThreshold() {
+ return alphaNodeHashingThreshold;
+ }
- // default values
- this.properties.put( RuleBaseConfiguration.PROPERTY_INDEX_LEFT_BETA_MEMORY,
- System.getProperty( RuleBaseConfiguration.PROPERTY_INDEX_LEFT_BETA_MEMORY,
- "false" ) );
- this.properties.put( RuleBaseConfiguration.PROPERTY_INDEX_RIGHT_BETA_MEMORY,
- System.getProperty( RuleBaseConfiguration.PROPERTY_INDEX_RIGHT_BETA_MEMORY,
- "true" ) );
- this.properties.put( RuleBaseConfiguration.PROPERTY_HASH_OBJECT_TYPE_NODES,
- System.getProperty( RuleBaseConfiguration.PROPERTY_HASH_OBJECT_TYPE_NODES,
- "true" ) );
- this.properties.put( RuleBaseConfiguration.PROPERTY_HASH_ALPHA_NODES,
- System.getProperty( RuleBaseConfiguration.PROPERTY_HASH_ALPHA_NODES,
- "false" ) );
- this.properties.put( RuleBaseConfiguration.PROPERTY_ASSERT_BEHAVIOR,
- System.getProperty( RuleBaseConfiguration.PROPERTY_ASSERT_BEHAVIOR,
- RuleBaseConfiguration.WM_BEHAVIOR_IDENTITY ) );
- this.properties.put( RuleBaseConfiguration.PROPERTY_LOGICAL_OVERRIDE_BEHAVIOR,
- System.getProperty( RuleBaseConfiguration.PROPERTY_HASH_OBJECT_TYPE_NODES,
- RuleBaseConfiguration.WM_BEHAVIOR_DISCARD ) );
+ public void setAlphaNodeHashingThreshold(int alphaNodeHashingThreshold) {
+ if ( !this.immutable ) {
+ this.alphaNodeHashingThreshold = alphaNodeHashingThreshold;
+ } else {
+ throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
+ }
}
- /**
- * Returns the current value for the given property or null if it is not set
- * @param prop
- * @return
- */
- public String getProperty(final String prop) {
- return (String) this.properties.get( prop );
+ public AssertBehaviour getAssertBehaviour() {
+ return assertBehaviour;
}
- /**
- * Convenience method that calls get() method and returns a boolean for the
- * given property.
- *
- * @param prop
- * @return
- */
- public boolean getBooleanProperty(final String prop) {
- return Boolean.valueOf( (String) this.properties.get( prop ) ).booleanValue();
+ public void setAssertBehaviour(AssertBehaviour assertBehaviour) {
+ if ( !this.immutable ) {
+ this.assertBehaviour = assertBehaviour;
+ } else {
+ throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
+ }
}
- /**
- * Sets the value of the given property
- *
- * @param prop
- * @param value
- */
- public void setProperty(final String prop,
- final String value) {
+ public int getCompositeKeyDepth() {
+ return compositeKeyDepth;
+ }
+
+ public void setCompositeKeyDepth(int compositeKeyDepth) {
if ( !this.immutable ) {
- this.properties.put( prop,
- value );
+ if ( compositeKeyDepth > 3 ) {
+ throw new UnsupportedOperationException( "compositeKeyDepth cannot be greater than 3" );
+ }
+ this.compositeKeyDepth = compositeKeyDepth;
} else {
throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
}
}
- /**
- * Makes the configuration object immutable. Once it becomes immutable,
- * there is no way to make it mutable again.
- * This is done to keep consistency.
- */
- public void makeImmutable() {
- this.immutable = true;
+ public boolean isIndexLeftBetaMemory() {
+ return indexLeftBetaMemory;
}
- /**
- * Returns true if this configuration object is immutable or false otherwise.
- * @return
- */
- public boolean isImmutable() {
- return this.immutable;
+ public void setIndexLeftBetaMemory(boolean indexLeftBetaMemory) {
+ if ( !this.immutable ) {
+ this.indexLeftBetaMemory = indexLeftBetaMemory;
+ } else {
+ throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
+ }
}
+ public boolean isIndexRightBetaMemory() {
+ return indexRightBetaMemory;
+ }
+
+ public void setIndexRightBetaMemory(boolean indexRightBetaMemory) {
+ if ( !this.immutable ) {
+ this.indexRightBetaMemory = indexRightBetaMemory;
+ } else {
+ throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
+ }
+ }
+
+ public LogicalOverride getLogicalOverride() {
+ return logicalOverride;
+ }
+
+ public void setLogicalOverride(LogicalOverride logicalOverride) {
+ if ( !this.immutable ) {
+ this.logicalOverride = logicalOverride;
+ } else {
+ throw new UnsupportedOperationException( "Can't set a property after configuration becomes immutable" );
+ }
+ }
+
+ public static class AssertBehaviour
+ implements
+ Serializable {
+ private static final long serialVersionUID = 320L;
+
+ public static final AssertBehaviour IDENTITY = new AssertBehaviour( 0 );
+ public static final AssertBehaviour EQUALITY = new AssertBehaviour( 1 );
+
+ private int value;
+
+ private AssertBehaviour(int value) {
+ this.value = value;
+ }
+
+ public static AssertBehaviour determineAssertBehaviour(String value) {
+ if ( value.equals( "IDENTITY" ) ) {
+ return IDENTITY;
+ } else if ( value.equals( "EQUALITY" ) ) {
+ return EQUALITY;
+ } else {
+ throw new IllegalArgumentException( "Illegal enum value '" + value + "' for AssertBehaviour" );
+ }
+ }
+
+ private Object readResolve() throws java.io.ObjectStreamException {
+ switch ( this.value ) {
+ case 0 :
+ return IDENTITY;
+ case 1 :
+ return EQUALITY;
+ default :
+ throw new IllegalArgumentException( "Illegal enum value '" + this.value + "' for AssertBehaviour" );
+ }
+ }
+ }
+
+ public static class LogicalOverride
+ implements
+ Serializable {
+ private static final long serialVersionUID = 320L;
+
+ public static final LogicalOverride PRESERVE = new LogicalOverride( 0 );
+ public static final LogicalOverride DISCARD = new LogicalOverride( 1 );
+
+ private int value;
+
+ private LogicalOverride(int value) {
+ this.value = value;
+ }
+
+ public static LogicalOverride determineLogicalOverride(String value) {
+ if ( value.equals( "PRESERVE" ) ) {
+ return PRESERVE;
+ } else if ( value.equals( "DISCARD" ) ) {
+ return DISCARD;
+ } else {
+ throw new IllegalArgumentException( "Illegal enum value '" + value + "' for LogicalOverride" );
+ }
+ }
+
+ private Object readResolve() throws java.io.ObjectStreamException {
+ switch ( this.value ) {
+ case 0 :
+ return PRESERVE;
+ case 1 :
+ return DISCARD;
+ default :
+ throw new IllegalArgumentException( "Illegal enum value '" + this.value + "' for LogicalOverride" );
+ }
+ }
+ }
+
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2006-10-27 01:17:40 UTC (rev 7162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/AbstractWorkingMemory.java 2006-10-27 01:19:10 UTC (rev 7163)
@@ -37,6 +37,8 @@
import org.drools.RuleBase;
import org.drools.RuleBaseConfiguration;
import org.drools.WorkingMemory;
+import org.drools.RuleBaseConfiguration.AssertBehaviour;
+import org.drools.RuleBaseConfiguration.LogicalOverride;
import org.drools.base.ShadowProxy;
import org.drools.event.AgendaEventListener;
import org.drools.event.AgendaEventSupport;
@@ -145,15 +147,17 @@
this.tms = new TruthMaintenanceSystem( this );
this.assertMap = new ObjectHashMap();
final RuleBaseConfiguration conf = this.ruleBase.getConfiguration();
-
- if ( RuleBaseConfiguration.WM_BEHAVIOR_IDENTITY.equals( conf.getProperty( RuleBaseConfiguration.PROPERTY_ASSERT_BEHAVIOR ) ) ) {
+
+
+
+ if ( conf.getAssertBehaviour() == AssertBehaviour.IDENTITY ) {
this.assertMap.setComparator( new IdentityAssertMapComparator( this.handleFactory.getFactHandleType() ) );
} else {
this.assertMap.setComparator( new EqualityAssertMapComparator( this.handleFactory.getFactHandleType() ) );
}
- // Only takes effect if are using idententity behaviour for assert
- if ( RuleBaseConfiguration.WM_BEHAVIOR_DISCARD.equals( conf.getProperty( RuleBaseConfiguration.PROPERTY_LOGICAL_OVERRIDE_BEHAVIOR ) ) ) {
+ // Only takes effect if are using idententity behaviour for assert
+ if ( conf.getLogicalOverride() == LogicalOverride.DISCARD ) {
this.discardOnLogicalOverride = true;
} else {
this.discardOnLogicalOverride = false;
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java 2006-10-27 01:17:40 UTC (rev 7162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/DoubleBetaConstraints.java 2006-10-27 01:19:10 UTC (rev 7163)
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.drools.RuleBaseConfiguration;
import org.drools.base.evaluators.Operator;
import org.drools.reteoo.BetaMemory;
import org.drools.reteoo.ReteTuple;
@@ -52,26 +53,30 @@
private boolean indexed0;
private boolean indexed1;
-
- public DoubleBetaConstraints(final BetaNodeFieldConstraint[] constraints) {
- this( constraints, true );
- }
- public DoubleBetaConstraints(final BetaNodeFieldConstraint[] constraints, boolean index) {
- final boolean i0 = index && isIndexable( constraints[0] );
- final boolean i1 = index && isIndexable( constraints[1] );
+ public DoubleBetaConstraints(final BetaNodeFieldConstraint[] constraints, RuleBaseConfiguration conf) {
+ if (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) {
+ this.indexed0 = false;
+ this.indexed1 = false;
+ } else {
+ int depth = conf.getCompositeKeyDepth();
- if ( i0 ) {
- this.indexed0 = true;
- }
-
- if ( i1 ) {
- if ( !i0 ) {
+ // Determine if this constraints are indexable
+ final boolean i0 = isIndexable( constraints[0] );
+ final boolean i1 = isIndexable( constraints[1] );
+
+ if ( depth >= 1 && i0 ) {
this.indexed0 = true;
- swap( constraints, 1, 0 );
- } else {
- this.indexed1 = true;
- }
+ }
+
+ if ( i1 ) {
+ if ( depth >= 1 && !i0 ) {
+ this.indexed0 = true;
+ swap( constraints, 1, 0 );
+ } else if ( depth >= 2 ) {
+ this.indexed1 = true;
+ }
+ }
}
this.constraint0 = constraints[0];
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java 2006-10-27 01:17:40 UTC (rev 7162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java 2006-10-27 01:19:10 UTC (rev 7163)
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.drools.RuleBaseConfiguration;
import org.drools.base.evaluators.Operator;
import org.drools.reteoo.BetaMemory;
import org.drools.reteoo.ReteTuple;
@@ -57,69 +58,74 @@
private boolean indexed1;
private boolean indexed2;
- public QuadroupleBetaConstraints(final BetaNodeFieldConstraint[] constraints) {
- this( constraints,
- true );
- }
-
public QuadroupleBetaConstraints(final BetaNodeFieldConstraint[] constraints,
- boolean index) {
- final boolean i0 = index && isIndexable( constraints[0] );
- final boolean i1 = index && isIndexable( constraints[1] );
- final boolean i2 = index && isIndexable( constraints[2] );
- final boolean i3 = index && isIndexable( constraints[3] );
+ final RuleBaseConfiguration conf) {
+ if (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) {
+ this.indexed0 = false;
+ this.indexed1 = false;
+ this.indexed2 = false;
+ } else {
+ int depth = conf.getCompositeKeyDepth();
- if ( i0 ) {
- this.indexed0 = true;
- }
-
- if ( i1 ) {
- if ( !i0 ) {
+ // Determine if this constraints are indexable
+ final boolean i0 = isIndexable( constraints[0] );
+ final boolean i1 = isIndexable( constraints[1] );
+ final boolean i2 = isIndexable( constraints[2] );
+ final boolean i3 = isIndexable( constraints[3] );
+
+ if ( depth >= 1 && i0 ) {
this.indexed0 = true;
- swap( constraints,
- 1,
- 0 );
- } else {
- this.indexed1 = true;
}
- }
-
- if ( i2 ) {
- if ( !i0 ) {
- this.indexed0 = true;
- swap( constraints,
- 2,
- 0 );
- } else if ( !i0 && !i1 ) {
- this.indexed1 = true;
- swap( constraints,
- 2,
- 1 );
- } else {
- this.indexed2 = true;
+
+ if ( i1 ) {
+ if ( depth >= 1 && !this.indexed0 ) {
+ this.indexed0 = true;
+ swap( constraints,
+ 1,
+ 0 );
+ } else if (depth >= 2 ) {
+ this.indexed1 = true;
+ }
}
- }
-
- if ( i3 ) {
- if ( !i0 ) {
- this.indexed0 = true;
- swap( constraints,
- 3,
- 0 );
- } else if ( !i0 && !i1 ) {
- this.indexed1 = true;
- swap( constraints,
- 3,
- 1 );
- } else if ( !i0 && !i1 && !i2 ) {
- this.indexed2 = true;
- swap( constraints,
- 3,
- 2 );
- } else {
- throw new IllegalArgumentException( "There cannot be more than 3 index" );
+
+ if ( i2 ) {
+ if ( depth >= 1 && !this.indexed0 ) {
+ this.indexed0 = true;
+ swap( constraints,
+ 2,
+ 0 );
+ } else if ( depth >= 2 && this.indexed0 && !this.indexed1 ) {
+ this.indexed1 = true;
+ swap( constraints,
+ 2,
+ 1 );
+ } else if ( depth >= 3 ) {
+ this.indexed2 = true;
+ }
}
+
+ if ( i3 ) {
+ if ( depth >= 1 && !this.indexed0 ) {
+ this.indexed0 = true;
+ swap( constraints,
+ 3,
+ 0 );
+ } else if ( depth >= 2 && this.indexed0 && !this.indexed1 ) {
+ this.indexed1 = true;
+ swap( constraints,
+ 3,
+ 1 );
+ } else if ( depth >= 3 && this.indexed0 && this.indexed1 && !this.indexed2 ) {
+ this.indexed2 = true;
+ swap( constraints,
+ 3,
+ 2 );
+ } else {
+ throw new IllegalArgumentException( "There cannot be more than 3 indexes" );
+ }
+ }
}
+
this.constraint0 = constraints[0];
this.context0 = this.constraint0.getContextEntry();
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java 2006-10-27 01:17:40 UTC (rev 7162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/SingleBetaConstraints.java 2006-10-27 01:19:10 UTC (rev 7163)
@@ -18,6 +18,8 @@
import java.io.Serializable;
+import org.drools.RuleBase;
+import org.drools.RuleBaseConfiguration;
import org.drools.base.evaluators.Operator;
import org.drools.reteoo.BetaMemory;
import org.drools.reteoo.ReteTuple;
@@ -47,18 +49,17 @@
private ContextEntry context;
private boolean indexed;
+
+ public SingleBetaConstraints(final BetaNodeFieldConstraint constraint, RuleBaseConfiguration conf ) {
+ if (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) {
+ this.indexed = false;
+ } else {
+ int depth = conf.getCompositeKeyDepth();
+ // Determine if this constraint is indexable
+ this.indexed = depth >= 1 && isIndexable( constraint );
+ }
- public SingleBetaConstraints(final BetaNodeFieldConstraint constraint) {
- this( constraint, true );
- }
-
- public SingleBetaConstraints(final BetaNodeFieldConstraint constraint, boolean index ) {
this.constraint = constraint;
- // Determine if this constraint is indexable
- if ( index && isIndexable( constraint ) ) {
- this.indexed = true;
- }
-
this.context = constraint.getContextEntry();
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java 2006-10-27 01:17:40 UTC (rev 7162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/TripleBetaConstraints.java 2006-10-27 01:19:10 UTC (rev 7163)
@@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.List;
+import org.drools.RuleBaseConfiguration;
import org.drools.base.evaluators.Operator;
import org.drools.reteoo.BetaMemory;
import org.drools.reteoo.ReteTuple;
@@ -56,48 +57,50 @@
private boolean indexed1;
private boolean indexed2;
- public TripleBetaConstraints(final BetaNodeFieldConstraint[] constraints) {
- this( constraints,
- true );
- }
+ public TripleBetaConstraints(final BetaNodeFieldConstraint[] constraints, RuleBaseConfiguration conf) {
+ if (!conf.isIndexLeftBetaMemory() && !conf.isIndexRightBetaMemory()) {
+ this.indexed0 = false;
+ this.indexed1 = false;
+ this.indexed2 = false;
+ } else {
+ int depth = conf.getCompositeKeyDepth();
- public TripleBetaConstraints(final BetaNodeFieldConstraint[] constraints,
- boolean index) {
- final boolean i0 = index && isIndexable( constraints[0] );
- final boolean i1 = index && isIndexable( constraints[1] );
- final boolean i2 = index && isIndexable( constraints[2] );
-
- if ( i0 ) {
- this.indexed0 = true;
- }
-
- if ( i1 ) {
- if ( !i0 ) {
+ // Determine if this constraints are indexable
+ final boolean i0 = isIndexable( constraints[0] );
+ final boolean i1 = isIndexable( constraints[1] );
+ final boolean i2 = depth >= 3 && isIndexable( constraints[2] );
+
+ if ( depth >= 1 && i0 ) {
this.indexed0 = true;
- swap( constraints,
- 1,
- 0 );
- } else {
- this.indexed1 = true;
}
- }
-
- if ( i2 ) {
- if ( !i0 ) {
- this.indexed0 = true;
- swap( constraints,
- 2,
- 0 );
- } else if ( !i0 && !i1 ) {
- this.indexed1 = true;
- swap( constraints,
- 2,
- 1 );
- } else {
- this.indexed2 = true;
+
+ if ( i1 ) {
+ if ( depth >= 1 && !this.indexed0 ) {
+ this.indexed0 = true;
+ swap( constraints,
+ 1,
+ 0 );
+ } else if ( depth >= 2 ) {
+ this.indexed1 = true;
+ }
}
+
+ if ( i2 ) {
+ if ( depth >= 1 && !this.indexed0 ) {
+ this.indexed0 = true;
+ swap( constraints,
+ 2,
+ 0 );
+ } else if ( depth >= 2 && this.indexed0 && !this.indexed1 ) {
+ this.indexed1 = true;
+ swap( constraints,
+ 2,
+ 1 );
+ } else if ( depth >= 3 ) {
+ this.indexed2 = true;
+ }
+ }
}
-
this.constraint0 = constraints[0];
this.context0 = this.constraint0.getContextEntry();
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 2006-10-27 01:17:40 UTC (rev 7162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/reteoo/ReteooBuilder.java 2006-10-27 01:19:10 UTC (rev 7163)
@@ -831,26 +831,26 @@
}
}
- public static BetaConstraints createBetaNodeConstraint(final List list) {
+ public BetaConstraints createBetaNodeConstraint(final List list) {
BetaConstraints constraints;
switch ( list.size() ) {
case 0 :
constraints = EmptyBetaConstraints.getInstance();
break;
case 1 :
- constraints = new SingleBetaConstraints( (BetaNodeFieldConstraint) list.get( 0 ) );
+ constraints = new SingleBetaConstraints( (BetaNodeFieldConstraint) list.get( 0 ), this.ruleBase.getConfiguration() );
break;
case 2 :
- constraints = new DoubleBetaConstraints( (BetaNodeFieldConstraint[]) list.toArray( new BetaNodeFieldConstraint[list.size()] ) );
+ constraints = new DoubleBetaConstraints( (BetaNodeFieldConstraint[]) list.toArray( new BetaNodeFieldConstraint[list.size()] ), this.ruleBase.getConfiguration() );
break;
case 3 :
- constraints = new TripleBetaConstraints( (BetaNodeFieldConstraint[]) list.toArray( new BetaNodeFieldConstraint[list.size()] ) );
+ constraints = new TripleBetaConstraints( (BetaNodeFieldConstraint[]) list.toArray( new BetaNodeFieldConstraint[list.size()] ), this.ruleBase.getConfiguration() );
break;
case 4 :
- constraints = new QuadroupleBetaConstraints( (BetaNodeFieldConstraint[]) list.toArray( new BetaNodeFieldConstraint[list.size()] ) );
+ constraints = new QuadroupleBetaConstraints( (BetaNodeFieldConstraint[]) list.toArray( new BetaNodeFieldConstraint[list.size()] ), this.ruleBase.getConfiguration() );
break;
default :
- constraints = new DefaultBetaConstraints( (BetaNodeFieldConstraint[]) list.toArray( new BetaNodeFieldConstraint[list.size()] ) );
+ constraints = new DefaultBetaConstraints( (BetaNodeFieldConstraint[]) list.toArray( new BetaNodeFieldConstraint[list.size()] ), this.ruleBase.getConfiguration() );
}
return constraints;
}
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java 2006-10-27 01:17:40 UTC (rev 7162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/AbstractHashTable.java 2006-10-27 01:19:10 UTC (rev 7163)
@@ -368,8 +368,8 @@
}
public static class FieldIndex {
- public FieldExtractor extractor;
- public Declaration declaration;
+ FieldExtractor extractor;
+ Declaration declaration;
public Evaluator evaluator;
public FieldIndex(final FieldExtractor extractor,
Modified: labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java 2006-10-27 01:17:40 UTC (rev 7162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/util/TupleIndexHashTable.java 2006-10-27 01:19:10 UTC (rev 7163)
@@ -299,9 +299,6 @@
return current;
}
- // public boolean matches(int otherHashCode) {
- // return this.hashCode == otherHashCode && this.index.equal( this.first.getFactHandle().getObject() );
- // }
public boolean matches(final Object object,
final int objectHashCode) {
More information about the jboss-svn-commits
mailing list