directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r642588 - in /directory/sandbox/akarasulu/bigbang/apacheds: btree-base/src/main/java/org/apache/directory/server/xdbm/search/ xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/
Date Sat, 29 Mar 2008 19:23:10 GMT
Author: akarasulu
Date: Sat Mar 29 12:23:05 2008
New Revision: 642588

URL: http://svn.apache.org/viewvc?rev=642588&view=rev
Log:
added presence cursor and got module to compile 

  o new PresenceCursor added 
  o modifications made to DefaultSearchEngine for generics and fixing compiler
    errors
  o added proper close() method override tocleanup to all Cursors that had 
    wrapped Cursors - close super call first always to prevent inconsistencies
  o fixed various verbose useless if/else statements in some Cursors like 
    EqualityCursor, ApproximateCursor, GreaterEqCursor and LessEqCursor
  o added PresenceCursor to CursorBuilder
  o fixed compilation issues with ScopeEvaluator and generics

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java
    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/DefaultSearchEngine.java
    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/GreaterEqCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ScopeEvaluator.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java?rev=642588&r1=642587&r2=642588&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/xdbm/search/SearchEngine.java
Sat Mar 29 12:23:05 2008
@@ -84,7 +84,7 @@
      * @return enumeration over SearchResults
      * @throws Exception if the search fails
      */
-    Cursor<IndexEntry<Long,E>> search( LdapDN base,
+    Cursor<IndexEntry<?,E>> search( LdapDN base,
                                        AliasDerefMode aliasDerefMode,
                                        ExprNode filter,
                                        SearchControls searchCtls ) throws Exception;

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java?rev=642588&r1=642587&r2=642588&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/AndCursor.java
Sat Mar 29 12:23:05 2008
@@ -146,6 +146,13 @@
     }
 
 
+    public void close() throws Exception
+    {
+        super.close();
+        wrapped.close();
+    }
+
+
     /**
      * TODO - duplicate code from AndEvaluator just make utility for this and
      * for the same code in the OrEvaluator once done.

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=642588&r1=642587&r2=642588&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 12:23:05 2008
@@ -85,10 +85,8 @@
         {
             return userIdxCursor.available();
         }
-        else
-        {
-            return available;
-        }
+
+        return available;
     }
 
 
@@ -166,19 +164,17 @@
         {
             return userIdxCursor.previous();
         }
-        else
+
+        while( ndnIdxCursor.previous() )
         {
-            while( ndnIdxCursor.previous() )
+            IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+            if ( approximateEvaluator.evaluate( candidate ) )
             {
-                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( approximateEvaluator.evaluate( candidate ) )
-                {
-                     return available = true;
-                }
+                 return available = true;
             }
-
-            return available = false;
         }
+
+        return available = false;
     }
 
 
@@ -188,19 +184,17 @@
         {
             return userIdxCursor.next();
         }
-        else
+
+        while( ndnIdxCursor.next() )
         {
-            while( ndnIdxCursor.next() )
+            IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+            if ( approximateEvaluator.evaluate( candidate ) )
             {
-                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( approximateEvaluator.evaluate( candidate ) )
-                {
-                     return available = true;
-                }
+                 return available = true;
             }
-
-            return available = false;
         }
+
+        return available = false;
     }
 
 
@@ -210,15 +204,13 @@
         {
             return userIdxCursor.get();
         }
-        else
-        {
-            if ( available )
-            {
-                return ndnIdxCursor.get();
-            }
 
-            throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
+        if ( available )
+        {
+            return ndnIdxCursor.get();
         }
+
+        throw new InvalidCursorPositionException( "Cursor has not been positioned yet." );
     }
 
 
@@ -228,9 +220,22 @@
         {
             return userIdxCursor.isElementReused();
         }
+
+        return ndnIdxCursor.isElementReused();
+    }
+
+
+    public void close() throws Exception
+    {
+        super.close();
+
+        if ( userIdxCursor != null )
+        {
+            userIdxCursor.close();
+        }
         else
         {
-            return ndnIdxCursor.isElementReused();
+            ndnIdxCursor.close();
         }
     }
 }

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=642588&r1=642587&r2=642588&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 12:23:05 2008
@@ -78,7 +78,7 @@
             case LESSEQ:
                 return new LessEqCursor( db, ( LessEqEvaluator ) evaluatorBuilder.build(
node ) );
             case PRESENCE:
-                throw new NotImplementedException();
+                return new PresenceCursor( db, ( PresenceEvaluator ) evaluatorBuilder.build(
node ) );
             case SCOPE:
                 throw new NotImplementedException();
             case SUBSTRING:

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java?rev=642588&r1=642587&r2=642588&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/DefaultSearchEngine.java
Sat Mar 29 12:23:05 2008
@@ -21,6 +21,7 @@
 
 
 import javax.naming.directory.SearchControls;
+import javax.naming.directory.Attributes;
 
 import org.apache.directory.shared.ldap.filter.AndNode;
 import org.apache.directory.shared.ldap.filter.BranchNode;
@@ -41,16 +42,16 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class DefaultSearchEngine<E> implements SearchEngine<E>
+public class DefaultSearchEngine implements SearchEngine<Attributes>
 {
     /** the Optimizer used by this DefaultSearchEngine */
     private final Optimizer optimizer;
     /** the Database this DefaultSearchEngine operates on */
-    private Store<E> db;
+    private Store<Attributes> db;
     /** Evaluator flyweight used for filter expression assertions */
-    private Evaluator<E> evaluator;
+    private Evaluator<? extends ExprNode, Attributes> evaluator;
     /** CursorBuilder flyweight that creates enumerations on filter expressions */
-    private CursorBuilder<E> cursorBuilder;
+    private CursorBuilder cursorBuilder;
 
 
     // ------------------------------------------------------------------------
@@ -65,7 +66,9 @@
      * @param evaluator an expression evaluator
      * @param optimizer an optimizer to use during search
      */
-    public DefaultSearchEngine( Store<E> db, Evaluator<E> evaluator, CursorBuilder<E>
cursorBuilder, Optimizer optimizer )
+    public DefaultSearchEngine( Store<Attributes> db,
+                                Evaluator<? extends ExprNode, Attributes> evaluator,
+                                CursorBuilder cursorBuilder, Optimizer optimizer )
     {
         this.db = db;
         this.evaluator = evaluator;
@@ -85,7 +88,7 @@
     }
 
 
-    public Cursor<IndexEntry<Long,E>> search( LdapDN base, AliasDerefMode aliasDerefMode,
ExprNode filter, SearchControls searchCtls )
+    public Cursor<IndexEntry<?,Attributes>> search( LdapDN base, AliasDerefMode
aliasDerefMode, ExprNode filter, SearchControls searchCtls )
         throws Exception
     {
         LdapDN effectiveBase;
@@ -124,17 +127,17 @@
 
         // Annotate the node with the optimizer and return search enumeration.
         optimizer.annotate( root );
-        return cursorBuilder.enumerate( root );
+        return cursorBuilder.build( root );
     }
 
 
     /**
      * @see SearchEngine#evaluate(ExprNode, Long)
      */
-    public boolean evaluate( ExprNode ilter, Long id ) throws Exception
+    public boolean evaluate( ExprNode filter, Long id ) throws Exception
     {
-        IndexEntry<Long,E> rec = new ForwardIndexEntry<Long,E>();
+        IndexEntry<?,Attributes> rec = new ForwardIndexEntry<Object,Attributes>();
         rec.setId( id );
-        return evaluator.evaluate( ilter, rec );
+        return evaluator.evaluate( rec );
     }
 }

Modified: 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/EqualityCursor.java?rev=642588&r1=642587&r2=642588&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/EqualityCursor.java
Sat Mar 29 12:23:05 2008
@@ -83,10 +83,8 @@
         {
             return userIdxCursor.available();
         }
-        else
-        {
-            return available;
-        }
+
+        return available;
     }
 
 
@@ -164,19 +162,17 @@
         {
             return userIdxCursor.previous();
         }
-        else
+
+        while( ndnIdxCursor.previous() )
         {
-            while( ndnIdxCursor.previous() )
+            IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+            if ( equalityEvaluator.evaluate( candidate ) )
             {
-                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( equalityEvaluator.evaluate( candidate ) )
-                {
-                     return available = true;
-                }
+                 return available = true;
             }
-
-            return available = false;
         }
+
+        return available = false;
     }
 
 
@@ -186,19 +182,17 @@
         {
             return userIdxCursor.next();
         }
-        else
+
+        while( ndnIdxCursor.next() )
         {
-            while( ndnIdxCursor.next() )
+            IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+            if ( equalityEvaluator.evaluate( candidate ) )
             {
-                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( equalityEvaluator.evaluate( candidate ) )
-                {
-                     return available = true;
-                }
+                 return available = true;
             }
-
-            return available = false;
         }
+
+        return available = false;
     }
 
 
@@ -208,15 +202,13 @@
         {
             return userIdxCursor.get();
         }
-        else
-        {
-            if ( available )
-            {
-                return ndnIdxCursor.get();
-            }
 
-            throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
+        if ( available )
+        {
+            return ndnIdxCursor.get();
         }
+
+        throw new InvalidCursorPositionException( "Cursor has not been positioned yet." );
     }
 
 
@@ -226,9 +218,22 @@
         {
             return userIdxCursor.isElementReused();
         }
+
+        return ndnIdxCursor.isElementReused();
+    }
+
+
+    public void close() throws Exception
+    {
+        super.close();
+
+        if ( userIdxCursor != null )
+        {
+            userIdxCursor.close();
+        }
         else
         {
-            return ndnIdxCursor.isElementReused();
+            ndnIdxCursor.close();
         }
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.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?rev=642588&r1=642587&r2=642588&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/GreaterEqCursor.java
Sat Mar 29 12:23:05 2008
@@ -218,19 +218,17 @@
 
             return available = false;
         }
-        else
+
+        while( ndnIdxCursor.previous() )
         {
-            while( ndnIdxCursor.previous() )
+            IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+            if ( greaterEqEvaluator.evaluate( candidate ) )
             {
-                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( greaterEqEvaluator.evaluate( candidate ) )
-                {
-                     return available = true;
-                }
+                 return available = true;
             }
-
-            return available = false;
         }
+
+        return available = false;
     }
 
 
@@ -244,19 +242,17 @@
              */
             return available = userIdxCursor.next();
         }
-        else
+
+        while( ndnIdxCursor.next() )
         {
-            while( ndnIdxCursor.next() )
+            IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+            if ( greaterEqEvaluator.evaluate( candidate ) )
             {
-                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( greaterEqEvaluator.evaluate( candidate ) )
-                {
-                     return available = true;
-                }
+                 return available = true;
             }
-
-            return available = false;
         }
+
+        return available = false;
     }
 
 
@@ -271,15 +267,13 @@
 
             throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
         }
-        else
-        {
-            if ( available )
-            {
-                return ndnIdxCursor.get();
-            }
 
-            throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
+        if ( available )
+        {
+            return ndnIdxCursor.get();
         }
+
+        throw new InvalidCursorPositionException( "Cursor has not been positioned yet." );
     }
 
 
@@ -289,9 +283,22 @@
         {
             return userIdxCursor.isElementReused();
         }
+
+        return ndnIdxCursor.isElementReused();
+    }
+
+
+    public void close() throws Exception
+    {
+        super.close();
+
+        if ( userIdxCursor != null )
+        {
+            userIdxCursor.close();
+        }
         else
         {
-            return ndnIdxCursor.isElementReused();
+            ndnIdxCursor.close();
         }
     }
 }

Modified: 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=642588&r1=642587&r2=642588&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/LessEqCursor.java
Sat Mar 29 12:23:05 2008
@@ -220,19 +220,17 @@
              */
             return available = userIdxCursor.previous();
         }
-        else
+
+        while( ndnIdxCursor.previous() )
         {
-            while( ndnIdxCursor.previous() )
+            IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+            if ( lessEqEvaluator.evaluate( candidate ) )
             {
-                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( lessEqEvaluator.evaluate( candidate ) )
-                {
-                     return available = true;
-                }
+                 return available = true;
             }
-
-            return available = false;
         }
+
+        return available = false;
     }
 
 
@@ -258,19 +256,17 @@
 
             return available = false;
         }
-        else
+
+        while( ndnIdxCursor.next() )
         {
-            while( ndnIdxCursor.next() )
+            IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+            if ( lessEqEvaluator.evaluate( candidate ) )
             {
-                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
-                if ( lessEqEvaluator.evaluate( candidate ) )
-                {
-                     return available = true;
-                }
+                 return available = true;
             }
-
-            return available = false;
         }
+
+        return available = false;
     }
 
 
@@ -285,15 +281,13 @@
 
             throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
         }
-        else
-        {
-            if ( available )
-            {
-                return ndnIdxCursor.get();
-            }
 
-            throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
+        if ( available )
+        {
+            return ndnIdxCursor.get();
         }
+
+        throw new InvalidCursorPositionException( "Cursor has not been positioned yet." );
     }
 
 
@@ -303,9 +297,22 @@
         {
             return userIdxCursor.isElementReused();
         }
+
+        return ndnIdxCursor.isElementReused();
+    }
+
+
+    public void close() throws Exception
+    {
+        super.close();
+
+        if ( userIdxCursor != null )
+        {
+            userIdxCursor.close();
+        }
         else
         {
-            return ndnIdxCursor.isElementReused();
+            ndnIdxCursor.close();
         }
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java?rev=642588&r1=642587&r2=642588&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/NotCursor.java
Sat Mar 29 12:23:05 2008
@@ -144,4 +144,11 @@
     {
         return ndnCursor.isElementReused();
     }
+
+
+    public void close() throws Exception
+    {
+        super.close();
+        ndnCursor.close();
+    }
 }

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java?rev=642588&r1=642587&r2=642588&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/OrCursor.java
Sat Mar 29 12:23:05 2008
@@ -227,10 +227,10 @@
 
     public void close() throws Exception
     {
+        super.close();
         for ( Cursor cursor : cursors )
         {
             cursor.close();
         }
-        super.close();
     }
 }

Added: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java?rev=642588&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceCursor.java
Sat Mar 29 12:23:05 2008
@@ -0,0 +1,235 @@
+/*
+ *  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.core.cursor.AbstractCursor;
+import org.apache.directory.server.core.cursor.Cursor;
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
+import org.apache.directory.shared.ldap.schema.AttributeType;
+
+import javax.naming.directory.Attributes;
+
+
+/**
+ * A returning candidates satisfying an attribute presence expression.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $$Rev$$
+ */
+public class PresenceCursor extends AbstractCursor<IndexEntry<?, Attributes>>
+{
+    private static final String UNSUPPORTED_MSG =
+        "PresenceCursors do not support positioning by element without a user index on the
presence attribute.";
+    private final Cursor<IndexEntry<String,Attributes>> ndnCursor;
+    private final Cursor<IndexEntry<String,Attributes>> existenceCursor;
+    private final PresenceEvaluator presenceEvaluator;
+    private boolean available = false;
+
+
+    public PresenceCursor( Store<Attributes> db, PresenceEvaluator presenceEvaluator
) throws Exception
+    {
+        this.presenceEvaluator = presenceEvaluator;
+        AttributeType type = presenceEvaluator.getAttributeType();
+
+        if ( db.hasUserIndexOn( type.getOid() ) )
+        {
+            existenceCursor = db.getExistanceIndex().forwardCursor( type.getOid() );
+            ndnCursor = null;
+        }
+        else
+        {
+            existenceCursor = null;
+            ndnCursor = db.getNdnIndex().forwardCursor();
+        }
+    }
+
+
+    public boolean available()
+    {
+        if ( existenceCursor != null )
+        {
+            return existenceCursor.available();
+        }
+
+        return available;
+    }
+
+
+    public void before( IndexEntry<?, Attributes> element ) throws Exception
+    {
+        if ( existenceCursor != null )
+        {
+            //noinspection unchecked
+            existenceCursor.before( ( IndexEntry<String,Attributes> ) element );
+        }
+
+        throw new UnsupportedOperationException( UNSUPPORTED_MSG );
+    }
+
+
+    public void after( IndexEntry<?, Attributes> element ) throws Exception
+    {
+        if ( existenceCursor != null )
+        {
+            //noinspection unchecked
+            existenceCursor.after( ( IndexEntry<String,Attributes> ) element );
+        }
+
+        throw new UnsupportedOperationException( UNSUPPORTED_MSG );
+    }
+
+
+    public void beforeFirst() throws Exception
+    {
+        if ( existenceCursor != null )
+        {
+            existenceCursor.beforeFirst();
+        }
+
+        ndnCursor.beforeFirst();
+        available = false;
+    }
+
+
+    public void afterLast() throws Exception
+    {
+        if ( existenceCursor != null )
+        {
+            existenceCursor.afterLast();
+        }
+
+        ndnCursor.afterLast();
+        available = false;
+    }
+
+
+    public boolean first() throws Exception
+    {
+        if ( existenceCursor != null )
+        {
+            return existenceCursor.first();
+        }
+
+        beforeFirst();
+        return next();
+    }
+
+
+    public boolean last() throws Exception
+    {
+        if ( existenceCursor != null )
+        {
+            return existenceCursor.last();
+        }
+
+        afterLast();
+        return previous();
+    }
+
+
+    public boolean previous() throws Exception
+    {
+        if ( existenceCursor != null )
+        {
+            return existenceCursor.previous();
+        }
+
+        while ( ndnCursor.previous() )
+        {
+            IndexEntry<?,Attributes> candidate = ndnCursor.get();
+            if ( presenceEvaluator.evaluate( candidate ) )
+            {
+                return available = true;
+            }
+        }
+        
+        return available = false;
+    }
+
+
+    public boolean next() throws Exception
+    {
+        if ( existenceCursor != null )
+        {
+            return existenceCursor.next();
+        }
+
+        while ( ndnCursor.next() )
+        {
+            IndexEntry<?,Attributes> candidate = ndnCursor.get();
+            if ( presenceEvaluator.evaluate( candidate ) )
+            {
+                return available = true;
+            }
+        }
+
+        return available = false;
+    }
+
+
+    public IndexEntry<String, Attributes> get() throws Exception
+    {
+        if ( existenceCursor != null )
+        {
+            if ( existenceCursor.available() )
+            {
+                return existenceCursor.get();
+            }
+
+            throw new InvalidCursorPositionException( "Cursor has not been positioned yet."
);
+        }
+
+        if ( available )
+        {
+            return ndnCursor.get();
+        }
+
+        throw new InvalidCursorPositionException( "Cursor has not been positioned yet." );
+    }
+
+
+    public boolean isElementReused()
+    {
+        if ( existenceCursor != null )
+        {
+            return existenceCursor.isElementReused();
+        }
+
+        return ndnCursor.isElementReused();
+    }
+
+
+    public void close() throws Exception
+    {
+        super.close();
+
+        if ( existenceCursor != null )
+        {
+            existenceCursor.close();
+        }
+        else
+        {
+            ndnCursor.close();
+        }
+    }
+}

Modified: 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=642588&r1=642587&r2=642588&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/PresenceEvaluator.java
Sat Mar 29 12:23:05 2008
@@ -55,16 +55,15 @@
         this.db = db;
         this.node = node;
         this.registries = registries;
+        this.type = registries.getAttributeTypeRegistry().lookup( node.getAttribute() );
 
         if ( db.hasUserIndexOn( node.getAttribute() ) )
         {
             idx = db.getExistanceIndex();
-            type = null;
         }
         else
         {
             idx = null;
-            type = registries.getAttributeTypeRegistry().lookup( node.getAttribute() );
         }
     }
 
@@ -72,6 +71,12 @@
     public PresenceNode getExpression()
     {
         return node;
+    }
+
+
+    public AttributeType getAttributeType()
+    {
+        return type;
     }
 
 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ScopeEvaluator.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ScopeEvaluator.java?rev=642588&r1=642587&r2=642588&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ScopeEvaluator.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ScopeEvaluator.java
Sat Mar 29 12:23:05 2008
@@ -22,7 +22,6 @@
 
 import javax.naming.directory.SearchControls;
 
-import org.apache.directory.shared.ldap.filter.ExprNode;
 import org.apache.directory.shared.ldap.filter.ScopeNode;
 import org.apache.directory.shared.ldap.message.AliasDerefMode;
 import org.apache.directory.server.xdbm.Index;
@@ -36,45 +35,52 @@
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class ScopeEvaluator<E> implements Evaluator<E>
+public class ScopeEvaluator<E> implements Evaluator<ScopeNode,E>
 {
     /** Database used to evaluate scope with */
-    private Store<E> db;
+    private final Store<E> db;
+    private final ScopeNode node;
 
 
     /**
      * Creates a scope node evaluator for search expressions.
      *
+     * @param node the scope node
      * @param db the database used to evaluate scope node
      */
-    public ScopeEvaluator( Store<E> db )
+    public ScopeEvaluator( ScopeNode node , Store<E> db )
     {
         this.db = db;
+        this.node = node;
     }
 
 
     /**
-     * @see Evaluator#evaluate(ExprNode, org.apache.directory.server.xdbm.IndexEntry)
+     * @see Evaluator#evaluate(org.apache.directory.server.xdbm.IndexEntry)
      */
-    public boolean evaluate( ExprNode node, IndexEntry<Long,E> entry ) throws Exception
+    public boolean evaluate( IndexEntry<?,E> entry ) throws Exception
     {
-        ScopeNode snode = ( ScopeNode ) node;
-
-        switch ( snode.getScope() )
+        switch ( node.getScope() )
         {
             case ( SearchControls.OBJECT_SCOPE  ):
                 String dn = db.getEntryDn( entry.getId() );
-                return dn.equals( snode.getBaseDn() );
+                return dn.equals( node.getBaseDn() );
                 
             case ( SearchControls.ONELEVEL_SCOPE  ):
-                return assertOneLevelScope( snode, entry.getId() );
+                return assertOneLevelScope( node, entry.getId() );
             
             case ( SearchControls.SUBTREE_SCOPE  ):
-                return assertSubtreeScope( snode, entry.getId() );
+                return assertSubtreeScope( node, entry.getId() );
             
             default:
                 throw new IllegalStateException( "Unrecognized search scope!" );
         }
+    }
+
+
+    public ScopeNode getExpression()
+    {
+        return node;
     }
 
 



Mime
View raw message