directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1551837 [1/2] - in /directory/mavibot/trunk/mavibot/src: main/java/org/apache/directory/mavibot/btree/ test/java/org/apache/directory/mavibot/btree/
Date Wed, 18 Dec 2013 04:42:26 GMT
Author: elecharny
Date: Wed Dec 18 04:42:25 2013
New Revision: 1551837

URL: http://svn.apache.org/r1551837
Log:
o Merged the PersistedBTreeFactory and InMemortFactory into a single BTreeFactory class
o Added the isLeaf/isNode methods in Page

Added:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
Removed:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeFactory.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeFactory.java
Modified:
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeTypeEnum.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeBuilder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeConfiguration.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryLeaf.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryNode.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryValueHolder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Page.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedValueHolder.java
    directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeDuplicateKeyTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeFlushTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeTestOps.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryLeafTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/MultiThreadedInMemoryBtreeTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilderTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/PersistedBTreeDuplicateKeyTest.java
    directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/RecordManagerTest.java

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/AbstractBTree.java Wed Dec 18 04:42:25 2013
@@ -24,8 +24,6 @@ import java.util.Comparator;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.locks.ReentrantLock;
 
-import net.sf.ehcache.Cache;
-
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
 
@@ -67,14 +65,11 @@ import org.apache.directory.mavibot.btre
     /** Flag to enable duplicate key support */
     private boolean allowDuplicates;
 
-    /** The cache associated with this BTree */
-    protected Cache cache;
-
-    /** The cache size, default to 1000 elements */
-    protected int cacheSize = DEFAULT_CACHE_SIZE;
-
     /** The thread responsible for the cleanup of timed out reads */
     protected Thread readTransactionsThread;
+    
+    /** The BTree type : either in-memory, disk backed or persisted */
+    private BTreeTypeEnum type;
 
     /**
      * Starts a Read Only transaction. If the transaction is not closed, it will be 
@@ -570,6 +565,24 @@ import org.apache.directory.mavibot.btre
 
 
     /**
+     * {@inheritDoc}
+     */
+    public BTreeTypeEnum getType()
+    {
+        return type;
+    }
+
+
+    /**
+     * @param type the type to set
+     */
+    public void setType( BTreeTypeEnum type )
+    {
+        this.type = type;
+    }
+
+
+    /**
      * Gets the number which is a power of 2 immediately above the given positive number.
      */
     private int getPowerOf2( int size )

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTree.java Wed Dec 18 04:42:25 2013
@@ -43,9 +43,12 @@ public interface BTree<K, V>
 
     /** Define a default delay for a read transaction. This is 10 seconds */
     static final long DEFAULT_READ_TIMEOUT = 10 * 1000L;
-
-    /** The default number of pages to keep in memory */
-    static final int DEFAULT_CACHE_SIZE = 1000;
+    
+    /** The BTree allows duplicate values */
+    static final boolean ALLOW_DUPLICATES = true;
+    
+    /** The BTree forbids duplicate values */
+    static final boolean FORBID_DUPLICATES = false;
 
 
     /**
@@ -380,4 +383,10 @@ public interface BTree<K, V>
      * @param allowDuplicates True if the BTree will allow duplicate values
      */
     void setAllowDuplicates( boolean allowDuplicates );
+
+
+    /**
+     * @return the type
+     */
+    BTreeTypeEnum getType();
 }

Added: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java?rev=1551837&view=auto
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java (added)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeFactory.java Wed Dec 18 04:42:25 2013
@@ -0,0 +1,851 @@
+/*
+ *   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 java.util.LinkedList;
+
+import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
+
+/**
+ * This class construct a BTree from a serialized version of a BTree. We need it
+ * to avoid exposing all the methods of the BTree class.<br>
+ * 
+ * All its methods are static.
+ *  
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ *
+ * @param <K> The BTree key type
+ * @param <V> The BTree valye type
+ */
+public class BTreeFactory<K, V>
+{
+    //--------------------------------------------------------------------------------------------
+    // Create persisted btrees
+    //--------------------------------------------------------------------------------------------
+    
+    /**
+     * Creates a new persisted BTree, with no initialization. 
+     */
+    public static <K, V> BTree<K, V> createPersistedBTree()
+    {
+        BTree<K, V> btree = new PersistedBTree<K, V>();
+
+        return btree;
+    }
+
+    
+    /**
+     * Creates a new persisted BTree using the BTreeConfiguration to initialize the 
+     * BTree
+     * 
+     * @param configuration The configuration to use
+     */
+    public static <K, V> BTree<K, V> createPersistedBTree( PersistedBTreeConfiguration<K, V> configuration )
+    {
+        BTree<K, V> btree = new PersistedBTree<K, V>( configuration );
+
+        return btree;
+    }
+    
+    
+    /**
+     * Creates a new persisted BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param allowDuplicates Tells if the BTree allows multiple value for a given key
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer )
+    {
+        PersistedBTreeConfiguration<K, V> configuration = new PersistedBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( BTree.DEFAULT_PAGE_SIZE );
+        configuration.setAllowDuplicates( BTree.FORBID_DUPLICATES );
+        configuration.setCacheSize( PersistedBTree.DEFAULT_CACHE_SIZE );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new PersistedBTree<K, V>( configuration );
+
+        return btree;
+    }
+
+    
+    /**
+     * Creates a new persisted BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param allowDuplicates Tells if the BTree allows multiple value for a given key
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, boolean allowDuplicates )
+    {
+        PersistedBTreeConfiguration<K, V> configuration = new PersistedBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( BTree.DEFAULT_PAGE_SIZE );
+        configuration.setAllowDuplicates( allowDuplicates );
+        configuration.setCacheSize( PersistedBTree.DEFAULT_CACHE_SIZE );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new PersistedBTree<K, V>( configuration );
+
+        return btree;
+    }
+    
+    
+    /**
+     * Creates a new persisted BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param allowDuplicates Tells if the BTree allows multiple value for a given key
+     * @param cacheSize The size to be used for this BTree cache
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, boolean allowDuplicates, int cacheSize )
+    {
+        PersistedBTreeConfiguration<K, V> configuration = new PersistedBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( BTree.DEFAULT_PAGE_SIZE );
+        configuration.setAllowDuplicates( allowDuplicates );
+        configuration.setCacheSize( cacheSize );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new PersistedBTree<K, V>( configuration );
+
+        return btree;
+    }
+    
+    
+    /**
+     * Creates a new persisted BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param pageSize Size of the page
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, int pageSize )
+    {
+        PersistedBTreeConfiguration<K, V> configuration = new PersistedBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( pageSize );
+        configuration.setAllowDuplicates( BTree.FORBID_DUPLICATES );
+        configuration.setCacheSize( PersistedBTree.DEFAULT_CACHE_SIZE );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new PersistedBTree<K, V>( configuration );
+
+        return btree;
+    }
+
+    
+    /**
+     * Creates a new persisted BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param pageSize Size of the page
+     * @param allowDuplicates Tells if the BTree allows multiple value for a given key
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates )
+    {
+        PersistedBTreeConfiguration<K, V> configuration = new PersistedBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( pageSize );
+        configuration.setAllowDuplicates( allowDuplicates );
+        configuration.setCacheSize( PersistedBTree.DEFAULT_CACHE_SIZE );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new PersistedBTree<K, V>( configuration );
+
+        return btree;
+    }
+    
+    
+    /**
+     * Creates a new persisted BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param pageSize Size of the page
+     * @param allowDuplicates Tells if the BTree allows multiple value for a given key
+     * @param cacheSize The size to be used for this BTree cache
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createPersistedBTree( String name, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates, int cacheSize )
+    {
+        PersistedBTreeConfiguration<K, V> configuration = new PersistedBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( pageSize );
+        configuration.setAllowDuplicates( allowDuplicates );
+        configuration.setCacheSize( cacheSize );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new PersistedBTree<K, V>( configuration );
+
+        return btree;
+    }
+
+
+    //--------------------------------------------------------------------------------------------
+    // Create in-memory btrees
+    //--------------------------------------------------------------------------------------------
+    /**
+     * Creates a new in-memory BTree, with no initialization. 
+     */
+    public static <K, V> BTree<K, V> createInMemoryBTree()
+    {
+        BTree<K, V> btree = new InMemoryBTree<K, V>();
+
+        return btree;
+    }
+
+
+    /**
+     * Creates a new in-memory BTree using the BTreeConfiguration to initialize the 
+     * BTree
+     * 
+     * @param configuration The configuration to use
+     */
+    public static <K, V> BTree<K, V> createInMemoryBTree( InMemoryBTreeConfiguration<K, V> configuration )
+    {
+        BTree<K, V> btree = new InMemoryBTree<K, V>( configuration );
+
+        return btree;
+    }
+    
+    
+    /**
+     * Creates a new in-memory BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     */
+    public static <K, V> BTree<K, V> createInMemoryBTree( String name, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer )
+    {
+        InMemoryBTreeConfiguration<K, V> configuration = new InMemoryBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( BTree.DEFAULT_PAGE_SIZE );
+        configuration.setAllowDuplicates( BTree.FORBID_DUPLICATES );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new InMemoryBTree<K, V>( configuration );
+
+        return btree;
+    }
+
+    
+    /**
+     * Creates a new in-memory BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param allowDuplicates Tells if the BTree allows multiple value for a given key
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createInMemoryBTree( String name, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, boolean allowDuplicates )
+    {
+        InMemoryBTreeConfiguration<K, V> configuration = new InMemoryBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( BTree.DEFAULT_PAGE_SIZE );
+        configuration.setAllowDuplicates( allowDuplicates );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new InMemoryBTree<K, V>( configuration );
+
+        return btree;
+    }
+
+    
+    /**
+     * Creates a new in-memory BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param pageSize Size of the page
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createInMemoryBTree( String name, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, int pageSize )
+    {
+        InMemoryBTreeConfiguration<K, V> configuration = new InMemoryBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( pageSize );
+        configuration.setAllowDuplicates( BTree.FORBID_DUPLICATES );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new InMemoryBTree<K, V>( configuration );
+
+        return btree;
+    }
+
+    
+    /**
+     * Creates a new in-memory BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param filePath The name of the data directory with absolute path
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createInMemoryBTree( String name, String filePath, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer )
+    {
+        InMemoryBTreeConfiguration<K, V> configuration = new InMemoryBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setFilePath( filePath );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( BTree.DEFAULT_PAGE_SIZE );
+        configuration.setAllowDuplicates( BTree.FORBID_DUPLICATES );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new InMemoryBTree<K, V>( configuration );
+
+        return btree;
+    }
+
+    
+    /**
+     * Creates a new in-memory BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param filePath The name of the data directory with absolute path
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param pageSize Size of the page
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createInMemoryBTree( String name, String filePath, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, int pageSize )
+    {
+        InMemoryBTreeConfiguration<K, V> configuration = new InMemoryBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setFilePath( filePath );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( pageSize );
+        configuration.setAllowDuplicates( BTree.FORBID_DUPLICATES );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new InMemoryBTree<K, V>( configuration );
+
+        return btree;
+    }
+    
+    
+    /**
+     * Creates a new in-memory BTree using the parameters to initialize the 
+     * BTree
+     * 
+     * @param name The BTree's name
+     * @param filePath The name of the data directory with absolute path
+     * @param keySerializer Key serializer
+     * @param valueSerializer Value serializer
+     * @param pageSize Size of the page
+     * @param allowDuplicates Tells if the BTree allows multiple value for a given key
+     * @throws IOException
+     */
+    public static <K, V> BTree<K, V> createInMemoryBTree( String name, String filePath, ElementSerializer<K> keySerializer,
+        ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates )
+    {
+        InMemoryBTreeConfiguration<K, V> configuration = new InMemoryBTreeConfiguration<K, V>();
+        
+        configuration.setName( name );
+        configuration.setFilePath( filePath );
+        configuration.setKeySerializer( keySerializer );
+        configuration.setValueSerializer( valueSerializer );
+        configuration.setPageSize( pageSize );
+        configuration.setAllowDuplicates( allowDuplicates );
+        configuration.setWriteBufferSize( BTree.DEFAULT_WRITE_BUFFER_SIZE );
+
+        BTree<K, V> btree = new InMemoryBTree<K, V>( configuration );
+
+        return btree;
+    }
+
+
+    //--------------------------------------------------------------------------------------------
+    // Create Pages
+    //--------------------------------------------------------------------------------------------
+    /**
+     * Create a new Leaf for the given BTree.
+     * 
+     * @param btree The BTree which will contain this leaf
+     * @param revision The Leaf's revision
+     * @param nbElems The number or elements in this leaf
+     * 
+     * @return A Leaf instance
+     */
+    /* no qualifier*/ static <K, V> Page<K, V> createLeaf( BTree<K, V> btree, long revision, int nbElems )
+    {
+        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        {
+            return new PersistedLeaf<K, V>( btree, revision, nbElems );
+        }
+        else
+        {
+            return new InMemoryLeaf<K, V>( btree, revision, nbElems );
+        }
+    }
+    
+    
+    /**
+     * Create a new Node for the given BTree.
+     * 
+     * @param btree The BTree which will contain this node
+     * @param revision The Node's revision
+     * @param nbElems The number or elements in this node
+     * @return A Node instance
+     */
+    /* no qualifier*/ static <K, V> Page<K, V> createNode( BTree<K, V> btree, long revision, int nbElems )
+    {
+        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        {
+            return new PersistedNode<K, V>( btree, revision, nbElems );
+        }
+        else
+        {
+            return new InMemoryNode<K, V>( btree, revision, nbElems );
+        }
+    }
+
+
+    //--------------------------------------------------------------------------------------------
+    // Update pages
+    //--------------------------------------------------------------------------------------------
+    /**
+     * Set the key at a give position
+     * 
+     * @param btree The BTree to update
+     * @param page The page to update
+     * @param pos The position in the keys array
+     * @param key The key to inject
+     */
+    /* no qualifier*/ static <K, V> void setKey( BTree<K, V> btree, Page<K, V> page, int pos, K key )
+    {
+        KeyHolder<K> keyHolder;
+        
+        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        {
+            keyHolder = new PersistedKeyHolder<K>( btree.getKeySerializer(), key );
+        }
+        else
+        {
+            keyHolder = new KeyHolder<K>( key );
+        }
+
+        ( ( AbstractPage<K, V> ) page ).setKey( pos, keyHolder );
+    }
+
+
+    /**
+     * Set the value at a give position
+     * @param pos The position in the values array
+     * @param value the value to inject
+     */
+    /* no qualifier*/ static <K, V> void setValue( BTree<K, V> btree, Page<K, V> page, int pos, ValueHolder<V> value )
+    {
+        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        {
+            ((PersistedLeaf<K, V>)page).setValue( pos, value );
+        }
+        else
+        {
+            ((InMemoryLeaf<K, V>)page).setValue( pos, value );
+        }
+    }
+
+
+    /**
+     * Set the page at a give position
+     * 
+     * @param btree The BTree to update
+     * @param page The page to update
+     * @param pos The position in the values array
+     * @param value the value to inject
+     */
+    /* no qualifier*/ static <K, V> void setPage( BTree<K, V> btree, Page<K, V> page, int pos, Page<K, V> child )
+    {
+        if ( btree.getType() == BTreeTypeEnum.PERSISTED )
+        {
+            ((PersistedNode<K, V>)page).setValue( pos, new PersistedPageHolder<K, V>( btree, child ) );
+        }
+        else
+        {
+            ((InMemoryNode<K, V>)page).setPageHolder( pos, new PageHolder<K, V>( btree, child ) );
+        }
+    }
+    
+
+    //--------------------------------------------------------------------------------------------
+    // Update BTree
+    //--------------------------------------------------------------------------------------------
+    /**
+     * Sets the KeySerializer into the BTree
+     *  
+     * @param btree The BTree to update
+     * @param keySerializerFqcn the Key serializer FQCN to set
+     * @throws ClassNotFoundException
+     * @throws InstantiationException 
+     * @throws IllegalAccessException
+     */
+    /* no qualifier*/ static <K, V> void setKeySerializer( BTree<K, V> btree, String keySerializerFqcn )
+        throws ClassNotFoundException, IllegalAccessException, InstantiationException
+    {
+        Class<?> keySerializer = Class.forName( keySerializerFqcn );
+        @SuppressWarnings("unchecked")
+        ElementSerializer<K> instance = ( ElementSerializer<K> ) keySerializer.newInstance();
+        btree.setKeySerializer( instance );
+    }
+
+
+    /**
+     * Sets the ValueSerializer into the BTree
+     *  
+     * @param btree The BTree to update
+     * @param valueSerializerFqcn the Value serializer FQCN to set
+     * @throws ClassNotFoundException
+     * @throws InstantiationException 
+     * @throws IllegalAccessException
+     */
+    /* no qualifier*/ static <K, V> void setValueSerializer( BTree<K, V> btree, String valueSerializerFqcn )
+        throws ClassNotFoundException, IllegalAccessException, InstantiationException
+    {
+        Class<?> valueSerializer = Class.forName( valueSerializerFqcn );
+        @SuppressWarnings("unchecked")
+        ElementSerializer<V> instance = ( ElementSerializer<V> ) valueSerializer.newInstance();
+        btree.setValueSerializer( instance );
+    }
+
+    
+    /**
+     * Set the new root page for this tree. Used for debug purpose only. The revision
+     * will always be 0;
+     * 
+     * @param btree The BTree to update
+     * @param root the new root page.
+     */
+    /* no qualifier*/ static <K, V> void setRootPage( BTree<K, V> btree, Page<K, V> root )
+    {
+        ((AbstractBTree<K, V>)btree).setRootPage( root );
+    }
+
+
+    /**
+     * Return the BTree root page
+     * 
+     * @param btree The Btree we want to root page from
+     * @return The root page
+     */
+    /* no qualifier */ static <K, V> Page<K, V> getRootPage( BTree<K, V> btree )
+    {
+        return btree.getRootPage();
+    }
+    
+    
+    /**
+     * update the BTree number of elements
+     * 
+     * @param btree The BTree to update
+     * @param nbElems the nbElems to set
+     */
+    /* no qualifier */static <K, V> void setNbElems( BTree<K, V> btree, long nbElems )
+    {
+        ((AbstractBTree<K, V>)btree).setNbElems( nbElems );
+    }
+
+
+    /**
+     * Update the btree revision
+     * 
+     * @param btree The BTree to update
+     * @param revision the revision to set
+     */
+    /* no qualifier*/static <K, V> void setRevision( BTree<K, V> btree, long revision )
+    {
+        ((AbstractBTree<K, V>)btree).setRevision( revision );
+    }
+
+
+    /**
+     * Set the BTree name
+     * 
+     * @param btree The BTree to update
+     * @param name the name to set
+     */
+    /* no qualifier */ static <K, V> void setName( BTree<K, V> btree, String name )
+    {
+        btree.setName( name );
+    }
+
+
+    /**
+     * Set the maximum number of elements we can store in a page.
+     * 
+     * @param btree The BTree to update
+     * @param pageSize The requested page size
+     */
+    /* no qualifier */ static <K, V> void setPageSize( BTree<K, V> btree, int pageSize )
+    {
+        btree.setPageSize( pageSize );
+    }
+
+
+    //--------------------------------------------------------------------------------------------
+    // Utility method
+    //--------------------------------------------------------------------------------------------
+    /**
+     * Includes the intermediate nodes in the path up to and including the right most leaf of the tree
+     * 
+     * @param btree the btree
+     * @return a LinkedList of all the nodes and the final leaf
+     */
+    /* no qualifier*/ static <K, V> LinkedList<ParentPos<K, V>> getPathToRightMostLeaf( BTree<K, V> btree )
+    {
+        LinkedList<ParentPos<K, V>> stack = new LinkedList<ParentPos<K, V>>();
+
+        ParentPos<K, V> last = new ParentPos<K, V>( btree.getRootPage(), btree.getRootPage().getNbElems() );
+        stack.push( last );
+
+        if ( btree.getRootPage().isLeaf() )
+        {
+            Page<K, V> leaf = btree.getRootPage();
+            ValueHolder<V> valueHolder = ((AbstractPage<K, V>)leaf).getValue( last.pos );
+            last.valueCursor = valueHolder.getCursor();
+        }
+        else
+        {
+            Page<K, V> node = btree.getRootPage();
+
+            while ( true )
+            {
+                Page<K, V> p = ((AbstractPage<K, V>)node).getPage( node.getNbElems() );
+
+                last = new ParentPos<K, V>( p, p.getNbElems() );
+                stack.push( last );
+
+                if ( p.isLeaf() )
+                {
+                    Page<K, V> leaf = last.page;
+                    ValueHolder<V> valueHolder = ((AbstractPage<K, V>)leaf).getValue( last.pos );
+                    last.valueCursor = valueHolder.getCursor();
+                    break;
+                }
+            }
+        }
+
+        return stack;
+    }
+    
+    
+    //--------------------------------------------------------------------------------------------
+    // Persisted BTree methods
+    //--------------------------------------------------------------------------------------------
+    /**
+     * Set the rootPage offset of the BTree
+     * 
+     * @param btree The btree to update
+     * @param rootPageOffset The rootPageOffset to set
+     */
+    /* no qualifier*/static <K, V> void setRootPageOffset( BTree<K, V> btree, long rootPageOffset )
+    {
+        if ( btree instanceof PersistedBTree )
+        {
+            ((PersistedBTree<K, V>)btree).setRootPageOffset( rootPageOffset );
+        }
+        else
+        {
+            throw new IllegalArgumentException( "The BTree must be a PersistedBTree" );
+        }
+    }
+
+    
+    /**
+     * Set the nextBTree offset
+     * 
+     * @param btree The btree to update
+     * @param nextBTreeOffset The nextBTreeOffset to set
+     */
+    /* no qualifier*/ static <K, V> void setNextBTreeOffset( BTree<K, V> btree, long nextBTreeOffset )
+    {
+        if ( btree instanceof PersistedBTree )
+        {
+            ((PersistedBTree<K, V>)btree).setNextBTreeOffset( nextBTreeOffset );
+        }
+        else
+        {
+            throw new IllegalArgumentException( "The BTree must be a PersistedBTree" );
+        }
+    }
+    
+    
+    /**
+     * Set the RecordManager
+     * 
+     * @param btree The btree to update
+     * @param recordManager The injected RecordManager
+     */
+    /* no qualifier*/ static <K, V> void setRecordManager( BTree<K, V> btree, RecordManager recordManager )
+    {
+        if ( btree instanceof PersistedBTree )
+        {
+            ((PersistedBTree<K, V>)btree).setRecordManager( recordManager );
+        }
+        else
+        {
+            throw new IllegalArgumentException( "The BTree must be a PersistedBTree" );
+        }
+    }
+    
+    
+    /**
+     * Set the key at a give position
+     * 
+     * @param btree The btree to update
+     * @param page The page to update
+     * @param pos The position of this key in the page
+     * @param buffer The byte[] containing the serialized key
+     */
+    /* no qualifier*/ static <K, V> void setKey( BTree<K, V> btree, Page<K, V> page, int pos, byte[] buffer )
+    {
+        if ( btree instanceof PersistedBTree )
+        {
+            KeyHolder<K> keyHolder = new PersistedKeyHolder<K>( btree.getKeySerializer(), buffer );
+            ( ( AbstractPage<K, V> ) page ).setKey( pos, keyHolder );
+        }
+        else
+        {
+            throw new IllegalArgumentException( "The BTree must be a PersistedBTree" );
+        }
+    }
+    
+    
+    /**
+     * Includes the intermediate nodes in the path up to and including the left most leaf of the tree
+     * 
+     * @param btree The btree to process
+     * @return a LinkedList of all the nodes and the final leaf
+     */
+    /* no qualifier*/ static <K, V> LinkedList<ParentPos<K, V>> getPathToLeftMostLeaf( BTree<K, V> btree )
+    {
+        if ( btree instanceof PersistedBTree )
+        {
+            LinkedList<ParentPos<K, V>> stack = new LinkedList<ParentPos<K, V>>();
+    
+            ParentPos<K, V> first = new ParentPos<K, V>( btree.getRootPage(), 0 );
+            stack.push( first );
+    
+            if ( btree.getRootPage().isLeaf() )
+            {
+                Page<K, V> leaf = btree.getRootPage();
+                ValueHolder<V> valueHolder = ((AbstractPage<K, V>)leaf).getValue( first.pos );
+                first.valueCursor = valueHolder.getCursor();
+            }
+            else
+            {
+                Page<K, V> node = btree.getRootPage();
+    
+                while ( true )
+                {
+                    Page<K, V> page = ((AbstractPage<K, V>)node).getPage( 0 );
+    
+                    first = new ParentPos<K, V>( page, 0 );
+                    stack.push( first );
+    
+                    if ( page.isLeaf() )
+                    {
+                        ValueHolder<V> valueHolder = ((AbstractPage<K, V>)page).getValue( first.pos );
+                        first.valueCursor = valueHolder.getCursor();
+                        break;
+                    }
+                }
+            }
+    
+            return stack;
+        }
+        else
+        {
+            throw new IllegalArgumentException( "The BTree must be a PersistedBTree" );
+        }
+    }
+}

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeTypeEnum.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeTypeEnum.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeTypeEnum.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/BTreeTypeEnum.java Wed Dec 18 04:42:25 2013
@@ -37,7 +37,7 @@ public enum BTreeTypeEnum
     IN_MEMORY,
 
     /** Persisted BTree */
-    PERSISTENT,
+    PERSISTED,
 
     /** In-memory BTree but saved on disk */
     BACKED_ON_DISK

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTree.java Wed Dec 18 04:42:25 2013
@@ -31,12 +31,8 @@ import java.nio.channels.FileChannel;
 import java.util.concurrent.ConcurrentLinkedQueue;
 import java.util.concurrent.locks.ReentrantLock;
 
-import net.sf.ehcache.Cache;
-import net.sf.ehcache.config.CacheConfiguration;
-
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
 import org.apache.directory.mavibot.btree.serializer.BufferHandler;
-import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
 import org.apache.directory.mavibot.btree.serializer.LongSerializer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -68,9 +64,6 @@ import org.slf4j.LoggerFactory;
     /** The associated file. If null, this is an in-memory btree  */
     private File file;
 
-    /** The BTree type : either in-memory, persistent or managed */
-    private BTreeTypeEnum type;
-
     /** A flag used to tell the BTree that the journal is activated */
     private boolean withJournal;
 
@@ -85,11 +78,11 @@ import org.slf4j.LoggerFactory;
     /**
      * Creates a new BTree, with no initialization. 
      */
-    public InMemoryBTree()
+    /* no qualifier */ InMemoryBTree()
     {
         super();
         btreeHeader = new BTreeHeader();
-        type = BTreeTypeEnum.IN_MEMORY;
+        setType( BTreeTypeEnum.IN_MEMORY );
     }
 
 
@@ -97,9 +90,9 @@ import org.slf4j.LoggerFactory;
      * Creates a new in-memory BTree using the BTreeConfiguration to initialize the 
      * BTree
      * 
-     * @param comparator The comparator to use
+     * @param configuration The configuration to use
      */
-    public InMemoryBTree( InMemoryBTreeConfiguration<K, V> configuration ) throws IOException
+    /* no qualifier */ InMemoryBTree( InMemoryBTreeConfiguration<K, V> configuration )
     {
         super();
         String name = configuration.getName();
@@ -129,8 +122,7 @@ import org.slf4j.LoggerFactory;
         readTimeOut = configuration.getReadTimeOut();
         writeBufferSize = configuration.getWriteBufferSize();
         btreeHeader.setAllowDuplicates( configuration.isAllowDuplicates() );
-        type = configuration.getType();
-        cacheSize = configuration.getCacheSize();
+        setType( configuration.getType() );
 
         if ( keySerializer.getComparator() == null )
         {
@@ -142,118 +134,14 @@ import org.slf4j.LoggerFactory;
         rootPage = new InMemoryLeaf<K, V>( this );
 
         // Now, initialize the BTree
-        init();
-    }
-
-
-    /**
-     * Creates a new in-memory BTree with a default page size and key/value serializers.
-     * 
-     * @param comparator The comparator to use
-     */
-    public InMemoryBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
-        throws IOException
-    {
-        this( name, keySerializer, valueSerializer, false );
-    }
-
-
-    public InMemoryBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
-        boolean allowDuplicates )
-        throws IOException
-    {
-        this( name, null, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE, allowDuplicates, DEFAULT_CACHE_SIZE );
-    }
-
-
-    /**
-     * Creates a new in-memory BTree with a default page size and key/value serializers.
-     * 
-     * @param comparator The comparator to use
-     */
-    public InMemoryBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize )
-        throws IOException
-    {
-        this( name, null, keySerializer, valueSerializer, pageSize );
-    }
-
-
-    /**
-     * Creates a new BTree with a default page size and a comparator, with an associated file.
-     * @param comparator The comparator to use
-     * @param serializer The serializer to use
-     */
-    public InMemoryBTree( String name, String path, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
-        throws IOException
-    {
-        this( name, path, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
-    }
-
-
-    /**
-     * 
-     * Creates a new instance of BTree with the given name and store it under the given dataDir if provided.
-     *
-     * @param name the name of the BTree
-     * @param dataDir the name of the data directory with absolute path
-     * @param keySerializer key serializer
-     * @param valueSerializer value serializer
-     * @param pageSize size of the page
-     * @throws IOException
-     */
-    public InMemoryBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
-        ElementSerializer<V> valueSerializer,
-        int pageSize )
-        throws IOException
-    {
-        this( name, dataDir, keySerializer, valueSerializer, pageSize, false, DEFAULT_CACHE_SIZE );
-    }
-
-
-    public InMemoryBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
-        ElementSerializer<V> valueSerializer,
-        int pageSize, boolean allowDuplicates )
-        throws IOException
-    {
-        this( name, dataDir, keySerializer, valueSerializer, pageSize, allowDuplicates, DEFAULT_CACHE_SIZE );
-    }
-
-
-    public InMemoryBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
-        ElementSerializer<V> valueSerializer,
-        int pageSize, boolean allowDuplicates, int cacheSize )
-        throws IOException
-    {
-        super();
-        btreeHeader = new BTreeHeader();
-        btreeHeader.setName( name );
-
-        if ( dataDir != null )
+        try
         {
-            envDir = new File( dataDir );
+            init();
+        }
+        catch ( IOException ioe )
+        {
+            throw new RuntimeException( ioe.getMessage() );
         }
-
-        setPageSize( pageSize );
-        writeBufferSize = DEFAULT_WRITE_BUFFER_SIZE;
-
-        this.cacheSize = cacheSize;
-
-        this.keySerializer = keySerializer;
-
-        btreeHeader.setKeySerializerFQCN( keySerializer.getClass().getName() );
-
-        this.valueSerializer = valueSerializer;
-
-        btreeHeader.setValueSerializerFQCN( valueSerializer.getClass().getName() );
-
-        btreeHeader.setAllowDuplicates( allowDuplicates );
-
-        // Create the first root page, with revision 0L. It will be empty
-        // and increment the revision at the same time
-        rootPage = new InMemoryLeaf<K, V>( this );
-
-        // Now, call the init() method
-        init();
     }
 
 
@@ -279,7 +167,7 @@ import org.slf4j.LoggerFactory;
             this.file = new File( envDir, btreeHeader.getName() + DATA_SUFFIX );
 
             this.journal = new File( envDir, file.getName() + JOURNAL_SUFFIX );
-            type = BTreeTypeEnum.BACKED_ON_DISK;
+            setType( BTreeTypeEnum.BACKED_ON_DISK );
         }
 
         // Create the queue containing the pending read transactions
@@ -289,7 +177,7 @@ import org.slf4j.LoggerFactory;
 
         // Check the files and create them if missing
         // Create the queue containing the modifications, if it's not a in-memory btree
-        if ( type == BTreeTypeEnum.BACKED_ON_DISK )
+        if ( getType() == BTreeTypeEnum.BACKED_ON_DISK )
         {
             if ( file.length() > 0 )
             {
@@ -309,23 +197,11 @@ import org.slf4j.LoggerFactory;
                 applyJournal();
             }
         }
-        else if ( type == null )
+        else 
         {
-            type = BTreeTypeEnum.IN_MEMORY;
+            setType( BTreeTypeEnum.IN_MEMORY );
         }
 
-        // Initialize the caches
-        CacheConfiguration cacheConfiguration = new CacheConfiguration();
-        cacheConfiguration.setName( "pages" );
-        cacheConfiguration.setEternal( true );
-        cacheConfiguration.setOverflowToDisk( false );
-        cacheConfiguration.setCacheLoaderTimeoutMillis( 0 );
-        cacheConfiguration.setMaxElementsInMemory( cacheSize );
-        cacheConfiguration.setMemoryStoreEvictionPolicy( "LRU" );
-
-        cache = new Cache( cacheConfiguration );
-        cache.initialise();
-
         // Initialize the txnManager thread
         //FIXME we should NOT create a new transaction manager thread for each BTree
         //createTransactionManager();
@@ -333,15 +209,6 @@ import org.slf4j.LoggerFactory;
 
 
     /**
-     * Return the cache we use in this BTree
-     */
-    /* No qualifier */Cache getCache()
-    {
-        return cache;
-    }
-
-
-    /**
      * Close the BTree, cleaning up all the data structure
      */
     public void close() throws IOException
@@ -350,7 +217,7 @@ import org.slf4j.LoggerFactory;
         // readTransactionsThread.interrupt();
         // readTransactions.clear();
 
-        if ( type == BTreeTypeEnum.BACKED_ON_DISK )
+        if ( getType() == BTreeTypeEnum.BACKED_ON_DISK )
         {
             // Flush the data
             flush();
@@ -767,7 +634,7 @@ import org.slf4j.LoggerFactory;
      */
     public void flush() throws IOException
     {
-        if ( type == BTreeTypeEnum.BACKED_ON_DISK )
+        if ( getType() == BTreeTypeEnum.BACKED_ON_DISK )
         {
             // Then flush the file
             flush( file );
@@ -799,7 +666,7 @@ import org.slf4j.LoggerFactory;
      */
     public boolean isInMemory()
     {
-        return type == BTreeTypeEnum.IN_MEMORY;
+        return getType() == BTreeTypeEnum.IN_MEMORY;
     }
 
 
@@ -808,7 +675,7 @@ import org.slf4j.LoggerFactory;
      */
     public boolean isPersistent()
     {
-        return type == BTreeTypeEnum.IN_MEMORY;
+        return getType() == BTreeTypeEnum.IN_MEMORY;
     }
 
 
@@ -855,7 +722,7 @@ import org.slf4j.LoggerFactory;
     {
         StringBuilder sb = new StringBuilder();
 
-        switch ( type )
+        switch ( getType() )
         {
             case IN_MEMORY:
                 sb.append( "In-memory " );
@@ -893,7 +760,7 @@ import org.slf4j.LoggerFactory;
 
         sb.append( ", DuplicatesAllowed: " ).append( btreeHeader.isAllowDuplicates() );
 
-        if ( type == BTreeTypeEnum.BACKED_ON_DISK )
+        if ( getType() == BTreeTypeEnum.BACKED_ON_DISK )
         {
             try
             {

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeBuilder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeBuilder.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeBuilder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeBuilder.java Wed Dec 18 04:42:25 2013
@@ -21,11 +21,6 @@
 package org.apache.directory.mavibot.btree;
 
 
-import static org.apache.directory.mavibot.btree.InMemoryBTreeFactory.createLeaf;
-import static org.apache.directory.mavibot.btree.InMemoryBTreeFactory.createNode;
-import static org.apache.directory.mavibot.btree.InMemoryBTreeFactory.setKey;
-import static org.apache.directory.mavibot.btree.InMemoryBTreeFactory.setValue;
-
 import java.io.IOException;
 import java.lang.reflect.Array;
 import java.util.ArrayList;
@@ -64,33 +59,35 @@ public class InMemoryBTreeBuilder<K, V>
     @SuppressWarnings("unchecked")
     public BTree<K, V> build( Iterator<Tuple<K, V>> sortedTupleItr ) throws IOException
     {
-        BTree<K, V> btree = new InMemoryBTree<K, V>( name, keySerializer, valueSerializer );
+        BTree<K, V> btree = BTreeFactory.createInMemoryBTree( name, keySerializer, valueSerializer );
         btree.init();
 
         List<Page<K, V>> lstLeaves = new ArrayList<Page<K, V>>();
 
         int totalTupleCount = 0;
 
-        InMemoryLeaf<K, V> leaf1 = createLeaf( btree, 0, numKeysInNode );
+        InMemoryLeaf<K, V> leaf1 = (InMemoryLeaf<K, V>)BTreeFactory.createLeaf( btree, 0, numKeysInNode );
         lstLeaves.add( leaf1 );
 
         int leafIndex = 0;
+        
         while ( sortedTupleItr.hasNext() )
         {
             Tuple<K, V> tuple = sortedTupleItr.next();
 
-            setKey( leaf1, leafIndex, tuple.getKey() );
+            BTreeFactory.setKey( btree, leaf1, leafIndex, tuple.getKey() );
 
             InMemoryValueHolder<V> eh = new InMemoryValueHolder<V>( btree, tuple.getValue() );
 
-            setValue( leaf1, leafIndex, eh );
+            BTreeFactory.setValue( btree, leaf1, leafIndex, eh );
 
             leafIndex++;
             totalTupleCount++;
+            
             if ( ( totalTupleCount % numKeysInNode ) == 0 )
             {
                 leafIndex = 0;
-                leaf1 = createLeaf( btree, 0, numKeysInNode );
+                leaf1 = (InMemoryLeaf<K, V>)BTreeFactory.createLeaf( btree, 0, numKeysInNode );
                 lstLeaves.add( leaf1 );
             }
         }
@@ -144,7 +141,7 @@ public class InMemoryBTreeBuilder<K, V>
 
         int numChildren = numKeysInNode + 1;
 
-        InMemoryNode<K, V> node = createNode( btree, 0, numKeysInNode );
+        InMemoryNode<K, V> node = (InMemoryNode<K, V>)BTreeFactory.createNode( btree, 0, numKeysInNode );
         lstNodes.add( node );
         int i = 0;
         int totalNodes = 0;
@@ -153,7 +150,7 @@ public class InMemoryBTreeBuilder<K, V>
         {
             if ( i != 0 )
             {
-                setKey( node, i - 1, p.getLeftMostKey() );
+                BTreeFactory.setKey( btree, node, i - 1, p.getLeftMostKey() );
             }
 
             node.setPageHolder( i, new PageHolder<K, V>( btree, p ) );
@@ -164,7 +161,7 @@ public class InMemoryBTreeBuilder<K, V>
             if ( ( totalNodes % numChildren ) == 0 )
             {
                 i = 0;
-                node = createNode( btree, 0, numKeysInNode );
+                node = (InMemoryNode<K, V>)BTreeFactory.createNode( btree, 0, numKeysInNode );
                 lstNodes.add( node );
             }
         }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeConfiguration.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeConfiguration.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeConfiguration.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryBTreeConfiguration.java Wed Dec 18 04:42:25 2013
@@ -87,9 +87,6 @@ public class InMemoryBTreeConfiguration<
     /** the type of BTree */
     private BTreeTypeEnum type;
 
-    /** The cache size */
-    private int cacheSize;
-
 
     /**
      * @return the pageSize
@@ -322,22 +319,4 @@ public class InMemoryBTreeConfiguration<
     {
         this.type = type;
     }
-
-
-    /**
-     * @return the cacheSize
-     */
-    public int getCacheSize()
-    {
-        return cacheSize;
-    }
-
-
-    /**
-     * @param cacheSize the cacheSize to set
-     */
-    public void setCacheSize( int cacheSize )
-    {
-        this.cacheSize = cacheSize;
-    }
 }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryLeaf.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryLeaf.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryLeaf.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryLeaf.java Wed Dec 18 04:42:25 2013
@@ -568,7 +568,7 @@ import org.apache.directory.mavibot.btre
      * @param pos The position in the values array
      * @param value the value to inject
      */
-    /* no qualifier */void setValue( int pos, InMemoryValueHolder<V> value )
+    /* no qualifier */void setValue( int pos, ValueHolder<V> value )
     {
         values[pos] = value;
     }
@@ -896,6 +896,24 @@ import org.apache.directory.mavibot.btre
 
         return new Tuple<K, V>( getKey( nbElems - 1 ), val );
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isLeaf()
+    {
+        return true;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isNode()
+    {
+        return false;
+    }
 
 
     /**

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryNode.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryNode.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryNode.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryNode.java Wed Dec 18 04:42:25 2013
@@ -1017,6 +1017,24 @@ import java.util.List;
 
         return children[nbElems - 1].getValue().getRightMostKey();
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isLeaf()
+    {
+        return false;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isNode()
+    {
+        return true;
+    }
 
 
     /**

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryValueHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryValueHolder.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryValueHolder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/InMemoryValueHolder.java Wed Dec 18 04:42:25 2013
@@ -121,20 +121,13 @@ import org.apache.directory.mavibot.btre
      */
     protected void createSubTree()
     {
-        try
-        {
-            InMemoryBTreeConfiguration<V, V> configuration = new InMemoryBTreeConfiguration<V, V>();
-            configuration.setAllowDuplicates( false );
-            configuration.setName( UUID.randomUUID().toString() );
-            configuration.setKeySerializer( valueSerializer );
-            configuration.setValueSerializer( valueSerializer );
+        InMemoryBTreeConfiguration<V, V> configuration = new InMemoryBTreeConfiguration<V, V>();
+        configuration.setAllowDuplicates( false );
+        configuration.setName( UUID.randomUUID().toString() );
+        configuration.setKeySerializer( valueSerializer );
+        configuration.setValueSerializer( valueSerializer );
 
-            valueBtree = new InMemoryBTree<V, V>( configuration );
-        }
-        catch ( IOException e )
-        {
-            throw new RuntimeException( e );
-        }
+        valueBtree = BTreeFactory.createInMemoryBTree( configuration );
     }
 
 

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Page.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Page.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Page.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/Page.java Wed Dec 18 04:42:25 2013
@@ -256,4 +256,18 @@ import org.apache.directory.mavibot.btre
      * @throws IOException If we have an error while trying to access the page
      */
     boolean hasKey( K key ) throws IOException;
+    
+    
+    /**
+     * Tells if the page is a leaf or not
+     * @return true if the page is a leaf
+     */
+    boolean isLeaf();
+    
+    
+    /**
+     * Tells if the page is a node or not
+     * @return true if the page is a node
+     */
+    boolean isNode();
 }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTree.java Wed Dec 18 04:42:25 2013
@@ -32,7 +32,6 @@ import net.sf.ehcache.Status;
 import net.sf.ehcache.config.CacheConfiguration;
 
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
-import org.apache.directory.mavibot.btree.serializer.ElementSerializer;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -53,6 +52,15 @@ public class PersistedBTree<K, V> extend
     /** The RecordManager if the BTree is managed */
     private RecordManager recordManager;
 
+    /** The cache associated with this BTree */
+    protected Cache cache;
+
+    /** The default number of pages to keep in memory */
+    static final int DEFAULT_CACHE_SIZE = 1000;
+
+    /** The cache size, default to 1000 elements */
+    protected int cacheSize = DEFAULT_CACHE_SIZE;
+
     /** A flag indicating if this BTree is a Sub BTree */
     private boolean isSubBtree = false;
 
@@ -70,19 +78,20 @@ public class PersistedBTree<K, V> extend
     /**
      * Creates a new BTree, with no initialization. 
      */
-    public PersistedBTree()
+    /* no qualifier */ PersistedBTree()
     {
         btreeHeader = new BTreeHeader();
+        setType( BTreeTypeEnum.PERSISTED );
     }
 
 
     /**
-     * Creates a new in-memory BTree using the BTreeConfiguration to initialize the 
+     * Creates a new persisted BTree using the BTreeConfiguration to initialize the 
      * BTree
      * 
-     * @param comparator The comparator to use
+     * @param configuration The configuration to use
      */
-    public PersistedBTree( PersistedBTreeConfiguration<K, V> configuration )
+    /* no qualifier */ PersistedBTree( PersistedBTreeConfiguration<K, V> configuration )
     {
         super();
         String name = configuration.getName();
@@ -107,6 +116,7 @@ public class PersistedBTree<K, V> extend
         writeBufferSize = configuration.getWriteBufferSize();
         btreeHeader.setAllowDuplicates( configuration.isAllowDuplicates() );
         cacheSize = configuration.getCacheSize();
+        setType( BTreeTypeEnum.PERSISTED );
 
         if ( keySerializer.getComparator() == null )
         {
@@ -131,110 +141,6 @@ public class PersistedBTree<K, V> extend
 
 
     /**
-     * Creates a new in-memory BTree with a default page size and key/value serializers.
-     * 
-     * @param comparator The comparator to use
-     */
-    public PersistedBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
-    {
-        this( name, keySerializer, valueSerializer, false );
-    }
-
-
-    public PersistedBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
-        boolean allowDuplicates )
-    {
-        this( name, null, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE, allowDuplicates, DEFAULT_CACHE_SIZE );
-    }
-
-
-    public PersistedBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer,
-        boolean allowDuplicates, int cacheSize )
-    {
-        this( name, null, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE, allowDuplicates, cacheSize );
-    }
-
-
-    /**
-     * Creates a new in-memory BTree with a default page size and key/value serializers.
-     * 
-     * @param comparator The comparator to use
-     */
-    public PersistedBTree( String name, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer, int pageSize )
-    {
-        this( name, null, keySerializer, valueSerializer, pageSize );
-    }
-
-
-    /**
-     * Creates a new BTree with a default page size and a comparator, with an associated file.
-     * @param comparator The comparator to use
-     * @param serializer The serializer to use
-     */
-    public PersistedBTree( String name, String path, ElementSerializer<K> keySerializer, ElementSerializer<V> valueSerializer )
-    {
-        this( name, path, keySerializer, valueSerializer, DEFAULT_PAGE_SIZE );
-    }
-
-
-    /**
-     * 
-     * Creates a new instance of BTree with the given name and store it under the given dataDir if provided.
-     *
-     * @param name the name of the BTree
-     * @param dataDir the name of the data directory with absolute path
-     * @param keySerializer key serializer
-     * @param valueSerializer value serializer
-     * @param pageSize size of the page
-     * @throws IOException
-     */
-    public PersistedBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
-        ElementSerializer<V> valueSerializer, int pageSize )
-    {
-        this( name, dataDir, keySerializer, valueSerializer, pageSize, false, DEFAULT_CACHE_SIZE );
-    }
-
-
-    public PersistedBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
-        ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates )
-    {
-        this( name, dataDir, keySerializer, valueSerializer, pageSize, allowDuplicates, DEFAULT_CACHE_SIZE );
-    }
-
-
-    public PersistedBTree( String name, String dataDir, ElementSerializer<K> keySerializer,
-        ElementSerializer<V> valueSerializer, int pageSize, boolean allowDuplicates, int cacheSize )
-    {
-        super();
-
-        btreeHeader = new BTreeHeader();
-        btreeHeader.setName( name );
-
-        setPageSize( pageSize );
-        writeBufferSize = DEFAULT_WRITE_BUFFER_SIZE;
-
-        this.cacheSize = cacheSize;
-
-        this.keySerializer = keySerializer;
-
-        btreeHeader.setKeySerializerFQCN( keySerializer.getClass().getName() );
-
-        this.valueSerializer = valueSerializer;
-
-        btreeHeader.setValueSerializerFQCN( valueSerializer.getClass().getName() );
-
-        btreeHeader.setAllowDuplicates( allowDuplicates );
-
-        // Create the first root page, with revision 0L. It will be empty
-        // and increment the revision at the same time
-        rootPage = new PersistedLeaf<K, V>( this );
-
-        // Now, call the init() method
-        init();
-    }
-
-
-    /**
      * Initialize the BTree.
      * 
      * @throws IOException If we get some exception while initializing the BTree

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilder.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedBTreeBuilder.java Wed Dec 18 04:42:25 2013
@@ -20,12 +20,6 @@
 
 package org.apache.directory.mavibot.btree;
 
-
-import static org.apache.directory.mavibot.btree.PersistedBTreeFactory.createLeaf;
-import static org.apache.directory.mavibot.btree.PersistedBTreeFactory.createNode;
-import static org.apache.directory.mavibot.btree.PersistedBTreeFactory.setKey;
-import static org.apache.directory.mavibot.btree.PersistedBTreeFactory.setValue;
-
 import java.io.IOException;
 import java.lang.reflect.Array;
 import java.util.ArrayList;
@@ -67,7 +61,7 @@ public class PersistedBTreeBuilder<K, V>
     @SuppressWarnings("unchecked")
     public BTree<K, V> build( Iterator<Tuple<K, V>> sortedTupleItr ) throws Exception
     {
-        BTree<K, V> btree = new PersistedBTree<K, V>( name, keySerializer, valueSerializer );
+        BTree<K, V> btree = BTreeFactory.createPersistedBTree( name, keySerializer, valueSerializer );
         btree.init();
 
         rm.manage( btree );
@@ -76,7 +70,7 @@ public class PersistedBTreeBuilder<K, V>
 
         int totalTupleCount = 0;
 
-        PersistedLeaf<K, V> leaf1 = createLeaf( btree, 0, numKeysInNode );
+        PersistedLeaf<K, V> leaf1 = (PersistedLeaf<K, V>)BTreeFactory.createLeaf( btree, 0, numKeysInNode );
         lstLeaves.add( leaf1 );
 
         int leafIndex = 0;
@@ -85,11 +79,11 @@ public class PersistedBTreeBuilder<K, V>
         {
             Tuple<K, V> tuple = sortedTupleItr.next();
             
-            setKey( btree, leaf1, leafIndex, tuple.getKey() );
+            BTreeFactory.setKey( btree, leaf1, leafIndex, tuple.getKey() );
 
             PersistedValueHolder<V> eh = new PersistedValueHolder<V>( btree, tuple.getValue() );
 
-            setValue( leaf1, leafIndex, eh );
+            BTreeFactory.setValue( btree, leaf1, leafIndex, eh );
 
             leafIndex++;
             totalTupleCount++;
@@ -99,7 +93,7 @@ public class PersistedBTreeBuilder<K, V>
                 
                 PersistedPageHolder<K, V> pageHolder = (PersistedPageHolder<K, V> ) rm.writePage( btree, leaf1, 1 );
                 
-                leaf1 = createLeaf( btree, 0, numKeysInNode );
+                leaf1 = (PersistedLeaf<K, V>)BTreeFactory.createLeaf( btree, 0, numKeysInNode );
                 lstLeaves.add( leaf1 );
             }
             
@@ -163,7 +157,7 @@ public class PersistedBTreeBuilder<K, V>
 
         int numChildren = numKeysInNode + 1;
 
-        PersistedNode<K, V> node = createNode( btree, 0, numKeysInNode );
+        PersistedNode<K, V> node = (PersistedNode<K, V>)BTreeFactory.createNode( btree, 0, numKeysInNode );
         lstNodes.add( node );
         int i = 0;
         int totalNodes = 0;
@@ -172,10 +166,10 @@ public class PersistedBTreeBuilder<K, V>
         {
             if ( i != 0 )
             {
-                setKey( btree, node, i - 1, page.getLeftMostKey() );
+                BTreeFactory.setKey( btree, node, i - 1, page.getLeftMostKey() );
             }
 
-            node.setPageHolder( i, new PersistedPageHolder<K, V>( btree, page ) );
+            BTreeFactory.setPage( btree, node, i, page );
 
             i++;
             totalNodes++;
@@ -186,7 +180,7 @@ public class PersistedBTreeBuilder<K, V>
                 
                 PersistedPageHolder<K, V> pageHolder = (PersistedPageHolder<K, V> ) rm.writePage( btree, node, 1 );
 
-                node = createNode( btree, 0, numKeysInNode );
+                node = (PersistedNode<K, V>)BTreeFactory.createNode( btree, 0, numKeysInNode );
                 lstNodes.add( node );
             }
         }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedLeaf.java Wed Dec 18 04:42:25 2013
@@ -1016,6 +1016,24 @@ import org.apache.directory.mavibot.btre
             cursor.close();
         }
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isLeaf()
+    {
+        return true;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isNode()
+    {
+        return false;
+    }
 
 
     /**

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedNode.java Wed Dec 18 04:42:25 2013
@@ -1109,6 +1109,24 @@ import java.util.List;
 
         return children[nbElems - 1].getValue().getRightMostKey();
     }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isLeaf()
+    {
+        return false;
+    }
+    
+    
+    /**
+     * {@inheritDoc}
+     */
+    public boolean isNode()
+    {
+        return true;
+    }
 
 
     /**

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedPageHolder.java Wed Dec 18 04:42:25 2013
@@ -67,11 +67,8 @@ import org.apache.directory.mavibot.btre
         offset = ((AbstractPage<K, V>)page).getOffset();
         lastOffset = ((AbstractPage<K, V>)page).getLastOffset();
 
-        if ( page instanceof Page<?, ?> )
-        {
-            ( ( AbstractPage<K, V> ) page ).setOffset( offset );
-            ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
-        }
+        ( ( AbstractPage<K, V> ) page ).setOffset( offset );
+        ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
 
         cache.put( new Element( offset, page ) );
     }
@@ -90,7 +87,7 @@ import org.apache.directory.mavibot.btre
         this.offset = offset;
         this.lastOffset = lastOffset;
 
-        if ( page instanceof Page<?, ?> )
+        if ( page != null )
         {
             ( ( AbstractPage<K, V> ) page ).setOffset( offset );
             ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
@@ -127,11 +124,8 @@ import org.apache.directory.mavibot.btre
             // We have to fetch the element from disk, using the offset now
             page = fetchElement();
 
-            if ( page instanceof Page<?, ?> )
-            {
-                ( ( AbstractPage<K, V> ) page ).setOffset( offset );
-                ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
-            }
+            ( ( AbstractPage<K, V> ) page ).setOffset( offset );
+            ( ( AbstractPage<K, V> ) page ).setLastOffset( lastOffset );
 
             cache.put( new Element( offset, page ) );
         }

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedValueHolder.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedValueHolder.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedValueHolder.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/PersistedValueHolder.java Wed Dec 18 04:42:25 2013
@@ -248,7 +248,7 @@ import org.apache.directory.mavibot.btre
             configuration.setParentBTree( parentBtree );
             configuration.setSubBtree( true );
             
-            valueBtree = PersistedBTreeFactory.createBTree( configuration );
+            valueBtree = BTreeFactory.createPersistedBTree( configuration );
 
             try
             {

Modified: directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java (original)
+++ directory/mavibot/trunk/mavibot/src/main/java/org/apache/directory/mavibot/btree/RecordManager.java Wed Dec 18 04:42:25 2013
@@ -33,8 +33,6 @@ import java.util.Map;
 import java.util.Set;
 import java.util.concurrent.atomic.AtomicLong;
 
-import net.sf.ehcache.Status;
-
 import org.apache.directory.mavibot.btree.exception.BTreeAlreadyManagedException;
 import org.apache.directory.mavibot.btree.exception.EndOfFileExceededException;
 import org.apache.directory.mavibot.btree.exception.KeyNotFoundException;
@@ -309,11 +307,11 @@ public class RecordManager
         endOfFileOffset = fileChannel.size();
 
         // Now, initialize the Copied Page BTree
-        copiedPageBTree = new PersistedBTree<RevisionName, long[]>( COPIED_PAGE_BTREE_NAME, new RevisionNameSerializer(),
+        copiedPageBTree = BTreeFactory.createPersistedBTree( COPIED_PAGE_BTREE_NAME, new RevisionNameSerializer(),
             new LongArraySerializer() );
 
         // and initialize the Revision BTree
-        revisionBTree = new PersistedBTree<RevisionName, Long>( REVISION_BTREE_NAME, new RevisionNameSerializer(),
+        revisionBTree = BTreeFactory.createPersistedBTree( REVISION_BTREE_NAME, new RevisionNameSerializer(),
             new LongSerializer() );
 
         // Inject these BTrees into the RecordManager
@@ -369,7 +367,7 @@ public class RecordManager
             PageIO[] pageIos = readPageIOs( HEADER_SIZE, Long.MAX_VALUE );
 
             // Create the BTree
-            copiedPageBTree = PersistedBTreeFactory.<RevisionName, long[]> createBTree();
+            copiedPageBTree = BTreeFactory.<RevisionName, long[]> createPersistedBTree();
             ((PersistedBTree<RevisionName, long[]>)copiedPageBTree).setBtreeOffset( btreeOffset );
 
             loadBTree( pageIos, copiedPageBTree );
@@ -378,7 +376,7 @@ public class RecordManager
             // And the Revision BTree
             pageIos = readPageIOs( nextBtreeOffset, Long.MAX_VALUE );
 
-            revisionBTree = PersistedBTreeFactory.<RevisionName, Long> createBTree();
+            revisionBTree = BTreeFactory.<RevisionName, Long> createPersistedBTree();
             ((PersistedBTree<RevisionName, Long>)revisionBTree).setBtreeOffset( nextBtreeOffset );
 
             loadBTree( pageIos, revisionBTree );
@@ -388,7 +386,7 @@ public class RecordManager
             for ( int i = 2; i < nbBtree; i++ )
             {
                 // Create the BTree
-                BTree<Object, Object> btree = PersistedBTreeFactory.createBTree();
+                BTree<Object, Object> btree = BTreeFactory.createPersistedBTree();
                 ((PersistedBTree<Object, Object>)btree).setRecordManager( this );
                 ((PersistedBTree<Object, Object>)btree).setBtreeOffset( nextBtreeOffset );
                 lastAddedBTreeOffset = nextBtreeOffset;
@@ -476,34 +474,34 @@ public class RecordManager
 
         // The BTree current revision
         long revision = readLong( pageIos, dataPos );
-        PersistedBTreeFactory.setRevision( btree, revision );
+        BTreeFactory.setRevision( btree, revision );
         dataPos += LONG_SIZE;
 
         // The nb elems in the tree
         long nbElems = readLong( pageIos, dataPos );
-        PersistedBTreeFactory.setNbElems( btree, nbElems );
+        BTreeFactory.setNbElems( btree, nbElems );
         dataPos += LONG_SIZE;
 
         // The BTree rootPage offset
         long rootPageOffset = readLong( pageIos, dataPos );
-        PersistedBTreeFactory.setRootPageOffset( btree, rootPageOffset );
+        BTreeFactory.setRootPageOffset( btree, rootPageOffset );
         dataPos += LONG_SIZE;
 
         // The next BTree offset
         long nextBTreeOffset = readLong( pageIos, dataPos );
-        PersistedBTreeFactory.setNextBTreeOffset( btree, nextBTreeOffset );
+        BTreeFactory.setNextBTreeOffset( btree, nextBTreeOffset );
         dataPos += LONG_SIZE;
 
         // The BTree page size
         int btreePageSize = readInt( pageIos, dataPos );
-        PersistedBTreeFactory.setPageSize( btree, btreePageSize );
+        BTreeFactory.setPageSize( btree, btreePageSize );
         dataPos += INT_SIZE;
 
         // The tree name
         ByteBuffer btreeNameBytes = readBytes( pageIos, dataPos );
         dataPos += INT_SIZE + btreeNameBytes.limit();
         String btreeName = Strings.utf8ToString( btreeNameBytes );
-        PersistedBTreeFactory.setName( btree, btreeName );
+        BTreeFactory.setName( btree, btreeName );
 
         // The keySerializer FQCN
         ByteBuffer keySerializerBytes = readBytes( pageIos, dataPos );
@@ -516,7 +514,7 @@ public class RecordManager
             keySerializerFqcn = Strings.utf8ToString( keySerializerBytes );
         }
 
-        PersistedBTreeFactory.setKeySerializer( btree, keySerializerFqcn );
+        BTreeFactory.setKeySerializer( btree, keySerializerFqcn );
 
         // The valueSerialier FQCN
         ByteBuffer valueSerializerBytes = readBytes( pageIos, dataPos );
@@ -529,7 +527,7 @@ public class RecordManager
             valueSerializerFqcn = Strings.utf8ToString( valueSerializerBytes );
         }
 
-        PersistedBTreeFactory.setValueSerializer( btree, valueSerializerFqcn );
+        BTreeFactory.setValueSerializer( btree, valueSerializerFqcn );
 
         // The BTree allowDuplicates flag
         int allowDuplicates = readInt( pageIos, dataPos );
@@ -549,15 +547,15 @@ public class RecordManager
         PageIO[] rootPageIos = readPageIOs( rootPageOffset, Long.MAX_VALUE );
 
         Page<K, V> btreeRoot = readPage( btree, rootPageIos );
-        PersistedBTreeFactory.setRecordManager( btree, this );
+        BTreeFactory.setRecordManager( btree, this );
 
-        PersistedBTreeFactory.setRootPage( btree, btreeRoot );
+        BTreeFactory.setRootPage( btree, btreeRoot );
     }
 
 
     private <K, V> Page<K, V> readNode( BTree<K, V> btree, long offset, long revision, int nbElems ) throws IOException
     {
-        Page<K, V> node = PersistedBTreeFactory.createNode( btree, revision, nbElems );
+        Page<K, V> node = BTreeFactory.createNode( btree, revision, nbElems );
 
         // Read the rootPage pages on disk
         PageIO[] pageIos = readPageIOs( offset, Long.MAX_VALUE );
@@ -626,7 +624,7 @@ public class RecordManager
         PageIO[] pageIos )
     {
         // Its a leaf, create it
-        PersistedLeaf<K, V> leaf = PersistedBTreeFactory.createLeaf( btree, revision, nbElems );
+        PersistedLeaf<K, V> leaf = (PersistedLeaf<K, V>)BTreeFactory.createLeaf( btree, revision, nbElems );
 
         // Store the page offset on disk
         leaf.setOffset( pageIos[0].getOffset() );
@@ -664,12 +662,12 @@ public class RecordManager
                 valueHolder = new PersistedValueHolder<V>( btree, nbValues, arrayBytes );
             }
 
-            PersistedBTreeFactory.setValue( leaf, i, valueHolder );
+            BTreeFactory.setValue( btree, leaf, i, valueHolder );
 
             keyLengths[i] = byteBuffer.getInt();
             byte[] data = new byte[keyLengths[i]];
             byteBuffer.get( data );
-            PersistedBTreeFactory.setKey( btree, leaf, i, data );
+            BTreeFactory.setKey( btree, leaf, i, data );
         }
 
         return leaf;
@@ -682,7 +680,7 @@ public class RecordManager
     private <K, V> PersistedNode<K, V> readNodeKeysAndValues( BTree<K, V> btree, int nbElems, long revision, ByteBuffer byteBuffer,
         PageIO[] pageIos ) throws IOException
     {
-        PersistedNode<K, V> node = PersistedBTreeFactory.createNode( btree, revision, nbElems );
+        PersistedNode<K, V> node = (PersistedNode<K, V>)BTreeFactory.createNode( btree, revision, nbElems );
 
         // Read each value and key
         for ( int i = 0; i < nbElems; i++ )
@@ -705,7 +703,7 @@ public class RecordManager
             // Set the new position now
             byteBuffer.position( currentPosition + keyLength );
             
-            PersistedBTreeFactory.setKey( btree, node, i, key );
+            BTreeFactory.setKey( btree, node, i, key );
         }
 
         // and read the last value, as it's a node
@@ -1002,7 +1000,7 @@ public class RecordManager
         IOException
     {
         LOG.debug( "Managing the btree {} which is an internam tree : {}", btree.getName(), internalTree );
-        PersistedBTreeFactory.setRecordManager( btree, this );
+        BTreeFactory.setRecordManager( btree, this );
 
         String name = btree.getName();
 
@@ -1066,7 +1064,7 @@ public class RecordManager
         position = store( position, btree.getNbElems(), pageIos );
 
         // Serialize the BTree root page
-        Page<K, V> rootPage = PersistedBTreeFactory.getRoot( btree );
+        Page<K, V> rootPage = BTreeFactory.getRootPage( btree );
 
         PageIO[] rootPageIos = serializePage( btree, btree.getRevision(), rootPage );
 
@@ -1165,7 +1163,7 @@ public class RecordManager
             int dataSize = 0;
             int serializedSize = 0;
 
-            if ( page instanceof PersistedNode )
+            if ( page.isNode() )
             {
                 // A Node has one more value to store
                 nbBuffers++;
@@ -1183,7 +1181,7 @@ public class RecordManager
             // Make it a negative value if it's a Node
             int pageNbElems = nbElems;
 
-            if ( page instanceof PersistedNode )
+            if ( page.isNode() )
             {
                 pageNbElems = -nbElems;
             }
@@ -1198,7 +1196,7 @@ public class RecordManager
             for ( int pos = 0; pos < nbElems; pos++ )
             {
                 // Start with the value
-                if ( page instanceof PersistedNode )
+                if ( page.isNode() )
                 {
                     dataSize += serializeNodeValue( (PersistedNode<K, V> ) page, pos, serializedData );
                     dataSize += serializeNodeKey( (PersistedNode<K, V> ) page, pos, serializedData );
@@ -1211,7 +1209,7 @@ public class RecordManager
             }
 
             // Nodes have one more value to serialize
-            if ( page instanceof PersistedNode )
+            if ( page.isNode() )
             {
                 dataSize += serializeNodeValue( (PersistedNode<K, V> ) page, nbElems, serializedData );
             }
@@ -3013,7 +3011,7 @@ public class RecordManager
         {
             PageIO[] pageIos = readPageIOs( offset, Long.MAX_VALUE );
 
-            BTree<K, V> subBtree = PersistedBTreeFactory.createBTree();
+            BTree<K, V> subBtree = BTreeFactory.createPersistedBTree();
             ((PersistedBTree<K, V>)subBtree).setBtreeOffset( offset );
 
             loadBTree( pageIos, subBtree );

Modified: directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeDuplicateKeyTest.java
URL: http://svn.apache.org/viewvc/directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeDuplicateKeyTest.java?rev=1551837&r1=1551836&r2=1551837&view=diff
==============================================================================
--- directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeDuplicateKeyTest.java (original)
+++ directory/mavibot/trunk/mavibot/src/test/java/org/apache/directory/mavibot/btree/InMemoryBTreeDuplicateKeyTest.java Wed Dec 18 04:42:25 2013
@@ -52,7 +52,7 @@ public class InMemoryBTreeDuplicateKeyTe
     {
         IntSerializer serializer = new IntSerializer();
 
-        BTree<Integer, Integer> btree = new InMemoryBTree<Integer, Integer>( "master", serializer, serializer );
+        BTree<Integer, Integer> btree = BTreeFactory.createInMemoryBTree( "master", serializer, serializer );
         btree.init();
 
         btree.insert( 1, null );
@@ -75,7 +75,7 @@ public class InMemoryBTreeDuplicateKeyTe
     {
         IntSerializer serializer = new IntSerializer();
 
-        BTree<Integer, Integer> btree = new InMemoryBTree<Integer, Integer>( "master", serializer, serializer );
+        BTree<Integer, Integer> btree = BTreeFactory.createInMemoryBTree( "master", serializer, serializer );
         btree.init();
 
         TupleCursor<Integer, Integer> cursor = btree.browse();



Mime
View raw message