directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 47611 - incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db
Date Thu, 30 Sep 2004 22:25:31 GMT
Author: akarasulu
Date: Thu Sep 30 15:25:30 2004
New Revision: 47611

Added:
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/package.html   (contents,
props changed)
Removed:
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ConjunctionEnumerator.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/DisjunctionEnumerator.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/NegationEnumerator.java
Modified:
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEnumerator.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEvaluator.java
   incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/LeafEvaluator.java
Log:
Commit changes ...

 o moved functionality in branch node enumerators into ExpressionEnumerator
   - ConjuctionEnumerator deleted func moved into ExpressionEnumerator
   - DisjuctionEnumerator deleted func moved into ExpressionEnumerator
   - NegationEnumerator deleted func moved into ExpressionEnumerator
 o added a package.html 
 o cleaned up other enumerators



Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEnumerator.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEnumerator.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEnumerator.java
Thu Sep 30 15:25:30 2004
@@ -30,6 +30,9 @@
 import org.apache.ldap.common.filter.SubstringNode;
 import org.apache.ldap.common.NotImplementedException;
 
+import java.util.ArrayList;
+import java.math.BigInteger;
+
 
 /**
  * Enumerates over candidates that satisfy a filter expression.
@@ -45,31 +48,24 @@
     private ScopeEnumerator scopeEnumerator;
     /** Enumerator flyweight for evaulating filter substring assertions */
     private SubstringEnumerator substringEnumerator;
-    /** Enumerator flyweight for evaulating filter conjunction assertions */
-    private ConjunctionEnumerator conjunctionEnumerator;
-    /** Enumerator flyweight for evaulating filter disjunction assertions */
-    private DisjunctionEnumerator disjunctionEnumerator;
-    /** Enumerator flyweight for evaulating filter negation assertions */
-    private NegationEnumerator negationEnumerator;
-    /** Evaluator dependency on a LeafNode leafEvaluator */
-    private LeafEvaluator leafEvaluator;
-
-
-    public ExpressionEnumerator( Database db,
-                           LeafEvaluator leafEvaluator,
-                           ScopeEnumerator scopeEnumerator,
-                           NegationEnumerator negationEnumerator,
-                           SubstringEnumerator substringEnumerator,
-                           ConjunctionEnumerator conjunctionEnumerator,
-                           DisjunctionEnumerator disjunctionEnumerator )
+    /** Evaluator dependency on a ExpressionEvaluator */
+    private ExpressionEvaluator evaluator;
+
+
+    /**
+     * Creates an expression tree enumerator.
+     *
+     * @param db database used by this enumerator
+     * @param evaluator
+     */
+    public ExpressionEnumerator( Database db, ExpressionEvaluator evaluator )
     {
         this.db = db;
-        this.leafEvaluator = leafEvaluator;
-        this.scopeEnumerator = scopeEnumerator;
-        this.negationEnumerator = negationEnumerator;
-        this.substringEnumerator = substringEnumerator;
-        this.conjunctionEnumerator = conjunctionEnumerator;
-        this.disjunctionEnumerator = disjunctionEnumerator;
+        this.evaluator = evaluator;
+
+        LeafEvaluator leafEvaluator = evaluator.getLeafEvaluator();
+        scopeEnumerator = new ScopeEnumerator( db, leafEvaluator.getScopeEvaluator() );
+        substringEnumerator = new SubstringEnumerator( db, leafEvaluator.getSubstringEvaluator()
);
     }
 
 
@@ -133,13 +129,13 @@
             switch( branch.getOperator() )
             {
             case( BranchNode.AND ):
-                list = conjunctionEnumerator.enumerate( branch );
+                list = enumConj( branch );
                 break;
             case( BranchNode.NOT ):
-                list = negationEnumerator.enumerate( branch );
+                list = enumNeg( branch );
                 break;
             case( BranchNode.OR ):
-                list = disjunctionEnumerator.enumerate( branch );
+                list = enumDisj( branch );
                 break;
             default:
                 throw new IllegalArgumentException( 
@@ -150,7 +146,126 @@
         return list;
     }
 
-    
+
+    /**
+     *
+     */
+    public NamingEnumeration enumDisj( ExprNode node ) throws NamingException
+    {
+        ArrayList children = ( ( BranchNode ) node ).getChildren();
+        NamingEnumeration [] childEnumerations = new NamingEnumeration [children.size()];
+
+        // Recursively create NamingEnumerations for each child expression node
+        for ( int ii = 0; ii < childEnumerations.length; ii++ )
+        {
+            childEnumerations[ii] = enumerate( ( ExprNode ) children.get( ii ) );
+        }
+
+        return new DisjunctionEnumeration( childEnumerations );
+    }
+
+
+    /**
+     *
+     */
+    private NamingEnumeration enumNeg( final BranchNode node ) throws NamingException
+    {
+        Index idx = null;
+        NamingEnumeration childEnumeration = null;
+        NamingEnumeration enumeration = null;
+
+        // Iterates over entire set of index values
+        if ( node.getChild().isLeaf() )
+        {
+            LeafNode child = ( LeafNode ) node.getChild();
+            idx = db.getUserIndex( child.getAttribute() );
+            childEnumeration = idx.listIndices();
+        }
+        // Iterates over the entire set of entries
+        else
+        {
+            idx = db.getNdnIndex();
+            childEnumeration = idx.listIndices();
+        }
+
+
+        IndexAssertion assertion = new IndexAssertion()
+        {
+            public boolean assertCandidate( IndexRecord rec ) throws NamingException
+            {
+                // NOTICE THE ! HERE
+                // The candidate is valid if it does not pass assertion. A
+                // candidate that passes assertion is therefore invalid.
+                return ! evaluator.evaluate( node.getChild(), rec );
+            }
+        };
+
+        enumeration = new IndexAssertionEnumeration( childEnumeration, assertion, true );
+        return enumeration;
+    }
+
+
+    /**
+     *
+     */
+    private NamingEnumeration enumConj( final BranchNode node ) throws NamingException
+    {
+        int minIndex = 0;
+        int minValue = Integer.MAX_VALUE;
+        int value = Integer.MAX_VALUE;
+
+        /*
+         * We scan the child nodes of a branch node searching for the child
+         * expression node with the smallest scan count.  This is the child
+         * we will use for iteration by creating a NamingEnumeration over its
+         * expression.
+         */
+        final ArrayList children = node.getChildren();
+        for ( int ii = 0; ii < children.size(); ii++ )
+        {
+            ExprNode child = ( ExprNode ) children.get( ii );
+            value = ( ( BigInteger ) child.get( "count" ) ).intValue();
+            minValue = Math.min( minValue, value );
+
+            if ( minValue == value )
+            {
+                minIndex = ii;
+            }
+        }
+
+        // Once found we build the child enumeration & the wrapping enum
+        final ExprNode minChild = ( ExprNode ) children.get( minIndex );
+        IndexAssertion assertion = new IndexAssertion()
+        {
+            public boolean assertCandidate( IndexRecord rec ) throws NamingException
+            {
+                for ( int ii = 0; ii < children.size(); ii++ )
+                {
+                    ExprNode child = ( ExprNode ) children.get( ii );
+
+                    // Skip the child (with min scan count) chosen for enum
+                    if ( child == minChild )
+                    {
+                        continue;
+                    }
+                    else if ( ! evaluator.evaluate( child, rec ) )
+                    {
+                        return false;
+                    }
+                }
+
+                return true;
+            }
+        };
+
+        // Do recursive call to build child enumeration then wrap and return
+        NamingEnumeration underlying = enumerate( minChild );
+        IndexAssertionEnumeration iae;
+        iae = new IndexAssertionEnumeration( underlying, assertion );
+        return iae;
+    }
+
+
     /**
      * Returns an enumeration over candidates that satisfy a presence attribute 
      * value assertion.
@@ -240,7 +355,7 @@
             public boolean assertCandidate( IndexRecord record ) 
                 throws NamingException
             {
-                return leafEvaluator.evaluate( node, record );
+                return evaluator.getLeafEvaluator().evaluate( node, record );
             }
         };
         

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEvaluator.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEvaluator.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/ExpressionEvaluator.java
Thu Sep 30 15:25:30 2004
@@ -23,6 +23,8 @@
 
 import org.apache.ldap.common.filter.ExprNode;
 import org.apache.ldap.common.filter.BranchNode;
+import org.apache.eve.schema.NormalizerRegistry;
+import org.apache.eve.schema.ComparatorRegistry;
 
 
 /**
@@ -115,5 +117,28 @@
             throw new NamingException( "Unrecognized branch node operator: "
                 + node.getOperator() );
         }
+    }
+
+
+    public LeafEvaluator getLeafEvaluator()
+    {
+        return leafEvaluator;
+    }
+
+
+    public static ExpressionEvaluator create( Database db,
+                                              NormalizerRegistry normReg,
+                                              ComparatorRegistry compReg )
+    {
+        LeafEvaluator leafEvaluator = null;
+        ScopeEvaluator scopeEvaluator = null;
+        SubstringEvaluator substringEvaluator = null;
+
+        scopeEvaluator = new ScopeEvaluator( db );
+        substringEvaluator = new SubstringEvaluator( db, normReg );
+        leafEvaluator = new LeafEvaluator( db, scopeEvaluator, normReg,
+            compReg, substringEvaluator );
+
+        return new ExpressionEvaluator( leafEvaluator );
     }
 }

Modified: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/LeafEvaluator.java
==============================================================================
--- incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/LeafEvaluator.java
(original)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/LeafEvaluator.java
Thu Sep 30 15:25:30 2004
@@ -80,11 +80,34 @@
     }
 
 
+    public ScopeEvaluator getScopeEvaluator()
+    {
+        return scopeEvaluator;
+    }
+
+
+    public NormalizerRegistry getNormalizerRegistry()
+    {
+        return normalizerRegistry;
+    }
+
+
+    public ComparatorRegistry getComparatorRegistry()
+    {
+        return comparatorRegistry;
+    }
+
+
+    public SubstringEvaluator getSubstringEvaluator()
+    {
+        return substringEvaluator;
+    }
+
+
     /**
      * @see org.apache.eve.db.Evaluator#evaluate(ExprNode, IndexRecord)
      */
-    public boolean evaluate( ExprNode node, IndexRecord record )
-        throws NamingException
+    public boolean evaluate( ExprNode node, IndexRecord record ) throws NamingException
     {
         if ( node instanceof ScopeNode )
         {

Added: incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/package.html
==============================================================================
--- (empty file)
+++ incubator/directory/eve/trunk/backend/core/src/java/org/apache/eve/db/package.html	Thu
Sep 30 15:25:30 2004
@@ -0,0 +1,5 @@
+
+<p>
+</p>
+
+

Mime
View raw message