directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1551187 [2/2] - in /directory/mavibot/trunk/mavibot/src: main/java/org/apache/directory/mavibot/btree/ main/java/org/apache/directory/mavibot/btree/memory/ main/java/org/apache/directory/mavibot/btree/persisted/ test/java/org/apache/direct...
Date Mon, 16 Dec 2013 11:46:33 GMT
Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java?rev=1551187&r1=1551186&r2=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java Mon Dec 16 11:46:32 2013
@@ -24,6 +24,7 @@ import java.io.IOException;
 import java.lang.reflect.Array;
 import java.util.List;
 
+import org.apache.directory.mavibot.btree.AbstractPage;
 import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.BorrowedFromSiblingResult;
 import org.apache.directory.mavibot.btree.BorrowedFromLeftResult;
@@ -54,10 +55,10 @@ import org.apache.directory.mavibot.btre
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-/* No qualifier */class Node<K, V> extends AbstractPersistedPage<K, V>
+/* No qualifier */class Node<K, V> extends AbstractPage<K, V>
 {
     /** Children pages associated with keys. */
-    protected PageHolder<K, V>[] children;
+    protected PersistedPageHolder<K, V>[] children;
 
 
     /**
@@ -75,7 +76,7 @@ import org.apache.directory.mavibot.btre
         super( btree, revision, nbElems );
 
         // Create the children array
-        children = ( PageHolder<K, V>[] ) Array.newInstance( PageHolder.class, nbElems + 1 );
+        children = ( PersistedPageHolder<K, V>[] ) Array.newInstance( PersistedPageHolder.class, nbElems + 1 );
     }
 
 
@@ -96,11 +97,11 @@ import org.apache.directory.mavibot.btre
         super( btree, revision, 1 );
 
         // Create the children array, and store the left and right children
-        children = ( PageHolder<K, V>[] ) Array.newInstance( PageHolder.class,
+        children = ( PersistedPageHolder<K, V>[] ) Array.newInstance( PersistedPageHolder.class,
             btree.getPageSize() + 1 );
 
-        children[0] = new PageHolder<K, V>( btree, leftPage );
-        children[1] = new PageHolder<K, V>( btree, rightPage );
+        children[0] = new PersistedPageHolder<K, V>( btree, leftPage );
+        children[1] = new PersistedPageHolder<K, V>( btree, rightPage );
 
         // Create the keys array and store the pivot into it
         // We get the type of array to create from the btree
@@ -123,13 +124,13 @@ import org.apache.directory.mavibot.btre
      * @param rightPage The right page
      */
     @SuppressWarnings("unchecked")
-    /* No qualifier */Node( BTree<K, V> btree, long revision, K key, PageHolder<K, V> leftPage,
-        PageHolder<K, V> rightPage )
+    /* No qualifier */Node( BTree<K, V> btree, long revision, K key, PersistedPageHolder<K, V> leftPage,
+        PersistedPageHolder<K, V> rightPage )
     {
         super( btree, revision, 1 );
 
         // Create the children array, and store the left and right children
-        children = ( PageHolder<K, V>[] ) Array.newInstance( PageHolder.class,
+        children = ( PersistedPageHolder<K, V>[] ) Array.newInstance( PersistedPageHolder.class,
             btree.getPageSize() + 1 );
 
         children[0] = leftPage;
@@ -158,7 +159,7 @@ import org.apache.directory.mavibot.btre
         }
 
         // Get the child page into which we will insert the <K, V> tuple
-        Page<K, V> child = children[pos].getValue( btree );
+        Page<K, V> child = children[pos].getValue();
 
         // and insert the <K, V> into this child
         InsertResult<K, V> result = child.insert( revision, key, value );
@@ -292,7 +293,7 @@ import org.apache.directory.mavibot.btre
         // Create the new sibling, with one less element at the beginning
         Node<K, V> newSibling = new Node<K, V>( btree, revision, sibling.getNbElems() - 1 );
 
-        K siblingKey = sibling.children[0].getValue( btree ).getLeftMostKey();
+        K siblingKey = sibling.children[0].getValue().getLeftMostKey();
 
         // Copy the keys and children of the old sibling in the new sibling
         System.arraycopy( sibling.keys, 1, newSibling.keys, 0, newSibling.getNbElems() );
@@ -376,7 +377,7 @@ import org.apache.directory.mavibot.btre
         Node<K, V> sibling, int pos ) throws IOException
     {
         // The sibling is on the left, borrow the rightmost element
-        Page<K, V> siblingChild = sibling.children[sibling.nbElems].getValue( btree );
+        Page<K, V> siblingChild = sibling.children[sibling.nbElems].getValue();
 
         // Create the new sibling, with one less element at the end
         Node<K, V> newSibling = new Node<K, V>( btree, revision, sibling.getNbElems() - 1 );
@@ -407,7 +408,7 @@ import org.apache.directory.mavibot.btre
         else
         {
             // Set the first key
-            newNode.keys[0] = new PersistedKeyHolder<K>( btree.getKeySerializer(), children[0].getValue( btree )
+            newNode.keys[0] = new PersistedKeyHolder<K>( btree.getKeySerializer(), children[0].getValue()
                 .getLeftMostKey() ); //2
 
             if ( index > 2 )
@@ -492,7 +493,7 @@ import org.apache.directory.mavibot.btre
             {
                 // Copy the left part of the node keys up to the deletion point
                 // Insert the new key
-                newNode.keys[half] = new PersistedKeyHolder<K>( btree.getKeySerializer(), children[0].getValue( btree )
+                newNode.keys[half] = new PersistedKeyHolder<K>( btree.getKeySerializer(), children[0].getValue()
                     .getLeftMostKey() ); // 3
 
                 if ( index > 2 )
@@ -601,12 +602,12 @@ import org.apache.directory.mavibot.btre
         if ( found )
         {
             index = -( pos + 1 );
-            child = children[-pos].getValue( btree );
+            child = children[-pos].getValue();
             deleteResult = child.delete( revision, key, value, this, -pos );
         }
         else
         {
-            child = children[pos].getValue( btree );
+            child = children[pos].getValue();
             deleteResult = child.delete( revision, key, value, this, pos );
         }
 
@@ -670,7 +671,7 @@ import org.apache.directory.mavibot.btre
                 // a sibling, or we will have to merge two pages
                 int siblingPos = selectSibling( ( Node<K, V> ) parent, parentPos );
 
-                Node<K, V> sibling = ( Node<K, V> ) ( ( ( Node<K, V> ) parent ).children[siblingPos].getValue( btree ) );
+                Node<K, V> sibling = ( Node<K, V> ) ( ( ( Node<K, V> ) parent ).children[siblingPos].getValue() );
 
                 if ( sibling.getNbElems() > halfSize )
                 {
@@ -871,11 +872,11 @@ import org.apache.directory.mavibot.btre
         {
             // Here, if we have found the key in the node, then we must go down into
             // the right child, not the left one
-            return children[-pos].getValue( btree ).get( key );
+            return children[-pos].getValue().get( key );
         }
         else
         {
-            return children[pos].getValue( btree ).get( key );
+            return children[pos].getValue().get( key );
         }
     }
 
@@ -892,11 +893,11 @@ import org.apache.directory.mavibot.btre
         {
             // Here, if we have found the key in the node, then we must go down into
             // the right child, not the left one
-            return children[-pos].getValue( btree ).getValues( key );
+            return children[-pos].getValue().getValues( key );
         }
         else
         {
-            return children[pos].getValue( btree ).getValues( key );
+            return children[pos].getValue().getValues( key );
         }
     }
 
@@ -913,11 +914,11 @@ import org.apache.directory.mavibot.btre
         {
             // Here, if we have found the key in the node, then we must go down into
             // the right child, not the left one
-            return children[-pos].getValue( btree ).hasKey( key );
+            return children[-pos].getValue().hasKey( key );
         }
         else
         {
-            Page<K, V> page = children[pos].getValue( btree );
+            Page<K, V> page = children[pos].getValue();
 
             if ( page == null )
             {
@@ -941,11 +942,11 @@ import org.apache.directory.mavibot.btre
         {
             // Here, if we have found the key in the node, then we must go down into
             // the right child, not the left one
-            return children[-pos].getValue( btree ).contains( key, value );
+            return children[-pos].getValue().contains( key, value );
         }
         else
         {
-            return children[pos].getValue( btree ).contains( key, value );
+            return children[pos].getValue().contains( key, value );
         }
     }
 
@@ -956,7 +957,7 @@ import org.apache.directory.mavibot.btre
      * @param pos The position in the values array
      * @param value the value to inject
      */
-    public void setValue( int pos, PageHolder<K, V> value )
+    public void setValue( int pos, PersistedPageHolder<K, V> value )
     {
         children[pos] = value;
     }
@@ -969,7 +970,7 @@ import org.apache.directory.mavibot.btre
     {
         if ( pos < nbElems + 1 )
         {
-            return children[pos].getValue( btree );
+            return children[pos].getValue();
         }
         else
         {
@@ -994,7 +995,7 @@ import org.apache.directory.mavibot.btre
         // We first stack the current page
         stack[depth++] = new ParentPos<K, V>( this, pos );
         
-        Page<K, V> page = children[pos].getValue( btree );
+        Page<K, V> page = children[pos].getValue();
 
         return page.browse( key, transaction, stack, depth );
     }
@@ -1008,7 +1009,7 @@ import org.apache.directory.mavibot.btre
     {
         stack[depth++] = new ParentPos<K, V>( this, 0 );
         
-        Page<K, V> page = children[0].getValue( btree );
+        Page<K, V> page = children[0].getValue();
 
         return page.browse( transaction, stack, depth );
     }
@@ -1053,9 +1054,9 @@ import org.apache.directory.mavibot.btre
      * @return A holder contaning a reference to the child page
      * @throws IOException If we have an error while trying to access the page
      */
-    private PageHolder<K, V> createHolder( Page<K, V> page ) throws IOException
+    private PersistedPageHolder<K, V> createHolder( Page<K, V> page ) throws IOException
     {
-        PageHolder<K, V> holder = ((PersistedBTree<K, V>)btree).getRecordManager().writePage( btree,
+        PersistedPageHolder<K, V> holder = ((PersistedBTree<K, V>)btree).getRecordManager().writePage( btree,
             page,
             revision );
 
@@ -1257,20 +1258,7 @@ import org.apache.directory.mavibot.btre
      */
     public K getLeftMostKey()
     {
-        try
-        {
-            return children[0].getValue( btree ).getLeftMostKey();
-        }
-        catch ( EndOfFileExceededException eofe )
-        {
-            eofe.printStackTrace();
-            return null;
-        }
-        catch ( IOException ioe )
-        {
-            ioe.printStackTrace();
-            return null;
-        }
+        return children[0].getValue().getLeftMostKey();
     }
 
 
@@ -1281,25 +1269,12 @@ import org.apache.directory.mavibot.btre
     {
         int index = ( nbElems + 1 ) - 1;
 
-        try
-        {
-            if ( children[index] != null )
-            {
-                return children[index].getValue( btree ).getRightMostKey();
-            }
-    
-            return children[nbElems - 1].getValue( btree ).getRightMostKey();
-        }
-        catch ( EndOfFileExceededException eofe )
-        {
-            eofe.printStackTrace();
-            return null;
-        }
-        catch ( IOException ioe )
+        if ( children[index] != null )
         {
-            ioe.printStackTrace();
-            return null;
+            return children[index].getValue().getRightMostKey();
         }
+
+        return children[nbElems - 1].getValue().getRightMostKey();
     }
 
 
@@ -1308,7 +1283,7 @@ import org.apache.directory.mavibot.btre
      */
     public Tuple<K, V> findLeftMost() throws EndOfFileExceededException, IOException
     {
-        return children[0].getValue( btree ).findLeftMost();
+        return children[0].getValue().findLeftMost();
     }
 
 
@@ -1317,7 +1292,7 @@ import org.apache.directory.mavibot.btre
      */
     public Tuple<K, V> findRightMost() throws EndOfFileExceededException, IOException
     {
-        return children[nbElems].getValue( btree ).findRightMost();
+        return children[nbElems].getValue().findRightMost();
     }
 
 
@@ -1332,39 +1307,32 @@ import org.apache.directory.mavibot.btre
         sb.append( super.toString() );
         sb.append( "] -> {" );
 
-        try
+        if ( nbElems > 0 )
         {
-            if ( nbElems > 0 )
+            // Start with the first child
+            if ( children[0] == null )
+            {
+                sb.append( "null" );
+            }
+            else
             {
-                // Start with the first child
-                if ( children[0] == null )
+                sb.append( 'r' ).append( children[0].getValue().getRevision() );
+            }
+
+            for ( int i = 0; i < nbElems; i++ )
+            {
+                sb.append( "|<" ).append( keys[i] ).append( ">|" );
+
+                if ( children[i + 1] == null )
                 {
                     sb.append( "null" );
                 }
                 else
                 {
-                    sb.append( 'r' ).append( children[0].getValue( btree ).getRevision() );
-                }
-
-                for ( int i = 0; i < nbElems; i++ )
-                {
-                    sb.append( "|<" ).append( keys[i] ).append( ">|" );
-
-                    if ( children[i + 1] == null )
-                    {
-                        sb.append( "null" );
-                    }
-                    else
-                    {
-                        sb.append( 'r' ).append( children[i + 1].getValue( btree ).getRevision() );
-                    }
+                    sb.append( 'r' ).append( children[i + 1].getValue().getRevision() );
                 }
             }
         }
-        catch ( IOException ioe )
-        {
-            // Do nothing
-        }
 
         sb.append( "}" );
 
@@ -1381,22 +1349,15 @@ import org.apache.directory.mavibot.btre
 
         if ( nbElems > 0 )
         {
-            try
-            {
-                // Start with the first child
-                sb.append( children[0].getValue( btree ).dumpPage( tabs + "    " ) );
+            // Start with the first child
+            sb.append( children[0].getValue().dumpPage( tabs + "    " ) );
 
-                for ( int i = 0; i < nbElems; i++ )
-                {
-                    sb.append( tabs );
-                    sb.append( "<" );
-                    sb.append( keys[i] ).append( ">\n" );
-                    sb.append( children[i + 1].getValue( btree ).dumpPage( tabs + "    " ) );
-                }
-            }
-            catch ( IOException ioe )
+            for ( int i = 0; i < nbElems; i++ )
             {
-                // Do nothing
+                sb.append( tabs );
+                sb.append( "<" );
+                sb.append( keys[i] ).append( ">\n" );
+                sb.append( children[i + 1].getValue().dumpPage( tabs + "    " ) );
             }
         }
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTree.java?rev=1551187&r1=1551186&r2=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTree.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTree.java Mon Dec 16 11:46:32 2013
@@ -31,6 +31,7 @@ import net.sf.ehcache.Cache;
 import net.sf.ehcache.config.CacheConfiguration;
 
 import org.apache.directory.mavibot.btree.AbstractBTree;
+import org.apache.directory.mavibot.btree.AbstractPage;
 import org.apache.directory.mavibot.btree.BTreeHeader;
 import org.apache.directory.mavibot.btree.DeleteResult;
 import org.apache.directory.mavibot.btree.InsertResult;
@@ -125,7 +126,7 @@ public class PersistedBTree<K, V> extend
 
         // Create the first root page, with revision 0L. It will be empty
         // and increment the revision at the same time
-        rootPage = new Leaf<K, V>( this );
+        rootPage = new PersistedLeaf<K, V>( this );
         
         if ( isSubBtree )
         {
@@ -237,7 +238,7 @@ public class PersistedBTree<K, V> extend
 
         // Create the first root page, with revision 0L. It will be empty
         // and increment the revision at the same time
-        rootPage = new Leaf<K, V>( this );
+        rootPage = new PersistedLeaf<K, V>( this );
 
         // Now, call the init() method
         init();
@@ -440,16 +441,16 @@ public class PersistedBTree<K, V> extend
                 // Write the modified page on disk
                 // Note that we don't use the holder, the new root page will
                 // remain in memory.
-                PageHolder<K, V> holder = recordManager.writePage( this, modifiedPage,
+                PersistedPageHolder<K, V> holder = recordManager.writePage( this, modifiedPage,
                     revision );
 
                 // Store the offset on disk in the page in memory
-                ( ( AbstractPersistedPage<K, V> ) modifiedPage ).setOffset( ( ( PageHolder<K, V> ) holder )
+                ( ( AbstractPage<K, V> ) modifiedPage ).setOffset( ( ( PersistedPageHolder<K, V> ) holder )
                     .getOffset() );
 
                 // Store the last offset on disk in the page in memory
-                ( ( AbstractPersistedPage<K, V> ) modifiedPage )
-                    .setLastOffset( ( ( PageHolder<K, V> ) holder )
+                ( ( AbstractPage<K, V> ) modifiedPage )
+                    .setLastOffset( ( ( PersistedPageHolder<K, V> ) holder )
                         .getLastOffset() );
 
                 // This is a new root
@@ -464,7 +465,7 @@ public class PersistedBTree<K, V> extend
 
                 // We have to update the rootPage on disk
                 // Update the BTree header now
-                recordManager.updateBtreeHeader( this, ( ( AbstractPersistedPage<K, V> ) rootPage ).getOffset() );
+                recordManager.updateBtreeHeader( this, ( ( AbstractPage<K, V> ) rootPage ).getOffset() );
             }
 
             recordManager.addFreePages( this, result.getCopiedPages() );
@@ -524,7 +525,7 @@ public class PersistedBTree<K, V> extend
             // Write the modified page on disk
             // Note that we don't use the holder, the new root page will
             // remain in memory.
-            PageHolder<K, V> holder = recordManager.writePage( this, modifiedPage,
+            PersistedPageHolder<K, V> holder = recordManager.writePage( this, modifiedPage,
                 revision );
             
             // The root has just been modified, we haven't split it
@@ -546,10 +547,10 @@ public class PersistedBTree<K, V> extend
 
             // If the BTree is managed, we have to write the two pages that were created
             // and to keep a track of the two offsets for the upper node
-            PageHolder<K, V> holderLeft = recordManager.writePage( this,
+            PersistedPageHolder<K, V> holderLeft = recordManager.writePage( this,
                 leftPage, revision );
 
-            PageHolder<K, V> holderRight = recordManager.writePage( this,
+            PersistedPageHolder<K, V> holderRight = recordManager.writePage( this,
                 rightPage, revision );
 
             // Create the new rootPage
@@ -557,7 +558,7 @@ public class PersistedBTree<K, V> extend
 
             // If the BTree is managed, we now have to write the page on disk
             // and to add this page to the list of modified pages
-            PageHolder<K, V> holder = recordManager
+            PersistedPageHolder<K, V> holder = recordManager
                 .writePage( this, newRootPage, revision );
 
             rootPage = newRootPage;
@@ -575,7 +576,7 @@ public class PersistedBTree<K, V> extend
         recordManager.updateRecordManagerHeader();
 
         // Update the BTree header now
-        recordManager.updateBtreeHeader( this, ( ( AbstractPersistedPage<K, V> ) rootPage ).getOffset() );
+        recordManager.updateBtreeHeader( this, ( ( AbstractPage<K, V> ) rootPage ).getOffset() );
 
         // Moved the free pages into the list of free pages
         recordManager.addFreePages( this, result.getCopiedPages() );

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTreeBuilder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTreeBuilder.java?rev=1551187&r1=1551186&r2=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTreeBuilder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTreeBuilder.java Mon Dec 16 11:46:32 2013
@@ -33,6 +33,7 @@ import java.util.Arrays;
 import java.util.Iterator;
 import java.util.List;
 
+import org.apache.directory.mavibot.btree.AbstractPage;
 import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.KeyHolder;
 import org.apache.directory.mavibot.btree.Page;
@@ -81,7 +82,7 @@ public class PersistedBTreeBuilder<K, V>
 
         int totalTupleCount = 0;
 
-        Leaf<K, V> leaf1 = createLeaf( btree, 0, numKeysInNode );
+        PersistedLeaf<K, V> leaf1 = createLeaf( btree, 0, numKeysInNode );
         lstLeaves.add( leaf1 );
 
         int leafIndex = 0;
@@ -90,7 +91,7 @@ public class PersistedBTreeBuilder<K, V>
         {
             Tuple<K, V> tuple = sortedTupleItr.next();
             
-            setKey( leaf1, leafIndex, tuple.getKey() );
+            setKey( btree, leaf1, leafIndex, tuple.getKey() );
 
             PersistedValueHolder<V> eh = new PersistedValueHolder<V>( btree, tuple.getValue() );
 
@@ -102,7 +103,7 @@ public class PersistedBTreeBuilder<K, V>
             {
                 leafIndex = 0;
                 
-                PageHolder<K, V> pageHolder = ( PageHolder<K, V> ) rm.writePage( btree, leaf1, 1 );
+                PersistedPageHolder<K, V> pageHolder = ( PersistedPageHolder<K, V> ) rm.writePage( btree, leaf1, 1 );
                 
                 leaf1 = createLeaf( btree, 0, numKeysInNode );
                 lstLeaves.add( leaf1 );
@@ -117,7 +118,7 @@ public class PersistedBTreeBuilder<K, V>
         }
 
         // remove null keys and values from the last leaf and resize
-        Leaf<K, V> lastLeaf = ( Leaf<K, V> ) lstLeaves.get( lstLeaves.size() - 1 );
+        PersistedLeaf<K, V> lastLeaf = ( PersistedLeaf<K, V> ) lstLeaves.get( lstLeaves.size() - 1 );
         for ( int i = 0; i < lastLeaf.getNbElems(); i++ )
         {
             if ( lastLeaf.getKey( i ) == null )
@@ -133,7 +134,7 @@ public class PersistedBTreeBuilder<K, V>
                 lastLeaf.values = ( PersistedValueHolder<V>[] ) Array.newInstance( PersistedValueHolder.class, n );
                 System.arraycopy( values, 0, lastLeaf.values, 0, n );
 
-                PageHolder<K, V> pageHolder = ( PageHolder<K, V> ) rm.writePage( btree, lastLeaf, 1 );
+                PersistedPageHolder<K, V> pageHolder = ( PersistedPageHolder<K, V> ) rm.writePage( btree, lastLeaf, 1 );
 
                 break;
             }
@@ -146,7 +147,7 @@ public class PersistedBTreeBuilder<K, V>
         //System.out.println("built rootpage : " + rootPage);
         ((PersistedBTree<K, V>)btree).setNbElems( totalTupleCount );
         
-        rm.updateBtreeHeader( btree, ( ( AbstractPersistedPage<K, V> ) rootPage ).getOffset() );
+        rm.updateBtreeHeader( btree, ( ( AbstractPage<K, V> ) rootPage ).getOffset() );
         
         rm.addFreePages( btree, Arrays.asList( btree.getRootPage() ) );
         
@@ -177,10 +178,10 @@ public class PersistedBTreeBuilder<K, V>
         {
             if ( i != 0 )
             {
-                setKey( node, i - 1, page.getLeftMostKey() );
+                setKey( btree, node, i - 1, page.getLeftMostKey() );
             }
 
-            node.children[i] = new PageHolder<K, V>( btree, page );
+            node.children[i] = new PersistedPageHolder<K, V>( btree, page );
 
             i++;
             totalNodes++;
@@ -189,7 +190,7 @@ public class PersistedBTreeBuilder<K, V>
             {
                 i = 0;
                 
-                PageHolder<K, V> pageHolder = ( PageHolder<K, V> ) rm.writePage( btree, node, 1 );
+                PersistedPageHolder<K, V> pageHolder = ( PersistedPageHolder<K, V> ) rm.writePage( btree, node, 1 );
 
                 node = createNode( btree, 0, numKeysInNode );
                 lstNodes.add( node );
@@ -197,7 +198,7 @@ public class PersistedBTreeBuilder<K, V>
         }
 
         // remove null keys and values from the last node and resize
-        AbstractPersistedPage<K, V> lastNode = ( AbstractPersistedPage<K, V> ) lstNodes.get( lstNodes.size() - 1 );
+        AbstractPage<K, V> lastNode = ( AbstractPage<K, V> ) lstNodes.get( lstNodes.size() - 1 );
 
         for ( int j = 0; j < lastNode.getNbElems(); j++ )
         {
@@ -210,7 +211,7 @@ public class PersistedBTreeBuilder<K, V>
                 lastNode.setKeys( ( KeyHolder[] ) Array.newInstance( KeyHolder.class, n ) );
                 System.arraycopy( keys, 0, lastNode.getKeys(), 0, n );
 
-                PageHolder<K, V> pageHolder = ( PageHolder<K, V> ) rm.writePage( btree, lastNode, 1 );
+                PersistedPageHolder<K, V> pageHolder = ( PersistedPageHolder<K, V> ) rm.writePage( btree, lastNode, 1 );
 
                 break;
             }

Copied: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedLeaf.java (from r1551070, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Leaf.java)
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedLeaf.java?p2=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedLeaf.java&p1=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Leaf.java&r1=1551070&r2=1551187&rev=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Leaf.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedLeaf.java Mon Dec 16 11:46:32 2013
@@ -23,6 +23,7 @@ package org.apache.directory.mavibot.btr
 import java.io.IOException;
 import java.lang.reflect.Array;
 
+import org.apache.directory.mavibot.btree.AbstractPage;
 import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.BorrowedFromLeftResult;
 import org.apache.directory.mavibot.btree.BorrowedFromRightResult;
@@ -52,7 +53,7 @@ import org.apache.directory.mavibot.btre
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-/* No qualifier */class Leaf<K, V> extends AbstractPersistedPage<K, V>
+/* No qualifier */class PersistedLeaf<K, V> extends AbstractPage<K, V>
 {
     /** Values associated with keys */
     protected ValueHolder<V>[] values;
@@ -63,7 +64,7 @@ import org.apache.directory.mavibot.btre
      * 
      * @param btree The BTree this page belongs to.
      */
-    /* No qualifier */Leaf( BTree<K, V> btree )
+    PersistedLeaf( BTree<K, V> btree )
     {
         super( btree );
     }
@@ -77,8 +78,7 @@ import org.apache.directory.mavibot.btre
      * @param nbElems The number of elements this page will contain
      */
     @SuppressWarnings("unchecked")
-    // Cannot create an array of generic objects
-    /* No qualifier */Leaf( BTree<K, V> btree, long revision, int nbElems )
+    PersistedLeaf( BTree<K, V> btree, long revision, int nbElems )
     {
         super( btree, revision, nbElems );
         values = ( ValueHolder<V>[] ) Array.newInstance( PersistedValueHolder.class, nbElems );
@@ -182,17 +182,17 @@ import org.apache.directory.mavibot.btre
             }
         }
 
-        Leaf<K, V> newLeaf = null;
+        PersistedLeaf<K, V> newLeaf = null;
 
         if ( keyRemoved )
         {
             // No value, we can remove the key
-            newLeaf = new Leaf<K, V>( btree, revision, nbElems - 1 );
+            newLeaf = new PersistedLeaf<K, V>( btree, revision, nbElems - 1 );
         }
         else
         {
             // Copy the page as we will delete a value from a ValueHolder
-            newLeaf = new Leaf<K, V>( btree, revision, nbElems );
+            newLeaf = new PersistedLeaf<K, V>( btree, revision, nbElems );
         }
 
         // Create the result
@@ -222,7 +222,7 @@ import org.apache.directory.mavibot.btre
                 // Check in both next and previous page, if they have the same parent
                 // and select the biggest page with the same parent to borrow an element.
                 int siblingPos = selectSibling( ( Node<K, V> ) parent, parentPos );
-                Leaf<K, V> sibling = ( Leaf<K, V> ) ( ( ( Node<K, V> ) parent ).children[siblingPos].getValue( btree ) );
+                PersistedLeaf<K, V> sibling = ( PersistedLeaf<K, V> ) ( ( ( Node<K, V> ) parent ).children[siblingPos].getValue() );
 
                 if ( sibling.getNbElems() == halfSize )
                 {
@@ -303,13 +303,13 @@ import org.apache.directory.mavibot.btre
      * @return The new created leaf containing the sibling and the old page.
      * @throws IOException If we have an error while trying to access the page
      */
-    private DeleteResult<K, V> mergeWithSibling( Tuple<K, V> removedElement, long revision, Leaf<K, V> sibling,
+    private DeleteResult<K, V> mergeWithSibling( Tuple<K, V> removedElement, long revision, PersistedLeaf<K, V> sibling,
         boolean isLeft, int pos )
         throws EndOfFileExceededException, IOException
     {
         // Create the new page. It will contain N - 1 elements (the maximum number)
         // as we merge two pages that contain N/2 elements minus the one we remove
-        Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, btree.getPageSize() - 1 );
+        PersistedLeaf<K, V> newLeaf = new PersistedLeaf<K, V>( btree, revision, btree.getPageSize() - 1 );
 
         if ( isLeft )
         {
@@ -364,7 +364,7 @@ import org.apache.directory.mavibot.btre
      * @return The resulting pages
      * @throws IOException If we have an error while trying to access the page 
      */
-    private DeleteResult<K, V> borrowFromLeft( Tuple<K, V> removedElement, long revision, Leaf<K, V> sibling, int pos )
+    private DeleteResult<K, V> borrowFromLeft( Tuple<K, V> removedElement, long revision, PersistedLeaf<K, V> sibling, int pos )
         throws IOException
     {
         // The sibling is on the left, borrow the rightmost element
@@ -372,11 +372,11 @@ import org.apache.directory.mavibot.btre
         ValueHolder<V> siblingValue = sibling.values[sibling.getNbElems() - 1];
 
         // Create the new sibling, with one less element at the end
-        Leaf<K, V> newSibling = ( Leaf<K, V> ) sibling.copy( revision, sibling.getNbElems() - 1 );
+        PersistedLeaf<K, V> newSibling = ( PersistedLeaf<K, V> ) sibling.copy( revision, sibling.getNbElems() - 1 );
 
         // Create the new page and add the new element at the beginning
         // First copy the current page, with the same size
-        Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, nbElems );
+        PersistedLeaf<K, V> newLeaf = new PersistedLeaf<K, V>( btree, revision, nbElems );
 
         // Insert the borrowed element
         newLeaf.keys[0] = new PersistedKeyHolder<K>( btree.getKeySerializer(), siblingKey );
@@ -411,7 +411,7 @@ import org.apache.directory.mavibot.btre
      * @return The resulting pages
      * @throws IOException If we have an error while trying to access the page 
      */
-    private DeleteResult<K, V> borrowFromRight( Tuple<K, V> removedElement, long revision, Leaf<K, V> sibling, int pos )
+    private DeleteResult<K, V> borrowFromRight( Tuple<K, V> removedElement, long revision, PersistedLeaf<K, V> sibling, int pos )
         throws IOException
     {
         // The sibling is on the left, borrow the rightmost element
@@ -419,7 +419,7 @@ import org.apache.directory.mavibot.btre
         ValueHolder<V> siblingHolder = sibling.values[0];
 
         // Create the new sibling
-        Leaf<K, V> newSibling = new Leaf<K, V>( btree, revision, sibling.getNbElems() - 1 );
+        PersistedLeaf<K, V> newSibling = new PersistedLeaf<K, V>( btree, revision, sibling.getNbElems() - 1 );
 
         // Copy the keys and the values from 1 to N in the new sibling
         System.arraycopy( sibling.keys, 1, newSibling.keys, 0, sibling.nbElems - 1 );
@@ -427,7 +427,7 @@ import org.apache.directory.mavibot.btre
 
         // Create the new page and add the new element at the end
         // First copy the current page, with the same size
-        Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, nbElems );
+        PersistedLeaf<K, V> newLeaf = new PersistedLeaf<K, V>( btree, revision, nbElems );
 
         // Insert the borrowed element at the end
         newLeaf.keys[nbElems - 1] = new PersistedKeyHolder<K>( btree.getKeySerializer(), siblingKey );
@@ -459,7 +459,7 @@ import org.apache.directory.mavibot.btre
      * @param pos The position into the page of the element to remove
      * @throws IOException If we have an error while trying to access the page
      */
-    private void copyAfterRemovingElement( boolean keyRemoved, V removedValue, Leaf<K, V> newLeaf, int pos ) throws IOException
+    private void copyAfterRemovingElement( boolean keyRemoved, V removedValue, PersistedLeaf<K, V> newLeaf, int pos ) throws IOException
     {
         if ( keyRemoved )
         {
@@ -752,7 +752,7 @@ import org.apache.directory.mavibot.btre
      */
     private Page<K, V> copy( long revision, int nbElems )
     {
-        Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, nbElems );
+        PersistedLeaf<K, V> newLeaf = new PersistedLeaf<K, V>( btree, revision, nbElems );
 
         // Copy the keys and the values
         System.arraycopy( keys, 0, newLeaf.keys, 0, nbElems );
@@ -797,12 +797,12 @@ import org.apache.directory.mavibot.btre
     private InsertResult<K, V> replaceElement( long revision, K key, V value, int pos )
         throws IOException
     {
-        Leaf<K, V> newLeaf = this;
+        PersistedLeaf<K, V> newLeaf = this;
 
         if ( this.revision != revision )
         {
             // The page hasn't been modified yet, we need to copy it first
-            newLeaf = ( Leaf<K, V> ) copy( revision, nbElems );
+            newLeaf = ( PersistedLeaf<K, V> ) copy( revision, nbElems );
         }
 
         // Get the previous value from the leaf (it's a copy)
@@ -844,7 +844,7 @@ import org.apache.directory.mavibot.btre
     private Page<K, V> addElement( long revision, K key, V value, int pos )
     {
         // First copy the current page, but add one element in the copied page
-        Leaf<K, V> newLeaf = new Leaf<K, V>( btree, revision, nbElems + 1 );
+        PersistedLeaf<K, V> newLeaf = new PersistedLeaf<K, V>( btree, revision, nbElems + 1 );
 
         // Create the value holder
         ValueHolder<V> valueHolder = new PersistedValueHolder<V>( btree, value );
@@ -893,15 +893,15 @@ import org.apache.directory.mavibot.btre
     private InsertResult<K, V> addAndSplit( long revision, K key, V value, int pos )
     {
         int middle = btree.getPageSize() >> 1;
-        Leaf<K, V> leftLeaf = null;
-        Leaf<K, V> rightLeaf = null;
+        PersistedLeaf<K, V> leftLeaf = null;
+        PersistedLeaf<K, V> rightLeaf = null;
         ValueHolder<V> valueHolder = new PersistedValueHolder<V>( btree, value );
 
         // Determinate where to store the new value
         if ( pos <= middle )
         {
             // The left page will contain the new value
-            leftLeaf = new Leaf<K, V>( btree, revision, middle + 1 );
+            leftLeaf = new PersistedLeaf<K, V>( btree, revision, middle + 1 );
 
             // Copy the keys and the values up to the insertion position
             System.arraycopy( keys, 0, leftLeaf.keys, 0, pos );
@@ -916,7 +916,7 @@ import org.apache.directory.mavibot.btre
             System.arraycopy( values, pos, leftLeaf.values, pos + 1, middle - pos );
 
             // Now, create the right page
-            rightLeaf = new Leaf<K, V>( btree, revision, middle );
+            rightLeaf = new PersistedLeaf<K, V>( btree, revision, middle );
 
             // Copy the keys and the values in the right page
             System.arraycopy( keys, middle, rightLeaf.keys, 0, middle );
@@ -925,14 +925,14 @@ import org.apache.directory.mavibot.btre
         else
         {
             // Create the left page
-            leftLeaf = new Leaf<K, V>( btree, revision, middle );
+            leftLeaf = new PersistedLeaf<K, V>( btree, revision, middle );
 
             // Copy all the element into the left page
             System.arraycopy( keys, 0, leftLeaf.keys, 0, middle );
             System.arraycopy( values, 0, leftLeaf.values, 0, middle );
 
             // Now, create the right page
-            rightLeaf = new Leaf<K, V>( btree, revision, middle + 1 );
+            rightLeaf = new PersistedLeaf<K, V>( btree, revision, middle + 1 );
 
             int rightPos = pos - middle;
 

Copied: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedPageHolder.java (from r1551070, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PageHolder.java)
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedPageHolder.java?p2=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedPageHolder.java&p1=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PageHolder.java&r1=1551070&r2=1551187&rev=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PageHolder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedPageHolder.java Mon Dec 16 11:46:32 2013
@@ -22,10 +22,13 @@ package org.apache.directory.mavibot.btr
 
 import java.io.IOException;
 
+import net.sf.ehcache.Cache;
 import net.sf.ehcache.Element;
 
+import org.apache.directory.mavibot.btree.AbstractPage;
 import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.Page;
+import org.apache.directory.mavibot.btree.PageHolder;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
 
 
@@ -40,10 +43,13 @@ import org.apache.directory.mavibot.btre
  *
  * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
  */
-public class PageHolder<K, V>
+public class PersistedPageHolder<K, V> extends PageHolder<K, V>
 {
-    /** The BTree */
-    private BTree<K, V> btree;
+    /** The RecordManager */
+    private RecordManager recordManager;
+    
+    /** The cache */
+    private  Cache cache;
 
     /** The offset of the first {@link PageIO} storing the page on disk */
     private long offset;
@@ -57,19 +63,21 @@ public class PageHolder<K, V>
      * 
      * @param page The element to store into a SoftReference
      */
-    public PageHolder( BTree<K, V> btree, Page<K, V> page )
+    public PersistedPageHolder( BTree<K, V> btree, Page<K, V> page )
     {
-        this.btree = btree;
-        this.offset = page.getOffset();
-        this.lastOffset = page.getLastOffset();
+        super( btree, page );
+        cache = ((PersistedBTree<K, V>)btree).getCache();
+        recordManager = ((PersistedBTree<K, V>)btree).getRecordManager();
+        offset = page.getOffset();
+        lastOffset = page.getLastOffset();
 
         if ( page instanceof Page<?, ?> )
         {
-            ( ( AbstractPersistedPage<K, V> ) page ).setOffset( offset );
-            ( ( AbstractPersistedPage<K, V> ) page ).setLastOffset( lastOffset );
+            ( ( AbstractPage<K, V> ) page ).setOffset( offset );
+            ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
         }
 
-        ((PersistedBTree<K, V>)btree).getCache().put( new Element( offset, page ) );
+        cache.put( new Element( offset, page ) );
     }
 
 
@@ -78,19 +86,21 @@ public class PageHolder<K, V>
      * 
      * @param page The element to store into a SoftReference
      */
-    public PageHolder( BTree<K, V> btree, Page<K, V> page, long offset, long lastOffset )
+    public PersistedPageHolder( BTree<K, V> btree, Page<K, V> page, long offset, long lastOffset )
     {
-        this.btree = btree;
+        super( btree, page );
+        cache = ((PersistedBTree<K, V>)btree).getCache();
+        recordManager = ((PersistedBTree<K, V>)btree).getRecordManager();
         this.offset = offset;
         this.lastOffset = lastOffset;
 
         if ( page instanceof Page<?, ?> )
         {
-            ( ( AbstractPersistedPage<K, V> ) page ).setOffset( offset );
-            ( ( AbstractPersistedPage<K, V> ) page ).setLastOffset( lastOffset );
+            ( ( AbstractPage<K, V> ) page ).setOffset( offset );
+            ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
         }
 
-        ((PersistedBTree<K, V>)btree).getCache().put( new Element( offset, page ) );
+        cache.put( new Element( offset, page ) );
     }
 
 
@@ -99,17 +109,17 @@ public class PageHolder<K, V>
      * @throws IOException 
      * @throws EndOfFileExceededException 
      */
-    public Page<K, V> getValue( BTree<K, V> btree ) throws EndOfFileExceededException, IOException
+    public Page<K, V> getValue()
     {
-        Element element = ((PersistedBTree<K, V>)btree).getCache().get( offset );
+        Element element = cache.get( offset );
 
         if ( element == null )
         {
             // We haven't found the element in the cache, reload it
             // We have to fetch the element from disk, using the offset now
-            Page<K, V> page = fetchElement( btree );
+            Page<K, V> page = fetchElement();
 
-            ((PersistedBTree<K, V>)btree).getCache().put( new Element( offset, page ) );
+            cache.put( new Element( offset, page ) );
 
             return page;
         }
@@ -119,15 +129,15 @@ public class PageHolder<K, V>
         if ( page == null )
         {
             // We have to fetch the element from disk, using the offset now
-            page = fetchElement( btree );
+            page = fetchElement();
 
             if ( page instanceof Page<?, ?> )
             {
-                ( ( AbstractPersistedPage<K, V> ) page ).setOffset( offset );
-                ( ( AbstractPersistedPage<K, V> ) page ).setLastOffset( lastOffset );
+                ( ( AbstractPage<K, V> ) page ).setOffset( offset );
+                ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
             }
 
-            ((PersistedBTree<K, V>)btree).getCache().put( new Element( offset, page ) );
+            cache.put( new Element( offset, page ) );
         }
 
         return page;
@@ -137,14 +147,23 @@ public class PageHolder<K, V>
     /**
      * Retrieve the value from the disk, using the BTree and offset
      * @return The deserialized element (
-     * @throws IOException 
-     * @throws EndOfFileExceededException 
      */
-    private Page<K, V> fetchElement( BTree<K, V> btree ) throws EndOfFileExceededException, IOException
+    private Page<K, V> fetchElement()
     {
-        Page<K, V> element = ((PersistedBTree<K, V>)btree).getRecordManager().deserialize( btree, offset );
-
-        return element;
+        try
+        {
+            Page<K, V> element = recordManager.deserialize( btree, offset );
+    
+            return element;
+        }
+        catch ( EndOfFileExceededException eofee )
+        {
+            throw new RuntimeException( eofee.getMessage() );
+        }
+        catch ( IOException ioe )
+        {
+            throw new RuntimeException( ioe.getMessage() );
+        }
     }
 
 
@@ -173,24 +192,17 @@ public class PageHolder<K, V>
     {
         StringBuilder sb = new StringBuilder();
 
-        try
-        {
-            Page<K, V> page = getValue( btree );
+        Page<K, V> page = getValue();
 
-            if ( page != null )
-            {
-                sb.append( btree.getName() ).append( "[" ).append( offset ).append( ", " ).append( lastOffset )
-                    .append( "]:" ).append( page );
-            }
-            else
-            {
-                sb.append( btree.getName() ).append( "[" ).append( offset ).append( ", " ).append( lastOffset )
-                    .append( "]" );
-            }
+        if ( page != null )
+        {
+            sb.append( btree.getName() ).append( "[" ).append( offset ).append( ", " ).append( lastOffset )
+                .append( "]:" ).append( page );
         }
-        catch ( IOException ioe )
+        else
         {
-            // Nothing we can do...
+            sb.append( btree.getName() ).append( "[" ).append( offset ).append( ", " ).append( lastOffset )
+                .append( "]" );
         }
 
         return sb.toString();

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedValueHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedValueHolder.java?rev=1551187&r1=1551186&r2=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedValueHolder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedValueHolder.java Mon Dec 16 11:46:32 2013
@@ -76,7 +76,7 @@ public class PersistedValueHolder<V> ext
 
         // We create the array of values if they fit in an array. If they are stored in a 
         // BTree, we do nothing atm.
-        if ( nbValues <= PersistedBTree.valueThresholdUp )
+        if ( nbValues <= valueThresholdUp )
         {
             // The values are contained into an array
             valueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), nbValues );

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/RecordManager.java?rev=1551187&r1=1551186&r2=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/RecordManager.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/RecordManager.java Mon Dec 16 11:46:32 2013
@@ -33,6 +33,7 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
+import org.apache.directory.mavibot.btree.AbstractPage;
 import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.KeyHolder;
 import org.apache.directory.mavibot.btree.Page;
@@ -389,6 +390,7 @@ public class RecordManager
             {
                 // Create the BTree
                 BTree<Object, Object> btree = BTreeFactory.createBTree();
+                ((PersistedBTree<Object, Object>)btree).setRecordManager( this );
                 ((PersistedBTree<Object, Object>)btree).setBtreeOffset( nextBtreeOffset );
                 lastAddedBTreeOffset = nextBtreeOffset;
 
@@ -537,6 +539,8 @@ public class RecordManager
 
         // Now, init the BTree
         btree.init();
+        
+        ((PersistedBTree<K, V>)btree).setRecordManager( this );
 
         // Now, load the rootPage, which can be a Leaf or a Node, depending 
         // on the number of elements in the tree : if it's above the pageSize,
@@ -570,8 +574,8 @@ public class RecordManager
 
         Page<K, V> page = readPage( btree, rootPageIos );
 
-        ( ( AbstractPersistedPage<K, V> ) page ).setOffset( rootPageIos[0].getOffset() );
-        ( ( AbstractPersistedPage<K, V> ) page ).setLastOffset( rootPageIos[rootPageIos.length - 1].getOffset() );
+        ( ( AbstractPage<K, V> ) page ).setOffset( rootPageIos[0].getOffset() );
+        ( ( AbstractPage<K, V> ) page ).setLastOffset( rootPageIos[rootPageIos.length - 1].getOffset() );
 
         return page;
     }
@@ -619,11 +623,11 @@ public class RecordManager
     /**
      * Deserialize a Leaf from some PageIOs
      */
-    private <K, V> Leaf<K, V> readLeafKeysAndValues( BTree<K, V> btree, int nbElems, long revision, ByteBuffer byteBuffer,
+    private <K, V> PersistedLeaf<K, V> readLeafKeysAndValues( BTree<K, V> btree, int nbElems, long revision, ByteBuffer byteBuffer,
         PageIO[] pageIos )
     {
         // Its a leaf, create it
-        Leaf<K, V> leaf = BTreeFactory.createLeaf( btree, revision, nbElems );
+        PersistedLeaf<K, V> leaf = BTreeFactory.createLeaf( btree, revision, nbElems );
 
         // Store the page offset on disk
         leaf.setOffset( pageIos[0].getOffset() );
@@ -666,7 +670,7 @@ public class RecordManager
             keyLengths[i] = byteBuffer.getInt();
             byte[] data = new byte[keyLengths[i]];
             byteBuffer.get( data );
-            BTreeFactory.setKey( leaf, i, data );
+            BTreeFactory.setKey( btree, leaf, i, data );
         }
 
         return leaf;
@@ -688,7 +692,7 @@ public class RecordManager
             long offset = OFFSET_SERIALIZER.deserialize( byteBuffer );
             long lastOffset = OFFSET_SERIALIZER.deserialize( byteBuffer );
 
-            PageHolder<K, V> valueHolder = new PageHolder<K, V>( btree, null, offset, lastOffset );
+            PersistedPageHolder<K, V> valueHolder = new PersistedPageHolder<K, V>( btree, null, offset, lastOffset );
             node.setValue( i, valueHolder );
 
             // Read the key length
@@ -702,14 +706,14 @@ public class RecordManager
             // Set the new position now
             byteBuffer.position( currentPosition + keyLength );
             
-            BTreeFactory.setKey( node, i, key );
+            BTreeFactory.setKey( btree, node, i, key );
         }
 
         // and read the last value, as it's a node
         long offset = OFFSET_SERIALIZER.deserialize( byteBuffer );
         long lastOffset = OFFSET_SERIALIZER.deserialize( byteBuffer );
 
-        PageHolder<K, V> valueHolder = new PageHolder<K, V>( btree, null, offset, lastOffset );
+        PersistedPageHolder<K, V> valueHolder = new PersistedPageHolder<K, V>( btree, null, offset, lastOffset );
         node.setValue( nbElems, valueHolder );
 
         return node;
@@ -1073,7 +1077,7 @@ public class RecordManager
         // Now, we can inject the BTree rootPage offset into the BTree header
         position = store( position, rootPageIo.getOffset(), pageIos );
         ((PersistedBTree<K, V>)btree).setRootPageOffset( rootPageIo.getOffset() );
-        ( ( Leaf<K, V> ) rootPage ).setOffset( rootPageIo.getOffset() );
+        ( ( PersistedLeaf<K, V> ) rootPage ).setOffset( rootPageIo.getOffset() );
 
         // The next BTree Header offset (-1L, as it's a new BTree)
         position = store( position, NO_PAGE, pageIos );
@@ -1202,8 +1206,8 @@ public class RecordManager
                 }
                 else
                 {
-                    dataSize += serializeLeafValue( ( Leaf<K, V> ) page, pos, serializedData );
-                    dataSize += serializeLeafKey( ( Leaf<K, V> ) page, pos, serializedData );
+                    dataSize += serializeLeafValue( ( PersistedLeaf<K, V> ) page, pos, serializedData );
+                    dataSize += serializeLeafKey( ( PersistedLeaf<K, V> ) page, pos, serializedData );
                 }
             }
 
@@ -1281,7 +1285,7 @@ public class RecordManager
     /**
      * Serialize a Leaf's key
      */
-    private <K, V> int serializeLeafKey( Leaf<K, V> leaf, int pos, List<byte[]> serializedData )
+    private <K, V> int serializeLeafKey( PersistedLeaf<K, V> leaf, int pos, List<byte[]> serializedData )
     {
         int dataSize = 0;
         KeyHolder<K> keyHolder = leaf.getKeyHolder( pos );
@@ -1310,7 +1314,7 @@ public class RecordManager
     /**
      * Serialize a Leaf's Value. We store 
      */
-    private <K, V> int serializeLeafValue( Leaf<K, V> leaf, int pos, List<byte[]> serializedData )
+    private <K, V> int serializeLeafValue( PersistedLeaf<K, V> leaf, int pos, List<byte[]> serializedData )
         throws IOException
     {
         // The value can be an Array or a sub-btree, but we don't care
@@ -1916,7 +1920,7 @@ public class RecordManager
      * @return The offset of the new page
      * @throws IOException 
      */
-    /* No qualifier*/<K, V> PageHolder<K, V> writePage( BTree<K, V> btree, Page<K, V> newPage,
+    /* No qualifier*/<K, V> PersistedPageHolder<K, V> writePage( BTree<K, V> btree, Page<K, V> newPage,
         long newRevision )
         throws IOException
     {
@@ -1931,7 +1935,7 @@ public class RecordManager
         // Build the resulting reference
         long offset = pageIos[0].getOffset();
         long lastOffset = pageIos[pageIos.length - 1].getOffset();
-        PageHolder<K, V> valueHolder = new PageHolder<K, V>( btree, newPage, offset,
+        PersistedPageHolder<K, V> valueHolder = new PersistedPageHolder<K, V>( btree, newPage, offset,
             lastOffset );
 
         if ( LOG_CHECK.isDebugEnabled() )

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.java?rev=1551187&r1=1551186&r2=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.java Mon Dec 16 11:46:32 2013
@@ -29,7 +29,6 @@ import org.apache.directory.mavibot.btre
 import org.apache.directory.mavibot.btree.ParentPos;
 import org.apache.directory.mavibot.btree.Transaction;
 import org.apache.directory.mavibot.btree.Tuple;
-import org.apache.directory.mavibot.btree.TupleCursor;
 import org.apache.directory.mavibot.btree.ValueHolder;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
 
@@ -130,7 +129,7 @@ public class TupleCursorImpl<K, V> exten
 
             try
             {
-                ValueHolder<V> valueHolder = ( ( Leaf<K, V> ) parentPos.page ).getValue( parentPos.pos );
+                ValueHolder<V> valueHolder = ( ( PersistedLeaf<K, V> ) parentPos.page ).getValue( parentPos.pos );
                 
                 parentPos.valueCursor = valueHolder.getCursor();
                 
@@ -142,7 +141,7 @@ public class TupleCursorImpl<K, V> exten
             }
         }
         
-        Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
+        PersistedLeaf<K, V> leaf = ( PersistedLeaf<K, V> ) ( parentPos.page );
         tuple.setKey( leaf.getKey( parentPos.pos ) );
         tuple.setValue( value );
 
@@ -184,7 +183,7 @@ public class TupleCursorImpl<K, V> exten
             {
                 // We can pick the next element at this level
                 parentPos.pos++;
-                child = ((Node<K, V>)parentPos.page).children[parentPos.pos].getValue( btree );
+                child = ((Node<K, V>)parentPos.page).children[parentPos.pos].getValue();
                 
                 // and go down the tree through the nodes
                 while ( currentDepth < depth - 1 )
@@ -193,14 +192,14 @@ public class TupleCursorImpl<K, V> exten
                     parentPos = stack[currentDepth];
                     parentPos.pos = 0;
                     parentPos.page = child;
-                    child = ((Node<K, V>)child).children[0].getValue( btree );
+                    child = ((Node<K, V>)child).children[0].getValue();
                 }
 
                 // and the leaf
                 parentPos = stack[depth];
                 parentPos.page = child;
                 parentPos.pos = 0;
-                parentPos.valueCursor = ((Leaf<K, V>)child).values[0].getCursor();
+                parentPos.valueCursor = ((PersistedLeaf<K, V>)child).values[0].getCursor();
 
                 return parentPos;
             }
@@ -243,13 +242,13 @@ public class TupleCursorImpl<K, V> exten
             else
             {
                 // We can pick the next element at this level
-                child = ((Node<K, V>)parentPos.page).children[parentPos.pos + 1].getValue( btree );
+                child = ((Node<K, V>)parentPos.page).children[parentPos.pos + 1].getValue();
                 
                 // and go down the tree through the nodes
                 while ( currentDepth < depth - 1 )
                 {
                     currentDepth++;
-                    child = ((Node<K, V>)child).children[0].getValue( btree );
+                    child = ((Node<K, V>)child).children[0].getValue();
                 }
 
                 return true;
@@ -293,13 +292,13 @@ public class TupleCursorImpl<K, V> exten
             else
             {
                 // We can pick the previous element at this level
-                child = ((Node<K, V>)parentPos.page).children[parentPos.pos - 1].getValue( btree );
+                child = ((Node<K, V>)parentPos.page).children[parentPos.pos - 1].getValue();
                 
                 // and go down the tree through the nodes
                 while ( currentDepth < depth - 1 )
                 {
                     currentDepth++;
-                    child = ((Node<K, V>)child).children[child.getNbElems()].getValue( btree );
+                    child = ((Node<K, V>)child).children[child.getNbElems()].getValue();
                 }
 
                 return true;
@@ -344,7 +343,7 @@ public class TupleCursorImpl<K, V> exten
             {
                 // We can pick the next element at this level
                 parentPos.pos--;
-                child = ((Node<K, V>)parentPos.page).children[parentPos.pos].getValue( btree );
+                child = ((Node<K, V>)parentPos.page).children[parentPos.pos].getValue();
                 
                 // and go down the tree through the nodes
                 while ( currentDepth < depth - 1 )
@@ -353,14 +352,14 @@ public class TupleCursorImpl<K, V> exten
                     parentPos = stack[currentDepth];
                     parentPos.pos = child.getNbElems();
                     parentPos.page = child;
-                    child = ((Node<K, V>)parentPos.page).children[parentPos.page.getNbElems()].getValue( btree );
+                    child = ((Node<K, V>)parentPos.page).children[parentPos.page.getNbElems()].getValue();
                 }
 
                 // and the leaf
                 parentPos = stack[depth];
                 parentPos.pos = child.getNbElems() - 1;
                 parentPos.page = child;
-                ValueHolder<V> valueHolder = ((Leaf<K, V>)parentPos.page).values[parentPos.pos];
+                ValueHolder<V> valueHolder = ((PersistedLeaf<K, V>)parentPos.page).values[parentPos.pos];
                 parentPos.valueCursor = valueHolder.getCursor();
                 parentPos.valueCursor.afterLast();
 
@@ -436,7 +435,7 @@ public class TupleCursorImpl<K, V> exten
                 
                 try
                 {
-                    ValueHolder<V> valueHolder = ( ( Leaf<K, V> ) parentPos.page ).getValue( parentPos.pos );
+                    ValueHolder<V> valueHolder = ( ( PersistedLeaf<K, V> ) parentPos.page ).getValue( parentPos.pos );
                     
                     parentPos.valueCursor = valueHolder.getCursor();
                     parentPos.valueCursor.afterLast();
@@ -451,7 +450,7 @@ public class TupleCursorImpl<K, V> exten
         }
 
 
-        Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
+        PersistedLeaf<K, V> leaf = ( PersistedLeaf<K, V> ) ( parentPos.page );
         tuple.setKey( leaf.getKey( parentPos.pos ) );
         tuple.setValue( value );
 
@@ -649,7 +648,7 @@ public class TupleCursorImpl<K, V> exten
             if ( ( newParentPos == null ) || ( newParentPos.page == null ) )
             {
                 // This is the end : no more value
-                Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
+                PersistedLeaf<K, V> leaf = ( PersistedLeaf<K, V> ) ( parentPos.page );
                 ValueHolder<V> valueHolder = leaf.values[parentPos.pos];
                 parentPos.pos = AFTER_LAST;
                 parentPos.valueCursor = valueHolder.getCursor();
@@ -669,7 +668,7 @@ public class TupleCursorImpl<K, V> exten
         }
 
         // The key
-        Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
+        PersistedLeaf<K, V> leaf = ( PersistedLeaf<K, V> ) ( parentPos.page );
         tuple.setKey( leaf.getKey( parentPos.pos ) );
         
         // The value
@@ -760,7 +759,7 @@ public class TupleCursorImpl<K, V> exten
         }
         
         // Update the Tuple 
-        Leaf<K, V> leaf = ( Leaf<K, V> ) ( parentPos.page );
+        PersistedLeaf<K, V> leaf = ( PersistedLeaf<K, V> ) ( parentPos.page );
 
         // The key
         tuple.setKey( leaf.getKey( parentPos.pos ) );
@@ -798,7 +797,7 @@ public class TupleCursorImpl<K, V> exten
                 parentPos.page = child;
             }
 
-            child = ((Node<K, V>)parentPos.page).children[0].getValue( btree );
+            child = ((Node<K, V>)parentPos.page).children[0].getValue();
         }
 
         // and leaf
@@ -812,7 +811,7 @@ public class TupleCursorImpl<K, V> exten
         
         if ( parentPos.valueCursor != null )
         {
-            parentPos.valueCursor = ((Leaf<K, V>)parentPos.page).values[0].getCursor();
+            parentPos.valueCursor = ((PersistedLeaf<K, V>)parentPos.page).values[0].getCursor();
             parentPos.valueCursor.beforeFirst();
         }
     }
@@ -846,7 +845,7 @@ public class TupleCursorImpl<K, V> exten
                 parentPos.pos = parentPos.page.getNbElems();
             }
 
-            child = ((Node<K, V>)parentPos.page).children[parentPos.pos].getValue( btree );
+            child = ((Node<K, V>)parentPos.page).children[parentPos.pos].getValue();
         }
         
         // and leaf
@@ -862,7 +861,7 @@ public class TupleCursorImpl<K, V> exten
             parentPos.pos = child.getNbElems() - 1;
         }
 
-        parentPos.valueCursor = ((Leaf<K, V>)parentPos.page).values[parentPos.pos].getCursor();
+        parentPos.valueCursor = ((PersistedLeaf<K, V>)parentPos.page).values[parentPos.pos].getCursor();
         parentPos.valueCursor.afterLast();
         parentPos.pos = AFTER_LAST;
     }

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeTest.java?rev=1551187&r1=1551186&r2=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeTest.java (original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeTest.java Mon Dec 16 11:46:32 2013
@@ -38,6 +38,7 @@ import java.util.Set;
 import org.apache.directory.mavibot.btree.BTree;
 import org.apache.directory.mavibot.btree.KeyHolder;
 import org.apache.directory.mavibot.btree.Page;
+import org.apache.directory.mavibot.btree.PageHolder;
 import org.apache.directory.mavibot.btree.Tuple;
 import org.apache.directory.mavibot.btree.TupleCursor;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
@@ -1044,7 +1045,7 @@ public class InMemoryBTreeTest
     private Page<Integer, String> createLeaf( BTree<Integer, String> btree, long revision,
         Tuple<Integer, String>... tuples )
     {
-        Leaf<Integer, String> leaf = new Leaf<Integer, String>( btree );
+        InMemoryLeaf<Integer, String> leaf = new InMemoryLeaf<Integer, String>( btree );
         int pos = 0;
         leaf.setRevision( revision );
         leaf.setNbElems( tuples.length );
@@ -1054,7 +1055,7 @@ public class InMemoryBTreeTest
 
         for ( Tuple<Integer, String> tuple : tuples )
         {
-            leaf.setKey( pos, tuple.getKey() );
+            leaf.setKey( pos, new KeyHolder<Integer>( tuple.getKey() ) );
             leaf.values[pos] = new InMemoryValueHolder<String>( btree, tuple.getValue() );
             pos++;
         }
@@ -1070,10 +1071,10 @@ public class InMemoryBTreeTest
 
         if ( pos > 0 )
         {
-            node.setKey( pos - 1, leftmost.getKey() );
+            node.setKey( pos - 1, new KeyHolder<Integer>( leftmost.getKey() ) );
         }
 
-        node.children[pos] = page;
+        node.setPageHolder( pos, new PageHolder<Integer, String>( btree, page ) );
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/LeafTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/LeafTest.java?rev=1551187&r1=1551186&r2=1551187&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/LeafTest.java (original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/LeafTest.java Mon Dec 16 11:46:32 2013
@@ -31,8 +31,10 @@ import org.apache.directory.mavibot.btre
 import org.apache.directory.mavibot.btree.BorrowedFromRightResult;
 import org.apache.directory.mavibot.btree.DeleteResult;
 import org.apache.directory.mavibot.btree.InsertResult;
+import org.apache.directory.mavibot.btree.KeyHolder;
 import org.apache.directory.mavibot.btree.NotPresentResult;
 import org.apache.directory.mavibot.btree.Page;
+import org.apache.directory.mavibot.btree.PageHolder;
 import org.apache.directory.mavibot.btree.RemoveResult;
 import org.apache.directory.mavibot.btree.Tuple;
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
@@ -75,11 +77,11 @@ public class LeafTest
      * A helper method to insert elements in a Leaf
      * @throws IOException 
      */
-    private Leaf<Long, String> insert( Leaf<Long, String> leaf, long key, String value ) throws IOException
+    private InMemoryLeaf<Long, String> insert( InMemoryLeaf<Long, String> leaf, long key, String value ) throws IOException
     {
         InsertResult<Long, String> result = leaf.insert( 1L, key, value );
 
-        return ( Leaf<Long, String> ) ( (org.apache.directory.mavibot.btree.ModifyResult<Long, String> ) result ).getModifiedPage();
+        return ( InMemoryLeaf<Long, String> ) ( (org.apache.directory.mavibot.btree.ModifyResult<Long, String> ) result ).getModifiedPage();
     }
 
 
@@ -90,7 +92,7 @@ public class LeafTest
     @Test
     public void testDeleteFromEmptyLeaf() throws IOException
     {
-        Leaf<Long, String> leaf = new Leaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> leaf = new InMemoryLeaf<Long, String>( btree );
 
         DeleteResult<Long, String> result = leaf.delete( 1L, 1L, null, null, -1 );
 
@@ -105,7 +107,7 @@ public class LeafTest
     @Test
     public void testDeleteNotPresentElementFromRootLeaf() throws IOException
     {
-        Leaf<Long, String> leaf = new Leaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> leaf = new InMemoryLeaf<Long, String>( btree );
         leaf = insert( leaf, 1L, "v1" );
         leaf = insert( leaf, 2L, "v2" );
         leaf = insert( leaf, 3L, "v3" );
@@ -124,7 +126,7 @@ public class LeafTest
     @Test
     public void testDeletePresentElementFromRootLeaf() throws IOException
     {
-        Leaf<Long, String> leaf = new Leaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> leaf = new InMemoryLeaf<Long, String>( btree );
         leaf = insert( leaf, 1L, "v1" );
         leaf = insert( leaf, 2L, "v2" );
         leaf = insert( leaf, 3L, "v3" );
@@ -171,7 +173,7 @@ public class LeafTest
     @Test
     public void testDeleteFirstElementFromRootLeaf() throws IOException
     {
-        Leaf<Long, String> leaf = new Leaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> leaf = new InMemoryLeaf<Long, String>( btree );
         leaf = insert( leaf, 1L, "v1" );
         leaf = insert( leaf, 2L, "v2" );
         leaf = insert( leaf, 3L, "v3" );
@@ -226,9 +228,9 @@ public class LeafTest
     public void testDeleteBorrowingFromLeftSibling() throws IOException
     {
         Node<Long, String> parent = new Node<Long, String>( btree, 1L, 2 );
-        Leaf<Long, String> left = new Leaf<Long, String>( btree );
-        Leaf<Long, String> target = new Leaf<Long, String>( btree );
-        Leaf<Long, String> right = new Leaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> left = new InMemoryLeaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> target = new InMemoryLeaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> right = new InMemoryLeaf<Long, String>( btree );
 
         // Fill the left page
         left = insert( left, 1L, "v1" );
@@ -249,13 +251,13 @@ public class LeafTest
         right = insert( right, 12L, "v12" );
         right = insert( right, 13L, "v13" );
 
-        parent.children[0] = left;
-        parent.children[1] = target;
-        parent.children[2] = right;
+        parent.setPageHolder( 0, new PageHolder<Long, String>( btree, left ) );
+        parent.setPageHolder( 1, new PageHolder<Long, String>( btree, target ) );
+        parent.setPageHolder( 2, new PageHolder<Long, String>( btree, right ) );
 
         // Update the parent
-        parent.setKey( 0, 6L );
-        parent.setKey( 1, 10L );
+        parent.setKey( 0, new KeyHolder<Long>( 6L ) );
+        parent.setKey( 1, new KeyHolder<Long>( 10L ) );
 
         // Now, delete the element from the target page
         DeleteResult<Long, String> result = target.delete( 2L, 7L, null, parent, 1 );
@@ -268,7 +270,7 @@ public class LeafTest
         assertEquals( Long.valueOf( 7L ), removedKey.getKey() );
 
         // Check the modified leaf
-        Leaf<Long, String> newLeaf = ( Leaf<Long, String> ) borrowed.getModifiedPage();
+        InMemoryLeaf<Long, String> newLeaf = ( InMemoryLeaf<Long, String> ) borrowed.getModifiedPage();
 
         assertEquals( 4, newLeaf.getNbElems() );
         assertEquals( Long.valueOf( 5L ), newLeaf.getKey( 0 ) );
@@ -277,7 +279,7 @@ public class LeafTest
         assertEquals( Long.valueOf( 9L ), newLeaf.getKey( 3 ) );
 
         // Check the sibling
-        Leaf<Long, String> leftSibling = ( Leaf<Long, String> ) borrowed.getModifiedSibling();
+        InMemoryLeaf<Long, String> leftSibling = ( InMemoryLeaf<Long, String> ) borrowed.getModifiedSibling();
 
         assertEquals( 4, leftSibling.getNbElems() );
         assertEquals( Long.valueOf( 1L ), leftSibling.getKey( 0 ) );
@@ -296,9 +298,9 @@ public class LeafTest
     public void testDeleteBorrowingFromRightSibling() throws IOException
     {
         Node<Long, String> parent = new Node<Long, String>( btree, 1L, 2 );
-        Leaf<Long, String> left = new Leaf<Long, String>( btree );
-        Leaf<Long, String> target = new Leaf<Long, String>( btree );
-        Leaf<Long, String> right = new Leaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> left = new InMemoryLeaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> target = new InMemoryLeaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> right = new InMemoryLeaf<Long, String>( btree );
 
         // Fill the left page
         left = insert( left, 1L, "v1" );
@@ -319,13 +321,13 @@ public class LeafTest
         right = insert( right, 13L, "v13" );
         right = insert( right, 14L, "v14" );
 
-        parent.children[0] = left;
-        parent.children[1] = target;
-        parent.children[2] = right;
+        parent.setPageHolder( 0, new PageHolder<Long, String>( btree, left ) );
+        parent.setPageHolder( 1, new PageHolder<Long, String>( btree, target ) );
+        parent.setPageHolder( 2, new PageHolder<Long, String>( btree, right ) );
 
         // Update the parent
-        parent.setKey( 0, 6L );
-        parent.setKey( 1, 10L );
+        parent.setKey( 0, new KeyHolder<Long>( 6L ) );
+        parent.setKey( 1, new KeyHolder<Long>( 10L ) );
 
         // Now, delete the element from the target page
         DeleteResult<Long, String> result = target.delete( 2L, 7L, null, parent, 1 );
@@ -339,7 +341,7 @@ public class LeafTest
         assertEquals( Long.valueOf( 7L ), removedKey.getKey() );
 
         // Check the modified leaf
-        Leaf<Long, String> newLeaf = ( Leaf<Long, String> ) borrowed.getModifiedPage();
+        InMemoryLeaf<Long, String> newLeaf = ( InMemoryLeaf<Long, String> ) borrowed.getModifiedPage();
 
         assertEquals( 4, newLeaf.getNbElems() );
         assertEquals( Long.valueOf( 6L ), newLeaf.getKey( 0 ) );
@@ -348,7 +350,7 @@ public class LeafTest
         assertEquals( Long.valueOf( 10L ), newLeaf.getKey( 3 ) );
 
         // Check the sibling
-        Leaf<Long, String> rightSibling = ( Leaf<Long, String> ) borrowed.getModifiedSibling();
+        InMemoryLeaf<Long, String> rightSibling = ( InMemoryLeaf<Long, String> ) borrowed.getModifiedSibling();
 
         assertEquals( 4, rightSibling.getNbElems() );
         assertEquals( Long.valueOf( 11L ), rightSibling.getKey( 0 ) );
@@ -367,9 +369,9 @@ public class LeafTest
     public void testDeleteMergeWithSibling() throws IOException
     {
         Node<Long, String> parent = new Node<Long, String>( btree, 1L, 2 );
-        Leaf<Long, String> left = new Leaf<Long, String>( btree );
-        Leaf<Long, String> target = new Leaf<Long, String>( btree );
-        Leaf<Long, String> right = new Leaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> left = new InMemoryLeaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> target = new InMemoryLeaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> right = new InMemoryLeaf<Long, String>( btree );
 
         // Fill the left page
         left = insert( left, 1L, "v1" );
@@ -389,13 +391,13 @@ public class LeafTest
         right = insert( right, 11L, "v11" );
         right = insert( right, 12L, "v12" );
 
-        parent.children[0] = left;
-        parent.children[1] = target;
-        parent.children[2] = right;
+        parent.setPageHolder( 0, new PageHolder<Long, String>( btree, left ) );
+        parent.setPageHolder( 1, new PageHolder<Long, String>( btree, target ) );
+        parent.setPageHolder( 2, new PageHolder<Long, String>( btree, right ) );
 
         // Update the parent
-        parent.setKey( 0, 5L );
-        parent.setKey( 1, 9L );
+        parent.setKey( 0, new KeyHolder<Long>( 5L ) );
+        parent.setKey( 1, new KeyHolder<Long>( 9L ) );
 
         // Now, delete the element from the target page
         DeleteResult<Long, String> result = target.delete( 2L, 7L, null, parent, 1 );
@@ -408,7 +410,7 @@ public class LeafTest
         assertEquals( Long.valueOf( 7L ), removedKey.getKey() );
 
         // Check the modified leaf
-        Leaf<Long, String> newLeaf = ( Leaf<Long, String> ) merged.getModifiedPage();
+        InMemoryLeaf<Long, String> newLeaf = ( InMemoryLeaf<Long, String> ) merged.getModifiedPage();
 
         assertEquals( 7, newLeaf.getNbElems() );
         assertEquals( Long.valueOf( 1L ), newLeaf.getKey( 0 ) );
@@ -428,13 +430,13 @@ public class LeafTest
     @Test
     public void testFindPos() throws Exception
     {
-        Leaf<Long, String> leaf = new Leaf<Long, String>( btree );
+        InMemoryLeaf<Long, String> leaf = new InMemoryLeaf<Long, String>( btree );
 
         // Inject the values
         for ( long i = 0; i < 8; i++ )
         {
             long value = i + i + 1;
-            leaf = ( Leaf<Long, String> ) ( (org.apache.directory.mavibot.btree.ModifyResult<Long, String> ) leaf.insert( 0L, value, "V" + value ) )
+            leaf = ( InMemoryLeaf<Long, String> ) ( (org.apache.directory.mavibot.btree.ModifyResult<Long, String> ) leaf.insert( 0L, value, "V" + value ) )
                 .getModifiedPage();
         }
 



Mime
View raw message