directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r607563 - in /directory/sandbox/akarasulu/bigbang/apacheds: btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ core-cursor/src/main/java/org/apache/directory/server/core/cursor/ jdbm-cursor/src/main/java/org/apa...
Date Sun, 30 Dec 2007 17:29:36 GMT
Author: akarasulu
Date: Sun Dec 30 09:29:28 2007
New Revision: 607563

URL: http://svn.apache.org/viewvc?rev=607563&view=rev
Log:
check pointing work done while traveling on cursors

Added:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/BTreeRedirect.java
      - copied, changed from r607324, directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirect.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursor.java
  (contents, props changed)
      - copied, changed from r607324, directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/keyonly/KeyCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/TupleCursor.java
      - copied, changed from r607324, directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/TupleCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
  (with props)
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/resources/
Removed:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/TupleCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/keyonly/
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/keyonly/
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/NoDupsCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/Cursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/EmptyCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/IteratorCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/ListCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/SingletonCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/NoDupsCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/NoDupsCursor.java?rev=607563&r1=607562&r2=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/NoDupsCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/NoDupsCursor.java
Sun Dec 30 09:29:28 2007
@@ -100,6 +100,12 @@
     }
 
 
+    public boolean available()
+    {
+        throw new NotImplementedException();
+    }
+
+
     public void before( Tuple element ) throws IOException
     {
         throw new NotImplementedException();

Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java?rev=607563&r1=607562&r2=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/ValueArrayCursor.java
Sun Dec 30 09:29:28 2007
@@ -73,6 +73,12 @@
     }
 
 
+    public boolean available()
+    {
+        return inRangeOnValue();
+    }
+
+
     public void before( Tuple element ) throws IOException
     {
         throw new NotImplementedException();

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/Cursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/Cursor.java?rev=607563&r1=607562&r2=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/Cursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/Cursor.java
Sun Dec 30 09:29:28 2007
@@ -43,6 +43,14 @@
 public interface Cursor<E>
 {
     /**
+     * Determines whether or not a call to get() will succeed.
+     *
+     * @return true if the cursor is valid get() will succeed, false otherwise
+     */
+    boolean available();
+
+
+    /**
      * Prepares this Cursor, so a subsequent call to Cursor#next() with a
      * true return value, will have positioned the Cursor on a dataset element
      * equal to or greater than the element argument but not less.  A call to
@@ -135,7 +143,10 @@
 
 
     /**
-     * Advances this Cursor to the previous position.
+     * Advances this Cursor to the previous position.  If called before
+     * explicitly positioning this Cursor, the position is presumed to be
+     * after the last element and this method moves the cursor back to the
+     * last element.
      *
      * @return true if the advance succeeded, false otherwise
      * @throws IOException if there are problems advancing to the next position
@@ -145,7 +156,10 @@
 
 
     /**
-     * Advances this Cursor to the next position.
+     * Advances this Cursor to the next position.  If called before
+     * explicitly positioning this Cursor, the position is presumed to be
+     * before the first element and this method moves the cursor forward to
+     * the first element.
      *
      * @return true if the advance succeeded, false otherwise
      * @throws IOException if there are problems advancing to this Cursor to

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/EmptyCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/EmptyCursor.java?rev=607563&r1=607562&r2=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/EmptyCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/EmptyCursor.java
Sun Dec 30 09:29:28 2007
@@ -30,6 +30,11 @@
  */
 public class EmptyCursor<E> extends AbstractCursor<E>
 {
+    public boolean available()
+    {
+        return false;
+    }
+
     public void before( E element ) throws IOException
     {
         checkClosed( "before()" );

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/IteratorCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/IteratorCursor.java?rev=607563&r1=607562&r2=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/IteratorCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/IteratorCursor.java
Sun Dec 30 09:29:28 2007
@@ -40,6 +40,12 @@
     }
 
 
+    public boolean available()
+    {
+        return current != null;    
+    }
+    
+
     public void before( E element ) throws IOException
     {
         throw new UnsupportedOperationException( "Cannot advance before an element on the
underlying Iterator." );

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/ListCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/ListCursor.java?rev=607563&r1=607562&r2=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/ListCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/ListCursor.java
Sun Dec 30 09:29:28 2007
@@ -187,6 +187,12 @@
     }
 
 
+    public boolean available()
+    {
+        return index >= 0 && index < end;
+    }
+
+
     /**
      * @throws IllegalStateException if the underlying list is not sorted
      * and/or a comparator is not provided.
@@ -218,14 +224,6 @@
         }
 
         throw new NotImplementedException( "don't know if list is sorted and checking that
is not worth it" );
-
-        // check if increasing or decreasing order is in effect
-//        if ( comparator.compare( list.get( 0 ), list.get( list.size() - 1 ) ) > 0 )
-//        {
-//        }
-//        else
-//        {
-//        }
     }
 
 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/SingletonCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/SingletonCursor.java?rev=607563&r1=607562&r2=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/SingletonCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/core-cursor/src/main/java/org/apache/directory/server/core/cursor/SingletonCursor.java
Sun Dec 30 09:29:28 2007
@@ -51,6 +51,12 @@
     }
 
 
+    public boolean available()
+    {
+        return onSingleton;
+    }
+    
+
     public void before( E element ) throws IOException
     {
         checkClosed( "before()" );

Copied: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/BTreeRedirect.java
(from r607324, directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirect.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/BTreeRedirect.java?p2=directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/BTreeRedirect.java&p1=directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirect.java&r1=607324&r2=607563&rev=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirect.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/BTreeRedirect.java
Sun Dec 30 09:29:28 2007
@@ -17,14 +17,14 @@
  *  under the License. 
  *  
  */
-package org.apache.directory.server.core.partition.impl.btree.jdbm;
+package org.apache.directory.server.core.partition.impl.btree.jdbm.cursor;
 
 import java.io.Serializable;
 
 
 /**
  * A redirection pointer to another BTree.
- * 
+ *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
@@ -34,20 +34,20 @@
 
     private Long recId;
 
-    
+
     public BTreeRedirect()
     {
     }
 
-    
+
     public BTreeRedirect( long recId )
     {
         this.recId = new Long( recId );
     }
-    
-    
+
+
     public Long getRecId()
     {
         return recId;
     }
-}
+}
\ No newline at end of file

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java?rev=607563&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsCursor.java
Sun Dec 30 09:29:28 2007
@@ -0,0 +1,269 @@
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
+
+
+import jdbm.helper.Tuple;
+import jdbm.btree.BTree;
+import org.apache.directory.server.core.cursor.AbstractCursor;
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
+import org.apache.directory.server.core.cursor.Cursor;
+import org.apache.directory.server.core.cursor.ListCursor;
+import org.apache.directory.server.core.partition.impl.btree.TupleComparator;
+import org.apache.directory.shared.ldap.NotImplementedException;
+
+import java.io.IOException;
+import java.util.*;
+
+
+/**
+ * A Cursor over a BTree which manages duplicate keys.
+ */
+public class DupsCursor extends AbstractCursor<Tuple> 
+{
+    private final JdbmTable table;
+    private final TupleComparator comparator;
+    private final TupleCursor wrapped;
+    private final Tuple tuple = new Tuple();
+
+    /**
+     * A Cursor over a set of value objects for the same key.  It traverses
+     * over either a TreeSet of values in a multi valued key or it traverses
+     * over a BTree of values.
+     */
+    private Cursor<Object> dupCursor;
+
+    /**
+     * The current Tuple returned from the underlying TupleCursor which may
+     * contain a TreeSet for Tuple values.  A TupleCursor on a Table that
+     * allows duplicates essentially returns Strings for keys and TreeSets or
+     * BTreeRedirect objects for their values.
+     */
+    private Tuple duplicates;
+    private boolean valueAvailable;
+
+
+    public DupsCursor( JdbmTable table, TupleCursor wrapped, TupleComparator comparator )
+    {
+        this.table = table;
+        this.wrapped = wrapped;
+        this.comparator = comparator;
+    }
+
+
+    public boolean available()
+    {
+        return valueAvailable;
+    }
+
+
+    public void before( Tuple element ) throws IOException
+    {
+        throw new NotImplementedException();
+    }
+
+
+    public void after(Tuple element) throws IOException
+    {
+        throw new NotImplementedException();
+    }
+
+
+    public void beforeFirst() throws IOException
+    {
+        throw new NotImplementedException();
+    }
+
+
+    public void afterLast() throws IOException
+    {
+        throw new NotImplementedException();
+    }
+
+
+    public boolean first() throws IOException
+    {
+        throw new NotImplementedException();
+    }
+
+
+    private void clearValue()
+    {
+        tuple.setKey( null );
+        tuple.setValue( null );
+        valueAvailable = false;
+    }
+
+
+    public boolean last() throws IOException
+    {
+        if ( wrapped.last() )
+        {
+            duplicates = wrapped.get();
+            Object values = duplicates.getValue();
+
+            if ( values instanceof TreeSet)
+            {
+                //noinspection unchecked
+                TreeSet<Object> set = ( TreeSet ) duplicates.getValue();
+                List<Object> list = new ArrayList<Object>( set.size() );
+                list.addAll( set );
+                dupCursor = new ListCursor<Object>( list );
+                if ( ! dupCursor.previous() )
+                {
+                    clearValue();
+                    return false;
+                }
+            }
+            else if ( values instanceof BTreeRedirect )
+            {
+                BTree tree = table.getBTree( ( BTreeRedirect ) values );
+                //noinspection unchecked
+                dupCursor = new KeyCursor( tree, comparator.getKeyComparator() );
+                if ( ! dupCursor.previous() )
+                {
+                    clearValue();
+                    return false;
+                }
+            }
+
+            /*
+             * If we get to this point then cursor has more elements and
+             * duplicates holds the Tuple containing the key and the btree or
+             * TreeSet of values for that key which the Cursor traverses.  All we
+             * need to do is populate our tuple object with the key and the value
+             * in the cursor.
+             */
+            tuple.setKey( duplicates.getKey() );
+            tuple.setValue( dupCursor.get() );
+            return valueAvailable = true;
+        }
+
+        clearValue();
+        return false;
+    }
+
+
+    public boolean previous() throws IOException
+    {
+        /*
+         * If the iterator over the values of the current key is null or is
+         * extinguished then we need to advance to the previous key.
+         */
+        while ( null == dupCursor || ! dupCursor.previous() )
+        {
+            /*
+             * If the underlying cursor has more elements we get the previous
+             * key/TreeSet Tuple to work with and get a cursor over it's
+             * values.
+             */
+            if ( wrapped.previous() )
+            {
+                duplicates = wrapped.get();
+                Object values = duplicates.getValue();
+
+                if ( values instanceof TreeSet )
+                {
+                    //noinspection unchecked
+                    TreeSet<Object> set = ( TreeSet ) duplicates.getValue();
+                    List<Object> list = new ArrayList<Object>( set.size() );
+                    list.addAll( set );
+                    dupCursor = new ListCursor<Object>( list );
+                    dupCursor.previous();
+                }
+                else if ( values instanceof BTreeRedirect )
+                {
+                    BTree tree = table.getBTree( ( BTreeRedirect ) values );
+                    //noinspection unchecked
+                    dupCursor = new KeyCursor( tree, comparator.getKeyComparator() );
+                    dupCursor.previous();
+                }
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        /*
+         * If we get to this point then cursor has more elements and
+         * duplicates holds the Tuple containing the key and the btree or
+         * TreeSet of values for that key which the Cursor traverses.  All we
+         * need to do is populate our tuple object with the key and the value
+         * in the cursor.
+         */
+        tuple.setKey( duplicates.getKey() );
+        tuple.setValue( dupCursor.get() );
+        return valueAvailable = true;
+    }
+
+
+    public boolean next() throws IOException
+    {
+        /*
+         * If the iterator over the values of the current key is null or is
+         * extinguished then we need to advance to the next key.
+         */
+        while ( null == dupCursor || ! dupCursor.next() )
+        {
+            /*
+             * If the underlying cursor has more elements we get the next
+             * key/TreeSet Tuple to work with and get a cursor over it.
+             */
+            if ( wrapped.next() )
+            {
+                duplicates = wrapped.get();
+                Object values = duplicates.getValue();
+
+                if ( values instanceof TreeSet)
+                {
+                    //noinspection unchecked
+                    TreeSet<Object> set = ( TreeSet ) duplicates.getValue();
+                    List<Object> list = new ArrayList<Object>( set.size() );
+                    list.addAll( set );
+                    dupCursor = new ListCursor<Object>( list );
+                    dupCursor.next();
+                }
+                else if ( values instanceof BTreeRedirect )
+                {
+                    BTree tree = table.getBTree( ( BTreeRedirect ) values );
+                    //noinspection unchecked
+                    dupCursor = new KeyCursor( tree, comparator.getKeyComparator() );
+                    dupCursor.next();
+                }
+            }
+            else
+            {
+                return false;
+            }
+        }
+
+        /*
+         * If we get to this point then cursor has more elements and
+         * duplicates holds the Tuple containing the key and the btree or
+         * TreeSet of values for that key which the Cursor traverses.  All we
+         * need to do is populate our tuple object with the key and the value
+         * in the cursor.
+         */
+        tuple.setKey( duplicates.getKey() );
+        tuple.setValue( dupCursor.get() );
+        return valueAvailable = true;
+    }
+
+
+    public Tuple get() throws IOException
+    {
+        checkClosed( "get()" );
+
+        if ( ! valueAvailable )
+        {
+            throw new InvalidCursorPositionException();
+        }
+
+        return tuple;
+    }
+
+
+    public boolean isElementReused()
+    {
+        return true;
+    }
+}

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?rev=607563&r1=607562&r2=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
Sun Dec 30 09:29:28 2007
@@ -29,8 +29,8 @@
 import org.apache.directory.server.core.cursor.IteratorCursor;
 import org.apache.directory.server.core.cursor.SingletonCursor;
 import org.apache.directory.server.core.partition.impl.btree.*;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.cursor.keyonly.KeyCursor;
-import org.apache.directory.server.core.partition.impl.btree.jdbm.cursor.TupleCursor;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.KeyCursor;
+import org.apache.directory.server.core.partition.impl.btree.jdbm.TupleCursor;
 import org.apache.directory.server.schema.SerializableComparator;
 
 import javax.naming.NamingException;
@@ -984,7 +984,7 @@
         if ( values instanceof BTreeRedirect )
         {
             BTree tree = getBTree( ( BTreeRedirect ) values );
-            return new KeyCursor( tree );
+            return new KeyCursor( tree, comparator.getKeyComparator() );
         }
         
         throw new IllegalStateException( "When using duplicate keys either a TreeSet or BTree
is used for values." );

Copied: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursor.java
(from r607324, directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/keyonly/KeyCursor.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursor.java?p2=directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursor.java&p1=directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/keyonly/KeyCursor.java&r1=607324&r2=607563&rev=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/keyonly/KeyCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursor.java
Sun Dec 30 09:29:28 2007
@@ -16,7 +16,7 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.directory.server.core.partition.impl.btree.jdbm.cursor.keyonly;
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
 
 
 import jdbm.btree.BTree;
@@ -72,6 +72,12 @@
     }
 
 
+    public boolean available()
+    {
+        return valueAvailable;
+    }
+
+
     public void before( E element ) throws IOException
     {
         browser = btree.browse( element );
@@ -155,6 +161,11 @@
 
     public boolean previous() throws IOException
     {
+        if ( browser == null )
+        {
+            browser = btree.browse( null );
+        }
+
         if ( browser.getPrevious( tuple ) )
         {
             return valueAvailable = true;
@@ -169,6 +180,11 @@
 
     public boolean next() throws IOException
     {
+        if ( browser == null )
+        {
+            browser = btree.browse();
+        }
+
         if ( browser.getNext( tuple ) )
         {
             return valueAvailable = true;

Propchange: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursor.java
------------------------------------------------------------------------------
    svn:executable = *

Copied: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/TupleCursor.java
(from r607324, directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/TupleCursor.java)
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/TupleCursor.java?p2=directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/TupleCursor.java&p1=directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/TupleCursor.java&r1=607324&r2=607563&rev=607563&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-cursor/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/cursor/TupleCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/TupleCursor.java
Sun Dec 30 09:29:28 2007
@@ -16,11 +16,11 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.directory.server.core.partition.impl.btree.jdbm.cursor;
+package org.apache.directory.server.core.partition.impl.btree.jdbm;
 
 
-import org.apache.directory.shared.ldap.NotImplementedException;
 import org.apache.directory.server.core.cursor.AbstractCursor;
+import org.apache.directory.server.core.cursor.InvalidCursorPositionException;
 
 import java.io.IOException;
 import java.util.Comparator;
@@ -32,123 +32,187 @@
 
 /**
  * Cursor over the Tuples of a JDBM BTree.  Duplicate keys are not supported
- * by JDBM natively so you will not see duplicate keys.
+ * by JDBM natively so you will not see duplicate keys.  For this reason as
+ * well before() and after() positioning only considers the key of the Tuple
+ * arguments provided.
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$, $Date$
  */
 public class TupleCursor extends AbstractCursor<Tuple>
 {
-    private final Object key;
     private final Comparator comparator;
     private final BTree btree;
 
     private Tuple tuple = new Tuple();
     private TupleBrowser browser;
-    private boolean success;
+    private boolean valueAvailable;
 
 
-    public TupleCursor( BTree btree, Object key, Comparator comparator )
-            throws IOException
+    /**
+     * Creates a Cursor over the tuples of a JDBM BTree.
+     *
+     * @param btree the JDBM BTree to build a Cursor over
+     * @param comparator the Comparator used to determine <b>key</b> ordering
+     * @throws IOException of there are problems accessing the BTree
+     */
+    public TupleCursor( BTree btree, Comparator comparator ) throws IOException
     {
-        this.key = key;
         this.btree = btree;
         this.comparator = comparator;
     }
 
 
-    public void before( Tuple element ) throws IOException
-    {
-        throw new NotImplementedException();
-    }
-
-
-    public void after( Tuple element ) throws IOException
-    {
-        throw new NotImplementedException();
-    }
-
-
-    public void beforeFirst() throws IOException
-    {
-        throw new NotImplementedException();
-    }
-
-
-    public void afterLast() throws IOException
+    private void clearValue()
     {
-        throw new NotImplementedException();
+        tuple.setKey( null );
+        tuple.setValue( null );
+        valueAvailable = false;
     }
 
 
-    public boolean absolute( int absolutePosition ) throws IOException
+    public boolean available()
     {
-        throw new NotImplementedException();
+        return valueAvailable;
     }
 
 
-    public boolean relative( int relativePosition ) throws IOException
+    /**
+     * Positions this Cursor before the key of the supplied tuple.
+     *
+     * @param element the tuple who's key is used to position this Cursor
+     * @throws IOException if there are failures to position the Cursor
+     */
+    public void before( Tuple element ) throws IOException
     {
-        throw new NotImplementedException();
+        browser = btree.browse( element.getKey() );
+        clearValue();
     }
 
 
-    public boolean first() throws IOException
+    public void after( Tuple element ) throws IOException
     {
-        throw new NotImplementedException();
-    }
+        browser = btree.browse( element.getKey() );
 
+        /*
+         * While the next value is less than or equal to the element keep
+         * advancing forward to the next item.  If we cannot advance any
+         * further then stop and return.  If we find a value greater than
+         * the element then we stop, backup, and return so subsequent calls
+         * to getNext() will return a value greater than the element.
+         */
+        while ( browser.getNext( tuple ) )
+        {
+            Object next = tuple.getKey();
+
+            //noinspection unchecked
+            int nextCompared = comparator.compare( next, element.getKey() );
+
+            if ( nextCompared <= 0 )
+            {
+                // just continue
+            }
+            else if ( nextCompared > 0 )
+            {
+                /*
+                 * If we just have values greater than the element argument
+                 * then we are before the first element and cannot backup, and
+                 * the call below to getPrevious() will fail.  In this special
+                 * case we just reset the Cursor's browser and return.
+                 */
+                if ( browser.getPrevious( tuple ) )
+                {
+                }
+                else
+                {
+                    browser = btree.browse( element.getKey() );
+                }
+
+                clearValue();
+                return;
+            }
+        }
 
-    public boolean last() throws IOException
-    {
-        throw new NotImplementedException();
+        clearValue();
+        // just return
     }
 
 
-    public boolean isFirst() throws IOException
+    public void beforeFirst() throws IOException
     {
-        throw new NotImplementedException();
+        browser = btree.browse();
+        clearValue();
     }
 
 
-    public boolean isLast() throws IOException
+    public void afterLast() throws IOException
     {
-        return false;
+        browser = btree.browse( null );
     }
 
 
-    public boolean isAfterLast() throws IOException
+    public boolean first() throws IOException
     {
-        return false;
+        beforeFirst();
+        return next();
     }
 
 
-    public boolean isBeforeFirst() throws IOException
+    public boolean last() throws IOException
     {
-        return false;
+        afterLast();
+        return previous();
     }
 
 
     public boolean previous() throws IOException
     {
-        return false;
+        if ( browser.getPrevious( tuple ) )
+        {
+            return valueAvailable = true;
+        }
+        else
+        {
+            clearValue();
+            return false;
+        }
     }
 
 
     public boolean next() throws IOException
     {
-        return false;
+        if ( browser.getNext( tuple ) )
+        {
+            return valueAvailable = true;
+        }
+        else
+        {
+            clearValue();
+            return false;
+        }
     }
 
 
     public Tuple get() throws IOException
     {
-        throw new NotImplementedException();
+        if ( valueAvailable )
+        {
+            //noinspection unchecked
+            return tuple;
+        }
+
+        throw new InvalidCursorPositionException();
     }
 
 
     public boolean isElementReused()
     {
         return true;
+    }
+
+
+    BTree getBTree()
+    {
+        return btree;
     }
 }

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java?rev=607563&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
Sun Dec 30 09:29:28 2007
@@ -0,0 +1,282 @@
+/*
+ * 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.core.partition.impl.btree.jdbm;
+
+
+import org.junit.*;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNull;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import jdbm.RecordManager;
+import jdbm.helper.StringComparator;
+import jdbm.helper.TupleBrowser;
+import jdbm.helper.Tuple;
+import jdbm.btree.BTree;
+import jdbm.recman.BaseRecordManager;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Comparator;
+
+
+
+/**
+ * Document me!
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class KeyCursorTest
+{
+    private static final Logger LOG = LoggerFactory.getLogger( KeyCursorTest.class.getSimpleName()
);
+    private static final byte[] EMPTY_BYTES = new byte[0];
+    private static final String TEST_OUTPUT_PATH = "test.output.path";
+
+    File dbFile;
+    RecordManager recman;
+    BTree bt;
+    Comparator<String> comparator;
+
+    KeyCursor<String> cursor;
+
+
+    @Before
+    public void createCursor() throws Exception
+    {
+        File tmpDir = null;
+        if ( System.getProperty( TEST_OUTPUT_PATH, null ) != null )
+        {
+            tmpDir = new File( System.getProperty( TEST_OUTPUT_PATH ) );
+        }
+
+        dbFile = File.createTempFile( KeyCursorTest.class.getName(), "db", tmpDir );
+        recman = new BaseRecordManager( dbFile.getAbsolutePath() );
+        comparator = new StringComparator();
+        bt = BTree.createInstance( recman, comparator );
+
+        // add some data to it
+        bt.insert( "0", EMPTY_BYTES, true );
+        bt.insert( "1", EMPTY_BYTES, true );
+        bt.insert( "2", EMPTY_BYTES, true );
+        bt.insert( "3", EMPTY_BYTES, true );
+        bt.insert( "4", EMPTY_BYTES, true );
+        bt.insert( "5", EMPTY_BYTES, true );
+        bt.insert( "6", EMPTY_BYTES, true );
+        bt.insert( "7", EMPTY_BYTES, true );
+        bt.insert( "8", EMPTY_BYTES, true );
+        bt.insert( "9", EMPTY_BYTES, true );
+
+        cursor = new KeyCursor<String>( bt, comparator );
+        LOG.debug( "Created new KeyCursor and populated it's btree" );
+    }
+
+
+    @After
+    public void destryCursor() throws Exception
+    {
+        recman.close();
+        recman = null;
+        dbFile.deleteOnExit();
+        dbFile = null;
+    }
+
+
+    @Test
+    public void testPreviousBeforePositioning() throws IOException
+    {
+        // test initial setup, advances after, and before inside elements
+        assertInvalidCursor();
+
+        assertTrue( cursor.previous() );
+        assertEquals( "9", cursor.get() );
+    }
+
+
+    @Test
+    public void testNextBeforePositioning() throws IOException
+    {
+        // test initial setup, advances after, and before inside elements
+        assertInvalidCursor();
+
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+    }
+
+
+    @Test
+    public void testOperations() throws IOException
+    {
+        // test initial setup, advances after, and before inside elements
+        assertInvalidCursor();
+
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+
+        cursor.after( "5" );
+        assertInvalidCursor();
+        assertTrue( cursor.next() );
+        assertEquals( "6", cursor.get() );
+
+        cursor.before( "2" );
+        assertInvalidCursor();
+        assertTrue( cursor.next() );
+        assertEquals( "2", cursor.get() );
+
+        // test advances up to and past the tail end
+        cursor.after( "9" );
+        assertInvalidCursor();
+        assertFalse( cursor.next() );
+        assertTrue( cursor.previous() );
+        assertEquals( "9", cursor.get() );
+
+        cursor.after( "a" );
+        assertInvalidCursor();
+        assertFalse( cursor.next() );
+        assertTrue( cursor.previous() );
+        assertEquals( "9", cursor.get() );
+
+        cursor.before( "a" );
+        assertInvalidCursor();
+        assertFalse( cursor.next() );
+        assertTrue( cursor.previous() );
+        assertEquals( "9", cursor.get() );
+
+        // test advances up to and past the head
+        cursor.before( "0" );
+        assertInvalidCursor();
+        assertFalse( cursor.previous() );
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+
+        cursor.after( "*" );
+        assertInvalidCursor();
+        assertFalse( cursor.previous() );
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+
+        cursor.before( "*" );
+        assertInvalidCursor();
+        assertFalse( cursor.previous() );
+        assertTrue( cursor.next() );
+        assertEquals( "0", cursor.get() );
+
+        bt.remove( "0" );
+        bt.remove( "1" );
+        bt.remove( "2" );
+        bt.remove( "3" );
+        bt.remove( "4" );
+        bt.remove( "6" );
+        bt.remove( "7" );
+        bt.remove( "8" );
+        bt.remove( "9" );
+
+        // now test with only one element: "5" remains now with others deleted
+        cursor.before( "5" );
+        assertInvalidCursor();
+        assertFalse( cursor.previous() );
+        assertTrue( cursor.next() );
+        assertEquals( "5", cursor.get() );
+        assertFalse( cursor.next() );
+
+        cursor.after( "5" );
+        assertInvalidCursor();
+        assertFalse( cursor.next() );
+        assertTrue( cursor.previous() );
+        assertEquals( "5", cursor.get() );
+        assertFalse( cursor.previous() );
+    }
+
+
+    @Test
+    public void testJdbmBrowse() throws Exception
+    {
+        bt.remove( "0" );
+        bt.remove( "5" );
+        bt.remove( "6" );
+        bt.remove( "7" );
+        bt.remove( "9" );
+
+        assertNull( bt.find( "0" ) );
+        assertNotNull( bt.find( "1" ) );
+        assertNotNull( bt.find( "2" ) );
+        assertNotNull( bt.find( "3" ) );
+        assertNotNull( bt.find( "4" ) );
+        assertNull( bt.find( "5" ) );
+        assertNull( bt.find( "6" ) );
+        assertNull( bt.find( "7" ) );
+        assertNotNull( bt.find( "8" ) );
+        assertNull( bt.find( "9" ) );
+
+        // browse will position us right after "4" and getNext() will return 8
+        // since "5", "6", and "7" do not exist
+        TupleBrowser browser = bt.browse( "5" );
+        assertNotNull( browser );
+        Tuple tuple = new Tuple();
+        browser.getNext( tuple );
+        assertEquals( "8", tuple.getKey() );
+
+        // browse will position us right after "1" and getNext() will return 2
+        // since "2" exists.
+        browser = bt.browse( "2" );
+        assertNotNull( browser );
+        tuple = new Tuple();
+        browser.getNext( tuple );
+        assertEquals( "2", tuple.getKey() );
+
+        // browse will position us right after "8" and getNext() will null
+        // since nothing else exists past 8.  We've come to the end.
+        browser = bt.browse( "9" );
+        assertNotNull( browser );
+        tuple = new Tuple();
+        browser.getNext( tuple );
+        assertNull( tuple.getKey() );
+
+        // browse will position us right before "1" and getPrevious() will
+        // null since nothing else exists before 1.  We've come to the end.
+        // getNext() will however return "1".
+        browser = bt.browse( "0" );
+        assertNotNull( browser );
+        tuple = new Tuple();
+        browser.getPrevious( tuple );
+        assertNull( tuple.getKey() );
+        browser.getNext( tuple );
+        assertEquals( "1", tuple.getKey() );
+    }
+
+
+    private void assertInvalidCursor()
+    {
+        try
+        {
+            cursor.get();
+            fail( "Invalid Cursor should not return valid value from get()" );
+        }
+        catch ( IOException e )
+        {
+            assertNotNull( e );
+        }
+    }
+}

Propchange: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message