directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r945964 - in /directory/apacheds/trunk: jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ jdbm/src/main/java/jdbm/btree/
Date Tue, 18 May 2010 23:41:33 GMT
Author: elecharny
Date: Tue May 18 23:41:32 2010
New Revision: 945964

URL: http://svn.apache.org/viewvc?rev=945964&view=rev
Log:
o Removed the createInstance() methods used to create BTree instances, replaced with plain
constructors. This allow the user to define generic BTrees easily
o As the Tuple is now generic, modify the using code accordingly
o the BTree.load() method is not anymore static, for the same reason than #1 : generics don't
like static methods.

Modified:
    directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
    directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmBrowserBugTest.java
    directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java
    directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
    directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java

Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?rev=945964&r1=945963&r2=945964&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
Tue May 18 23:41:32 2010
@@ -27,6 +27,7 @@ import java.util.Map;
 import jdbm.RecordManager;
 import jdbm.btree.BTree;
 import jdbm.helper.Serializer;
+import jdbm.helper.Tuple;
 import jdbm.helper.TupleBrowser;
 
 import org.apache.directory.server.core.avltree.ArrayMarshaller;
@@ -79,7 +80,7 @@ public class JdbmTable<K,V> implements T
     private int count;
     
     /** the wrappedCursor JDBM btree used in this Table */
-    private BTree bt;
+    private BTree<K, V> bt;
 
     /** the limit at which we start using btree redirection for duplicates */
     private int numDupLimit = JdbmIndex.DEFAULT_DUPLICATE_LIMIT;
@@ -174,7 +175,7 @@ public class JdbmTable<K,V> implements T
             // explicitly managed by this code.  Value serialization is delegated to these
             // marshallers.
 
-            bt = BTree.createInstance( recMan, keyComparator, keySerializer, null );
+            bt = new BTree<K, V>( recMan, keyComparator, keySerializer, null );
             recId = bt.getRecid();
             recMan.setNamedObject( name, recId );
             recId = recMan.insert( 0 );
@@ -182,7 +183,7 @@ public class JdbmTable<K,V> implements T
         }
         else // Load existing BTree
         {
-            bt = BTree.load( recMan, recId );
+            bt= new BTree<K, V>().load( recMan, recId );
             ((SerializableComparator<K>)bt.getComparator()).setSchemaManager( schemaManager
);
             recId = recMan.getNamedObject( name + SZSUFFIX );
             count = ( Integer ) recMan.fetch( recId );
@@ -234,7 +235,7 @@ public class JdbmTable<K,V> implements T
 
         if ( recId != 0 )
         {
-            bt = BTree.load( recMan, recId );
+            bt = new BTree<K, V>().load( recMan, recId );
             ((SerializableComparator<K>)bt.getComparator()).setSchemaManager( schemaManager
);
             bt.setValueSerializer( valueSerializer );
             recId = recMan.getNamedObject( name + SZSUFFIX );
@@ -242,7 +243,7 @@ public class JdbmTable<K,V> implements T
         }
         else
         {
-            bt = BTree.createInstance( recMan, keyComparator, keySerializer, valueSerializer
);
+            bt = new BTree<K, V>( recMan, keyComparator, keySerializer, valueSerializer
);
             recId = bt.getRecid();
             recMan.setNamedObject( name, recId );
             recId = recMan.insert( 0 );
@@ -518,7 +519,7 @@ public class JdbmTable<K,V> implements T
     {
         // Can only find greater than or equal to with JDBM so we find that
         // and work backwards to see if we can find one less than the key
-        jdbm.helper.Tuple tuple = bt.findGreaterOrEqual( key );
+        Tuple<K, V> tuple = bt.findGreaterOrEqual( key );
 
         // Test for equality first since it satisfies equal to condition
         if ( null != tuple && keyComparator.compare( ( K ) tuple.getKey(), key )
== 0 )
@@ -546,6 +547,7 @@ public class JdbmTable<K,V> implements T
              * be the previous tuple if it exists.
              */
             TupleBrowser browser = bt.browse( tuple.getKey() );
+            
             if ( browser.getPrevious( tuple ) )
             {
                 return true;
@@ -647,7 +649,7 @@ public class JdbmTable<K,V> implements T
                 {
                     BTree tree = convertToBTree( set );
                     BTreeRedirect redirect = new BTreeRedirect( tree.getRecid() );
-                    bt.insert( key, BTreeRedirectMarshaller.INSTANCE.serialize( redirect
), true );
+                    bt.insert( key, (V)BTreeRedirectMarshaller.INSTANCE.serialize( redirect
), true );
                     
                     if ( LOG.isDebugEnabled() )
                     {
@@ -656,7 +658,7 @@ public class JdbmTable<K,V> implements T
                 }
                 else
                 {
-                    bt.insert( key, marshaller.serialize( set ), true );
+                    bt.insert( key, (V)marshaller.serialize( set ), true );
                     
                     if ( LOG.isDebugEnabled() )
                     {
@@ -748,7 +750,7 @@ public class JdbmTable<K,V> implements T
                     }
                     else
                     {
-                        bt.insert( key, marshaller.serialize( set ), true );
+                        bt.insert( key, (V)marshaller.serialize( set ), true );
                     }
                     count--;
 
@@ -777,7 +779,7 @@ public class JdbmTable<K,V> implements T
                     if ( tree.size() <= numDupLimit )
                     {
                         ArrayTree<V> avlTree = convertToArrayTree( tree );
-                        bt.insert( key, marshaller.serialize( avlTree ), true );
+                        bt.insert( key, (V)marshaller.serialize( avlTree ), true );
                         recMan.delete( tree.getRecid() );
                     }
                     
@@ -1053,7 +1055,7 @@ public class JdbmTable<K,V> implements T
             return duplicateBtrees.get( redirect.getRecId() );
         }
         
-        BTree tree = BTree.load( recMan, redirect.getRecId() );
+        BTree<K, V> tree = new BTree<K, V>().load( recMan, redirect.getRecId()
);
         ((SerializableComparator<K>)tree.getComparator()).setSchemaManager( schemaManager
);
         duplicateBtrees.put( redirect.getRecId(), tree );
         return tree;
@@ -1119,11 +1121,11 @@ public class JdbmTable<K,V> implements T
 
         if ( valueSerializer != null )
         {
-            bTree = BTree.createInstance( recMan, valueComparator, valueSerializer, null
);
+            bTree = new BTree<K, V>( recMan, valueComparator, valueSerializer, null
);
         }
         else
         {
-            bTree = BTree.createInstance( recMan, valueComparator );
+            bTree = new BTree<K, V>( recMan, valueComparator );
         }
 
         Cursor<V> keys = new ArrayTreeCursor<V>( arrayTree );

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmBrowserBugTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmBrowserBugTest.java?rev=945964&r1=945963&r2=945964&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmBrowserBugTest.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmBrowserBugTest.java
Tue May 18 23:41:32 2010
@@ -76,7 +76,7 @@ public class JdbmBrowserBugTest
 
         dbFile = File.createTempFile( getClass().getSimpleName(), "db", tmpDir );
         recman = new BaseRecordManager( dbFile.getAbsolutePath() );
-        bt = BTree.createInstance( recman, new IntegerComparator(), new IntegerSerializer(),
new IntegerSerializer() );
+        bt = new BTree<Integer, Integer>( recman, new IntegerComparator(), new IntegerSerializer(),
new IntegerSerializer() );
         LOG.debug( "created new BTree" );
     }
 

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java?rev=945964&r1=945963&r2=945964&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyBTreeCursorTest.java
Tue May 18 23:41:32 2010
@@ -78,7 +78,7 @@ public class KeyBTreeCursorTest
         dbFile = File.createTempFile( KeyBTreeCursorTest.class.getName(), "db", tmpDir );
         recman = new BaseRecordManager( dbFile.getAbsolutePath() );
         comparator = new StringComparator();
-        bt = BTree.createInstance( recman, comparator );
+        bt = new BTree<String, byte[]>( recman, comparator );
 
         // add some data to it
         bt.insert( "0", EMPTY_BYTES, true );

Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java?rev=945964&r1=945963&r2=945964&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
(original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/KeyCursorTest.java
Tue May 18 23:41:32 2010
@@ -78,7 +78,7 @@ public class KeyCursorTest
         dbFile = File.createTempFile( KeyCursorTest.class.getName(), "db", tmpDir );
         recman = new BaseRecordManager( dbFile.getAbsolutePath() );
         comparator = new StringComparator();
-        bt = BTree.createInstance( recman, comparator );
+        bt = new BTree<String, byte[]>( recman, comparator );
 
         // add some data to it
         bt.insert( "0", EMPTY_BYTES, true );

Modified: directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java?rev=945964&r1=945963&r2=945964&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java (original)
+++ directory/apacheds/trunk/jdbm/src/main/java/jdbm/btree/BTree.java Tue May 18 23:41:32
2010
@@ -148,9 +148,9 @@ public class BTree<K, V> implements Exte
      * @param recman Record manager used for persistence.
      * @param comparator Comparator used to order index entries
      */
-    public static BTree createInstance( RecordManager recman, Comparator<?> comparator
) throws IOException
+    public BTree( RecordManager recman, Comparator<?> comparator ) throws IOException
     {
-        return createInstance( recman, comparator, null, null, DEFAULT_SIZE );
+        createInstance( recman, comparator, null, null, DEFAULT_SIZE );
     }
 
 
@@ -162,10 +162,10 @@ public class BTree<K, V> implements Exte
      * @param valueSerializer Serializer used to serialize index values (optional)
      * @param comparator Comparator used to order index entries
      */
-    public static BTree createInstance( RecordManager recman, Comparator<?> comparator,
Serializer keySerializer,
+    public BTree( RecordManager recman, Comparator<?> comparator, Serializer keySerializer,
         Serializer valueSerializer ) throws IOException
     {
-        return createInstance( recman, comparator, keySerializer, valueSerializer, DEFAULT_SIZE
);
+        createInstance( recman, comparator, keySerializer, valueSerializer, DEFAULT_SIZE
);
     }
 
 
@@ -178,11 +178,16 @@ public class BTree<K, V> implements Exte
      * @param valueSerializer Serializer used to serialize index values (optional)
      * @param pageSize Number of entries per page (must be even).
      */
-    public static BTree createInstance( RecordManager recman, Comparator<?> comparator,
Serializer keySerializer,
+    public BTree( RecordManager recman, Comparator<?> comparator, Serializer keySerializer,
         Serializer valueSerializer, int pageSize ) throws IOException
     {
-        BTree btree;
-
+        createInstance( recman, comparator, keySerializer, valueSerializer, pageSize );
+    }
+    
+    
+    private void createInstance(RecordManager recman, Comparator<?> comparator, Serializer
keySerializer,
+        Serializer valueSerializer, int pageSize) throws IOException
+    {
         if ( recman == null )
         {
             throw new IllegalArgumentException( I18n.err( I18n.ERR_517 ) );
@@ -214,17 +219,14 @@ public class BTree<K, V> implements Exte
             throw new IllegalArgumentException( I18n.err( I18n.ERR_522 ) );
         }
 
-        btree = new BTree();
-        btree.recordManager = recman;
-        btree.comparator = comparator;
-        btree.keySerializer = keySerializer;
-        btree.valueSerializer = valueSerializer;
-        btree.pageSize = pageSize;
-        btree.bpageSerializer = new BPage<Object, Object>();
-        btree.bpageSerializer.btree = btree;
-        btree.recordId = recman.insert( btree );
-        
-        return btree;
+        this.recordManager = recman;
+        this.comparator = comparator;
+        this.keySerializer = keySerializer;
+        this.valueSerializer = valueSerializer;
+        this.pageSize = pageSize;
+        this.bpageSerializer = new BPage<K, V>();
+        this.bpageSerializer.btree = this;
+        this.recordId = recman.insert( this );
     }
 
 
@@ -234,12 +236,12 @@ public class BTree<K, V> implements Exte
      * @param recman RecordManager used to store the persistent btree
      * @param recid Record id of the BTree
      */
-    public static BTree load( RecordManager recman, long recid ) throws IOException
+    public BTree<K, V> load( RecordManager recman, long recid ) throws IOException
     {
-        BTree btree = ( BTree ) recman.fetch( recid );
+        BTree<K, V> btree = (BTree<K, V>) recman.fetch( recid );
         btree.recordId = recid;
         btree.recordManager = recman;
-        btree.bpageSerializer = new BPage<Object, Object>();
+        btree.bpageSerializer = new BPage<K, V>();
         btree.bpageSerializer.btree = btree;
         
         return btree;



Mime
View raw message