directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r642490 - in /directory/sandbox/akarasulu/bigbang: apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ shared/ldap/src/main/java/org/apache/directory/shared/ldap/filter/
Date Sat, 29 Mar 2008 02:22:18 GMT
Author: akarasulu
Date: Fri Mar 28 19:22:16 2008
New Revision: 642490

URL: http://svn.apache.org/viewvc?rev=642490&view=rev
Log:
Adding leaf node based evaluators ...
 
 o corrected doco in LeafNode - nothing major
 o changing generics on Evaluator interface to include type for ExprNode
 o added new Evaluators
    - GreaterEqEvaluator
    - LessEqEvaluator
    - EqualityEvaluator
    - PresenceEvaluator
 o generic changes to SubstringEvaluator to match changes in Evaluator interface
 o removed cast in SubstringCursor
 o other changes don't matter
 

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionCursorBuilder.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionEvaluatorBuilder.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
    directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LeafNode.java

Added: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java?rev=642490&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityEvaluator.java
Fri Mar 28 19:22:16 2008
@@ -0,0 +1,177 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.server.xdbm.search.impl;
+
+
+import org.apache.directory.shared.ldap.filter.EqualityNode;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.schema.registries.Registries;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingEnumeration;
+import java.util.Iterator;
+import java.util.Comparator;
+
+
+/**
+ * An Evaluator which determines if candidates are matched by GreaterEqNode
+ * assertions.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class EqualityEvaluator implements Evaluator<EqualityNode, Attributes>
+{
+    private final EqualityNode node;
+    private final Store<Attributes> db;
+    private final Registries registries;
+    private final AttributeType type;
+    private final Normalizer normalizer;
+    private final Comparator comparator;
+    private final Index<Number,Attributes> idx;
+
+
+    public EqualityEvaluator( EqualityNode node, Store<Attributes> db, Registries registries
)
+        throws Exception
+    {
+        this.db = db;
+        this.node = node;
+        this.registries = registries;
+
+        if ( db.hasUserIndexOn( node.getAttribute() ) )
+        {
+            //noinspection unchecked
+            idx = db.getUserIndex( node.getAttribute() );
+            type = null;
+            normalizer = null;
+            comparator = null;
+        }
+        else
+        {
+            idx = null;
+            type = registries.getAttributeTypeRegistry().lookup( node.getAttribute() );
+
+            MatchingRule mr = type.getEquality();
+
+            if ( mr == null )
+            {
+                throw new IllegalStateException(
+                    "Could not find matchingRule to use for EqualityNode evaluation: " +
node );
+            }
+
+            normalizer = mr.getNormalizer();
+            comparator = mr.getComparator();
+        }
+    }
+
+
+    public EqualityNode getExpression()
+    {
+        return node;
+    }
+
+
+    public boolean evaluate( IndexEntry<?,Attributes> indexEntry ) throws Exception
+    {
+        if ( idx != null )
+        {
+            return idx.has( ( Number ) indexEntry.getValue(), indexEntry.getId() );
+        }
+
+        Attributes entry = indexEntry.getObject();
+
+        // resuscitate the entry if it has not been and set entry in IndexEntry
+        if ( null == entry )
+        {
+            entry = db.lookup( indexEntry.getId() );
+            indexEntry.setObject( entry );
+        }
+
+        // get the attribute
+        Attribute attr = AttributeUtils.getAttribute( entry, type );
+
+        // if the attribute does not exist just return false
+        if ( attr != null && evaluate( attr ) )
+        {
+            return true;
+        }
+
+        // If we do not have the attribute, loop through the sub classes of
+        // the attributeType.  Perhaps the entry has an attribute value of a
+        // subtype (descendant) that will produce a match
+        if ( registries.getAttributeTypeRegistry().hasDescendants( node.getAttribute() )
)
+        {
+            // TODO check to see if descendant handling is necessary for the
+            // index so we can match properly even when for example a name
+            // attribute is used instead of more specific commonName
+            Iterator<AttributeType> descendants =
+                registries.getAttributeTypeRegistry().descendants( node.getAttribute() );
+
+            while ( descendants.hasNext() )
+            {
+                AttributeType descendant = descendants.next();
+
+                attr = AttributeUtils.getAttribute( entry, descendant );
+
+                if ( attr != null && evaluate( attr ) )
+                {
+                    return true;
+                }
+            }
+        }
+
+        // we fell through so a match was not found - assertion was false.
+        return false;
+    }
+
+
+    private boolean evaluate( Attribute attribute ) throws Exception
+    {
+        /*
+         * Cycle through the attribute values testing normalized version
+         * obtained from using the ordering or equality matching rule's
+         * normalizer.  The test uses the comparator obtained from the
+         * appropriate matching rule to perform the check.
+         */
+        NamingEnumeration values = attribute.getAll();
+
+        while ( values.hasMore() )
+        {
+            Object value = normalizer.normalize( values.next() );
+
+            // Once match is found cleanup and return true
+            //noinspection unchecked
+            if ( comparator.compare( value, node.getValue() ) == 0 )
+            {
+                values.close();
+                return true;
+            }
+        }
+
+        return false;
+    }
+}
\ No newline at end of file

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java?rev=642490&r1=642489&r2=642490&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/Evaluator.java
Fri Mar 28 19:22:16 2008
@@ -30,7 +30,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public interface Evaluator<E>
+public interface Evaluator<N extends ExprNode,E>
 {
     /**
      * Evaluates a candidate to determine if a filter expression selects it.
@@ -47,5 +47,5 @@
      *
      * @return the AST for the expression
      */
-    ExprNode getExpression();
+    N getExpression();
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionCursorBuilder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionCursorBuilder.java?rev=642490&r1=642489&r2=642490&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionCursorBuilder.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionCursorBuilder.java
Fri Mar 28 19:22:16 2008
@@ -24,6 +24,7 @@
 
 import javax.naming.NamingEnumeration;
 import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
 
 import org.apache.directory.server.schema.registries.AttributeTypeRegistry;
 import org.apache.directory.server.xdbm.ForwardIndexEntry;
@@ -63,10 +64,8 @@
     private Store<E> db = null;
     /** CursorBuilder flyweight for evaulating filter scope assertions */
     private ScopeCursorBuilder<E> scopeEnumerator;
-    /** CursorBuilder flyweight for evaulating filter substring assertions */
-    private SubstringCursorBuilder<E> substringEnumerator;
     /** Evaluator dependency on a ExpressionEvaluatorBuilder */
-    private ExpressionEvaluatorBuilder<E> evaluatorBuilder;
+    private ExpressionEvaluatorBuilder<Attributes> evaluatorBuilder;
 
 
     /**

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionEvaluatorBuilder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionEvaluatorBuilder.java?rev=642490&r1=642489&r2=642490&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionEvaluatorBuilder.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ExpressionEvaluatorBuilder.java
Fri Mar 28 19:22:16 2008
@@ -21,9 +21,10 @@
 
 
 import javax.naming.NamingException;
+import javax.naming.directory.Attributes;
 
 import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.shared.ldap.filter.AndNode;
 import org.apache.directory.shared.ldap.filter.BranchNode;
 import org.apache.directory.shared.ldap.filter.ExprNode;
@@ -37,70 +38,43 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ExpressionEvaluatorBuilder implements EvaluatorBuilder
+public class ExpressionEvaluatorBuilder implements EvaluatorBuilder<Attributes>
 {
-    /** Leaf Evaluator flyweight use for leaf filter assertions */
-    private LeafEvaluator leafEvaluator;
+    private final Store<Attributes> db;
+    private final Registries registries;
 
 
     // ------------------------------------------------------------------------
     // C O N S T R U C T O R S
     // ------------------------------------------------------------------------
 
-    /**
-     * Creates a top level Evaluator where leaves are delegated to a leaf node
-     * evaluator which is already provided.
-     *
-     * @param leafEvaluator handles leaf node evaluation.
-     */
-    public ExpressionEvaluatorBuilder(LeafEvaluator leafEvaluator)
-    {
-        this.leafEvaluator = leafEvaluator;
-    }
-
 
     /**
      * Creates a top level Evaluator where leaves are delegated to a leaf node
      * evaluator which will be created.
      *
      * @param db the database this evaluator operates upon
-     * @param oidRegistry the oid reg used for attrID to oid resolution
-     * @param attributeTypeRegistry the attribtype reg used for value comparison
-     */
-    public ExpressionEvaluatorBuilder(BTreePartition db, Registries registries )
-    {
-        ScopeEvaluator scopeEvaluator = null;
-        SubstringEvaluator substringEvaluator = null;
-
-        scopeEvaluator = new ScopeEvaluator( db );
-        substringEvaluator = new SubstringEvaluator( db, registries );
-        leafEvaluator = new LeafEvaluator( db, registries, scopeEvaluator, substringEvaluator
);
-    }
-
-
-    /**
-     * Gets the leaf evaluator used by this top level expression evaluator.
-     *
-     * @return the leaf evaluator used by this top level expression evaluator
      */
-    public LeafEvaluator getLeafEvaluator()
+    public ExpressionEvaluatorBuilder( Store<Attributes> db, Registries registries
) throws Exception
     {
-        return leafEvaluator;
+        this.db = db;
+        this.registries = registries;
     }
 
 
     // ------------------------------------------------------------------------
-    // Evaluator.evaluate() implementation
+    // EvaluatorBuilder.build() implementation
     // ------------------------------------------------------------------------
 
+
     /**
-     * @see Evaluator#evaluate(ExprNode, IndexEntry)
+     * @see EvaluatorBuilder#build(ExprNode)
      */
-    public boolean evaluate( ExprNode node, IndexEntry entry ) throws NamingException
+    public Evaluator<Attributes> build( ExprNode node ) throws NamingException
     {
         if ( node.isLeaf() )
         {
-            return leafEvaluator.evaluate( node, entry );
+            return new LeafEvaluator( node );
         }
 
         BranchNode bnode = ( BranchNode ) node;

Added: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java?rev=642490&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java
Fri Mar 28 19:22:16 2008
@@ -0,0 +1,188 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.server.xdbm.search.impl;
+
+
+import org.apache.directory.shared.ldap.filter.GreaterEqNode;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.schema.registries.Registries;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingEnumeration;
+import java.util.Iterator;
+import java.util.Comparator;
+
+
+/**
+ * An Evaluator which determines if candidates are matched by GreaterEqNode
+ * assertions.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class GreaterEqEvaluator implements Evaluator<GreaterEqNode, Attributes>
+{
+    private final GreaterEqNode node;
+    private final Store<Attributes> db;
+    private final Registries registries;
+    private final AttributeType type;
+    private final Normalizer normalizer;
+    private final Comparator comparator;
+    private final Index<Number,Attributes> idx;
+
+
+    public GreaterEqEvaluator( GreaterEqNode node, Store<Attributes> db, Registries
registries )
+        throws Exception
+    {
+        this.db = db;
+        this.node = node;
+        this.registries = registries;
+
+        if ( db.hasUserIndexOn( node.getAttribute() ) )
+        {
+            //noinspection unchecked
+            idx = db.getUserIndex( node.getAttribute() );
+            type = null;
+            normalizer = null;
+            comparator = null;
+        }
+        else
+        {
+            idx = null;
+            type = registries.getAttributeTypeRegistry().lookup( node.getAttribute() );
+
+            /*
+             * We prefer matching using the Normalizer and Comparator pair from
+             * the ordering matchingRule if one is available.  It may very well
+             * not be.  If so then we resort to using the Normalizer and
+             * Comparator from the equality matchingRule as a last resort.
+             */
+            MatchingRule mr = type.getOrdering();
+
+            if ( mr == null )
+            {
+                mr = type.getEquality();
+            }
+
+            if ( mr == null )
+            {
+                throw new IllegalStateException(
+                    "Could not find matchingRule to use for GreaterEqNode evaluation: " +
node );
+            }
+
+            normalizer = mr.getNormalizer();
+            comparator = mr.getComparator();
+        }
+    }
+
+
+    public GreaterEqNode getExpression()
+    {
+        return node;
+    }
+
+
+    public boolean evaluate( IndexEntry<?,Attributes> indexEntry ) throws Exception
+    {
+        if ( idx != null )
+        {
+            return idx.hasGreaterOrEqual( ( Number ) indexEntry.getValue(), indexEntry.getId()
);
+        }
+
+        Attributes entry = indexEntry.getObject();
+
+        // resuscitate the entry if it has not been and set entry in IndexEntry
+        if ( null == entry )
+        {
+            entry = db.lookup( indexEntry.getId() );
+            indexEntry.setObject( entry );
+        }
+
+        // get the attribute
+        Attribute attr = AttributeUtils.getAttribute( entry, type );
+
+        // if the attribute does not exist just return false
+        if ( attr != null && evaluate( attr ) )
+        {
+            return true;
+        }
+
+        // If we do not have the attribute, loop through the sub classes of
+        // the attributeType.  Perhaps the entry has an attribute value of a
+        // subtype (descendant) that will produce a match
+        if ( registries.getAttributeTypeRegistry().hasDescendants( node.getAttribute() )
)
+        {
+            // TODO check to see if descendant handling is necessary for the
+            // index so we can match properly even when for example a name
+            // attribute is used instead of more specific commonName
+            Iterator<AttributeType> descendants =
+                registries.getAttributeTypeRegistry().descendants( node.getAttribute() );
+
+            while ( descendants.hasNext() )
+            {
+                AttributeType descendant = descendants.next();
+
+                attr = AttributeUtils.getAttribute( entry, descendant );
+
+                if ( attr != null && evaluate( attr ) )
+                {
+                    return true;
+                }
+            }
+        }
+
+        // we fell through so a match was not found - assertion was false.
+        return false;
+    }
+
+
+    private boolean evaluate( Attribute attribute ) throws Exception
+    {
+        /*
+         * Cycle through the attribute values testing normalized version
+         * obtained from using the ordering or equality matching rule's
+         * normalizer.  The test uses the comparator obtained from the
+         * appropriate matching rule to perform the check.
+         */
+        NamingEnumeration values = attribute.getAll();
+
+        while ( values.hasMore() )
+        {
+            Object value = normalizer.normalize( values.next() );
+
+            // Once match is found cleanup and return true
+            //noinspection unchecked
+            if ( comparator.compare( value, node.getValue() ) >= 0 )
+            {
+                values.close();
+                return true;
+            }
+        }
+
+        return false;
+    }
+}

Added: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java?rev=642490&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java
Fri Mar 28 19:22:16 2008
@@ -0,0 +1,188 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.server.xdbm.search.impl;
+
+
+import org.apache.directory.shared.ldap.filter.LessEqNode;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.shared.ldap.schema.MatchingRule;
+import org.apache.directory.shared.ldap.schema.Normalizer;
+import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.schema.registries.Registries;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import javax.naming.NamingEnumeration;
+import java.util.Iterator;
+import java.util.Comparator;
+
+
+/**
+ * An Evaluator which determines if candidates are matched by GreaterEqNode
+ * assertions.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LessEqEvaluator implements Evaluator<LessEqNode, Attributes>
+{
+    private final LessEqNode node;
+    private final Store<Attributes> db;
+    private final Registries registries;
+    private final AttributeType type;
+    private final Normalizer normalizer;
+    private final Comparator comparator;
+    private final Index<Number,Attributes> idx;
+
+
+    public LessEqEvaluator( LessEqNode node, Store<Attributes> db, Registries registries
)
+        throws Exception
+    {
+        this.db = db;
+        this.node = node;
+        this.registries = registries;
+
+        if ( db.hasUserIndexOn( node.getAttribute() ) )
+        {
+            //noinspection unchecked
+            idx = db.getUserIndex( node.getAttribute() );
+            type = null;
+            normalizer = null;
+            comparator = null;
+        }
+        else
+        {
+            idx = null;
+            type = registries.getAttributeTypeRegistry().lookup( node.getAttribute() );
+
+            /*
+             * We prefer matching using the Normalizer and Comparator pair from
+             * the ordering matchingRule if one is available.  It may very well
+             * not be.  If so then we resort to using the Normalizer and
+             * Comparator from the equality matchingRule as a last resort.
+             */
+            MatchingRule mr = type.getOrdering();
+
+            if ( mr == null )
+            {
+                mr = type.getEquality();
+            }
+
+            if ( mr == null )
+            {
+                throw new IllegalStateException(
+                    "Could not find matchingRule to use for LessEqNode evaluation: " + node
);
+            }
+
+            normalizer = mr.getNormalizer();
+            comparator = mr.getComparator();
+        }
+    }
+
+
+    public LessEqNode getExpression()
+    {
+        return node;
+    }
+
+
+    public boolean evaluate( IndexEntry<?,Attributes> indexEntry ) throws Exception
+    {
+        if ( idx != null )
+        {
+            return idx.hasLessOrEqual( ( Number ) indexEntry.getValue(), indexEntry.getId()
);
+        }
+
+        Attributes entry = indexEntry.getObject();
+
+        // resuscitate the entry if it has not been and set entry in IndexEntry
+        if ( null == entry )
+        {
+            entry = db.lookup( indexEntry.getId() );
+            indexEntry.setObject( entry );
+        }
+
+        // get the attribute
+        Attribute attr = AttributeUtils.getAttribute( entry, type );
+
+        // if the attribute does not exist just return false
+        if ( attr != null && evaluate( attr ) )
+        {
+            return true;
+        }
+
+        // If we do not have the attribute, loop through the sub classes of
+        // the attributeType.  Perhaps the entry has an attribute value of a
+        // subtype (descendant) that will produce a match
+        if ( registries.getAttributeTypeRegistry().hasDescendants( node.getAttribute() )
)
+        {
+            // TODO check to see if descendant handling is necessary for the
+            // index so we can match properly even when for example a name
+            // attribute is used instead of more specific commonName
+            Iterator<AttributeType> descendants =
+                registries.getAttributeTypeRegistry().descendants( node.getAttribute() );
+
+            while ( descendants.hasNext() )
+            {
+                AttributeType descendant = descendants.next();
+
+                attr = AttributeUtils.getAttribute( entry, descendant );
+
+                if ( attr != null && evaluate( attr ) )
+                {
+                    return true;
+                }
+            }
+        }
+
+        // we fell through so a match was not found - assertion was false.
+        return false;
+    }
+
+
+    private boolean evaluate( Attribute attribute ) throws Exception
+    {
+        /*
+         * Cycle through the attribute values testing normalized version
+         * obtained from using the ordering or equality matching rule's
+         * normalizer.  The test uses the comparator obtained from the
+         * appropriate matching rule to perform the check.
+         */
+        NamingEnumeration values = attribute.getAll();
+
+        while ( values.hasMore() )
+        {
+            Object value = normalizer.normalize( values.next() );
+
+            // Once match is found cleanup and return true
+            //noinspection unchecked
+            if ( comparator.compare( value, node.getValue() ) <= 0 )
+            {
+                values.close();
+                return true;
+            }
+        }
+
+        return false;
+    }
+}
\ No newline at end of file

Added: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java?rev=642490&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java
Fri Mar 28 19:22:16 2008
@@ -0,0 +1,130 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.apache.directory.server.xdbm.search.impl;
+
+
+import org.apache.directory.shared.ldap.filter.PresenceNode;
+import org.apache.directory.shared.ldap.util.AttributeUtils;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.Index;
+import org.apache.directory.server.schema.registries.Registries;
+
+import javax.naming.directory.Attributes;
+import javax.naming.directory.Attribute;
+import java.util.Iterator;
+
+
+/**
+ * An Evaluator which determines if candidates are matched by GreaterEqNode
+ * assertions.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class PresenceEvaluator implements Evaluator<PresenceNode, Attributes>
+{
+    private final PresenceNode node;
+    private final Store<Attributes> db;
+    private final Registries registries;
+    private final AttributeType type;
+    private final Index<String,Attributes> idx;
+
+
+    public PresenceEvaluator( PresenceNode node, Store<Attributes> db, Registries registries
)
+        throws Exception
+    {
+        this.db = db;
+        this.node = node;
+        this.registries = registries;
+
+        if ( db.hasUserIndexOn( node.getAttribute() ) )
+        {
+            idx = db.getExistanceIndex();
+            type = null;
+        }
+        else
+        {
+            idx = null;
+            type = registries.getAttributeTypeRegistry().lookup( node.getAttribute() );
+        }
+    }
+
+
+    public PresenceNode getExpression()
+    {
+        return node;
+    }
+
+
+    public boolean evaluate( IndexEntry<?,Attributes> indexEntry ) throws Exception
+    {
+        if ( idx != null )
+        {
+            return idx.has( type.getOid(), indexEntry.getId() );
+        }
+
+        Attributes entry = indexEntry.getObject();
+
+        // resuscitate the entry if it has not been and set entry in IndexEntry
+        if ( null == entry )
+        {
+            entry = db.lookup( indexEntry.getId() );
+            indexEntry.setObject( entry );
+        }
+
+        // get the attribute
+        Attribute attr = AttributeUtils.getAttribute( entry, type );
+
+        // if the attribute exists just return true
+        if ( attr != null )
+        {
+            return true;
+        }
+
+        // If we do not have the attribute, loop through the sub classes of
+        // the attributeType.  Perhaps the entry has an attribute value of a
+        // subtype (descendant) that will produce a match
+        if ( registries.getAttributeTypeRegistry().hasDescendants( node.getAttribute() )
)
+        {
+            // TODO check to see if descendant handling is necessary for the
+            // index so we can match properly even when for example a name
+            // attribute is used instead of more specific commonName
+            Iterator<AttributeType> descendants =
+                registries.getAttributeTypeRegistry().descendants( node.getAttribute() );
+
+            while ( descendants.hasNext() )
+            {
+                AttributeType descendant = descendants.next();
+
+                attr = AttributeUtils.getAttribute( entry, descendant );
+
+                if ( attr != null )
+                {
+                    return true;
+                }
+            }
+        }
+
+        // we fell through so a match was not found - assertion was false.
+        return false;
+    }
+}
\ No newline at end of file

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java?rev=642490&r1=642489&r2=642490&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringCursor.java
Fri Mar 28 19:22:16 2008
@@ -50,7 +50,7 @@
     public SubstringCursor( Store<Attributes> db,
                             final SubstringEvaluator substringEvaluator ) throws Exception
     {
-        SubstringNode node = ( SubstringNode ) substringEvaluator.getExpression();
+        SubstringNode node = substringEvaluator.getExpression();
 
         if ( db.hasUserIndexOn( node.getAttribute() ) )
         {

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java?rev=642490&r1=642489&r2=642490&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/SubstringEvaluator.java
Fri Mar 28 19:22:16 2008
@@ -32,7 +32,6 @@
 import org.apache.directory.server.xdbm.IndexEntry;
 import org.apache.directory.server.xdbm.Store;
 import org.apache.directory.server.core.cursor.Cursor;
-import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.SubstringNode;
 import org.apache.directory.shared.ldap.schema.AttributeType;
 import org.apache.directory.shared.ldap.schema.MatchingRule;
@@ -46,7 +45,7 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class SubstringEvaluator implements Evaluator<Attributes>
+public class SubstringEvaluator implements Evaluator<SubstringNode,Attributes>
 {
     /** Database used while evaluating candidates */
     private final Store<Attributes> db;
@@ -64,7 +63,7 @@
 
     private final Normalizer normalizer;
 
-    private final Index idx;
+    private final Index<String,Attributes> idx;
 
 
     /**
@@ -97,6 +96,7 @@
 
         if ( db.hasUserIndexOn( node.getAttribute() ) )
         {
+            //noinspection unchecked
             idx = db.getUserIndex( node.getAttribute() );
         }
         else
@@ -129,7 +129,7 @@
     }
 
 
-    public ExprNode getExpression()
+    public SubstringNode getExpression()
     {
         return node;
     }
@@ -143,8 +143,7 @@
          * Otherwise we would have to scan the entire index if there were
          * no reverse lookups.
          */
-        //noinspection unchecked
-        Cursor<IndexEntry<?,Attributes>> entries = idx.reverseCursor( indexEntry.getId()
);
+        Cursor<IndexEntry<String,Attributes>> entries = idx.reverseCursor( indexEntry.getId()
);
 
         // cycle through the attribute values testing for a match
         while ( entries.next() )

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LeafNode.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LeafNode.java?rev=642490&r1=642489&r2=642490&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LeafNode.java
(original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/filter/LeafNode.java
Fri Mar 28 19:22:16 2008
@@ -36,7 +36,6 @@
      * Creates a leaf node.
      * 
      * @param attribute the attribute this node is based on
-     * @param type the type of this leaf node
      */
     protected LeafNode( String attribute )
     {
@@ -109,11 +108,12 @@
             return false;
         }
 
+        //noinspection SimplifiableIfStatement
         if ( other.getClass() != this.getClass() )
         {
         	return false;
         }
-            
+
         return attribute.equals( ( ( LeafNode ) other ).getAttribute() );
     }
 



Mime
View raw message