You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ak...@apache.org on 2008/03/13 02:08:39 UTC
svn commit: r636595 - in /directory/sandbox/akarasulu/bigbang/apacheds:
btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/
jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/
jdbm-store/src/...
Author: akarasulu
Date: Wed Mar 12 18:08:33 2008
New Revision: 636595
URL: http://svn.apache.org/viewvc?rev=636595&view=rev
Log:
modifications to jdbm store ...
o removed need to use this tuple comparator object
o cleaned up some of the constructurs to make them more explicit
with regard to the fact that one is for duplicates and the
other is for tables without duplicate keys
o using a long serializer and tracking both serializers and comparators for
keys and values
o fixed jdbm index to utilize these new constructors
Added:
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/LongSerializer.java
Modified:
directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshaller.java
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
Modified: directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java?rev=636595&r1=636594&r2=636595&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/btree-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/Table.java Wed Mar 12 18:08:33 2008
@@ -22,6 +22,8 @@
import org.apache.directory.server.core.cursor.Cursor;
+import java.util.Comparator;
+
/**
* A wrapper interface around BTree implementations used to abstract away
@@ -33,13 +35,23 @@
public interface Table<K, V>
{
/**
- * Gets the comparator pair used by this Table: may be null if this Table
+ * Gets the key comparator used by this Table: may be null if this Table
+ * was not initialized with one.
+ *
+ * @return the key comparator or null if this Table was not created with
+ * one.
+ */
+ Comparator<K> getKeyComparator();
+
+
+ /**
+ * Gets the value comparator used by this Table: may be null if this Table
* was not initialized with one.
*
- * @return the comparator pair or null if this Table was not created with
+ * @return the value comparator or null if this Table was not created with
* one.
*/
- TupleComparator<K,V> getComparator();
+ Comparator<V> getValueComparator();
/**
Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshaller.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshaller.java?rev=636595&r1=636594&r2=636595&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshaller.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/BTreeRedirectMarshaller.java Wed Mar 12 18:08:33 2008
@@ -120,6 +120,11 @@
*/
public static boolean isNotRedirect( byte[] bites )
{
+ if ( bites == null )
+ {
+ return true;
+ }
+
// faster to check if invalid than valid
return bites.length != SIZE ||
bites[0] != 'r' ||
Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java?rev=636595&r1=636594&r2=636595&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursor.java Wed Mar 12 18:08:33 2008
@@ -106,14 +106,12 @@
if ( noDupsTuple.getValue() instanceof byte[] )
{
LOG.debug( "Duplicates tuple {} stored in a AvlTree", noDupsTuple );
- AvlTree<V> set = ( AvlTree<V> ) table.getMarshaller().deserialize( ( byte[] ) noDupsTuple.getValue() );
+ AvlTree<V> set = table.getMarshaller().deserialize( ( byte[] ) noDupsTuple.getValue() );
}
else
{
LOG.debug( "Duplicates tuple {} are stored in a BTree", noDupsTuple );
BTreeRedirect redirect = ( BTreeRedirect ) noDupsTuple.getValue();
-
-
}
}
// throw new NotImplementedException();
@@ -174,7 +172,7 @@
{
BTree tree = table.getBTree( ( BTreeRedirect ) values );
//noinspection unchecked
- dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getComparator().getKeyComparator() );
+ dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getKeyComparator() );
if ( ! dupCursor.previous() )
{
clearValue();
@@ -228,7 +226,7 @@
{
BTree tree = table.getBTree( ( BTreeRedirect ) values );
//noinspection unchecked
- dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getComparator().getKeyComparator() );
+ dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getKeyComparator() );
dupCursor.previous();
}
}
@@ -279,7 +277,7 @@
{
BTree tree = table.getBTree( ( BTreeRedirect ) values );
//noinspection unchecked
- dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getComparator().getKeyComparator() );
+ dupCursor = new KeyCursor<V>( tree, ( Comparator<V> ) table.getKeyComparator() );
dupCursor.next();
}
}
Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java?rev=636595&r1=636594&r2=636595&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmIndex.java Wed Mar 12 18:08:33 2008
@@ -181,12 +181,10 @@
*/
forward = new JdbmTable<K, Long>(
attribute.getName() + FORWARD_BTREE,
- true,
numDupLimit,
recMan,
- new ForwardIndexComparator<K>( comp ),
- null, null );
- //LongSerializer.INSTANCE );
+ comp, null,
+ null, LongSerializer.INSTANCE );
/*
* Now the reverse map stores the primary key into the master table as
@@ -194,14 +192,25 @@
* is single valued according to its specification based on a schema
* then duplicate keys should not be allowed within the reverse table.
*/
- reverse = new JdbmTable<Long,K>(
- attribute.getName() + REVERSE_BTREE,
- !attribute.isSingleValue(),
- numDupLimit,
- recMan,
- new ReverseIndexComparator<K>( comp ),
- null, //LongSerializer.INSTANCE,
- null);
+ if ( attribute.isSingleValue() )
+ {
+ reverse = new JdbmTable<Long,K>(
+ attribute.getName() + REVERSE_BTREE,
+ recMan,
+ null,
+ LongSerializer.INSTANCE,
+ null);
+ }
+ else
+ {
+ reverse = new JdbmTable<Long,K>(
+ attribute.getName() + REVERSE_BTREE,
+ numDupLimit,
+ recMan,
+ null, comp,
+ LongSerializer.INSTANCE,
+ null);
+ }
}
Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java?rev=636595&r1=636594&r2=636595&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmNoDupsCursor.java Wed Mar 12 18:08:33 2008
@@ -101,10 +101,11 @@
*/
while ( browser.getNext( jdbmTuple ) )
{
+ //noinspection unchecked
K next = ( K ) jdbmTuple.getKey();
//noinspection unchecked
- int nextCompared = table.getComparator().getKeyComparator().compare( next, element.getKey() );
+ int nextCompared = table.getKeyComparator().compare( next, element.getKey() );
if ( nextCompared <= 0 )
{
Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java?rev=636595&r1=636594&r2=636595&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTable.java Wed Mar 12 18:08:33 2008
@@ -56,8 +56,10 @@
private final RecordManager recMan;
/** whether or not this table allows for duplicates */
private final boolean allowsDuplicates;
- /** a pair of comparators for the keys and values in this Table */
- private final TupleComparator<K,V> comparator;
+ /** a key comparator for the keys in this Table */
+ private final Comparator<K> keyComparator;
+ /** a value comparator for the values in this Table */
+ private final Comparator<V> valueComparator;
/** the current count of entries in this Table */
private int count;
@@ -71,7 +73,11 @@
private int numDupLimit = JdbmIndex.DEFAULT_DUPLICATE_LIMIT;
/** a cache of duplicate BTrees */
private final Map<Long, BTree> duplicateBtrees;
-
+
+ private final Serializer keySerializer;
+
+ private final Serializer valueSerializer;
+
AvlTreeMarshaller<V> marshaller;
@@ -85,53 +91,44 @@
* duplicates.
*
* @param name the name of the table
- * @param allowsDuplicates whether or not duplicates are enabled
* @param numDupLimit the size limit of duplicates before switching to
* BTrees for values instead of AvlTrees
* @param manager the record manager to be used for this table
- * @param comparator a tuple comparator
+ * @param keyComparator a key comparator
+ * @param valueComparator a value comparator
* @param keySerializer a serializer to use for the keys instead of using
* default Java serialization which could be very expensive
* @param valueSerializer a serializer to use for the values instead of
* using default Java serialization which could be very expensive
* @throws IOException if the table's file cannot be created
*/
- public JdbmTable( String name, boolean allowsDuplicates, int numDupLimit,
- RecordManager manager, TupleComparator<K,V> comparator, Serializer keySerializer,
- Serializer valueSerializer )
+ public JdbmTable( String name, int numDupLimit, RecordManager manager,
+ Comparator<K> keyComparator, Comparator<V> valueComparator,
+ Serializer keySerializer, Serializer valueSerializer )
throws IOException
{
- /*System.out.println( "Creating BTree for " + name + ", key serializer = " +
- (keySerializer == null ? "null" : keySerializer.getClass().getName()) +
- ", valueSerializer = " +
- (valueSerializer == null ? "null" : valueSerializer.getClass().getName()) );*/
-
- if( allowsDuplicates && valueSerializer == null )
+ if( valueSerializer == null )
{
throw new IllegalArgumentException("Value serializer cannot be null when duplicates are allowed in JdbmTable");
}
- if( allowsDuplicates )
- {
- // TODO make the size of the duplicate btree cache configurable via constructor
- //noinspection unchecked
- duplicateBtrees = new SynchronizedLRUMap( 100 );
- //TODO the IntegerKeyMarshaller should be replaced with the appropriate marshaller for type V
- marshaller = new AvlTreeMarshaller<V>( comparator.getValueComparator(),
- new MarshallerSerializerBridge<V>( valueSerializer ) );
- // the value serializer causes problems between BTree and AvlTree cause each use it in a different way
- valueSerializer = null; // set this to null
- }
- else
- {
- duplicateBtrees = null;
- }
-
+ // TODO make the size of the duplicate btree cache configurable via constructor
+ //noinspection unchecked
+ duplicateBtrees = new SynchronizedLRUMap( 100 );
+ marshaller = new AvlTreeMarshaller<V>( valueComparator,
+ new MarshallerSerializerBridge<V>( valueSerializer ) );
+
this.numDupLimit = numDupLimit;
this.name = name;
this.recMan = manager;
- this.comparator = comparator;
- this.allowsDuplicates = allowsDuplicates;
+
+ this.keyComparator = keyComparator;
+ this.valueComparator = valueComparator;
+
+ this.keySerializer = keySerializer;
+ this.valueSerializer = valueSerializer;
+
+ this.allowsDuplicates = true;
long recId = recMan.getNamedObject( name );
@@ -147,7 +144,12 @@
}
else
{
- bt = BTree.createInstance( recMan, comparator.getKeyComparator(), keySerializer, valueSerializer );
+ // we do not use the value serializer in the btree since duplicates will use
+ // either BTreeRedirect objects or AvlTree objects whose marshalling is
+ // explicitly managed by this code. Value serialization is delegated to these
+ // marshallers.
+
+ bt = BTree.createInstance( recMan, keyComparator, keySerializer, null );
recId = bt.getRecid();
recMan.setNamedObject( name, recId );
recId = recMan.insert( 0 );
@@ -174,8 +176,35 @@
Serializer keySerializer, Serializer valueSerializer )
throws IOException
{
- this( name, false, Integer.MAX_VALUE, manager, new KeyOnlyComparator<K,V>( keyComparator ),
- keySerializer, valueSerializer );
+ this.duplicateBtrees = null;
+ this.numDupLimit = Integer.MAX_VALUE;
+ this.name = name;
+ this.recMan = manager;
+
+ this.keyComparator = keyComparator;
+ this.valueComparator = null;
+
+ this.keySerializer = keySerializer;
+ this.valueSerializer = valueSerializer;
+
+ this.allowsDuplicates = false;
+
+ long recId = recMan.getNamedObject( name );
+
+ if ( recId != 0 )
+ {
+ bt = BTree.load( recMan, recId );
+ recId = recMan.getNamedObject( name + SZSUFFIX );
+ count = ( Integer ) recMan.fetch( recId );
+ }
+ else
+ {
+ bt = BTree.createInstance( recMan, keyComparator, keySerializer, valueSerializer );
+ recId = bt.getRecid();
+ recMan.setNamedObject( name, recId );
+ recId = recMan.insert( 0 );
+ recMan.setNamedObject( name + SZSUFFIX, recId );
+ }
}
@@ -185,11 +214,32 @@
/**
- * @see org.apache.directory.server.core.partition.impl.btree.Table#getComparator()
+ * @see Table#getKeyComparator()
*/
- public TupleComparator<K,V> getComparator()
+ public Comparator<K> getKeyComparator()
{
- return comparator;
+ return keyComparator;
+ }
+
+
+ /**
+ * @see Table#getValueComparator()
+ */
+ public Comparator<V> getValueComparator()
+ {
+ return valueComparator;
+ }
+
+
+ public Serializer getKeySerializer()
+ {
+ return keySerializer;
+ }
+
+
+ public Serializer getValueSerializer()
+ {
+ return valueSerializer;
}
@@ -333,6 +383,17 @@
{
//noinspection unchecked
AvlTree<V> set = values.getAvlTree();
+
+ if ( set == null )
+ {
+ return null;
+ }
+
+ if ( set.getFirst() == null )
+ {
+ return null;
+ }
+
return set.getFirst().getKey();
}
@@ -442,7 +503,7 @@
// Test for equality first since it satisfies both greater/less than
//noinspection unchecked
- if ( null != tuple && comparator.compareKey( ( K ) tuple.getKey(), key ) == 0 )
+ if ( null != tuple && keyComparator.compare( ( K ) tuple.getKey(), key ) == 0 )
{
return true;
}
@@ -478,7 +539,7 @@
if ( browser.getNext( tuple ) )
{
//noinspection unchecked
- return comparator.compareKey( ( K ) tuple.getKey(), key ) <= 0;
+ return keyComparator.compare( ( K ) tuple.getKey(), key ) <= 0;
}
}
else
@@ -492,7 +553,7 @@
// key so we need to step forward once then back. Remember this
// key represents a key greater than or equal to key.
//noinspection unchecked
- if ( comparator.compareKey( ( K ) tuple.getKey(), key ) <= 0 )
+ if ( keyComparator.compare( ( K ) tuple.getKey(), key ) <= 0 )
{
return true;
}
@@ -505,7 +566,7 @@
while ( browser.getPrevious( tuple ) )
{
//noinspection unchecked
- if ( comparator.compareKey( ( K ) tuple.getKey(), key ) <= 0 )
+ if ( keyComparator.compare( ( K ) tuple.getKey(), key ) <= 0 )
{
return true;
}
@@ -582,11 +643,6 @@
DupsContainer values = getDups( key );
- if ( values == null )
- {
- values = new DupsContainer( new AvlTree<V>( comparator.getValueComparator() ) );
- }
-
if ( values.isAvlTree() )
{
AvlTree<V> set = values.getAvlTree();
@@ -777,10 +833,11 @@
}
- public Marshaller getMarshaller()
+ public Marshaller<AvlTree<V>> getMarshaller()
{
return marshaller;
}
+
// ------------------------------------------------------------------------
// Private Utility Methods
@@ -816,14 +873,17 @@
{
byte[] serialized = ( byte[] ) bt.find( key );
- if ( BTreeRedirectMarshaller.isNotRedirect( serialized ) )
+ if ( serialized == null )
{
- return new DupsContainer<V>( marshaller.deserialize( serialized ) );
+ return new DupsContainer<V>( new AvlTree<V>( valueComparator ) );
}
- else
+
+ if ( BTreeRedirectMarshaller.isNotRedirect( serialized ) )
{
- return new DupsContainer<V>( BTreeRedirectMarshaller.INSTANCE.deserialize( serialized ) );
+ return new DupsContainer<V>( marshaller.deserialize( serialized ) );
}
+
+ return new DupsContainer<V>( BTreeRedirectMarshaller.INSTANCE.deserialize( serialized ) );
}
throw new IllegalStateException(
@@ -907,7 +967,7 @@
//noinspection unchecked
V biggerKey = ( V ) tuple.getKey();
- if ( comparator.compareValue( key, biggerKey ) == 0 )
+ if ( valueComparator.compare( key, biggerKey ) == 0 )
{
return true;
}
@@ -932,7 +992,7 @@
*/
//noinspection unchecked
- if ( comparator.compareValue( key, ( V ) tuple.getKey() ) == 0 )
+ if ( valueComparator.compare( key, ( V ) tuple.getKey() ) == 0 )
{
return true;
}
@@ -962,7 +1022,17 @@
private BTree convertToBTree( AvlTree<V> set ) throws IOException
{
- BTree tree = BTree.createInstance( recMan, comparator.getValueComparator() );
+ BTree tree;
+
+ if ( valueSerializer != null )
+ {
+ tree = BTree.createInstance( recMan, valueComparator, valueSerializer, valueSerializer );
+ }
+ else
+ {
+ tree = BTree.createInstance( recMan, valueComparator );
+ }
+
List<V> keys = set.getKeys();
for ( V element : keys )
{
Added: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/LongSerializer.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/LongSerializer.java?rev=636595&view=auto
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/LongSerializer.java (added)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/LongSerializer.java Wed Mar 12 18:08:33 2008
@@ -0,0 +1,77 @@
+/*
+ * 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.server.core.partition.impl.btree.jdbm;
+
+
+import jdbm.helper.Serializer;
+
+import java.io.IOException;
+
+
+/**
+ * A serializer for Longs
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$
+ */
+public class LongSerializer implements Serializer
+{
+ public static final LongSerializer INSTANCE = new LongSerializer();
+
+
+ public byte[] serialize( Object o ) throws IOException
+ {
+ long id = ( Long ) o;
+ byte[] bites = new byte[8];
+
+ bites[0] = ( byte ) ( id >> 56 );
+ bites[1] = ( byte ) ( id >> 48 );
+ bites[2] = ( byte ) ( id >> 40 );
+ bites[3] = ( byte ) ( id >> 32 );
+ bites[4] = ( byte ) ( id >> 24 );
+ bites[5] = ( byte ) ( id >> 16 );
+ bites[6] = ( byte ) ( id >> 8 );
+ bites[7] = ( byte ) id;
+
+ return bites;
+ }
+
+
+ public Object deserialize( byte[] bites ) throws IOException
+ {
+ long id;
+ id = bites[0] + ( ( bites[0] < 0 ) ? 256 : 0 );
+ id <<= 8;
+ id += bites[1] + ( ( bites[1] < 0 ) ? 256 : 0 );
+ id <<= 8;
+ id += bites[2] + ( ( bites[2] < 0 ) ? 256 : 0 );
+ id <<= 8;
+ id += bites[3] + ( ( bites[3] < 0 ) ? 256 : 0 );
+ id <<= 8;
+ id += bites[4] + ( ( bites[4] < 0 ) ? 256 : 0 );
+ id <<= 8;
+ id += bites[5] + ( ( bites[5] < 0 ) ? 256 : 0 );
+ id <<= 8;
+ id += bites[6] + ( ( bites[6] < 0 ) ? 256 : 0 );
+ id <<= 8;
+ id += bites[7] + ( ( bites[7] < 0 ) ? 256 : 0 );
+ return id;
+ }
+}
Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java?rev=636595&r1=636594&r2=636595&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmDupsCursorTest.java Wed Mar 12 18:08:33 2008
@@ -21,10 +21,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.apache.directory.server.core.partition.impl.btree.DefaultTupleComparator;
import org.apache.directory.server.core.partition.impl.btree.Table;
import org.apache.directory.server.core.partition.impl.btree.Tuple;
-import org.apache.directory.server.core.partition.impl.btree.TupleComparator;
import org.apache.directory.server.core.cursor.Cursor;
import org.apache.directory.server.schema.SerializableComparator;
import org.apache.directory.server.schema.registries.ComparatorRegistry;
@@ -79,11 +77,10 @@
// gosh this is a terrible use of a global static variable
SerializableComparator.setRegistry( new MockComparatorRegistry() );
- TupleComparator<Integer,Integer> comparator =
- new DefaultTupleComparator<Integer,Integer>(
- new SerializableComparator<Integer>( "" ),
- new SerializableComparator<Integer>( "" ) );
- table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator, null, new IntegerSerializer() );
+ table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
+ new SerializableComparator<Integer>( "" ),
+ new SerializableComparator<Integer>( "" ),
+ null, new IntegerSerializer() );
LOG.debug( "Created new table and populated it with data" );
}
Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java?rev=636595&r1=636594&r2=636595&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableNoDuplicatesTest.java Wed Mar 12 18:08:33 2008
@@ -118,7 +118,7 @@
table.setRenderer( null );
assertNull( table.getRenderer() );
assertEquals( "test", table.getName() );
- assertNotNull( table.getComparator() );
+ assertNotNull( table.getKeyComparator() );
}
Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java?rev=636595&r1=636594&r2=636595&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmTableWithDuplicatesTest.java Wed Mar 12 18:08:33 2008
@@ -27,8 +27,6 @@
import static org.junit.Assert.*;
import org.apache.directory.server.core.partition.impl.btree.Table;
-import org.apache.directory.server.core.partition.impl.btree.TupleComparator;
-import org.apache.directory.server.core.partition.impl.btree.DefaultTupleComparator;
import org.apache.directory.server.core.partition.impl.btree.TupleRenderer;
import org.apache.directory.server.schema.SerializableComparator;
import org.apache.directory.server.schema.registries.ComparatorRegistry;
@@ -77,11 +75,10 @@
// gosh this is a terrible use of a global static variable
SerializableComparator.setRegistry( new MockComparatorRegistry() );
- TupleComparator<Integer,Integer> comparator =
- new DefaultTupleComparator<Integer,Integer>(
- new SerializableComparator<Integer>( "" ),
- new SerializableComparator<Integer>( "" ) );
- table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator, null, new IntegerSerializer() );
+ table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
+ new SerializableComparator<Integer>( "" ),
+ new SerializableComparator<Integer>( "" ),
+ null, new IntegerSerializer() );
LOG.debug( "Created new table and populated it with data" );
}
@@ -103,11 +100,10 @@
{
table.put( 1, 2 );
table.close();
- TupleComparator<Integer,Integer> comparator =
- new DefaultTupleComparator<Integer,Integer>(
- new SerializableComparator<Integer>( "" ),
- new SerializableComparator<Integer>( "" ) );
- table = new JdbmTable<Integer,Integer>( "test", true, SIZE, recman, comparator, null, new IntegerSerializer() );
+ table = new JdbmTable<Integer,Integer>( "test", SIZE, recman,
+ new SerializableComparator<Integer>( "" ),
+ new SerializableComparator<Integer>( "" ),
+ null, new IntegerSerializer() );
assertTrue( 2 == table.get( 1 ) );
}
@@ -131,7 +127,7 @@
table.setRenderer( null );
assertNull( table.getRenderer() );
assertEquals( "test", table.getName() );
- assertNotNull( table.getComparator() );
+ assertNotNull( table.getKeyComparator() );
}