directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: r637270 - in /directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src: main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/
Date Fri, 14 Mar 2008 21:25:58 GMT
Author: akarasulu
Date: Fri Mar 14 14:25:57 2008
New Revision: 637270

URL: http://svn.apache.org/viewvc?rev=637270&view=rev
Log:
cleaning up cursor implementations

 o added the required cursor implementations separating the dependence of the
   duplicates cursor on the no duplicates cursor which greatly simplifies the
   implementation of the duplicates cursor without mixing concerns


Added:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java
Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainer.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainer.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/DupsContainer.java?rev=637270&r1=637269&r2=637270&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainer.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainer.java
Fri Mar 14 14:25:57 2008
@@ -24,7 +24,15 @@
 
 
 /**
- * A wrapper around duplicate key values.
+ * A wrapper around duplicate key values.  This class wraps either a single
+ * value, an AvlTree or a BTreeRedirect.  Only the AvlTree and BTreeRedirect
+ * forms are used for the two value persistence mechanisms used to implement
+ * duplicate keys over JDBM btrees.  The value form is almost a hack so we can
+ * pass a value to the DupsContainerCursor to position it without breaking
+ * with the API.  The positioning methods expect a Tuple with a K key object
+ * and a value of DupsContainer<V> for the Tuple value so we have this form
+ * to facilitate that.  For most practical purposes the value form can be
+ * ignored
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  * @version $Rev$
@@ -32,13 +40,23 @@
 public class DupsContainer<V>
 {
     private final AvlTree<V> avlTree;
+    private final V value;
     private final BTreeRedirect btreeRedirect;
 
 
+    DupsContainer( V value )
+    {
+        this.value = value;
+        avlTree = null;
+        btreeRedirect = null;
+    }
+
+
     DupsContainer( AvlTree<V> avlTree )
     {
         this.avlTree = avlTree;
         btreeRedirect = null;
+        value = null;
     }
 
 
@@ -46,6 +64,7 @@
     {
         avlTree = null;
         this.btreeRedirect = btreeRedirect;
+        value = null;
     }
 
 
@@ -61,14 +80,41 @@
     }
 
 
+    final boolean isValue()
+    {
+        return value != null;
+    }
+
+
+    final V getValue()
+    {
+        if ( value == null )
+        {
+            throw new IllegalStateException( "this is not a value container" );
+        }
+
+        return value;
+    }
+
+
     final AvlTree<V> getAvlTree()
     {
+        if ( avlTree == null )
+        {
+            throw new IllegalStateException( "this is not a avlTree container" );
+        }
+
         return avlTree;
     }
 
 
     final BTreeRedirect getBTreeRedirect()
     {
+        if ( btreeRedirect == null )
+        {
+            throw new IllegalStateException( "this is not a btreeRedirect container" );
+        }
+
         return btreeRedirect;
     }
 }

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.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/DupsContainerCursor.java?rev=637270&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/DupsContainerCursor.java
Fri Mar 14 14:25:57 2008
@@ -0,0 +1,232 @@
+/*
+ *  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.apache.directory.server.core.cursor.InvalidCursorPositionException;
+import org.apache.directory.server.core.cursor.AbstractCursor;
+import org.apache.directory.server.core.partition.impl.btree.Tuple;
+import jdbm.helper.TupleBrowser;
+
+import java.io.IOException;
+
+
+/**
+ * A cursor for browsing tables with duplicates which returns the container
+ * for values rather than just the value.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $$Rev$$
+ */
+public class DupsContainerCursor<K,V> extends AbstractCursor<Tuple<K, DupsContainer<V>>>
+{
+    private final JdbmTable<K,V> table;
+
+    private jdbm.helper.Tuple jdbmTuple = new jdbm.helper.Tuple();
+    private Tuple<K,DupsContainer<V>> returnedTuple = new Tuple<K,DupsContainer<V>>();
+    private TupleBrowser browser;
+    private boolean valueAvailable;
+
+
+    /**
+     * Creates a Cursor over the tuples of a JDBM table.
+     *
+     * @param table the JDBM Table to build a Cursor over
+     * @throws java.io.IOException of there are problems accessing the BTree
+     */
+    public DupsContainerCursor( JdbmTable<K,V> table ) throws IOException
+    {
+        if ( ! table.isDupsEnabled() )
+        {
+            throw new IllegalStateException(
+                "This cursor can only be used with tables that have duplicate keys enabled."
);
+        }
+
+        this.table = table;
+    }
+
+
+    private void clearValue()
+    {
+        returnedTuple.setKey( null );
+        returnedTuple.setValue( null );
+        jdbmTuple.setKey( null );
+        jdbmTuple.setValue( null );
+        valueAvailable = false;
+    }
+
+
+    public boolean available()
+    {
+        return valueAvailable;
+    }
+
+
+    /**
+     * 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<K,DupsContainer<V>> element ) throws IOException
+    {
+        browser = table.getBTree().browse( element.getKey() );
+        clearValue();
+    }
+
+
+    public void after( Tuple<K,DupsContainer<V>> element ) throws IOException
+    {
+        browser = table.getBTree().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( jdbmTuple ) )
+        {
+            //noinspection unchecked
+            K next = ( K ) jdbmTuple.getKey();
+
+            //noinspection unchecked
+            int nextCompared = table.getKeyComparator().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( jdbmTuple ) )
+                {
+                }
+                else
+                {
+                    browser = table.getBTree().browse( element.getKey() );
+                }
+
+                clearValue();
+                return;
+            }
+        }
+
+        clearValue();
+        // just return
+    }
+
+
+    public void beforeFirst() throws IOException
+    {
+        browser = table.getBTree().browse();
+        clearValue();
+    }
+
+
+    public void afterLast() throws IOException
+    {
+        browser = table.getBTree().browse( null );
+        clearValue();
+    }
+
+
+    public boolean first() throws IOException
+    {
+        beforeFirst();
+        return next();
+    }
+
+
+    public boolean last() throws IOException
+    {
+        afterLast();
+        return previous();
+    }
+
+
+    public boolean previous() throws IOException
+    {
+        if ( browser == null )
+        {
+            afterLast();
+        }
+
+        if ( browser.getPrevious( jdbmTuple ) )
+        {
+            //noinspection unchecked
+            returnedTuple.setKey( ( K ) jdbmTuple.getKey() );
+            returnedTuple.setValue( table.getDupsContainer( ( byte[] ) jdbmTuple.getValue()
) );
+            return valueAvailable = true;
+        }
+        else
+        {
+            clearValue();
+            return false;
+        }
+    }
+
+
+    public boolean next() throws IOException
+    {
+        if ( browser == null )
+        {
+            beforeFirst();
+        }
+
+        if ( browser.getNext( jdbmTuple ) )
+        {
+            //noinspection unchecked
+            returnedTuple.setKey( ( K ) jdbmTuple.getKey() );
+            returnedTuple.setValue( table.getDupsContainer( ( byte[] ) jdbmTuple.getValue()
) );
+            return valueAvailable = true;
+        }
+        else
+        {
+            clearValue();
+            return false;
+        }
+    }
+
+
+    public Tuple<K,DupsContainer<V>> get() throws Exception
+    {
+        if ( valueAvailable )
+        {
+            //noinspection unchecked
+            return returnedTuple;
+        }
+
+        throw new InvalidCursorPositionException();
+    }
+
+
+    public boolean isElementReused()
+    {
+        return false;
+    }
+}

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.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/JdbmDupsCursor.java?rev=637270&r1=637269&r2=637270&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java
Fri Mar 14 14:25:57 2008
@@ -34,7 +34,7 @@
      * positions it may return different values for the same key if the table
      * supports duplicate keys.
      */
-    private final Tuple<K,V> dupsTuple = new Tuple<K,V>();
+    private final Tuple<K,V> returnedTuple = new Tuple<K,V>();
 
     /**
      * The underlying Cursor which is simply returns Tuples with key value
@@ -48,7 +48,7 @@
      * In essence the AvlTree and the BTreeRedirect are used to store multiple
      * values for the same key.
      */
-    private final JdbmNoDupsCursor<K,V> noDupsCursor;
+    private final DupsContainerCursor<K,V> containerCursor;
 
     /**
      * A Cursor over a set of value objects for the current key.  A new Cursor
@@ -57,7 +57,7 @@
      * of values in a multi-valued key or it traverses over a BTree which
      * contains the values in it's keys.
      */
-    private Cursor<V> dupCursor;
+    private Cursor<V> dupsCursor;
 
     /**
      * The current Tuple returned from the underlying JdbmNoDupsCursor which
@@ -65,7 +65,7 @@
      * JdbmNoDupsCursor on a Table that allows duplicates returns AvlTrees or
      * BTreeRedirect objects for Tuple values.
      */
-    private Tuple<K,V> noDupsTuple;
+    private Tuple<K,DupsContainer<V>> containerTuple;
 
     /**
      * Whether or not a value is available when get() is called.
@@ -76,7 +76,7 @@
     public JdbmDupsCursor( JdbmTable<K,V> table ) throws Exception
     {
         this.table = table;
-        this.noDupsCursor = new JdbmNoDupsCursor<K,V>( table );
+        this.containerCursor = new DupsContainerCursor<K,V>( table );
     }
 
 
@@ -97,23 +97,25 @@
      */
     public void before( Tuple<K,V> element ) throws Exception
     {
-        noDupsCursor.before( element );
+        DupsContainer<V> container = new DupsContainer<V>( element.getValue()
);
+        containerCursor.before( new Tuple<K,DupsContainer<V>>( element.getKey(),
container ) );
         
-        if ( noDupsCursor.next() )
+        if ( containerCursor.next() )
         {
-            noDupsTuple = noDupsCursor.get();
+            containerTuple = containerCursor.get();
             
-            if ( noDupsTuple.getValue() instanceof byte[] )
+            if ( containerTuple.getValue().isAvlTree() )
             {
-                LOG.debug( "Duplicates tuple {} stored in a AvlTree", noDupsTuple );
-                AvlTree<V> set = table.getMarshaller().deserialize( ( byte[] ) noDupsTuple.getValue()
);
+                LOG.debug( "Duplicates tuple {} stored in a AvlTree", containerTuple );
+                AvlTree<V> set = containerTuple.getValue().getAvlTree();
             }
             else 
             {
-                LOG.debug( "Duplicates tuple {} are stored in a BTree", noDupsTuple );
-                BTreeRedirect redirect = ( BTreeRedirect ) noDupsTuple.getValue();
+                LOG.debug( "Duplicates tuple {} are stored in a BTree", containerTuple );
+                BTreeRedirect redirect = containerTuple.getValue().getBTreeRedirect();
             }
         }
+
 //        throw new NotImplementedException();
     }
 
@@ -144,36 +146,35 @@
 
     private void clearValue()
     {
-        dupsTuple.setKey( null );
-        dupsTuple.setValue( null );
+        returnedTuple.setKey( null );
+        returnedTuple.setValue( null );
         valueAvailable = false;
     }
 
 
     public boolean last() throws Exception
     {
-        if ( noDupsCursor.last() )
+        if ( containerCursor.last() )
         {
-            noDupsTuple = noDupsCursor.get();
-            Object values = noDupsTuple.getValue();
+            containerTuple = containerCursor.get();
+            DupsContainer values = containerTuple.getValue();
 
-            if ( values instanceof AvlTree)
+            if ( values.isAvlTree() )
             {
                 //noinspection unchecked
-                AvlTree<V> set = ( AvlTree<V> ) noDupsTuple.getValue();
-                dupCursor = new AvlTreeCursor<V>( set );
-                if ( ! dupCursor.previous() )
+                AvlTree<V> set = values.getAvlTree();
+                dupsCursor = new AvlTreeCursor<V>( set );
+                if ( ! dupsCursor.previous() )
                 {
                     clearValue();
                     return false;
                 }
             }
-            else if ( values instanceof BTreeRedirect )
+            else if ( values.isBTreeRedirect() )
             {
-                BTree tree = table.getBTree( ( BTreeRedirect ) values );
-                //noinspection unchecked
-                dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getKeyComparator()
);
-                if ( ! dupCursor.previous() )
+                BTree tree = table.getBTree( values.getBTreeRedirect() );
+                dupsCursor = new KeyCursor<V>( tree, table.getValueComparator() );
+                if ( ! dupsCursor.previous() )
                 {
                     clearValue();
                     return false;
@@ -182,13 +183,13 @@
 
             /*
              * If we get to this point then cursor has more elements and
-             * noDupsTuple holds the Tuple containing the key and the btree or
+             * containerTuple holds the Tuple containing the key and the btree or
              * AvlTree 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.
              */
-            dupsTuple.setKey( noDupsTuple.getKey() );
-            dupsTuple.setValue( dupCursor.get() );
+            returnedTuple.setKey( containerTuple.getKey() );
+            returnedTuple.setValue( dupsCursor.get() );
             return valueAvailable = true;
         }
 
@@ -203,31 +204,31 @@
          * 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() )
+        while ( null == dupsCursor || ! dupsCursor.previous() )
         {
             /*
              * If the underlying cursor has more elements we get the previous
              * key/AvlTree Tuple to work with and get a cursor over it's
              * values.
              */
-            if ( noDupsCursor.previous() )
+            if ( containerCursor.previous() )
             {
-                noDupsTuple = noDupsCursor.get();
-                Object values = noDupsTuple.getValue();
+                containerTuple = containerCursor.get();
+                DupsContainer<V> values = containerTuple.getValue();
 
-                if ( values instanceof AvlTree )
+                if ( values.isAvlTree() )
                 {
                     //noinspection unchecked
-                    AvlTree<V> set = ( AvlTree ) noDupsTuple.getValue();
-                    dupCursor = new AvlTreeCursor<V>( set );
-                    dupCursor.previous();
+                    AvlTree<V> set = values.getAvlTree();
+                    dupsCursor = new AvlTreeCursor<V>( set );
+                    dupsCursor.previous();
                 }
-                else if ( values instanceof BTreeRedirect )
+                else if ( values.isBTreeRedirect() )
                 {
-                    BTree tree = table.getBTree( ( BTreeRedirect ) values );
+                    BTree tree = table.getBTree( values.getBTreeRedirect() );
                     //noinspection unchecked
-                    dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getKeyComparator()
);
-                    dupCursor.previous();
+                    dupsCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getKeyComparator()
);
+                    dupsCursor.previous();
                 }
             }
             else
@@ -238,13 +239,13 @@
 
         /*
          * If we get to this point then cursor has more elements and
-         * noDupsTuple holds the Tuple containing the key and the btree or
+         * containerTuple holds the Tuple containing the key and the btree or
          * AvlTree 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.
          */
-        dupsTuple.setKey( noDupsTuple.getKey() );
-        dupsTuple.setValue( dupCursor.get() );
+        returnedTuple.setKey( containerTuple.getKey() );
+        returnedTuple.setValue( dupsCursor.get() );
         return valueAvailable = true;
     }
 
@@ -255,30 +256,30 @@
          * 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() )
+        while ( null == dupsCursor || ! dupsCursor.next() )
         {
             /*
              * If the underlying cursor has more elements we get the next
              * key/AvlTree Tuple to work with and get a cursor over it.
              */
-            if ( noDupsCursor.next() )
+            if ( containerCursor.next() )
             {
-                noDupsTuple = noDupsCursor.get();
-                Object values = noDupsTuple.getValue();
+                containerTuple = containerCursor.get();
+                DupsContainer<V> values = containerTuple.getValue();
 
-                if ( values instanceof AvlTree)
+                if ( values.isAvlTree() )
                 {
                     //noinspection unchecked
-                    AvlTree<V> set = ( AvlTree<V> ) noDupsTuple.getValue();
-                    dupCursor = new AvlTreeCursor<V>( set );
-                    dupCursor.next();
+                    AvlTree<V> set = values.getAvlTree();
+                    dupsCursor = new AvlTreeCursor<V>( set );
+                    dupsCursor.next();
                 }
-                else if ( values instanceof BTreeRedirect )
+                else if ( values.isBTreeRedirect() )
                 {
-                    BTree tree = table.getBTree( ( BTreeRedirect ) values );
+                    BTree tree = table.getBTree( values.getBTreeRedirect() );
                     //noinspection unchecked
-                    dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getKeyComparator()
);
-                    dupCursor.next();
+                    dupsCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getKeyComparator()
);
+                    dupsCursor.next();
                 }
             }
             else
@@ -289,13 +290,13 @@
 
         /*
          * If we get to this point then cursor has more elements and
-         * noDupsTuple holds the Tuple containing the key and the btree or
+         * containerTuple holds the Tuple containing the key and the btree or
          * AvlTree 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.
          */
-        dupsTuple.setKey( noDupsTuple.getKey() );
-        dupsTuple.setValue( dupCursor.get() );
+        returnedTuple.setKey( containerTuple.getKey() );
+        returnedTuple.setValue( dupsCursor.get() );
         return valueAvailable = true;
     }
 
@@ -309,7 +310,7 @@
             throw new InvalidCursorPositionException();
         }
 
-        return dupsTuple;
+        return returnedTuple;
     }
 
 

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.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/JdbmNoDupsCursor.java?rev=637270&r1=637269&r2=637270&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java
Fri Mar 14 14:25:57 2008
@@ -147,6 +147,7 @@
     public void afterLast() throws IOException
     {
         browser = table.getBTree().browse( null );
+        clearValue();
     }
 
 
@@ -166,6 +167,11 @@
 
     public boolean previous() throws IOException
     {
+        if ( browser == null )
+        {
+            afterLast();
+        }
+
         if ( browser.getPrevious( jdbmTuple ) )
         {
             //noinspection unchecked
@@ -184,6 +190,11 @@
 
     public boolean next() throws IOException
     {
+        if ( browser == null )
+        {
+            beforeFirst();
+        }
+
         if ( browser.getNext( jdbmTuple ) )
         {
             //noinspection unchecked

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=637270&r1=637269&r2=637270&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
Fri Mar 14 14:25:57 2008
@@ -892,28 +892,32 @@
     }
 
 
-    private DupsContainer getDups( K key ) throws IOException
+    DupsContainer<V> getDupsContainer( byte[] serialized ) throws IOException
     {
-        if ( null == key )
+        if ( serialized == null )
         {
-            return null;
+            return new DupsContainer<V>( new AvlTree<V>( valueComparator ) );
         }
 
-        if ( allowsDuplicates )
+        if ( BTreeRedirectMarshaller.isNotRedirect( serialized ) )
         {
-            byte[] serialized = ( byte[] ) bt.find( key );
+            return new DupsContainer<V>( marshaller.deserialize( serialized ) );
+        }
+
+        return new DupsContainer<V>( BTreeRedirectMarshaller.INSTANCE.deserialize(
serialized ) );
+    }
 
-            if ( serialized == null )
-            {
-                return new DupsContainer<V>( new AvlTree<V>( valueComparator
) );
-            }
 
-            if ( BTreeRedirectMarshaller.isNotRedirect( serialized ) )
-            {
-                return new DupsContainer<V>( marshaller.deserialize( serialized ) );
-            }
+    private DupsContainer<V> getDups( K key ) throws IOException
+    {
+        if ( null == key )
+        {
+            return null;
+        }
 
-            return new DupsContainer<V>( BTreeRedirectMarshaller.INSTANCE.deserialize(
serialized ) );
+        if ( allowsDuplicates )
+        {
+            return getDupsContainer( ( byte[] ) bt.find( key ) );
         }
 
         throw new IllegalStateException(

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.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/JdbmDupsCursorTest.java?rev=637270&r1=637269&r2=637270&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
(original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
Fri Mar 14 14:25:57 2008
@@ -25,24 +25,18 @@
 import org.apache.directory.server.core.partition.impl.btree.Tuple;
 import org.apache.directory.server.core.cursor.Cursor;
 import org.apache.directory.server.schema.SerializableComparator;
-import org.apache.directory.server.schema.registries.ComparatorRegistry;
-import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
 import org.junit.Before;
 import org.junit.After;
 import org.junit.Test;
 
-import static org.junit.Assert.assertNotNull;import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.*;
 
 import java.io.File;
-import java.util.Comparator;
-import java.util.Iterator;
 
 import jdbm.RecordManager;
 import jdbm.helper.IntegerSerializer;
 import jdbm.recman.BaseRecordManager;
 
-import javax.naming.NamingException;
-
 
 /**
  * Tests the Cursor functionality of a JdbmTable when duplicate keys are 
@@ -98,6 +92,27 @@
 
 
     @Test
+    public void testNextUnderDupLimit() throws Exception
+    {
+        // first try without duplicates at all
+        for ( int ii = 0; ii < SIZE-2; ii++ )
+        {
+            table.put( ii, ii );
+        }
+        Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
+
+        int ii = 0;
+        while ( cursor.next() )
+        {
+            Tuple<Integer,Integer> tuple = cursor.get();
+            assertEquals( ii, ( int ) tuple.getKey() );
+            assertEquals( ii, ( int ) tuple.getValue() );
+            ii++;
+        }
+    }
+
+
+    @Test
     public void testOnEmptyTable() throws Exception
     {
         Cursor<Tuple<Integer,Integer>> cursor = table.cursor();
@@ -148,66 +163,5 @@
         
         cursor.before( new Tuple<Integer, Integer>( 7, 2 ) );
         assertFalse( cursor.available() );
-    }
-
-    
-    private class MockComparatorRegistry implements ComparatorRegistry
-    {
-        private Comparator<Integer> comparator = new Comparator<Integer>()
-        {
-            public int compare( Integer i1, Integer i2 )
-            {
-                return i1.compareTo( i2 );
-            }
-        };
-
-        public String getSchemaName( String oid ) throws NamingException
-        {
-            return null;
-        }
-
-
-        public void register( ComparatorDescription description, Comparator comparator )
throws NamingException
-        {
-        }
-
-
-        public Comparator lookup( String oid ) throws NamingException
-        {
-            return comparator;
-        }
-
-
-        public boolean hasComparator( String oid )
-        {
-            return true;
-        }
-
-
-        public Iterator<String> oidIterator()
-        {
-            return null;
-        }
-
-
-        public Iterator<ComparatorDescription> comparatorDescriptionIterator()
-        {
-            return null;
-        }
-
-
-        public void unregister( String oid ) throws NamingException
-        {
-        }
-
-
-        public void unregisterSchemaElements( String schemaName )
-        {
-        }
-
-
-        public void renameSchema( String originalSchemaName, String newSchemaName )
-        {
-        }
     }
 }

Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.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/MockComparatorRegistry.java?rev=637270&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java
(added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/MockComparatorRegistry.java
Fri Mar 14 14:25:57 2008
@@ -0,0 +1,95 @@
+/*
+ *  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.apache.directory.server.schema.registries.ComparatorRegistry;
+import org.apache.directory.shared.ldap.schema.syntax.ComparatorDescription;
+
+import javax.naming.NamingException;
+import java.util.Comparator;
+import java.util.Iterator;
+
+
+/**
+ * TODO doc me!
+*
+* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+* @version $$Rev$$
+*/
+class MockComparatorRegistry implements ComparatorRegistry
+{
+    private Comparator<Integer> comparator = new Comparator<Integer>()
+    {
+        public int compare( Integer i1, Integer i2 )
+        {
+            return i1.compareTo( i2 );
+        }
+    };
+
+    public String getSchemaName( String oid ) throws NamingException
+    {
+        return null;
+    }
+
+
+    public void register( ComparatorDescription description, Comparator comparator ) throws
NamingException
+    {
+    }
+
+
+    public Comparator lookup( String oid ) throws NamingException
+    {
+        return comparator;
+    }
+
+
+    public boolean hasComparator( String oid )
+    {
+        return true;
+    }
+
+
+    public Iterator<String> oidIterator()
+    {
+        return null;
+    }
+
+
+    public Iterator<ComparatorDescription> comparatorDescriptionIterator()
+    {
+        return null;
+    }
+
+
+    public void unregister( String oid ) throws NamingException
+    {
+    }
+
+
+    public void unregisterSchemaElements( String schemaName )
+    {
+    }
+
+
+    public void renameSchema( String originalSchemaName, String newSchemaName )
+    {
+    }
+}



Mime
View raw message