Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 8703910651 for ; Mon, 16 Dec 2013 11:47:08 +0000 (UTC) Received: (qmail 66048 invoked by uid 500); 16 Dec 2013 11:47:07 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 66008 invoked by uid 500); 16 Dec 2013 11:47:07 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 65999 invoked by uid 99); 16 Dec 2013 11:47:06 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Dec 2013 11:47:06 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 16 Dec 2013 11:46:56 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id E877F2388A29; Mon, 16 Dec 2013 11:46:33 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1551187 [1/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 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20131216114633.E877F2388A29@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: elecharny Date: Mon Dec 16 11:46:32 2013 New Revision: 1551187 URL: http://svn.apache.org/r1551187 Log: o Fixed a NPE in the Array holding for values o Added a PageHolder common class for in-memory and persisted btrees o The abstract in-memory and persisted page class have been removed o The in-memory/persisted Leaf classes have been removed to InMemoryLeaf/PersistedLeaf Added: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PageHolder.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryLeaf.java - copied, changed from r1551071, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Leaf.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedLeaf.java - copied, changed from r1551070, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Leaf.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedPageHolder.java - copied, changed from r1551070, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PageHolder.java Removed: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/AbstractInMemoryPage.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Leaf.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/AbstractPersistedPage.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Leaf.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PageHolder.java Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTupleCursor.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractValueHolder.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeFactory.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTree.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeBuilder.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryValueHolder.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/BTreeFactory.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/Node.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTree.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedBTreeBuilder.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/PersistedValueHolder.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/RecordManager.java directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/TupleCursorImpl.java directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeTest.java directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/memory/LeafTest.java Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractPage.java Mon Dec 16 11:46:32 2013 @@ -20,6 +20,9 @@ package org.apache.directory.mavibot.btree; +import java.io.IOException; +import java.lang.reflect.Array; + import org.apache.directory.mavibot.btree.KeyHolder; import org.apache.directory.mavibot.btree.Page; import org.apache.directory.mavibot.btree.exception.KeyNotFoundException; @@ -42,6 +45,9 @@ public abstract class AbstractPage /** Keys of children nodes */ protected KeyHolder[] keys; + /** Children pages associated with keys. */ + protected PageHolder[] children; + /** The number of current values in the Page */ protected int nbElems; @@ -69,6 +75,19 @@ public abstract class AbstractPage } /** + * Internal constructor used to create Page instance used when a page is being copied or overflow + */ + @SuppressWarnings("unchecked") + // Cannot create an array of generic objects + protected AbstractPage( BTree btree, long revision, int nbElems ) + { + this.btree = btree; + this.revision = revision; + this.nbElems = nbElems; + this.keys = ( KeyHolder[] ) Array.newInstance( KeyHolder.class, nbElems ); + } + + /** * {@inheritDoc} */ public int getNbElems() @@ -102,6 +121,76 @@ public abstract class AbstractPage /** * {@inheritDoc} */ + public Page getPage( int pos ) + { + if ( ( pos >= 0 ) && ( pos < children.length ) ) + { + return children[pos].getValue(); + } + else + { + return null; + } + } + + + /** + * {@inheritDoc} + */ + public void setPageHolder( int pos, PageHolder pageHolder ) + { + if ( ( pos >= 0 ) && ( pos < children.length ) ) + { + children[pos] = pageHolder; + } + } + + + /** + * Selects the sibling (the previous or next page with the same parent) which has + * the more element assuming it's above N/2 + * + * @param parent The parent of the current page + * @param The position of the current page reference in its parent + * @return The position of the sibling, or -1 if we have'nt found any sibling + * @throws IOException If we have an error while trying to access the page + */ + protected int selectSibling( Page parent, int parentPos ) throws IOException + { + if ( parentPos == 0 ) + { + // The current page is referenced on the left of its parent's page : + // we will not have a previous page with the same parent + return 1; + } + + if ( parentPos == parent.getNbElems() ) + { + // The current page is referenced on the right of its parent's page : + // we will not have a next page with the same parent + return parentPos - 1; + } + + Page prevPage = ((AbstractPage)parent).getPage( parentPos - 1 ); + Page nextPage = ((AbstractPage)parent).getPage( parentPos + 1 ); + + int prevPageSize = prevPage.getNbElems(); + int nextPageSize = nextPage.getNbElems(); + + if ( prevPageSize >= nextPageSize ) + { + return parentPos - 1; + } + else + { + return parentPos + 1; + } + } + + + /** + * {@inheritDoc} + */ public K getLeftMostKey() { return keys[0].getKey(); @@ -163,6 +252,18 @@ public abstract class AbstractPage /** + * Sets the key at a give position + * + * @param pos The position in the keys array + * @param key the key to inject + */ + public void setKey( int pos, KeyHolder key ) + { + keys[pos] = key; + } + + + /** * @param revision the keys to set */ public void setKeys( KeyHolder[] keys ) @@ -311,6 +412,15 @@ public abstract class AbstractPage /** + * @return the btree + */ + public BTree getBtree() + { + return btree; + } + + + /** * {@inheritDoc} */ public String dumpPage( String tabs ) Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTupleCursor.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTupleCursor.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTupleCursor.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractTupleCursor.java Mon Dec 16 11:46:32 2013 @@ -60,56 +60,6 @@ public abstract class AbstractTupleCurso /** * {@inheritDoc} - * - public void afterLast() throws IOException - { - // First check that we have elements in the BTree - if ( ( stack == null ) || ( stack.length == 0 ) ) - { - return; - } - - Page child = null; - - for ( int i = 0; i < depth; i++ ) - { - ParentPos parentPos = stack[i]; - - if ( child != null ) - { - parentPos.page = child; - parentPos.pos = child.getNbElems(); - } - else - { - // We have N+1 children if the page is a Node, so we don't decrement the nbElems field - parentPos.pos = parentPos.page.getNbElems(); - } - - child = ((Node)parentPos.page).children[parentPos.pos]; - } - - // and leaf - ParentPos parentPos = stack[depth]; - - if ( child == null ) - { - parentPos.pos = parentPos.page.getNbElems() - 1; - } - else - { - parentPos.page = child; - parentPos.pos = child.getNbElems() - 1; - } - - parentPos.valueCursor = ((Leaf)parentPos.page).values[parentPos.pos].getCursor(); - parentPos.valueCursor.afterLast(); - parentPos.pos = AFTER_LAST; - } - - - /** - * {@inheritDoc} */ public void close() { Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractValueHolder.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractValueHolder.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractValueHolder.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractValueHolder.java Mon Dec 16 11:46:32 2013 @@ -48,6 +48,9 @@ public abstract class AbstractValueHolde protected int valueThresholdUp = 1; protected int valueThresholdLow = 1; + protected int nbArrayElems; + + /** * {@inheritDoc} */ @@ -272,7 +275,7 @@ public abstract class AbstractValueHolde private void addInArray( V value ) { // We have to check that we have reached the threshold or not - if ( valueArray.length >= valueThresholdUp ) + if ( size() >= valueThresholdUp ) { // Ok, transform the array into a btree createSubTree(); @@ -287,6 +290,7 @@ public abstract class AbstractValueHolde } // We can delete the array now + nbArrayElems = 0; valueArray = null; // And inject the new value @@ -300,27 +304,37 @@ public abstract class AbstractValueHolde } else { - // First check that the value is not already present in the ValueHolder - int pos = findPos( value ); - - if ( pos >= 0 ) + // Create the array if it's null + if ( valueArray == null ) { - // The value exists : nothing to do - return; + valueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), 1 ); + nbArrayElems = 1; + valueArray[0] = value; + } + else + { + // check that the value is not already present in the ValueHolder + int pos = findPos( value ); + + if ( pos >= 0 ) + { + // The value exists : nothing to do + return; + } + + // Ok, we just have to insert the new element at the right position + // We transform the position to a positive value + pos = -( pos + 1 ); + // First, copy the array + V[] newValueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), valueArray.length + 1 ); + + System.arraycopy( valueArray, 0, newValueArray, 0, pos ); + newValueArray[pos] = value; + System.arraycopy( valueArray, pos, newValueArray, pos + 1, valueArray.length - pos ); + + // And switch the arrays + valueArray = newValueArray; } - - // Ok, we just have to insert the new element at the right position - // We transform the position to a positive value - pos = -( pos + 1 ); - // First, copy the array - V[] newValueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), valueArray.length + 1 ); - - System.arraycopy( valueArray, 0, newValueArray, 0, pos ); - newValueArray[pos] = value; - System.arraycopy( valueArray, pos, newValueArray, pos + 1, valueArray.length - pos ); - - // And switch the arrays - valueArray = newValueArray; } } @@ -347,7 +361,7 @@ public abstract class AbstractValueHolde */ public void add( V value ) { - if ( valueArray != null ) + if ( valueBtree == null ) { addInArray( value ); } Added: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PageHolder.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PageHolder.java?rev=1551187&view=auto ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PageHolder.java (added) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PageHolder.java Mon Dec 16 11:46:32 2013 @@ -0,0 +1,55 @@ +/* + * 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.mavibot.btree; + +import java.io.IOException; + +import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException; + +public class PageHolder +{ + /** The BTree */ + protected BTree btree; + + /** The stored page */ + private Page page; + + /** + * Create a new holder storing an offset and a SoftReference containing the element. + * + * @param page The element to store into a SoftReference + **/ + public PageHolder( BTree btree, Page page ) + { + this.btree = btree; + this.page = page; + } + + + /** + * {@inheritDoc} + * @throws IOException + * @throws EndOfFileExceededException + */ + public Page getValue() + { + return page; + } +} Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeFactory.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeFactory.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeFactory.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/BTreeFactory.java Mon Dec 16 11:46:32 2013 @@ -23,8 +23,11 @@ package org.apache.directory.mavibot.btr import java.io.IOException; import java.util.LinkedList; +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; +import org.apache.directory.mavibot.btree.PageHolder; import org.apache.directory.mavibot.btree.ParentPos; import org.apache.directory.mavibot.btree.ValueHolder; import org.apache.directory.mavibot.btree.serializer.ElementSerializer; @@ -77,9 +80,9 @@ public class BTreeFactory * @param nbElems The number or elements in this leaf * @return A Leaf instance */ - public static Leaf createLeaf( BTree btree, long revision, int nbElems ) + public static InMemoryLeaf createLeaf( BTree btree, long revision, int nbElems ) { - Leaf leaf = new Leaf( btree, revision, nbElems ); + InMemoryLeaf leaf = new InMemoryLeaf( btree, revision, nbElems ); return leaf; } @@ -192,7 +195,8 @@ public class BTreeFactory */ public static void setKey( Page page, int pos, K key ) { - ( ( AbstractInMemoryPage ) page ).setKey( pos, key ); + KeyHolder keyHolder = new KeyHolder( key ); + ( ( AbstractPage ) page ).setKey( pos, keyHolder ); } @@ -201,7 +205,7 @@ public class BTreeFactory * @param pos The position in the values array * @param value the value to inject */ - public static void setValue( Leaf page, int pos, InMemoryValueHolder value ) + public static void setValue( InMemoryLeaf page, int pos, InMemoryValueHolder value ) { page.setValue( pos, value ); } @@ -212,9 +216,9 @@ public class BTreeFactory * @param pos The position in the values array * @param value the value to inject */ - public static void setValue( Node page, int pos, Page value ) + public static void setValue( BTree btree, Node page, int pos, Page value ) { - page.children[pos] = value; + page.setPageHolder( pos, new PageHolder( btree, value ) ); } @@ -232,9 +236,9 @@ public class BTreeFactory ParentPos last = new ParentPos( btree.getRootPage(), btree.getRootPage().getNbElems() ); stack.push( last ); - if ( btree.getRootPage() instanceof Leaf ) + if ( btree.getRootPage() instanceof InMemoryLeaf ) { - Leaf leaf = ( Leaf ) ( btree.getRootPage() ); + InMemoryLeaf leaf = ( InMemoryLeaf ) ( btree.getRootPage() ); ValueHolder valueHolder = leaf.values[last.pos]; last.valueCursor = valueHolder.getCursor(); } @@ -244,14 +248,14 @@ public class BTreeFactory while ( true ) { - Page p = node.children[node.getNbElems()]; + Page p = node.getPage( node.getNbElems() ); last = new ParentPos( p, p.getNbElems() ); stack.push( last ); - if ( p instanceof Leaf ) + if ( p instanceof InMemoryLeaf ) { - Leaf leaf = ( Leaf ) ( last.page ); + InMemoryLeaf leaf = ( InMemoryLeaf ) ( last.page ); ValueHolder valueHolder = leaf.values[last.pos]; last.valueCursor = valueHolder.getCursor(); break; Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTree.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTree.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTree.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTree.java Mon Dec 16 11:46:32 2013 @@ -154,7 +154,7 @@ public class InMemoryBTree extends // Create the first root page, with revision 0L. It will be empty // and increment the revision at the same time - rootPage = new Leaf( this ); + rootPage = new InMemoryLeaf( this ); // Now, initialize the BTree init(); @@ -265,7 +265,7 @@ public class InMemoryBTree extends // Create the first root page, with revision 0L. It will be empty // and increment the revision at the same time - rootPage = new Leaf( this ); + rootPage = new InMemoryLeaf( this ); // Now, call the init() method init(); Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeBuilder.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeBuilder.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeBuilder.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryBTreeBuilder.java Mon Dec 16 11:46:32 2013 @@ -36,6 +36,7 @@ import org.apache.directory.mavibot.btre 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.ValueHolder; import org.apache.directory.mavibot.btree.serializer.ElementSerializer; @@ -77,7 +78,7 @@ public class InMemoryBTreeBuilder int totalTupleCount = 0; - Leaf leaf1 = createLeaf( btree, 0, numKeysInNode ); + InMemoryLeaf leaf1 = createLeaf( btree, 0, numKeysInNode ); lstLeaves.add( leaf1 ); int leafIndex = 0; @@ -107,7 +108,7 @@ public class InMemoryBTreeBuilder } // remove null keys and values from the last leaf and resize - Leaf lastLeaf = ( Leaf ) lstLeaves.get( lstLeaves.size() - 1 ); + InMemoryLeaf lastLeaf = ( InMemoryLeaf ) lstLeaves.get( lstLeaves.size() - 1 ); for ( int i = 0; i < lastLeaf.getNbElems(); i++ ) { if ( lastLeaf.getKeys()[i] == null ) @@ -161,7 +162,7 @@ public class InMemoryBTreeBuilder setKey( node, i - 1, p.getLeftMostKey() ); } - node.children[i] = p; + node.setPageHolder( i, new PageHolder( btree, p ) ); i++; totalNodes++; Copied: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryLeaf.java (from r1551071, directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Leaf.java) URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryLeaf.java?p2=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryLeaf.java&p1=directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Leaf.java&r1=1551071&r2=1551187&rev=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Leaf.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryLeaf.java Mon Dec 16 11:46:32 2013 @@ -23,11 +23,13 @@ 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; 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.ModifyResult; import org.apache.directory.mavibot.btree.NotPresentResult; import org.apache.directory.mavibot.btree.Page; @@ -51,7 +53,7 @@ import org.apache.directory.mavibot.btre * * @author Apache Directory Project */ -/* No qualifier */class Leaf extends AbstractInMemoryPage +/* No qualifier */class InMemoryLeaf extends AbstractPage { /** Values associated with keys */ protected ValueHolder[] values; @@ -62,7 +64,7 @@ import org.apache.directory.mavibot.btre * * @param btree The BTree this page belongs to. */ - /* No qualifier */Leaf( BTree btree ) + InMemoryLeaf( BTree btree ) { super( btree ); } @@ -76,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 btree, long revision, int nbElems ) + InMemoryLeaf( BTree btree, long revision, int nbElems ) { super( btree, revision, nbElems ); @@ -193,15 +194,15 @@ import org.apache.directory.mavibot.btre } } - Leaf newLeaf = null; + InMemoryLeaf newLeaf = null; if ( keyRemoved ) { - newLeaf = new Leaf( btree, revision, nbElems - 1 ); + newLeaf = new InMemoryLeaf( btree, revision, nbElems - 1 ); } else { - newLeaf = new Leaf( btree, revision, nbElems ); + newLeaf = new InMemoryLeaf( btree, revision, nbElems ); } // Create the result @@ -231,7 +232,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 ) parent, parentPos ); - Leaf sibling = ( Leaf ) ( ( ( Node ) parent ).children[siblingPos] ); + InMemoryLeaf sibling = ( InMemoryLeaf ) ( ( ( Node ) parent ).getPage( siblingPos ) ); if ( sibling.getNbElems() == halfSize ) { @@ -298,13 +299,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 mergeWithSibling( Tuple removedElement, long revision, Leaf sibling, + private DeleteResult mergeWithSibling( Tuple removedElement, long revision, InMemoryLeaf 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 newLeaf = new Leaf( btree, revision, btree.getPageSize() - 1 ); + InMemoryLeaf newLeaf = new InMemoryLeaf( btree, revision, btree.getPageSize() - 1 ); if ( isLeft ) { @@ -359,7 +360,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 borrowFromLeft( Tuple removedElement, long revision, Leaf sibling, int pos ) + private DeleteResult borrowFromLeft( Tuple removedElement, long revision, InMemoryLeaf sibling, int pos ) throws IOException { // The sibling is on the left, borrow the rightmost element @@ -367,14 +368,14 @@ import org.apache.directory.mavibot.btre ValueHolder siblingValue = sibling.values[sibling.getNbElems() - 1]; // Create the new sibling, with one less element at the end - Leaf newSibling = ( Leaf ) sibling.copy( revision, sibling.getNbElems() - 1 ); + InMemoryLeaf newSibling = ( InMemoryLeaf ) 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 newLeaf = new Leaf( btree, revision, nbElems ); + InMemoryLeaf newLeaf = new InMemoryLeaf( btree, revision, nbElems ); // Insert the borrowed element - newLeaf.setKey( 0, siblingKey ); + newLeaf.setKey( 0, new KeyHolder( siblingKey ) ); newLeaf.values[0] = siblingValue; // Copy the keys and the values up to the insertion position, @@ -406,7 +407,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 borrowFromRight( Tuple removedElement, long revision, Leaf sibling, int pos ) + private DeleteResult borrowFromRight( Tuple removedElement, long revision, InMemoryLeaf sibling, int pos ) throws IOException { // The sibling is on the left, borrow the rightmost element @@ -414,7 +415,7 @@ import org.apache.directory.mavibot.btre ValueHolder siblingHolder = sibling.values[0]; // Create the new sibling - Leaf newSibling = new Leaf( btree, revision, sibling.getNbElems() - 1 ); + InMemoryLeaf newSibling = new InMemoryLeaf( btree, revision, sibling.getNbElems() - 1 ); // Copy the keys and the values from 1 to N in the new sibling System.arraycopy( sibling.getKeys(), 1, newSibling.getKeys(), 0, sibling.nbElems - 1 ); @@ -422,10 +423,10 @@ 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 newLeaf = new Leaf( btree, revision, nbElems ); + InMemoryLeaf newLeaf = new InMemoryLeaf( btree, revision, nbElems ); // Insert the borrowed element at the end - newLeaf.setKey( nbElems - 1, siblingKey ); + newLeaf.setKey( nbElems - 1, new KeyHolder( siblingKey ) ); newLeaf.values[nbElems - 1] = siblingHolder; // Copy the keys and the values up to the deletion position, @@ -454,7 +455,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, Leaf newLeaf, int pos ) throws IOException + private void copyAfterRemovingElement( boolean keyRemoved, InMemoryLeaf newLeaf, int pos ) throws IOException { if ( keyRemoved ) { @@ -703,7 +704,7 @@ import org.apache.directory.mavibot.btre */ private Page copy( long revision, int nbElems ) { - Leaf newLeaf = new Leaf( btree, revision, nbElems ); + InMemoryLeaf newLeaf = new InMemoryLeaf( btree, revision, nbElems ); // Copy the keys and the values System.arraycopy( getKeys(), 0, newLeaf.getKeys(), 0, nbElems ); @@ -726,12 +727,12 @@ import org.apache.directory.mavibot.btre private InsertResult replaceElement( long revision, K key, V value, int pos ) throws IOException { - Leaf newLeaf = this; + InMemoryLeaf newLeaf = this; if ( this.revision != revision ) { // The page hasn't been modified yet, we need to copy it first - newLeaf = ( Leaf ) copy( revision, nbElems ); + newLeaf = ( InMemoryLeaf ) copy( revision, nbElems ); } // Get the previous value from the leaf (it's a copy) @@ -773,7 +774,7 @@ import org.apache.directory.mavibot.btre private Page addElement( long revision, K key, V value, int pos ) { // First copy the current page, but add one element in the copied page - Leaf newLeaf = new Leaf( btree, revision, nbElems + 1 ); + InMemoryLeaf newLeaf = new InMemoryLeaf( btree, revision, nbElems + 1 ); // Atm, store the value in memory InMemoryValueHolder valueHolder = new InMemoryValueHolder( btree, value ); @@ -781,7 +782,7 @@ import org.apache.directory.mavibot.btre // Deal with the special case of an empty page if ( nbElems == 0 ) { - newLeaf.setKey( 0, key ); + newLeaf.setKey( 0, new KeyHolder( key ) ); newLeaf.values[0] = valueHolder; } else @@ -791,7 +792,7 @@ import org.apache.directory.mavibot.btre System.arraycopy( values, 0, newLeaf.values, 0, pos ); // Add the new element - newLeaf.setKey( pos, key ); + newLeaf.setKey( pos, new KeyHolder( key ) ); newLeaf.values[pos] = valueHolder; // And copy the remaining elements @@ -821,22 +822,22 @@ import org.apache.directory.mavibot.btre private InsertResult addAndSplit( long revision, K key, V value, int pos ) { int middle = btree.getPageSize() >> 1; - Leaf leftLeaf = null; - Leaf rightLeaf = null; + InMemoryLeaf leftLeaf = null; + InMemoryLeaf rightLeaf = null; InMemoryValueHolder valueHolder = new InMemoryValueHolder( btree, value ); // Determinate where to store the new value if ( pos <= middle ) { // The left page will contain the new value - leftLeaf = new Leaf( btree, revision, middle + 1 ); + leftLeaf = new InMemoryLeaf( btree, revision, middle + 1 ); // Copy the keys and the values up to the insertion position System.arraycopy( getKeys(), 0, leftLeaf.getKeys(), 0, pos ); System.arraycopy( values, 0, leftLeaf.values, 0, pos ); // Add the new element - leftLeaf.setKey( pos, key ); + leftLeaf.setKey( pos, new KeyHolder( key ) ); leftLeaf.values[pos] = valueHolder; // And copy the remaining elements @@ -844,7 +845,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( btree, revision, middle ); + rightLeaf = new InMemoryLeaf( btree, revision, middle ); // Copy the keys and the values in the right page System.arraycopy( getKeys(), middle, rightLeaf.getKeys(), 0, middle ); @@ -853,14 +854,14 @@ import org.apache.directory.mavibot.btre else { // Create the left page - leftLeaf = new Leaf( btree, revision, middle ); + leftLeaf = new InMemoryLeaf( btree, revision, middle ); // Copy all the element into the left page System.arraycopy( getKeys(), 0, leftLeaf.getKeys(), 0, middle ); System.arraycopy( values, 0, leftLeaf.values, 0, middle ); // Now, create the right page - rightLeaf = new Leaf( btree, revision, middle + 1 ); + rightLeaf = new InMemoryLeaf( btree, revision, middle + 1 ); int rightPos = pos - middle; @@ -869,7 +870,7 @@ import org.apache.directory.mavibot.btre System.arraycopy( values, middle, rightLeaf.values, 0, rightPos ); // Add the new element - rightLeaf.setKey( rightPos, key ); + rightLeaf.setKey( rightPos, new KeyHolder( key ) ); rightLeaf.values[rightPos] = valueHolder; // And copy the remaining elements Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryValueHolder.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryValueHolder.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryValueHolder.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/InMemoryValueHolder.java Mon Dec 16 11:46:32 2013 @@ -29,6 +29,7 @@ import org.apache.directory.mavibot.btre import org.apache.directory.mavibot.btree.BTree; import org.apache.directory.mavibot.btree.Tuple; import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException; +import org.apache.directory.mavibot.btree.persisted.PersistedBTree; /** @@ -51,12 +52,17 @@ public class InMemoryValueHolder exte InMemoryValueHolder( BTree parentBtree, int nbValues ) { valueSerializer = parentBtree.getValueSerializer(); + + if ( nbValues <= 1 ) + { + valueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), nbValues ); + } } /** * Creates a new instance of a ValueHolder, containing Values. This constructor is called - * whe we need to create a new ValueHolder with deserialized values. + * when we need to create a new ValueHolder with deserialized values. * * @param parentBtree The parent BTree * @param values The Values stored in the ValueHolder @@ -69,10 +75,12 @@ public class InMemoryValueHolder exte { int nbValues = values.length; - if ( nbValues < 2 ) + if ( nbValues == 1 ) { // Store the value - valueArray = values; + valueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), nbValues ); + valueArray[0] = values[0]; + nbArrayElems = nbValues; } else { @@ -107,7 +115,7 @@ public class InMemoryValueHolder exte } else { - return 1; + return nbArrayElems; } } @@ -191,6 +199,7 @@ public class InMemoryValueHolder exte { valueArray = ( V[] ) Array.newInstance( valueSerializer.getType(), 1 ); valueArray[0] = valueBtree.browse().next().getKey(); + nbArrayElems = 1; valueBtree.close(); valueBtree = null; } @@ -226,7 +235,7 @@ public class InMemoryValueHolder exte else { V returnedValue = valueArray[0]; - valueArray[0] = null; + nbArrayElems = 0; return returnedValue; } @@ -278,7 +287,12 @@ public class InMemoryValueHolder exte else { sb.append( ", {" ); - sb.append( valueArray[0] ); + + if ( size() != 0 ) + { + sb.append( valueArray[0] ); + } + sb.append( "}" ); } Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/Node.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/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.BorrowedFromLeftResult; import org.apache.directory.mavibot.btree.BorrowedFromRightResult; @@ -34,6 +35,7 @@ import org.apache.directory.mavibot.btre import org.apache.directory.mavibot.btree.ModifyResult; 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.ParentPos; import org.apache.directory.mavibot.btree.RemoveResult; import org.apache.directory.mavibot.btree.SplitResult; @@ -54,12 +56,8 @@ import org.apache.directory.mavibot.btre * * @author Apache Directory Project */ -/* No qualifier */class Node extends AbstractInMemoryPage +/* No qualifier */class Node extends AbstractPage { - /** Children pages associated with keys. */ - protected Page[] children; - - /** * Creates a new Node which will contain only one key, with references to * a left and right page. This is a specific constructor used by the btree @@ -75,7 +73,7 @@ import org.apache.directory.mavibot.btre super( btree, revision, nbElems ); // Create the children array - children = ( Page[] ) Array.newInstance( Page.class, nbElems + 1 ); + children = ( PageHolder[] ) Array.newInstance( PageHolder.class, nbElems + 1 ); } @@ -96,18 +94,17 @@ import org.apache.directory.mavibot.btre super( btree, revision, 1 ); // Create the children array, and store the left and right children - children = ( Page[] ) Array.newInstance( Page.class, - btree.getPageSize() + 1 ); + children = ( PageHolder[] ) Array.newInstance( PageHolder.class, btree.getPageSize() + 1 ); - children[0] = leftPage; - children[1] = rightPage; + children[0] = new PageHolder( btree, leftPage ); + children[1] = new PageHolder( btree, rightPage ); // Create the keys array and store the pivot into it // We get the type of array to create from the btree // Yes, this is an hack... setKeys( ( KeyHolder[] ) Array.newInstance( KeyHolder.class, btree.getPageSize() ) ); - setKey( 0, key ); + setKey( 0, new KeyHolder( key ) ); } @@ -127,7 +124,7 @@ import org.apache.directory.mavibot.btre } // Get the child page into which we will insert the tuple - Page child = children[pos]; + Page child = children[pos].getValue(); // and insert the into this child InsertResult result = child.insert( revision, key, value ); @@ -190,16 +187,16 @@ import org.apache.directory.mavibot.btre if ( found ) { - newPage.children[index + 1] = modifiedPage; + newPage.children[index + 1] = new PageHolder( btree, modifiedPage ); } else { - newPage.children[index] = modifiedPage; + newPage.children[index] = new PageHolder( btree, modifiedPage ); } if ( pos < 0 ) { - newPage.setKey( index, removeResult.getModifiedPage().getLeftMostKey() ); + newPage.setKey( index, new KeyHolder( removeResult.getModifiedPage().getLeftMostKey() ) ); } // Modify the result and return @@ -261,7 +258,7 @@ import org.apache.directory.mavibot.btre // Create the new sibling, with one less element at the beginning Node newSibling = new Node( btree, revision, sibling.getNbElems() - 1 ); - K siblingKey = sibling.children[0].getLeftMostKey(); + K siblingKey = sibling.children[0].getValue().getLeftMostKey(); // Copy the keys and children of the old sibling in the new sibling System.arraycopy( sibling.getKeys(), 1, newSibling.getKeys(), 0, newSibling.getNbElems() ); @@ -275,7 +272,7 @@ import org.apache.directory.mavibot.btre int index = Math.abs( pos ); // Copy the key and children from sibling - newNode.setKey( nbElems - 1, siblingKey ); // 1 + newNode.setKey( nbElems - 1, new KeyHolder( siblingKey ) ); // 1 newNode.children[nbElems] = sibling.children[0]; // 8 if ( index < 2 ) @@ -285,7 +282,7 @@ import org.apache.directory.mavibot.btre // Inject the modified page Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[0] = modifiedPage; + newNode.children[0] = new PageHolder( btree, modifiedPage ); // Copy the children System.arraycopy( children, 2, newNode.children, 1, nbElems - 1 ); @@ -299,7 +296,7 @@ import org.apache.directory.mavibot.btre } // Inject the new modified page key - newNode.setKey( index - 2, mergedResult.getModifiedPage().getLeftMostKey() ); // 2 + newNode.setKey( index - 2, new KeyHolder( mergedResult.getModifiedPage().getLeftMostKey() ) ); // 2 if ( index < nbElems ) { @@ -315,7 +312,7 @@ import org.apache.directory.mavibot.btre // Inject the modified page Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[index - 1] = modifiedPage; // 6 + newNode.children[index - 1] = new PageHolder( btree, modifiedPage ); // 6 } // Create the result @@ -344,7 +341,7 @@ import org.apache.directory.mavibot.btre Node sibling, int pos ) throws IOException { // The sibling is on the left, borrow the rightmost element - Page siblingChild = sibling.children[sibling.nbElems]; + Page siblingChild = sibling.children[sibling.nbElems].getValue(); // Create the new sibling, with one less element at the end Node newSibling = new Node( btree, revision, sibling.getNbElems() - 1 ); @@ -358,23 +355,23 @@ import org.apache.directory.mavibot.btre Node newNode = new Node( btree, revision, nbElems ); // Sets the first children - newNode.children[0] = siblingChild; //1 + newNode.children[0] = new PageHolder( btree, siblingChild ); //1 int index = Math.abs( pos ); if ( index < 2 ) { - newNode.setKey( 0, mergedResult.getModifiedPage().getLeftMostKey() ); + newNode.setKey( 0, new KeyHolder( mergedResult.getModifiedPage().getLeftMostKey() ) ); System.arraycopy( getKeys(), 1, newNode.getKeys(), 1, nbElems - 1 ); Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[1] = modifiedPage; + newNode.children[1] = new PageHolder( btree, modifiedPage ); System.arraycopy( children, 2, newNode.children, 2, nbElems - 1 ); } else { // Set the first key - newNode.setKey( 0, children[0].getLeftMostKey() ); //2 + newNode.setKey( 0, new KeyHolder( children[0].getValue().getLeftMostKey() ) ); //2 if ( index > 2 ) { @@ -383,7 +380,7 @@ import org.apache.directory.mavibot.btre } // Inject the modified key - newNode.setKey( index - 1, mergedResult.getModifiedPage().getLeftMostKey() ); // 3 + newNode.setKey( index - 1, new KeyHolder( mergedResult.getModifiedPage().getLeftMostKey() ) ); // 3 if ( index < nbElems ) { @@ -399,7 +396,7 @@ import org.apache.directory.mavibot.btre // Insert the modified page Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[index] = modifiedPage; // 7 + newNode.children[index] = new PageHolder( btree, modifiedPage ); // 7 } // Create the result @@ -445,18 +442,18 @@ import org.apache.directory.mavibot.btre // Then copy all the elements up to the deletion point if ( index < 2 ) { - newNode.setKey( half, mergedResult.getModifiedPage().getLeftMostKey() ); + newNode.setKey( half, new KeyHolder( mergedResult.getModifiedPage().getLeftMostKey() ) ); System.arraycopy( getKeys(), 1, newNode.getKeys(), half + 1, half - 1 ); Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[half + 1] = modifiedPage; + newNode.children[half + 1] = new PageHolder( btree, modifiedPage ); System.arraycopy( children, 2, newNode.children, half + 2, half - 1 ); } else { // Copy the left part of the node keys up to the deletion point // Insert the new key - newNode.setKey( half, children[0].getLeftMostKey() ); // 3 + newNode.setKey( half, new KeyHolder( children[0].getValue().getLeftMostKey() ) ); // 3 if ( index > 2 ) { @@ -464,7 +461,7 @@ import org.apache.directory.mavibot.btre } // Inject the new merged key - newNode.setKey( half + index - 1, mergedResult.getModifiedPage().getLeftMostKey() ); //5 + newNode.setKey( half + index - 1, new KeyHolder( mergedResult.getModifiedPage().getLeftMostKey() ) ); //5 if ( index < half ) { @@ -477,7 +474,7 @@ import org.apache.directory.mavibot.btre // Inject the new merged child Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[half + index] = modifiedPage; //8 + newNode.children[half + index] = new PageHolder( btree, modifiedPage ); //8 } } else @@ -490,7 +487,7 @@ import org.apache.directory.mavibot.btre // Insert the first child Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[0] = modifiedPage; + newNode.children[0] = new PageHolder( btree, modifiedPage ); // Copy the node children System.arraycopy( children, 2, newNode.children, 1, half - 1 ); @@ -508,11 +505,11 @@ import org.apache.directory.mavibot.btre System.arraycopy( children, 0, newNode.children, 0, index - 1 ); //6 // Inject the modified key - newNode.setKey( index - 2, mergedResult.getModifiedPage().getLeftMostKey() ); //2 + newNode.setKey( index - 2, new KeyHolder( mergedResult.getModifiedPage().getLeftMostKey() ) ); //2 // Inject the modified children Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[index - 1] = modifiedPage; // 7 + newNode.children[index - 1] = new PageHolder( btree, modifiedPage ); // 7 // Add the remaining node's key if needed if ( index < half ) @@ -525,7 +522,7 @@ import org.apache.directory.mavibot.btre } // Inject the new key from sibling - newNode.setKey( half - 1, sibling.findLeftMost().getKey() ); //3 + newNode.setKey( half - 1, new KeyHolder( sibling.findLeftMost().getKey() ) ); //3 // Copy the sibling keys System.arraycopy( sibling.getKeys(), 0, newNode.getKeys(), half, half ); @@ -562,12 +559,12 @@ import org.apache.directory.mavibot.btre if ( found ) { index = -( pos + 1 ); - child = children[-pos]; + child = children[-pos].getValue(); deleteResult = child.delete( revision, key, value, this, -pos ); } else { - child = children[pos]; + child = children[pos].getValue(); deleteResult = child.delete( revision, key, value, this, pos ); } @@ -631,7 +628,7 @@ import org.apache.directory.mavibot.btre // a sibling, or we will have to merge two pages int siblingPos = selectSibling( ( Node ) parent, parentPos ); - Node sibling = ( Node ) ( ( ( Node ) parent ).children[siblingPos] ); + Node sibling = ( Node ) ( ( ( Node ) parent ).children[siblingPos].getValue() ); if ( sibling.getNbElems() > halfSize ) { @@ -690,21 +687,21 @@ import org.apache.directory.mavibot.btre if ( borrowedResult.isFromRight() ) { // Update the keys - newPage.setKey( pos, modifiedPage.findLeftMost().getKey() ); - newPage.setKey( pos + 1, modifiedSibling.findLeftMost().getKey() ); + newPage.setKey( pos, new KeyHolder( modifiedPage.findLeftMost().getKey() ) ); + newPage.setKey( pos + 1, new KeyHolder( modifiedSibling.findLeftMost().getKey() ) ); // Update the children - newPage.children[pos + 1] = modifiedPage; - newPage.children[pos + 2] = modifiedSibling; + newPage.children[pos + 1] = new PageHolder( btree, modifiedPage ); + newPage.children[pos + 2] = new PageHolder( btree, modifiedSibling ); } else { // Update the keys - newPage.setKey( pos, modifiedPage.findLeftMost().getKey() ); + newPage.setKey( pos, new KeyHolder( modifiedPage.findLeftMost().getKey() ) ); // Update the children - newPage.children[pos] = modifiedSibling; - newPage.children[pos + 1] = modifiedPage; + newPage.children[pos] = new PageHolder( btree, modifiedSibling ); + newPage.children[pos + 1] = new PageHolder( btree, modifiedPage ); } } else @@ -712,20 +709,20 @@ import org.apache.directory.mavibot.btre if ( borrowedResult.isFromRight() ) { // Update the keys - newPage.setKey( pos, modifiedSibling.findLeftMost().getKey() ); + newPage.setKey( pos, new KeyHolder( modifiedSibling.findLeftMost().getKey() ) ); // Update the children - newPage.children[pos] = modifiedPage; - newPage.children[pos + 1] = modifiedSibling; + newPage.children[pos] = new PageHolder( btree, modifiedPage ); + newPage.children[pos + 1] = new PageHolder( btree, modifiedSibling ); } else { // Update the keys - newPage.setKey( pos - 1, modifiedPage.findLeftMost().getKey() ); + newPage.setKey( pos - 1, new KeyHolder( modifiedPage.findLeftMost().getKey() ) ); // Update the children - newPage.children[pos - 1] = modifiedSibling; - newPage.children[pos] = modifiedPage; + newPage.children[pos - 1] = new PageHolder( btree, modifiedSibling ); + newPage.children[pos] = new PageHolder( btree, modifiedPage ); } } @@ -762,7 +759,7 @@ import org.apache.directory.mavibot.btre // Copy the keys and the children System.arraycopy( getKeys(), 1, newNode.getKeys(), 0, newNode.nbElems ); Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[0] = modifiedPage; + newNode.children[0] = new PageHolder( btree, modifiedPage ); System.arraycopy( children, 2, newNode.children, 1, nbElems - 1 ); } else @@ -773,7 +770,7 @@ import org.apache.directory.mavibot.btre System.arraycopy( getKeys(), 0, newNode.getKeys(), 0, index ); } - newNode.setKey( index, mergedResult.getModifiedPage().findLeftMost().getKey() ); + newNode.setKey( index, new KeyHolder( mergedResult.getModifiedPage().findLeftMost().getKey() ) ); if ( index < nbElems - 2 ) { @@ -784,7 +781,7 @@ import org.apache.directory.mavibot.btre System.arraycopy( children, 0, newNode.children, 0, index + 1 ); Page modifiedPage = mergedResult.getModifiedPage(); - newNode.children[index + 1] = modifiedPage; + newNode.children[index + 1] = new PageHolder( btree, modifiedPage ); if ( index < nbElems - 2 ) { @@ -813,11 +810,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].get( key ); + return children[-pos].getValue().get( key ); } else { - return children[pos].get( key ); + return children[pos].getValue().get( key ); } } @@ -834,11 +831,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].getValues( key ); + return children[-pos].getValue().getValues( key ); } else { - return children[pos].getValues( key ); + return children[pos].getValue().getValues( key ); } } @@ -855,11 +852,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].hasKey( key ); + return children[-pos].getValue().hasKey( key ); } else { - Page page = children[pos]; + Page page = children[pos].getValue(); if ( page == null ) { @@ -883,11 +880,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].contains( key, value ); + return children[-pos].getValue().contains( key, value ); } else { - return children[pos].contains( key, value ); + return children[pos].getValue().contains( key, value ); } } @@ -900,7 +897,7 @@ import org.apache.directory.mavibot.btre */ public void setValue( int pos, Page value ) { - children[pos] = value; + children[pos] = new PageHolder( btree, value ); } @@ -911,7 +908,7 @@ import org.apache.directory.mavibot.btre { if ( pos < nbElems + 1 ) { - return children[pos]; + return children[pos].getValue(); } else { @@ -936,7 +933,7 @@ import org.apache.directory.mavibot.btre // We first stack the current page stack[depth++] = new ParentPos( this, pos ); - Page page = children[pos]; + Page page = children[pos].getValue(); return page.browse( key, transaction, stack, depth ); } @@ -950,7 +947,7 @@ import org.apache.directory.mavibot.btre { stack[depth++] = new ParentPos( this, 0 ); - Page page = children[0]; + Page page = children[0].getValue(); return page.browse( transaction, stack, depth ); } @@ -976,7 +973,7 @@ import org.apache.directory.mavibot.btre // to point on the modified child Page modifiedPage = result.getModifiedPage(); - ( ( Node ) newPage ).children[pos] = modifiedPage; + ( ( Node ) newPage ).children[pos] = new PageHolder( btree, modifiedPage ); // We can return the result, where we update the modifiedPage, // to avoid the creation of a new object @@ -1016,12 +1013,12 @@ import org.apache.directory.mavibot.btre } // Add the new key and children - newNode.setKey( pos, key ); + newNode.setKey( pos, new KeyHolder( key ) ); // If the BTree is managed, we now have to write the modified page on disk // and to add this page to the list of modified pages - newNode.children[pos] = leftPage; - newNode.children[pos + 1] = rightPage; + newNode.children[pos] = new PageHolder( btree, leftPage ); + newNode.children[pos + 1] = new PageHolder( btree, rightPage ); // And copy the remaining keys and children if ( nbElems > 0 ) @@ -1075,9 +1072,9 @@ import org.apache.directory.mavibot.btre System.arraycopy( children, 0, newLeftPage.children, 0, pos ); // Add the new element - newLeftPage.setKey( pos, pivot ); - newLeftPage.children[pos] = leftPage; - newLeftPage.children[pos + 1] = rightPage; + newLeftPage.setKey( pos, new KeyHolder( pivot ) ); + newLeftPage.children[pos] = new PageHolder( btree, leftPage ); + newLeftPage.children[pos + 1] = new PageHolder( btree, rightPage ); // And copy the remaining elements minus the new pivot System.arraycopy( getKeys(), pos, newLeftPage.getKeys(), pos + 1, middle - pos - 1 ); @@ -1100,12 +1097,12 @@ import org.apache.directory.mavibot.btre // Copy the keys and the children up to the insertion position (here, middle) System.arraycopy( getKeys(), 0, newLeftPage.getKeys(), 0, middle ); System.arraycopy( children, 0, newLeftPage.children, 0, middle ); - newLeftPage.children[middle] = leftPage; + newLeftPage.children[middle] = new PageHolder( btree, leftPage ); // And process the right page now System.arraycopy( getKeys(), middle, newRightPage.getKeys(), 0, middle ); System.arraycopy( children, middle + 1, newRightPage.children, 1, middle ); - newRightPage.children[0] = rightPage; + newRightPage.children[0] = new PageHolder( btree, rightPage ); // Create the result InsertResult result = new SplitResult( copiedPages, pivot, newLeftPage, newRightPage ); @@ -1124,9 +1121,9 @@ import org.apache.directory.mavibot.btre System.arraycopy( children, middle + 1, newRightPage.children, 0, pos - middle - 1 ); // Add the new element - newRightPage.setKey( pos - middle - 1, pivot ); - newRightPage.children[pos - middle - 1] = leftPage; - newRightPage.children[pos - middle] = rightPage; + newRightPage.setKey( pos - middle - 1, new KeyHolder( pivot ) ); + newRightPage.children[pos - middle - 1] = new PageHolder( btree, leftPage ); + newRightPage.children[pos - middle] = new PageHolder( btree, rightPage ); // And copy the remaining elements minus the new pivot System.arraycopy( getKeys(), pos, newRightPage.getKeys(), pos - middle, nbElems - pos ); @@ -1166,7 +1163,7 @@ import org.apache.directory.mavibot.btre */ public K getLeftMostKey() { - return children[0].getLeftMostKey(); + return children[0].getValue().getLeftMostKey(); } @@ -1179,10 +1176,10 @@ import org.apache.directory.mavibot.btre if ( children[index] != null ) { - return children[index].getRightMostKey(); + return children[index].getValue().getRightMostKey(); } - return children[nbElems - 1].getRightMostKey(); + return children[nbElems - 1].getValue().getRightMostKey(); } @@ -1191,7 +1188,7 @@ import org.apache.directory.mavibot.btre */ public Tuple findLeftMost() throws EndOfFileExceededException, IOException { - return children[0].findLeftMost(); + return children[0].getValue().findLeftMost(); } @@ -1200,7 +1197,7 @@ import org.apache.directory.mavibot.btre */ public Tuple findRightMost() throws EndOfFileExceededException, IOException { - return children[nbElems].findRightMost(); + return children[nbElems].getValue().findRightMost(); } @@ -1224,7 +1221,7 @@ import org.apache.directory.mavibot.btre } else { - sb.append( 'r' ).append( children[0].getRevision() ); + sb.append( 'r' ).append( children[0].getValue().getRevision() ); } for ( int i = 0; i < nbElems; i++ ) @@ -1237,7 +1234,7 @@ import org.apache.directory.mavibot.btre } else { - sb.append( 'r' ).append( children[i + 1].getRevision() ); + sb.append( 'r' ).append( children[i + 1].getValue().getRevision() ); } } } @@ -1258,14 +1255,14 @@ import org.apache.directory.mavibot.btre if ( nbElems > 0 ) { // Start with the first child - sb.append( children[0].dumpPage( tabs + " " ) ); + sb.append( children[0].getValue().dumpPage( tabs + " " ) ); for ( int i = 0; i < nbElems; i++ ) { sb.append( tabs ); sb.append( "<" ); sb.append( getKey( i ) ).append( ">\n" ); - sb.append( children[i + 1].dumpPage( tabs + " " ) ); + sb.append( children[i + 1].getValue().dumpPage( tabs + " " ) ); } } Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/memory/TupleCursorImpl.java Mon Dec 16 11:46:32 2013 @@ -86,7 +86,7 @@ public class TupleCursorImpl exten parentPos.pos = parentPos.page.getNbElems(); } - child = ((Node)parentPos.page).children[parentPos.pos]; + child = ((Node)parentPos.page).getPage( parentPos.pos ); } // and leaf @@ -102,7 +102,7 @@ public class TupleCursorImpl exten parentPos.pos = child.getNbElems() - 1; } - parentPos.valueCursor = ((Leaf)parentPos.page).values[parentPos.pos].getCursor(); + parentPos.valueCursor = ((InMemoryLeaf)parentPos.page).values[parentPos.pos].getCursor(); parentPos.valueCursor.afterLast(); parentPos.pos = AFTER_LAST; } @@ -131,7 +131,7 @@ public class TupleCursorImpl exten parentPos.page = child; } - child = ((Node)parentPos.page).children[0]; + child = ((Node)parentPos.page).getPage( 0 ); } // and leaf @@ -145,7 +145,7 @@ public class TupleCursorImpl exten if ( parentPos.valueCursor != null ) { - parentPos.valueCursor = ((Leaf)parentPos.page).values[0].getCursor(); + parentPos.valueCursor = ((InMemoryLeaf)parentPos.page).values[0].getCursor(); parentPos.valueCursor.beforeFirst(); } } @@ -185,7 +185,7 @@ public class TupleCursorImpl exten { // We can pick the next element at this level parentPos.pos++; - child = ((Node)parentPos.page).children[parentPos.pos]; + child = ((Node)parentPos.page).getPage( parentPos.pos ); // and go down the tree through the nodes while ( currentDepth < depth - 1 ) @@ -194,14 +194,14 @@ public class TupleCursorImpl exten parentPos = stack[currentDepth]; parentPos.pos = 0; parentPos.page = child; - child = ((Node)child).children[0]; + child = ((Node)child).getPage( 0 ); } // and the leaf parentPos = stack[depth]; parentPos.page = child; parentPos.pos = 0; - parentPos.valueCursor = ((Leaf)child).values[0].getCursor(); + parentPos.valueCursor = ((InMemoryLeaf)child).values[0].getCursor(); return parentPos; } @@ -245,7 +245,7 @@ public class TupleCursorImpl exten { // We can pick the next element at this level parentPos.pos--; - child = ((Node)parentPos.page).children[parentPos.pos]; + child = ((Node)parentPos.page).getPage( parentPos.pos ); // and go down the tree through the nodes while ( currentDepth < depth - 1 ) @@ -254,14 +254,14 @@ public class TupleCursorImpl exten parentPos = stack[currentDepth]; parentPos.pos = child.getNbElems(); parentPos.page = child; - child = ((Node)parentPos.page).children[parentPos.page.getNbElems()]; + child = ((Node)parentPos.page).getPage( parentPos.page.getNbElems() ); } // and the leaf parentPos = stack[depth]; parentPos.pos = child.getNbElems() - 1; parentPos.page = child; - ValueHolder valueHolder = ((Leaf)parentPos.page).values[parentPos.pos]; + ValueHolder valueHolder = ((InMemoryLeaf)parentPos.page).values[parentPos.pos]; parentPos.valueCursor = valueHolder.getCursor(); parentPos.valueCursor.afterLast(); @@ -402,13 +402,13 @@ public class TupleCursorImpl exten else { // We can pick the next element at this level - child = ((Node)parentPos.page).children[parentPos.pos + 1]; + child = ((Node)parentPos.page).getPage( parentPos.pos + 1 ); // and go down the tree through the nodes while ( currentDepth < depth - 1 ) { currentDepth++; - child = ((Node)child).children[0]; + child = ((Node)child).getPage( 0 ); } return true; @@ -548,13 +548,13 @@ public class TupleCursorImpl exten else { // We can pick the previous element at this level - child = ((Node)parentPos.page).children[parentPos.pos - 1]; + child = ((Node)parentPos.page).getPage( parentPos.pos - 1 ); // and go down the tree through the nodes while ( currentDepth < depth - 1 ) { currentDepth++; - child = ((Node)child).children[child.getNbElems()]; + child = ((Node)child).getPage( child.getNbElems() ); } return true; @@ -630,7 +630,7 @@ public class TupleCursorImpl exten try { - ValueHolder valueHolder = ( ( Leaf ) parentPos.page ).getValue( parentPos.pos ); + ValueHolder valueHolder = ( ( InMemoryLeaf ) parentPos.page ).getValue( parentPos.pos ); parentPos.valueCursor = valueHolder.getCursor(); @@ -642,7 +642,7 @@ public class TupleCursorImpl exten } } - Leaf leaf = ( Leaf ) ( parentPos.page ); + InMemoryLeaf leaf = ( InMemoryLeaf ) ( parentPos.page ); tuple.setKey( leaf.getKey( parentPos.pos ) ); tuple.setValue( value ); @@ -681,7 +681,7 @@ public class TupleCursorImpl exten if ( ( newParentPos == null ) || ( newParentPos.page == null ) ) { // This is the end : no more value - Leaf leaf = ( Leaf ) ( parentPos.page ); + InMemoryLeaf leaf = ( InMemoryLeaf ) ( parentPos.page ); ValueHolder valueHolder = leaf.values[parentPos.pos]; parentPos.pos = AFTER_LAST; parentPos.valueCursor = valueHolder.getCursor(); @@ -701,7 +701,7 @@ public class TupleCursorImpl exten } // The key - Leaf leaf = ( Leaf ) ( parentPos.page ); + InMemoryLeaf leaf = ( InMemoryLeaf ) ( parentPos.page ); tuple.setKey( leaf.getKey( parentPos.pos ) ); // The value @@ -778,7 +778,7 @@ public class TupleCursorImpl exten try { - ValueHolder valueHolder = ( ( Leaf ) parentPos.page ).getValue( parentPos.pos ); + ValueHolder valueHolder = ( ( InMemoryLeaf ) parentPos.page ).getValue( parentPos.pos ); parentPos.valueCursor = valueHolder.getCursor(); parentPos.valueCursor.afterLast(); @@ -793,7 +793,7 @@ public class TupleCursorImpl exten } - Leaf leaf = ( Leaf ) ( parentPos.page ); + InMemoryLeaf leaf = ( InMemoryLeaf ) ( parentPos.page ); tuple.setKey( leaf.getKey( parentPos.pos ) ); tuple.setValue( value ); @@ -846,7 +846,7 @@ public class TupleCursorImpl exten } // Update the Tuple - Leaf leaf = ( Leaf ) ( parentPos.page ); + InMemoryLeaf leaf = ( InMemoryLeaf ) ( parentPos.page ); // The key tuple.setKey( leaf.getKey( parentPos.pos ) ); Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/BTreeFactory.java URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/BTreeFactory.java?rev=1551187&r1=1551186&r2=1551187&view=diff ============================================================================== --- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/BTreeFactory.java (original) +++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/persisted/BTreeFactory.java Mon Dec 16 11:46:32 2013 @@ -23,7 +23,9 @@ package org.apache.directory.mavibot.btr import java.io.IOException; import java.util.LinkedList; +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; import org.apache.directory.mavibot.btree.ParentPos; import org.apache.directory.mavibot.btree.ValueHolder; @@ -90,9 +92,9 @@ public class BTreeFactory * @param nbElems The number or elements in this leaf * @return A Leaf instance */ - public static Leaf createLeaf( BTree btree, long revision, int nbElems ) + public static PersistedLeaf createLeaf( BTree btree, long revision, int nbElems ) { - Leaf leaf = new Leaf( btree, revision, nbElems ); + PersistedLeaf leaf = new PersistedLeaf( btree, revision, nbElems ); return leaf; } @@ -232,9 +234,10 @@ public class BTreeFactory * @param pos The position in the keys array * @param key the key to inject */ - public static void setKey( Page page, int pos, K key ) + public static void setKey( BTree btree, Page page, int pos, K key ) { - ( ( AbstractPersistedPage ) page ).setKey( pos, key ); + KeyHolder keyHolder = new PersistedKeyHolder( btree.getKeySerializer(), key ); + ( ( AbstractPage ) page ).setKey( pos, keyHolder ); } @@ -244,9 +247,10 @@ public class BTreeFactory * @param pos the position of this key in the page * @param buffer the byte[] containing the serialized key */ - public static void setKey( Page page, int pos, byte[] buffer ) + public static void setKey( BTree btree, Page page, int pos, byte[] buffer ) { - ( ( AbstractPersistedPage ) page ).setKey( pos, buffer ); + KeyHolder keyHolder = new PersistedKeyHolder( btree.getKeySerializer(), buffer ); + ( ( AbstractPage ) page ).setKey( pos, keyHolder ); } @@ -255,7 +259,7 @@ public class BTreeFactory * @param pos The position in the values array * @param value the value to inject */ - public static void setValue( Leaf page, int pos, PersistedValueHolder value ) + public static void setValue( PersistedLeaf page, int pos, PersistedValueHolder value ) { page.setValue( pos, value ); } @@ -266,7 +270,7 @@ public class BTreeFactory * @param pos The position in the values array * @param value the value to inject */ - public static void setValue( Node page, int pos, PageHolder value ) + public static void setValue( Node page, int pos, PersistedPageHolder value ) { page.setValue( pos, value ); } @@ -286,9 +290,9 @@ public class BTreeFactory ParentPos last = new ParentPos( btree.getRootPage(), btree.getRootPage().getNbElems() ); stack.push( last ); - if ( btree.getRootPage() instanceof Leaf ) + if ( btree.getRootPage() instanceof PersistedLeaf ) { - Leaf leaf = ( Leaf ) ( btree.getRootPage() ); + PersistedLeaf leaf = ( PersistedLeaf ) ( btree.getRootPage() ); ValueHolder valueHolder = leaf.values[last.pos]; last.valueCursor = valueHolder.getCursor(); } @@ -298,14 +302,14 @@ public class BTreeFactory while ( true ) { - Page p = node.children[node.getNbElems()].getValue( btree ); + Page p = node.children[node.getNbElems()].getValue(); last = new ParentPos( p, p.getNbElems() ); stack.push( last ); - if ( p instanceof Leaf ) + if ( p instanceof PersistedLeaf ) { - Leaf leaf = ( Leaf ) ( last.page ); + PersistedLeaf leaf = ( PersistedLeaf ) ( last.page ); ValueHolder valueHolder = leaf.values[last.pos]; last.valueCursor = valueHolder.getCursor(); break; @@ -331,9 +335,9 @@ public class BTreeFactory ParentPos first = new ParentPos( btree.getRootPage(), 0 ); stack.push( first ); - if ( btree.getRootPage() instanceof Leaf ) + if ( btree.getRootPage() instanceof PersistedLeaf ) { - Leaf leaf = ( Leaf ) ( btree.getRootPage() ); + PersistedLeaf leaf = ( PersistedLeaf ) ( btree.getRootPage() ); ValueHolder valueHolder = leaf.values[first.pos]; first.valueCursor = valueHolder.getCursor(); } @@ -343,14 +347,14 @@ public class BTreeFactory while ( true ) { - Page page = node.children[0].getValue( btree ); + Page page = node.children[0].getValue(); first = new ParentPos( page, 0 ); stack.push( first ); - if ( page instanceof Leaf ) + if ( page instanceof PersistedLeaf ) { - Leaf leaf = ( Leaf ) ( page ); + PersistedLeaf leaf = ( PersistedLeaf ) ( page ); ValueHolder valueHolder = leaf.values[first.pos]; first.valueCursor = valueHolder.getCursor(); break;