directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r642565 - /directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/
Date Sat, 29 Mar 2008 17:40:30 GMT
Author: akarasulu
Date: Sat Mar 29 10:40:29 2008
New Revision: 642565

URL: http://svn.apache.org/viewvc?rev=642565&view=rev
Log:
initial implementation for LessEqCursor and GreaterEqCursor ...

  o added respective Cursors 
  o cleaned up CursorBuilder somewhat 
  o added creation of these Cursors to CursorBuilder
  o modified respective evaluators for these Cursors to expose access to 
    elements needed by them to perform proper evaluation
 

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java
      - copied, changed from r642550, directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.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

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java?rev=642565&r1=642564&r2=642565&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java
Sat Mar 29 10:40:29 2008
@@ -44,7 +44,7 @@
 public class ApproximateCursor extends AbstractCursor<IndexEntry<?, Attributes>>
 {
     private static final String UNSUPPORTED_MSG =
-        "EqualityCursors only support positioning by element when a user index exists on
the asserted attribute.";
+        "ApproximateCursors only support positioning by element when a user index exists
on the asserted attribute.";
 
     /** An approximate evaluator for candidates */
     private final ApproximateEvaluator approximateEvaluator;

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java?rev=642565&r1=642564&r2=642565&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java
Sat Mar 29 10:40:29 2008
@@ -23,35 +23,16 @@
 import java.util.List;
 import java.util.ArrayList;
 
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
 import javax.naming.directory.Attributes;
 
-import org.apache.directory.server.schema.registries.Registries;
-import org.apache.directory.server.xdbm.ForwardIndexEntry;
-import org.apache.directory.server.xdbm.Index;
 import org.apache.directory.server.xdbm.IndexEntry;
 import org.apache.directory.server.xdbm.Store;
-import org.apache.directory.server.core.partition.impl.btree.IndexAssertion;
-import org.apache.directory.server.core.partition.impl.btree.IndexAssertionEnumeration;
 import org.apache.directory.server.core.cursor.Cursor;
 import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.shared.ldap.filter.AndNode;
-import org.apache.directory.shared.ldap.filter.ApproximateNode;
-import org.apache.directory.shared.ldap.filter.AssertionNode;
-import org.apache.directory.shared.ldap.filter.BranchNode;
-import org.apache.directory.shared.ldap.filter.EqualityNode;
 import org.apache.directory.shared.ldap.filter.ExprNode;
-import org.apache.directory.shared.ldap.filter.ExtensibleNode;
-import org.apache.directory.shared.ldap.filter.GreaterEqNode;
-import org.apache.directory.shared.ldap.filter.LeafNode;
-import org.apache.directory.shared.ldap.filter.LessEqNode;
 import org.apache.directory.shared.ldap.filter.NotNode;
 import org.apache.directory.shared.ldap.filter.OrNode;
-import org.apache.directory.shared.ldap.filter.PresenceNode;
-import org.apache.directory.shared.ldap.filter.ScopeNode;
-import org.apache.directory.shared.ldap.filter.SimpleNode;
-import org.apache.directory.shared.ldap.filter.SubstringNode;
 
 
 /**
@@ -64,9 +45,9 @@
 {
     /** The database used by this builder */
     private Store<Attributes> db = null;
+
     /** Evaluator dependency on a EvaluatorBuilder */
     private EvaluatorBuilder evaluatorBuilder;
-    private final Registries registries;
 
 
     /**
@@ -74,15 +55,11 @@
      *
      * @param db database used by this enumerator
      * @param evaluatorBuilder the evaluator builder
-     * @param registries the schema registries
      */
-    public CursorBuilder( Store<Attributes> db,
-                          EvaluatorBuilder evaluatorBuilder,
-                          Registries registries )
+    public CursorBuilder( Store<Attributes> db, EvaluatorBuilder evaluatorBuilder )
     {
         this.db = db;
         this.evaluatorBuilder = evaluatorBuilder;
-        this.registries = registries;
     }
 
 
@@ -97,9 +74,9 @@
             case EQUALITY:
                 return new EqualityCursor( db, ( EqualityEvaluator ) evaluatorBuilder.build(
node ) );
             case GREATEREQ:
-                throw new NotImplementedException();
+                return new GreaterEqCursor( db, ( GreaterEqEvaluator ) evaluatorBuilder.build(
node ) );
             case LESSEQ:
-                throw new NotImplementedException();
+                return new LessEqCursor( db, ( LessEqEvaluator ) evaluatorBuilder.build(
node ) );
             case PRESENCE:
                 throw new NotImplementedException();
             case SCOPE:
@@ -129,95 +106,11 @@
 
 
     /**
-     * Creates an enumeration to enumerate through the set of candidates 
-     * satisfying a filter expression.
-     * 
-     * @param node a filter expression root
-     * @return an enumeration over the 
-     * @throws NamingException if database access fails
-     */
-    public NamingEnumeration<ForwardIndexEntry> enumerate( ExprNode node ) throws NamingException
-    {
-    	NamingEnumeration<ForwardIndexEntry> list = null;
-
-        if ( node instanceof ScopeNode )
-        {
-            list = scopeEnumerator.enumerate( node );
-        }
-        else if ( node instanceof AssertionNode )
-        {
-            throw new IllegalArgumentException( "Cannot produce enumeration " + "on an AssertionNode"
);
-        }
-        else if ( node.isLeaf() )
-        {
-            LeafNode leaf = ( LeafNode ) node;
-
-            if ( node instanceof PresenceNode )
-            {
-                list = enumPresence( ( PresenceNode ) node );
-            }
-            else if ( node instanceof EqualityNode )
-            {
-                list = enumEquality( ( EqualityNode ) node );
-            }
-            else if ( node instanceof GreaterEqNode )
-            {
-                list = enumGreaterOrLesser( ( SimpleNode ) node, SimpleNode.EVAL_GREATER
);
-            }
-            else if ( node instanceof LessEqNode )
-            {
-                list = enumGreaterOrLesser( ( SimpleNode ) node, SimpleNode.EVAL_LESSER );
-            }
-            else if ( node instanceof SubstringNode )
-            {
-                list = substringEnumerator.enumerate( leaf );
-            }
-            else if ( node instanceof ExtensibleNode )
-            {
-                // N O T   I M P L E M E N T E D   Y E T !
-                throw new NotImplementedException();
-            }
-            else if ( node instanceof ApproximateNode )
-            {
-                list = enumEquality( ( EqualityNode ) node );
-            }
-            else
-            {
-                throw new IllegalArgumentException( "Unknown leaf assertion" );
-            }
-        }
-        else
-        {
-            BranchNode branch = ( BranchNode ) node;
-
-            if ( node instanceof AndNode )
-            {
-                list = enumConj( (AndNode)branch );
-            }
-            else if ( node instanceof OrNode )
-            {
-                list = enumDisj( (OrNode)branch );
-            }
-            else if ( node instanceof NotNode )
-            {
-                list = enumNeg( (NotNode)branch );
-            }
-            else
-            {
-                throw new IllegalArgumentException( "Unknown branch logical operator" );
-            }
-        }
-
-        return list;
-    }
-
-
-    /**
      * Creates a OrCursor over a disjunction expression branch node.
      *
      * @param node the disjunction expression branch node
      * @return Cursor over candidates satisfying disjunction expression
-     * @throws Exception on db or registry access failures
+     * @throws Exception on db access failures
      */
     private Cursor<IndexEntry<?,Attributes>> buildOrCursor( OrNode node ) throws
Exception
     {
@@ -242,11 +135,13 @@
      *
      * @param node a conjunction expression branch node
      * @return Cursor over the conjunction expression
+     * @throws Exception on db access failures
      */
     private Cursor<IndexEntry<?,Attributes>> buildAndCursor( AndNode node ) throws
Exception
     {
         int minIndex = 0;
         long minValue = Long.MAX_VALUE;
+        //noinspection UnusedAssignment
         long value = Long.MAX_VALUE;
 
         /*
@@ -288,116 +183,58 @@
     }
 
 
-    /**
-     * Returns an enumeration over candidates that satisfy a presence attribute 
-     * value assertion.
-     * 
-     * @param node the presence AVA node
-     * @return an enumeration over the index records matching the AVA
-     * @throws NamingException if there is a failure while accessing the db
-     */
-    private NamingEnumeration<ForwardIndexEntry> enumPresence( final PresenceNode node
) throws NamingException
-    {
-        if ( db.hasUserIndexOn( node.getAttribute() ) )
-        {
-            Index idx = db.getExistanceIndex();
-            try
-            {
-                return idx.listIndices( node.getAttribute() );
-            }
-            catch ( java.io.IOException e )
-            {
-                e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-            }
-        }
-
-        return nonIndexedScan( node );
-    }
-
-
-    /**
-     * Returns an enumeration over candidates that satisfy a simple greater than
-     * or less than or equal to attribute value assertion.
-     * 
-     * @param node the AVA node
-     * @param isGreater true if >= false if <= is used
-     * @return an enumeration over the index records matching the AVA
-     * @throws NamingException if there is a failure while accessing the db
-     */
-    private NamingEnumeration<ForwardIndexEntry> enumGreaterOrLesser( final SimpleNode
node, final boolean isGreaterOrLesser ) throws NamingException
-    {
-        if ( db.hasUserIndexOn( node.getAttribute() ) )
-        {
-            Index idx = db.getUserIndex( node.getAttribute() );
-
-            try
-            {
-                return idx.listIndices( node.getValue(), isGreaterOrLesser );
-            }
-            catch ( java.io.IOException e )
-            {
-                e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-            }
-        }
-
-        return nonIndexedScan( node );
-    }
-
-
-    /**
-     * Returns an enumeration over candidates that satisfy a simple equality 
-     * attribute value assertion.
-     * 
-     * @param node the equality AVA node
-     * @return an enumeration over the index records matching the AVA
-     * @throws NamingException if there is a failure while accessing the db
-     */
-    private NamingEnumeration<ForwardIndexEntry> enumEquality( final EqualityNode node
) throws NamingException
-    {
-        if ( db.hasUserIndexOn( node.getAttribute() ) )
-        {
-            Index idx = db.getUserIndex( node.getAttribute() );
-            try
-            {
-                return idx.listIndices( node.getValue() );
-            }
-            catch ( java.io.IOException e )
-            {
-                e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-            }
-        }
-
-        return nonIndexedScan( node );
-    }
-
-
-    /**
-     * Creates a scan over all entries in the database with an assertion to test
-     * for the correct evaluation of a filter expression on a LeafNode.
-     * 
-     * @param node the leaf node to produce a scan over
-     * @return the enumeration over all perspective candidates satisfying expr
-     * @throws NamingException if db access failures result
-     */
-    private NamingEnumeration<ForwardIndexEntry> nonIndexedScan( final LeafNode node
) throws NamingException
-    {
-        try
-        {
-            NamingEnumeration<ForwardIndexEntry> underlying = db.getNdnIndex().listIndices();
-        }
-        catch ( java.io.IOException e )
-        {
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-        }
-
-        IndexAssertion assertion = new IndexAssertion()
-        {
-            public boolean assertCandidate( IndexEntry entry ) throws NamingException
-            {
-                return evaluatorBuilder.getLeafEvaluator().evaluate( node, entry );
-            }
-        };
-
-        return new IndexAssertionEnumeration( underlying, assertion );
-    }
+//    /**
+//     * Returns an enumeration over candidates that satisfy a presence attribute
+//     * value assertion.
+//     *
+//     * @param node the presence AVA node
+//     * @return an enumeration over the index records matching the AVA
+//     * @throws NamingException if there is a failure while accessing the db
+//     */
+//    private NamingEnumeration<ForwardIndexEntry> enumPresence( final PresenceNode
node ) throws NamingException
+//    {
+//        if ( db.hasUserIndexOn( node.getAttribute() ) )
+//        {
+//            Index idx = db.getExistanceIndex();
+//            try
+//            {
+//                return idx.listIndices( node.getAttribute() );
+//            }
+//            catch ( java.io.IOException e )
+//            {
+//                e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+//            }
+//        }
+//
+//        return nonIndexedScan( node );
+//    }
+//
+//
+//    /**
+//     * Returns an enumeration over candidates that satisfy a simple greater than
+//     * or less than or equal to attribute value assertion.
+//     *
+//     * @param node the AVA node
+//     * @param isGreater true if >= false if <= is used
+//     * @return an enumeration over the index records matching the AVA
+//     * @throws NamingException if there is a failure while accessing the db
+//     */
+//    private NamingEnumeration<ForwardIndexEntry> enumGreaterOrLesser( final SimpleNode
node, final boolean isGreaterOrLesser ) throws NamingException
+//    {
+//        if ( db.hasUserIndexOn( node.getAttribute() ) )
+//        {
+//            Index idx = db.getUserIndex( node.getAttribute() );
+//
+//            try
+//            {
+//                return idx.listIndices( node.getValue(), isGreaterOrLesser );
+//            }
+//            catch ( java.io.IOException e )
+//            {
+//                e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+//            }
+//        }
+//
+//        return nonIndexedScan( node );
+//    }
 }

Copied: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java
(from r642550, directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java?p2=directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java&p1=directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java&r1=642550&r2=642565&rev=642565&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java
Sat Mar 29 10:40:29 2008
@@ -22,6 +22,7 @@
 
 import org.apache.directory.server.xdbm.IndexEntry;
 import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
 import org.apache.directory.server.core.cursor.AbstractCursor;
 import org.apache.directory.server.core.cursor.Cursor;
 import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
@@ -30,22 +31,22 @@
 
 
 /**
- * A Cursor over entry candidates matching an equality assertion filter.  This
+ * A Cursor over entry candidates matching a GreaterEq assertion filter.  This
  * Cursor operates in two modes.  The first is when an index exists for the
- * attribute the equality assertion is built on.  The second is when the user
- * index for the assertion attribute does not exist.  Different Cursors are
- * used in each of these cases where the other remains null.
+ * attribute the assertion is built on.  The second is when the user index for
+ * the assertion attribute does not exist.  Different Cursors are used in each
+ * of these cases where the other remains null.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $$Rev$$
  */
-public class EqualityCursor extends AbstractCursor<IndexEntry<?, Attributes>>
+public class GreaterEqCursor extends AbstractCursor<IndexEntry<?, Attributes>>
 {
     private static final String UNSUPPORTED_MSG =
-        "EqualityCursors only support positioning by element when a user index exists on
the asserted attribute.";
+        "GreaterEqCursors only support positioning by element when a user index exists on
the asserted attribute.";
 
-    /** An equality evaluator for candidates */
-    private final EqualityEvaluator equalityEvaluator;
+    /** An greater eq evaluator for candidates */
+    private final GreaterEqEvaluator greaterEqEvaluator;
 
     /** Cursor over attribute entry matching filter: set when index present */
     private final Cursor<IndexEntry<?,Attributes>> userIdxCursor;
@@ -53,20 +54,19 @@
     /** NDN Cursor on all entries in  (set when no index on user attribute) */
     private final Cursor<IndexEntry<String,Attributes>> ndnIdxCursor;
 
-    /** used only when ndnIdxCursor is used (no index on attribute) */
+    /** used in both modes */
     private boolean available = false;
 
 
-    public EqualityCursor( Store<Attributes> db, EqualityEvaluator equalityEvaluator
) throws Exception
+    public GreaterEqCursor( Store<Attributes> db, GreaterEqEvaluator greaterEqEvaluator
) throws Exception
     {
-        this.equalityEvaluator = equalityEvaluator;
+        this.greaterEqEvaluator = greaterEqEvaluator;
 
-        String attribute = equalityEvaluator.getExpression().getAttribute();
-        Object value = equalityEvaluator.getExpression().getValue();
+        String attribute = greaterEqEvaluator.getExpression().getAttribute();
         if ( db.hasUserIndexOn( attribute ) )
         {
             //noinspection unchecked
-            userIdxCursor = db.getUserIndex( attribute ).forwardCursor( value );
+            userIdxCursor = db.getUserIndex( attribute ).forwardCursor();
             ndnIdxCursor = null;
         }
         else
@@ -79,14 +79,7 @@
 
     public boolean available()
     {
-        if ( userIdxCursor != null )
-        {
-            return userIdxCursor.available();
-        }
-        else
-        {
-            return available;
-        }
+        return available;
     }
 
 
@@ -94,7 +87,24 @@
     {
         if ( userIdxCursor != null )
         {
+            /*
+             * First we need to check and make sure this element is within
+             * bounds as mandated by the assertion node.  To do so we compare
+             * it's value with the value of the node.  If it is smaller or
+             * equal to this lower bound then we simply position the
+             * userIdxCursor before the first node.  Otherwise we let the
+             * underlying userIdx Cursor position the element.
+             */
+            //noinspection unchecked
+            if ( greaterEqEvaluator.getComparator().compare( element.getValue(),
+                 greaterEqEvaluator.getExpression().getValue() ) <= 0 )
+            {
+                beforeFirst();
+                return;
+            }
+
             userIdxCursor.before( element );
+            available = false;
         }
         else
         {
@@ -107,7 +117,33 @@
     {
         if ( userIdxCursor != null )
         {
+            //noinspection unchecked
+            int comparedValue = greaterEqEvaluator.getComparator().compare( element.getValue(),
+                 greaterEqEvaluator.getExpression().getValue() );
+
+            /*
+             * First we need to check and make sure this element is within
+             * bounds as mandated by the assertion node.  To do so we compare
+             * it's value with the value of the node.  If it is equal to this
+             * lower bound then we simply position the userIdxCursor after
+             * this first node.  If it is less than this value then we
+             * position the Cursor before the first entry.
+             */
+            if ( comparedValue == 0 )
+            {
+                userIdxCursor.after( element );
+                available = false;
+                return;
+            }
+            else if ( comparedValue < 0 )
+            {
+                beforeFirst();
+                return;
+            }
+
+            // Element is in the valid range as specified by assertion
             userIdxCursor.after( element );
+            available = false;
         }
         else
         {
@@ -120,13 +156,16 @@
     {
         if ( userIdxCursor != null )
         {
-            userIdxCursor.beforeFirst();
+            IndexEntry<Object,Attributes> advanceTo = new ForwardIndexEntry<Object,Attributes>();
+            advanceTo.setValue( greaterEqEvaluator.getExpression().getValue() );
+            userIdxCursor.before( advanceTo );
         }
         else
         {
             ndnIdxCursor.beforeFirst();
-            available = false;
         }
+
+        available = false;
     }
 
 
@@ -139,8 +178,9 @@
         else
         {
             ndnIdxCursor.afterLast();
-            available = false;
         }
+
+        available = false;
     }
 
 
@@ -162,14 +202,28 @@
     {
         if ( userIdxCursor != null )
         {
-            return userIdxCursor.previous();
+            /*
+             * We have to check and make sure the previous value complies by
+             * being greater than or eq to the expression node's value
+             */
+            while ( userIdxCursor.previous() )
+            {
+                IndexEntry<?,Attributes> candidate = userIdxCursor.get();
+                //noinspection unchecked
+                if ( greaterEqEvaluator.getComparator().compare( candidate.getValue(), greaterEqEvaluator.getExpression().getValue()
) >= 0 )
+                {
+                    return available = true;
+                }
+            }
+
+            return available = false;
         }
         else
         {
             while( ndnIdxCursor.previous() )
             {
                 IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( equalityEvaluator.evaluate( candidate ) )
+                if ( greaterEqEvaluator.evaluate( candidate ) )
                 {
                      return available = true;
                 }
@@ -184,14 +238,18 @@
     {
         if ( userIdxCursor != null )
         {
-            return userIdxCursor.next();
+            /*
+             * No need to do the same check that is done in previous() since
+             * values are increasing with calls to next().
+             */
+            return available = userIdxCursor.next();
         }
         else
         {
             while( ndnIdxCursor.next() )
             {
                 IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( equalityEvaluator.evaluate( candidate ) )
+                if ( greaterEqEvaluator.evaluate( candidate ) )
                 {
                      return available = true;
                 }
@@ -206,7 +264,12 @@
     {
         if ( userIdxCursor != null )
         {
-            return userIdxCursor.get();
+            if ( available )
+            {
+                return userIdxCursor.get();
+            }
+
+            throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
         }
         else
         {
@@ -231,4 +294,4 @@
             return ndnIdxCursor.isElementReused();
         }
     }
-}
+}
\ No newline at end of file

Modified: 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=642565&r1=642564&r2=642565&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqEvaluator.java
Sat Mar 29 10:40:29 2008
@@ -61,48 +61,63 @@
         this.db = db;
         this.node = node;
         this.registries = registries;
+        this.type = registries.getAttributeTypeRegistry().lookup( node.getAttribute() );
 
         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 );
-            }
+        /*
+         * 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();
 
-            normalizer = mr.getNormalizer();
-            comparator = mr.getComparator();
+        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 AttributeType getAttributeType()
+    {
+        return type;
+    }
+
+
+    public Normalizer getNormalizer()
+    {
+        return normalizer;
+    }
+
+
+    public Comparator getComparator()
+    {
+        return comparator;
     }
 
 

Added: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java?rev=642565&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java
Sat Mar 29 10:40:29 2008
@@ -0,0 +1,311 @@
+/*
+ *  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.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.Store;
+import org.apache.directory.server.xdbm.ForwardIndexEntry;
+import org.apache.directory.server.core.cursor.AbstractCursor;
+import org.apache.directory.server.core.cursor.Cursor;
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
+
+import javax.naming.directory.Attributes;
+
+
+/**
+ * A Cursor over entry candidates matching a LessEq assertion filter.  This
+ * Cursor operates in two modes.  The first is when an index exists for the
+ * attribute the assertion is built on.  The second is when the user index for
+ * the assertion attribute does not exist.  Different Cursors are used in each
+ * of these cases where the other remains null.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $$Rev$$
+ */
+public class LessEqCursor extends AbstractCursor<IndexEntry<?, Attributes>>
+{
+    private static final String UNSUPPORTED_MSG =
+        "LessEqCursors only support positioning by element when a user index exists on the
asserted attribute.";
+
+    /** An less eq evaluator for candidates */
+    private final LessEqEvaluator lessEqEvaluator;
+
+    /** Cursor over attribute entry matching filter: set when index present */
+    private final Cursor<IndexEntry<?,Attributes>> userIdxCursor;
+
+    /** NDN Cursor on all entries in  (set when no index on user attribute) */
+    private final Cursor<IndexEntry<String,Attributes>> ndnIdxCursor;
+
+    /** used in both modes */
+    private boolean available = false;
+
+
+    public LessEqCursor( Store<Attributes> db, LessEqEvaluator lessEqEvaluator ) throws
Exception
+    {
+        this.lessEqEvaluator = lessEqEvaluator;
+
+        String attribute = lessEqEvaluator.getExpression().getAttribute();
+        if ( db.hasUserIndexOn( attribute ) )
+        {
+            //noinspection unchecked
+            userIdxCursor = db.getUserIndex( attribute ).forwardCursor();
+            ndnIdxCursor = null;
+        }
+        else
+        {
+            ndnIdxCursor = db.getNdnIndex().forwardCursor();
+            userIdxCursor = null;
+        }
+    }
+
+
+    public boolean available()
+    {
+        return available;
+    }
+
+
+    public void before( IndexEntry<?, Attributes> element ) throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            /*
+             * First we need to check and make sure this element is within
+             * bounds as mandated by the assertion node.  To do so we compare
+             * it's value with the value of the expression node.  If the
+             * element's value is greater than this upper bound then we
+             * position the userIdxCursor after the last node.
+             *
+             * If the element's value is equal to this upper bound then we
+             * position the userIdxCursor right before the last node.
+             *
+             * If the element's value is smaller, then we delegate to the
+             * before() method of the userIdxCursor.
+             */
+            //noinspection unchecked
+            int compareValue = lessEqEvaluator.getComparator().compare( element.getValue(),
+                 lessEqEvaluator.getExpression().getValue() );
+
+            if ( compareValue > 0 )
+            {
+                afterLast();
+                return;
+            }
+            else if ( compareValue == 0 )
+            {
+                last();
+                previous();
+                available = false;
+                return;
+            }
+
+            userIdxCursor.before( element );
+            available = false;
+        }
+        else
+        {
+            throw new UnsupportedOperationException( UNSUPPORTED_MSG );
+        }
+    }
+
+
+    public void after( IndexEntry<?, Attributes> element ) throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            //noinspection unchecked
+            int comparedValue = lessEqEvaluator.getComparator().compare( element.getValue(),
+                 lessEqEvaluator.getExpression().getValue() );
+
+            /*
+             * First we need to check and make sure this element is within
+             * bounds as mandated by the assertion node.  To do so we compare
+             * it's value with the value of the expression node.
+             *
+             * If the element's value is equal to or greater than this upper
+             * bound then we position the userIdxCursor after the last node.
+             *
+             * If the element's value is smaller, then we delegate to the
+             * after() method of the userIdxCursor.
+             */
+            if ( comparedValue >= 0 )
+            {
+                afterLast();
+                return;
+            }
+
+            // Element is in the valid range as specified by assertion
+            userIdxCursor.after( element );
+            available = false;
+        }
+        else
+        {
+            throw new UnsupportedOperationException( UNSUPPORTED_MSG );
+        }
+    }
+
+
+    public void beforeFirst() throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            userIdxCursor.beforeFirst();
+        }
+        else
+        {
+            ndnIdxCursor.beforeFirst();
+        }
+
+        available = false;
+    }
+
+
+    public void afterLast() throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            IndexEntry<Object,Attributes> advanceTo = new ForwardIndexEntry<Object,Attributes>();
+            advanceTo.setValue( lessEqEvaluator.getExpression().getValue() );
+            userIdxCursor.after( advanceTo );
+        }
+        else
+        {
+            ndnIdxCursor.afterLast();
+        }
+
+        available = false;
+    }
+
+
+    public boolean first() throws Exception
+    {
+        beforeFirst();
+        return next();
+    }
+
+
+    public boolean last() throws Exception
+    {
+        afterLast();
+        return previous();
+    }
+
+
+    public boolean previous() throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            /*
+             * No need to do the same check that is done in next() since
+             * values are decreasing with calls to previous().  We will
+             * always have lesser values.
+             */
+            return available = userIdxCursor.previous();
+        }
+        else
+        {
+            while( ndnIdxCursor.previous() )
+            {
+                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+                if ( lessEqEvaluator.evaluate( candidate ) )
+                {
+                     return available = true;
+                }
+            }
+
+            return available = false;
+        }
+    }
+
+
+    public boolean next() throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            /*
+             * We have to check and make sure the next value complies by
+             * being less than or eq to the expression node's value.  We need
+             * to do this since values are increasing and we must limit to our
+             * upper bound.
+             */
+            while ( userIdxCursor.next() )
+            {
+                IndexEntry<?,Attributes> candidate = userIdxCursor.get();
+                //noinspection unchecked
+                if ( lessEqEvaluator.getComparator().compare( candidate.getValue(), lessEqEvaluator.getExpression().getValue()
) <= 0 )
+                {
+                    return available = true;
+                }
+            }
+
+            return available = false;
+        }
+        else
+        {
+            while( ndnIdxCursor.next() )
+            {
+                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+                if ( lessEqEvaluator.evaluate( candidate ) )
+                {
+                     return available = true;
+                }
+            }
+
+            return available = false;
+        }
+    }
+
+
+    public IndexEntry<?, Attributes> get() throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            if ( available )
+            {
+                return userIdxCursor.get();
+            }
+
+            throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
+        }
+        else
+        {
+            if ( available )
+            {
+                return ndnIdxCursor.get();
+            }
+
+            throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
+        }
+    }
+
+
+    public boolean isElementReused()
+    {
+        if ( userIdxCursor != null )
+        {
+            return userIdxCursor.isElementReused();
+        }
+        else
+        {
+            return ndnIdxCursor.isElementReused();
+        }
+    }
+}
\ No newline at end of file

Modified: 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=642565&r1=642564&r2=642565&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqEvaluator.java
Sat Mar 29 10:40:29 2008
@@ -38,7 +38,7 @@
 
 
 /**
- * An Evaluator which determines if candidates are matched by GreaterEqNode
+ * An Evaluator which determines if candidates are matched by LessEqNode
  * assertions.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
@@ -61,48 +61,63 @@
         this.db = db;
         this.node = node;
         this.registries = registries;
+        this.type = registries.getAttributeTypeRegistry().lookup( node.getAttribute() );
 
         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
);
-            }
+        /*
+         * 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();
 
-            normalizer = mr.getNormalizer();
-            comparator = mr.getComparator();
+        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 AttributeType getAttributeType()
+    {
+        return type;
+    }
+
+
+    public Normalizer getNormalizer()
+    {
+        return normalizer;
+    }
+
+
+    public Comparator getComparator()
+    {
+        return comparator;
     }
 
 



Mime
View raw message