Author: elecharny
Date: Thu Aug  9 17:35:05 2012
New Revision: 1371329

URL: http://svn.apache.org/viewvc?rev=1371329&view=rev
Log:
o Added a constructor taking a BTreeConfiguration parameter
o Added an init() method to separate the construction of a btree from its 
initialization
o Renamed the read() method to load()

Modified:
    labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
    
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java

Modified: 
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java
URL: 
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java?rev=1371329&r1=1371328&r2=1371329&view=diff
==============================================================================
--- 
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java 
(original)
+++ 
labs/mavibot/trunk/mavibot/src/main/java/org/apache/mavibot/btree/BTree.java 
Thu Aug  9 17:35:05 2012
@@ -86,6 +86,45 @@ public class BTree<K, V>
 
 
     /**
+     * Creates a new in-memory BTree using the BTreeConfiguration to 
initialize the 
+     * BTree
+     * 
+     * @param comparator The comparator to use
+     */
+    public BTree( BTreeConfiguration<K, V> configuration ) throws IOException
+    {
+        String fileName = configuration.getFilePrefix() + "." + 
configuration.getFileSuffix();
+
+        File btreeFile = new File( configuration.getFilePath(), fileName );
+
+        pageSize = configuration.getPageSize();
+        comparator = configuration.getComparator();
+        serializer = configuration.getSerializer();
+
+        if ( comparator == null )
+        {
+            throw new IllegalArgumentException( "Comparator should not be 
null" );
+        }
+
+        // Now, initialize the BTree
+        init();
+
+        // Last, we load the data from the file, if it exists.
+        if ( btreeFile.exists() )
+        {
+            // The file already exists, load it.
+            file = btreeFile;
+            load( file );
+        }
+        else
+        {
+            // We will create the new file
+            file = btreeFile;
+        }
+    }
+
+
+    /**
      * Creates a new in-memory BTree with a default page size and a comparator.
      * 
      * @param comparator The comparator to use
@@ -192,7 +231,20 @@ public class BTree<K, V>
         setPageSize( pageSize );
         this.serializer = serializer;
 
-        // Create the map contaning all the revisions
+        // Now, call the init() method
+        init();
+    }
+
+
+    /**
+     * Initialize the BTree.
+     * 
+     * @throws IOException If we get some exceptio while initializing the BTree
+     */
+    public void init() throws IOException
+    {
+
+        // Create the map containing all the revisions
         roots = new ConcurrentHashMap<Long, Page<K, V>>();
 
         // Initialize the PageId counter
@@ -707,7 +759,7 @@ public class BTree<K, V>
      * @param file
      * @throws IOException
      */
-    public void read( File file ) throws IOException
+    public void load( File file ) throws IOException
     {
         long revision = generateRevision();
 

Modified: 
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java
URL: 
http://svn.apache.org/viewvc/labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java?rev=1371329&r1=1371328&r2=1371329&view=diff
==============================================================================
--- 
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java
 (original)
+++ 
labs/mavibot/trunk/mavibot/src/test/java/org/apache/mavibot/btree/BTreeFlushTest.java
 Thu Aug  9 17:35:05 2012
@@ -163,7 +163,7 @@ public class BTreeFlushTest
         BTree<Integer, String> btreeLoaded = new BTree<Integer, String>( file, 
new IntComparator(), serializer );
         btree.setPageSize( 8 );
 
-        btreeLoaded.read( file );
+        btreeLoaded.load( file );
 
         Cursor<Integer, String> cursor1 = btree.browse();
         Cursor<Integer, String> cursor2 = btree.browse();



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to