directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r642550 - in /directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl: ApproximateCursor.java CursorBuilder.java EqualityCursor.java
Date Sat, 29 Mar 2008 15:52:17 GMT
Author: akarasulu
Date: Sat Mar 29 08:52:15 2008
New Revision: 642550

URL: http://svn.apache.org/viewvc?rev=642550&view=rev
Log:
Adding equality and approximate match filters:

  o added both EqualityCursor and ApproximateCursor
  o filters work in dual modes: with a user index and without
  o approximate matching is not really supported so it falls back to using the
    same algorithm as an equality match: the two Cursors are copies of one 
    another and I don't like this but for now it works so we'll keep it like
    this until we can figure out a better way to refactor
  o added new cursors to be built by the CursorBuilder


Added:
    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/EqualityCursor.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/CursorBuilder.java

Added: 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=642550&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/ApproximateCursor.java
Sat Mar 29 08:52:15 2008
@@ -0,0 +1,236 @@
+/*
+ *  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 javax.naming.directory.Attributes;
+
+
+/**
+ * A Cursor over entry candidates matching an approximate assertion filter.
+ * This Cursor really is a copy of EqualityCursor for now but later on
+ * approximate matching can be implemented and this can change.  It operates
+ * in two modes.  The first is when an index exists for the attribute the
+ * approximate 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 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.";
+
+    /** An approximate evaluator for candidates */
+    private final ApproximateEvaluator approximateEvaluator;
+
+    /** 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 only when ndnIdxCursor is used (no index on attribute) */
+    private boolean available = false;
+
+
+    public ApproximateCursor( Store<Attributes> db, ApproximateEvaluator approximateEvaluator
) throws Exception
+    {
+        this.approximateEvaluator = approximateEvaluator;
+
+        String attribute = approximateEvaluator.getExpression().getAttribute();
+        Object value = approximateEvaluator.getExpression().getValue();
+        if ( db.hasUserIndexOn( attribute ) )
+        {
+            //noinspection unchecked
+            userIdxCursor = db.getUserIndex( attribute ).forwardCursor( value );
+            ndnIdxCursor = null;
+        }
+        else
+        {
+            ndnIdxCursor = db.getNdnIndex().forwardCursor();
+            userIdxCursor = null;
+        }
+    }
+
+
+    public boolean available()
+    {
+        if ( userIdxCursor != null )
+        {
+            return userIdxCursor.available();
+        }
+        else
+        {
+            return available;
+        }
+    }
+
+
+    public void before( IndexEntry<?, Attributes> element ) throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            userIdxCursor.before( element );
+        }
+        else
+        {
+            throw new UnsupportedOperationException( UNSUPPORTED_MSG );
+        }
+    }
+
+
+    public void after( IndexEntry<?, Attributes> element ) throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            userIdxCursor.after( element );
+        }
+        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 )
+        {
+            userIdxCursor.afterLast();
+        }
+        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 )
+        {
+            return userIdxCursor.previous();
+        }
+        else
+        {
+            while( ndnIdxCursor.previous() )
+            {
+                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+                if ( approximateEvaluator.evaluate( candidate ) )
+                {
+                     return available = true;
+                }
+            }
+
+            return available = false;
+        }
+    }
+
+
+    public boolean next() throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            return userIdxCursor.next();
+        }
+        else
+        {
+            while( ndnIdxCursor.next() )
+            {
+                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+                if ( approximateEvaluator.evaluate( candidate ) )
+                {
+                     return available = true;
+                }
+            }
+
+            return available = false;
+        }
+    }
+
+
+    public IndexEntry<?, Attributes> get() throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            return userIdxCursor.get();
+        }
+        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/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=642550&r1=642549&r2=642550&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 08:52:15 2008
@@ -58,7 +58,7 @@
  * Builds Cursors over candidates that satisfy a filter expression.
  * 
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
- * @version $Rev: 642490 $
+ * @version $Rev$
  */
 public class CursorBuilder
 {
@@ -93,9 +93,9 @@
             /* ---------- LEAF NODE HANDLING ---------- */
 
             case APPROXIMATE:
-                throw new NotImplementedException();
+                return new ApproximateCursor( db, ( ApproximateEvaluator ) evaluatorBuilder.build(
node ) );
             case EQUALITY:
-                throw new NotImplementedException();
+                return new EqualityCursor( db, ( EqualityEvaluator ) evaluatorBuilder.build(
node ) );
             case GREATEREQ:
                 throw new NotImplementedException();
             case LESSEQ:

Added: 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=642550&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/xdbm-search/src/main/java/org/apache/directory/server/xdbm/search/impl/EqualityCursor.java
Sat Mar 29 08:52:15 2008
@@ -0,0 +1,234 @@
+/*
+ *  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 javax.naming.directory.Attributes;
+
+
+/**
+ * A Cursor over entry candidates matching an equality 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.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $$Rev$$
+ */
+public class EqualityCursor 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.";
+
+    /** An equality evaluator for candidates */
+    private final EqualityEvaluator equalityEvaluator;
+
+    /** 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 only when ndnIdxCursor is used (no index on attribute) */
+    private boolean available = false;
+
+
+    public EqualityCursor( Store<Attributes> db, EqualityEvaluator equalityEvaluator
) throws Exception
+    {
+        this.equalityEvaluator = equalityEvaluator;
+
+        String attribute = equalityEvaluator.getExpression().getAttribute();
+        Object value = equalityEvaluator.getExpression().getValue();
+        if ( db.hasUserIndexOn( attribute ) )
+        {
+            //noinspection unchecked
+            userIdxCursor = db.getUserIndex( attribute ).forwardCursor( value );
+            ndnIdxCursor = null;
+        }
+        else
+        {
+            ndnIdxCursor = db.getNdnIndex().forwardCursor();
+            userIdxCursor = null;
+        }
+    }
+
+
+    public boolean available()
+    {
+        if ( userIdxCursor != null )
+        {
+            return userIdxCursor.available();
+        }
+        else
+        {
+            return available;
+        }
+    }
+
+
+    public void before( IndexEntry<?, Attributes> element ) throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            userIdxCursor.before( element );
+        }
+        else
+        {
+            throw new UnsupportedOperationException( UNSUPPORTED_MSG );
+        }
+    }
+
+
+    public void after( IndexEntry<?, Attributes> element ) throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            userIdxCursor.after( element );
+        }
+        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 )
+        {
+            userIdxCursor.afterLast();
+        }
+        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 )
+        {
+            return userIdxCursor.previous();
+        }
+        else
+        {
+            while( ndnIdxCursor.previous() )
+            {
+                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+                if ( equalityEvaluator.evaluate( candidate ) )
+                {
+                     return available = true;
+                }
+            }
+
+            return available = false;
+        }
+    }
+
+
+    public boolean next() throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            return userIdxCursor.next();
+        }
+        else
+        {
+            while( ndnIdxCursor.next() )
+            {
+                IndexEntry<?,Attributes> candidate = ndnIdxCursor.get();
+                if ( equalityEvaluator.evaluate( candidate ) )
+                {
+                     return available = true;
+                }
+            }
+
+            return available = false;
+        }
+    }
+
+
+    public IndexEntry<?, Attributes> get() throws Exception
+    {
+        if ( userIdxCursor != null )
+        {
+            return userIdxCursor.get();
+        }
+        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();
+        }
+    }
+}



Mime
View raw message