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

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Fri Apr 20 13:26:09 EDT 2007


Author: tirelli
Date: 2007-04-20 13:26:09 -0400 (Fri, 20 Apr 2007)
New Revision: 11163

Added:
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/QuadroupleBetaConstraintsTest.java
Modified:
   labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java
   labs/jbossrules/trunk/drools-core/src/test/java/org/drools/Person.java
Log:
JBRULES-812: fixing indexing limitation

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	2007-04-20 17:03:23 UTC (rev 11162)
+++ labs/jbossrules/trunk/drools-core/src/main/java/org/drools/common/QuadroupleBetaConstraints.java	2007-04-20 17:26:09 UTC (rev 11163)
@@ -60,6 +60,7 @@
     private boolean                       indexed0;
     private boolean                       indexed1;
     private boolean                       indexed2;
+    private boolean                       indexed3;
 
     private RuleBaseConfiguration         conf;
 
@@ -70,6 +71,7 @@
             this.indexed0 = false;
             this.indexed1 = false;
             this.indexed2 = false;
+            this.indexed3 = false;
         } else {
             final int depth = conf.getCompositeKeyDepth();
 
@@ -126,8 +128,8 @@
                     swap( constraints,
                           3,
                           2 );
-                } else {
-                    throw new IllegalArgumentException( "There cannot be more than 3 indexes" );
+                } else if ( depth >= 4 ){
+                    this.indexed3 = true;
                 }
             }
         }
@@ -205,8 +207,8 @@
                                                                        object )) && (this.indexed1 || this.constraint1.isAllowedCachedLeft( this.context1,
                                                                                                                                             object )) && (this.indexed2 || this.constraint2.isAllowedCachedLeft( this.context2,
                                                                                                                                                                                                                  object ))
-               && this.constraint3.isAllowedCachedLeft( this.context3,
-                                                        object );
+               && (this.indexed3 || this.constraint3.isAllowedCachedLeft( this.context3,
+                                                        object ));
     }
 
     /* (non-Javadoc)
@@ -216,8 +218,8 @@
         return this.constraint0.isAllowedCachedRight( tuple,
                                                       this.context0 ) && this.constraint1.isAllowedCachedRight( tuple,
                                                                                                                 this.context1 ) && this.constraint2.isAllowedCachedRight( tuple,
-                                                                                                                                                                          this.context2 ) && this.constraint3.isAllowedCachedRight( tuple,
-                                                                                                                                                                                                                                    this.context3 );
+                                                                                                                                                                          this.context2 ) && ( this.indexed3 || this.constraint3.isAllowedCachedRight( tuple,
+                                                                                                                                                                                                                                    this.context3 ));
     }
 
     public boolean isIndexed() {
@@ -258,6 +260,14 @@
             list.add( index );
         }
 
+        if ( this.indexed3 ) {
+            final VariableConstraint variableConstraint = (VariableConstraint) this.constraint3;
+            final FieldIndex index = new FieldIndex( variableConstraint.getFieldExtractor(),
+                                                     variableConstraint.getRequiredDeclarations()[0],
+                                                     variableConstraint.getEvaluator() );
+            list.add( index );
+        }
+
         if ( !list.isEmpty() ) {
             final FieldIndex[] indexes = (FieldIndex[]) list.toArray( new FieldIndex[list.size()] );
             TupleMemory tupleMemory;

Modified: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/Person.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/Person.java	2007-04-20 17:03:23 UTC (rev 11162)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/Person.java	2007-04-20 17:26:09 UTC (rev 11163)
@@ -4,6 +4,11 @@
 
     private String name;
     private int    age;
+    
+    private String street;
+    private String city;
+    private String state;
+    private String country;
 
     public Person(final String name,
                   final int age) {
@@ -39,4 +44,36 @@
         this.name = name;
     }
 
+    public String getCity() {
+        return city;
+    }
+
+    public void setCity(String city) {
+        this.city = city;
+    }
+
+    public String getCountry() {
+        return country;
+    }
+
+    public void setCountry(String country) {
+        this.country = country;
+    }
+
+    public String getState() {
+        return state;
+    }
+
+    public void setState(String state) {
+        this.state = state;
+    }
+
+    public String getStreet() {
+        return street;
+    }
+
+    public void setStreet(String street) {
+        this.street = street;
+    }
+
 }

Added: labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/QuadroupleBetaConstraintsTest.java
===================================================================
--- labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/QuadroupleBetaConstraintsTest.java	                        (rev 0)
+++ labs/jbossrules/trunk/drools-core/src/test/java/org/drools/common/QuadroupleBetaConstraintsTest.java	2007-04-20 17:26:09 UTC (rev 11163)
@@ -0,0 +1,83 @@
+/**
+ * 
+ */
+package org.drools.common;
+
+import org.drools.Person;
+import org.drools.RuleBaseConfiguration;
+import org.drools.base.ClassFieldExtractorFactory;
+import org.drools.base.ClassObjectType;
+import org.drools.base.evaluators.Operator;
+import org.drools.base.evaluators.StringFactory;
+import org.drools.rule.Column;
+import org.drools.rule.Declaration;
+import org.drools.rule.VariableConstraint;
+import org.drools.spi.BetaNodeFieldConstraint;
+import org.drools.spi.Evaluator;
+import org.drools.spi.FieldExtractor;
+
+import junit.framework.TestCase;
+
+/**
+ * @author etirelli
+ *
+ */
+public class QuadroupleBetaConstraintsTest extends TestCase {
+
+    private RuleBaseConfiguration     conf;
+    private BetaNodeFieldConstraint[] constraints;
+
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#setUp()
+     */
+    protected void setUp() throws Exception {
+        conf = new RuleBaseConfiguration();
+
+        constraints = new BetaNodeFieldConstraint[4];
+        Class clazz = Person.class;
+        constraints[0] = getConstraint( "street",
+                                        clazz );
+        constraints[1] = getConstraint( "city",
+                                        clazz );
+        constraints[2] = getConstraint( "state",
+                                        clazz );
+        constraints[3] = getConstraint( "country",
+                                        clazz );
+        super.setUp();
+    }
+
+    private BetaNodeFieldConstraint getConstraint(String fieldName,
+                                                  Class clazz) {
+        FieldExtractor extractor = ClassFieldExtractorFactory.getClassFieldExtractor( clazz,
+                                                                                      fieldName );
+        Declaration declaration = new Declaration( fieldName,
+                                                   extractor,
+                                                   new Column( 0,
+                                                               new ClassObjectType( clazz ) ) );
+        Evaluator evaluator = StringFactory.getInstance().getEvaluator( Operator.EQUAL );
+        return new VariableConstraint( extractor,
+                                       declaration,
+                                       evaluator );
+    }
+
+    /* (non-Javadoc)
+     * @see junit.framework.TestCase#tearDown()
+     */
+    protected void tearDown() throws Exception {
+        super.tearDown();
+    }
+
+    /**
+     * Test method for {@link org.drools.common.QuadroupleBetaConstraints#QuadroupleBetaConstraints(org.drools.spi.BetaNodeFieldConstraint[], org.drools.RuleBaseConfiguration)}.
+     */
+    public void testQuadroupleBetaConstraints() {
+        try {
+            QuadroupleBetaConstraints qbc = new QuadroupleBetaConstraints( constraints,
+                                                                           conf );
+        } catch (Exception e) {
+            fail( "Should not raise any exception: "+e.getMessage());
+        }
+
+    }
+
+}




More information about the jboss-svn-commits mailing list