You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2010/04/29 23:21:16 UTC
svn commit: r939483 - in /directory/apacheds/trunk:
avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/
avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/
jdbm-store/src/main/java/org/apache/directory/se...
Author: seelmann
Date: Thu Apr 29 21:21:14 2010
New Revision: 939483
URL: http://svn.apache.org/viewvc?rev=939483&view=rev
Log:
o added ParentIdAndRdn class and use it for the RDN index
o removed parentId from RDN class
o removed unused getParentId(String) method from Store interface
o removed unused getParentId(Sting|ID) method from BTreePartition
Added:
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdnComparator.java
Removed:
directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/InternalRdnComparator.java
Modified:
directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java
directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java
directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java
directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java
directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java
Modified: directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java (original)
+++ directory/apacheds/trunk/avl-partition/src/main/java/org/apache/directory/server/core/partition/avl/AvlStore.java Thu Apr 29 21:21:14 2010
@@ -333,16 +333,6 @@ public class AvlStore<E> extends Abstrac
/**
* {@inheritDoc}
*/
- public Long getParentId( String dn ) throws Exception
- {
- Long childId = ndnIdx.forwardLookup( dn );
- return oneLevelIdx.reverseLookup( childId );
- }
-
-
- /**
- * {@inheritDoc}
- */
public Long getParentId( Long childId ) throws Exception
{
return oneLevelIdx.reverseLookup( childId );
Modified: directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java (original)
+++ directory/apacheds/trunk/avl-partition/src/test/java/org/apache/directory/server/core/partition/avl/AvlStoreTest.java Thu Apr 29 21:21:14 2010
@@ -393,7 +393,7 @@ public class AvlStoreTest
assertEquals( dn.getName(), store.getEntryUpdn( 1L ) );
// note that the suffix entry returns 0 for it's parent which does not exist
- assertEquals( 0L, ( long ) store.getParentId( dn.getNormName() ) );
+ assertEquals( 0L, ( long ) store.getParentId( store.getEntryId( dn ) ) );
assertNull( store.getParentId( 0L ) );
// should NOW be allowed
Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndex.java Thu Apr 29 21:21:14 2010
@@ -32,10 +32,11 @@ import jdbm.recman.CacheRecordManager;
import org.apache.directory.server.core.partition.impl.btree.LongComparator;
import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
+import org.apache.directory.server.xdbm.ParentIdAndRdnComparator;
import org.apache.directory.shared.ldap.schema.AttributeType;
import org.apache.directory.shared.ldap.schema.MatchingRule;
import org.apache.directory.shared.ldap.schema.SchemaManager;
-import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
import org.apache.directory.shared.ldap.util.SynchronizedLRUMap;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -47,11 +48,11 @@ import org.slf4j.LoggerFactory;
* @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
* @version $Rev$, $Date$
*/
-public class JdbmRdnIndex<K, O> extends JdbmIndex<K, O>
+public class JdbmRdnIndex extends JdbmIndex<ParentIdAndRdn<Long>, Long>
{
/** A logger for this class */
- private static final Logger LOG = LoggerFactory.getLogger( JdbmRdnIndex.class.getSimpleName() );
+ private static final Logger LOG = LoggerFactory.getLogger( JdbmRdnIndex.class );
public JdbmRdnIndex()
@@ -120,18 +121,18 @@ public class JdbmRdnIndex<K, O> extends
throw new IOException( I18n.err( I18n.ERR_574, attribute.getName() ) );
}
- SerializableComparator comp = new InternalRdnComparator( mr.getOid() );
+ ParentIdAndRdnComparator<Long> comp = new ParentIdAndRdnComparator<Long>( mr.getOid() );
LongComparator.INSTANCE.setSchemaManager( schemaManager );
- forward = new JdbmTable<K, Long>( schemaManager, attribute.getName() + FORWARD_BTREE, recMan, comp, null,
- LongSerializer.INSTANCE );
- reverse = new JdbmTable<Long, K>( schemaManager, attribute.getName() + REVERSE_BTREE, recMan,
- LongComparator.INSTANCE, LongSerializer.INSTANCE, null );
+ forward = new JdbmTable<ParentIdAndRdn<Long>, Long>( schemaManager, attribute.getName() + FORWARD_BTREE,
+ recMan, comp, null, LongSerializer.INSTANCE );
+ reverse = new JdbmTable<Long, ParentIdAndRdn<Long>>( schemaManager, attribute.getName() + REVERSE_BTREE,
+ recMan, LongComparator.INSTANCE, LongSerializer.INSTANCE, null );
}
- public void add( K rdn, Long entryId ) throws Exception
+ public void add( ParentIdAndRdn<Long> rdn, Long entryId ) throws Exception
{
forward.put( rdn, entryId );
reverse.put( entryId, rdn );
@@ -140,13 +141,13 @@ public class JdbmRdnIndex<K, O> extends
public void drop( Long entryId ) throws Exception
{
- K rdn = reverse.get( entryId );
+ ParentIdAndRdn<Long> rdn = reverse.get( entryId );
forward.remove( rdn );
reverse.remove( entryId );
}
- public void drop( K rdn, Long id ) throws Exception
+ public void drop( ParentIdAndRdn<Long> rdn, Long id ) throws Exception
{
long val = forward.get( rdn );
if ( val == id )
@@ -157,7 +158,7 @@ public class JdbmRdnIndex<K, O> extends
}
- public K getNormalized( K rdn ) throws Exception
+ public ParentIdAndRdn<Long> getNormalized( ParentIdAndRdn<Long> rdn ) throws Exception
{
return rdn;
}
Modified: directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java Thu Apr 29 21:21:14 2010
@@ -36,6 +36,7 @@ import org.apache.directory.server.xdbm.
import org.apache.directory.server.xdbm.Index;
import org.apache.directory.server.xdbm.IndexCursor;
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
import org.apache.directory.shared.ldap.MultiException;
import org.apache.directory.shared.ldap.constants.SchemaConstants;
import org.apache.directory.shared.ldap.cursor.Cursor;
@@ -72,7 +73,7 @@ public class JdbmStore<E> extends Abstra
private JdbmMasterTable<Entry> master;
/** the relative distinguished name index */
- private JdbmRdnIndex<RDN, Long> rdnIdx;
+ private JdbmRdnIndex rdnIdx;
/** Static declarations to avoid lookup all over the code */
private static AttributeType OBJECT_CLASS_AT;
@@ -158,7 +159,7 @@ public class JdbmStore<E> extends Abstra
{
if ( rdnIdx == null )
{
- rdnIdx = new JdbmRdnIndex<RDN, Long>();
+ rdnIdx = new JdbmRdnIndex();
rdnIdx.setAttributeId( ApacheSchemaConstants.APACHE_RDN_AT_OID );
systemIndices.put( ApacheSchemaConstants.APACHE_RDN_AT_OID, ( JdbmIndex ) rdnIdx );
}
@@ -321,15 +322,13 @@ public class JdbmStore<E> extends Abstra
int dnSize = dn.size();
int i = suffixDn.size();
- RDN key = new RDN( suffixDn.getNormName() );
- key._setParentId( 0 );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, suffixDn.getRdn() );
Long curEntryId = rdnIdx.forwardLookup( key );
for ( ; i < dnSize; i++ )
{
- key = dn.getRdn( i );
- key._setParentId( curEntryId );
+ key = new ParentIdAndRdn<Long>( curEntryId, dn.getRdn( i ) );
curEntryId = rdnIdx.forwardLookup( key );
if ( curEntryId == null )
{
@@ -366,14 +365,14 @@ public class JdbmStore<E> extends Abstra
do
{
- RDN curRdn = rdnIdx.reverseLookup( parentId );
- parentId = curRdn._getParentId();
-
+ ParentIdAndRdn<Long> cur = rdnIdx.reverseLookup( parentId );
+ RDN curRdn = cur.getRdn();
+ parentId = cur.getParentId();
if ( parentId == 0 )
{
// we reached the suffix, add the context entry DN
// we do this because the suffix can consist
- // of multiple RDNs, e.g. ec=example,dc=com
+ // of multiple RDNs, e.g. dc=example,dc=com
if ( contextEntryDn == null )
{
contextEntryDn = new DN( curRdn.getName() );
@@ -409,21 +408,20 @@ public class JdbmStore<E> extends Abstra
*/
private DN buildEntryDn( String dn ) throws Exception
{
+ // TODO: what is this for???
DN normDN = new DN( dn );
normDN.normalize( schemaManager.getNormalizerMapping() );
int dnSize = normDN.size();
int i = suffixDn.size();
- RDN key = new RDN( suffixDn.getNormName() );
- key._setParentId( 0 );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>(0L, suffixDn.getRdn());
Long curEntryId = rdnIdx.forwardLookup( key );
for ( ; i < dnSize; i++ )
{
- key = normDN.getRdn( i );
- key._setParentId( curEntryId );
+ key = new ParentIdAndRdn<Long>(curEntryId, normDN.getRdn( i ));
curEntryId = rdnIdx.forwardLookup( key );
}
@@ -431,41 +429,15 @@ public class JdbmStore<E> extends Abstra
}
- /**
- * Gets the Long id of an entry's parent using the child entry's
- * normalized DN. Note that the suffix entry returns 0, which does not
- * map to any entry.
- *
- * @param dn the normalized distinguished name of the child
- * @return the id of the parent entry or zero if the suffix entry the
- * normalized suffix DN string is used
- * @throws Exception on failures to access the underlying store
- */
- public Long getParentId( String dn ) throws Exception
- {
- DN normDN = new DN( dn );
- normDN.normalize( schemaManager.getNormalizerMapping() );
-
- if ( suffixDn.equals( normDN ) )
- {
- return 0L;
- }
-
- normDN = buildEntryDn( dn );
- return normDN.getRdn()._getParentId();
- }
-
-
public Long getParentId( Long childId ) throws Exception
{
- //return oneLevelIdx.reverseLookup( childId );
- RDN rdn = rdnIdx.reverseLookup( childId );
- if ( rdn == null )
+ ParentIdAndRdn<Long> key = rdnIdx.reverseLookup( childId );
+ if ( key == null )
{
return null;
}
- return rdn._getParentId();
+ return key.getParentId();
}
@@ -599,7 +571,9 @@ public class JdbmStore<E> extends Abstra
}
// L O O K U P T A R G E T I D
- targetId = rdnIdx.forwardLookup( normalizedAliasTargetDn.getRdn() );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( getParentId( getEntryId( normalizedAliasTargetDn ) ),
+ normalizedAliasTargetDn.getRdn() );
+ targetId = rdnIdx.forwardLookup( key );
/*
* Check For Target Existence
@@ -725,8 +699,8 @@ public class JdbmStore<E> extends Abstra
throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_216, parentDn ) );
}
- rdn._setParentId( parentId );
- rdnIdx.add( rdn, id );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( parentId, rdn );
+ rdnIdx.add( key, id );
EntryAttribute objectClass = entry.get( OBJECT_CLASS_AT );
@@ -1385,10 +1359,6 @@ public class JdbmStore<E> extends Abstra
// gotta normalize cuz this thang is cloned and not normalized by default
newUpdn.normalize( schemaManager.getNormalizerMapping() );
- // restore the parentId from the old RDN
- newRdn = newUpdn.getRdn();
- newRdn._setParentId( updn.getRdn()._getParentId() );
-
modifyDn( id, newUpdn, false ); // propagate dn changes
// Update the current entry
@@ -1432,7 +1402,9 @@ public class JdbmStore<E> extends Abstra
updn.getRdn().normalize( schemaManager.getNormalizerMapping() );
}
- rdnIdx.add( updn.getRdn(), id );
+ Long parentId = getEntryId( updn.getParent() );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( parentId, updn.getRdn() );
+ rdnIdx.add( key, id );
/*
* Read Alias Index Tuples
@@ -1538,7 +1510,6 @@ public class JdbmStore<E> extends Abstra
DN childUpdn = buildEntryDn( childId );
RDN childRdn = childUpdn.getRdn( childUpdn.size() - 1 );
- childRdn._setParentId( newParentId );
DN newUpdn = buildEntryDn( newParentId );
newUpdn.add( childRdn );
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmRdnIndexTest.java Thu Apr 29 21:21:14 2010
@@ -33,6 +33,7 @@ import org.apache.commons.io.FileUtils;
import org.apache.directory.server.constants.ApacheSchemaConstants;
import org.apache.directory.server.xdbm.Index;
import org.apache.directory.server.xdbm.IndexEntry;
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
import org.apache.directory.shared.ldap.cursor.Cursor;
import org.apache.directory.shared.ldap.name.DN;
import org.apache.directory.shared.ldap.name.RDN;
@@ -57,7 +58,7 @@ import org.junit.Test;
public class JdbmRdnIndexTest
{
private static File dbFileDir;
- Index<RDN, Long, Long> idx;
+ Index<ParentIdAndRdn<Long>, Long, Long> idx;
private static SchemaManager schemaManager;
@@ -134,15 +135,15 @@ public class JdbmRdnIndexTest
void initIndex() throws Exception
{
- initIndex( new JdbmRdnIndex<RDN, Long>() );
+ initIndex( new JdbmRdnIndex() );
}
- void initIndex( JdbmRdnIndex<RDN, Long> jdbmIdx ) throws Exception
+ void initIndex( JdbmRdnIndex jdbmIdx ) throws Exception
{
if ( jdbmIdx == null )
{
- jdbmIdx = new JdbmRdnIndex<RDN, Long>();
+ jdbmIdx = new JdbmRdnIndex();
}
jdbmIdx.init( schemaManager, schemaManager.lookupAttributeTypeRegistry( ApacheSchemaConstants.APACHE_RDN_AT_OID ), dbFileDir );
@@ -184,9 +185,9 @@ public class JdbmRdnIndexTest
public void testWkDirPath() throws Exception
{
// uninitialized index
- JdbmRdnIndex<RDN, Long> JdbmRdnIndex = new JdbmRdnIndex<RDN, Long>();
- JdbmRdnIndex.setWkDirPath( new File( dbFileDir, "foo" ) );
- assertEquals( "foo", JdbmRdnIndex.getWkDirPath().getName() );
+ JdbmRdnIndex jdbmRdnIndex = new JdbmRdnIndex();
+ jdbmRdnIndex.setWkDirPath( new File( dbFileDir, "foo" ) );
+ assertEquals( "foo", jdbmRdnIndex.getWkDirPath().getName() );
// initialized index
initIndex();
@@ -201,11 +202,11 @@ public class JdbmRdnIndexTest
assertEquals( dbFileDir, idx.getWkDirPath() );
destroyIndex();
- JdbmRdnIndex = new JdbmRdnIndex<RDN, Long>();
+ jdbmRdnIndex = new JdbmRdnIndex();
File wkdir = new File( dbFileDir, "foo" );
wkdir.mkdirs();
- JdbmRdnIndex.setWkDirPath( wkdir );
- initIndex( JdbmRdnIndex );
+ jdbmRdnIndex.setWkDirPath( wkdir );
+ initIndex( jdbmRdnIndex );
assertEquals( wkdir, idx.getWkDirPath() );
}
@@ -239,15 +240,13 @@ public class JdbmRdnIndexTest
initIndex();
assertEquals( 0, idx.count() );
- RDN key = new RDN( "cn=key" );
- key._setParentId( 0 );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
idx.add( key, 0l );
assertEquals( 1, idx.count() );
// setting a different parentId should make this key a different key
- key = new RDN( "cn=key" );
- key._setParentId( 1 );
+ key = new ParentIdAndRdn<Long>( 1L, new RDN( "cn=key" ) );
idx.add( key, 1l );
assertEquals( 2, idx.count() );
@@ -256,8 +255,7 @@ public class JdbmRdnIndexTest
idx.add( key, 2l );
assertEquals( 2, idx.count() );
- key = new RDN( "cn=key" );
- key._setParentId( 2 );
+ key = new ParentIdAndRdn<Long>( 2L, new RDN( "cn=key" ) );
idx.add( key, 3l );
assertEquals( 3, idx.count() );
}
@@ -268,7 +266,7 @@ public class JdbmRdnIndexTest
{
initIndex();
- RDN key = new RDN( "cn=key" );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
assertEquals( 0, idx.count( key ) );
@@ -286,7 +284,7 @@ public class JdbmRdnIndexTest
{
initIndex();
- RDN key = new RDN( "cn=key" );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
assertNull( idx.forwardLookup( key ) );
@@ -301,7 +299,7 @@ public class JdbmRdnIndexTest
{
initIndex();
- RDN key = new RDN( "cn=key" );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
assertNull( idx.forwardLookup( key ) );
@@ -324,17 +322,16 @@ public class JdbmRdnIndexTest
{
initIndex();
- RDN key = new RDN( "cn=key" );
+ ParentIdAndRdn<Long> key = new ParentIdAndRdn<Long>( 0L, new RDN( "cn=key" ) );
assertEquals( 0, idx.count() );
idx.add( key, 0l );
assertEquals( 1, idx.count() );
- for( int i=1; i< 5; i++ )
+ for( long i=1; i< 5; i++ )
{
- key = new RDN( "cn=key" + i );
- key._setParentId( i );
+ key = new ParentIdAndRdn<Long>( i, new RDN( "cn=key" + i ) );
idx.add( key, ( long ) i );
}
@@ -342,44 +339,44 @@ public class JdbmRdnIndexTest
assertEquals( 5, idx.count() );
// use forward index's cursor
- Cursor<IndexEntry<RDN, Long, Long>> cursor = idx.forwardCursor();
+ Cursor<IndexEntry<ParentIdAndRdn<Long>, Long, Long>> cursor = idx.forwardCursor();
cursor.beforeFirst();
cursor.next();
- IndexEntry<RDN, Long, Long> e1 = cursor.get();
+ IndexEntry<ParentIdAndRdn<Long>, Long, Long> e1 = cursor.get();
assertEquals( 0, ( long ) e1.getId() );
- assertEquals( "cn=key", e1.getValue().getName() );
- assertEquals( -1, e1.getValue()._getParentId() );
+ assertEquals( "cn=key", e1.getValue().getRdn().getName() );
+ assertEquals( 0, e1.getValue().getParentId().longValue() );
cursor.next();
- IndexEntry<RDN, Long, Long> e2 = cursor.get();
+ IndexEntry<ParentIdAndRdn<Long>, Long, Long> e2 = cursor.get();
assertEquals( 1, ( long ) e2.getId() );
- assertEquals( "cn=key1", e2.getValue().getName() );
- assertEquals( 1, e2.getValue()._getParentId() );
+ assertEquals( "cn=key1", e2.getValue().getRdn().getName() );
+ assertEquals( 1, e2.getValue().getParentId().longValue() );
cursor.next();
- IndexEntry<RDN, Long, Long> e3 = cursor.get();
+ IndexEntry<ParentIdAndRdn<Long>, Long, Long> e3 = cursor.get();
assertEquals( 2, ( long ) e3.getId() );
- assertEquals( "cn=key2", e3.getValue().getName() );
- assertEquals( 2, e3.getValue()._getParentId() );
+ assertEquals( "cn=key2", e3.getValue().getRdn().getName() );
+ assertEquals( 2, e3.getValue().getParentId().longValue() );
}
- @Test
- public void testStoreRdnWithTwoATAVs() throws Exception
- {
- initIndex();
-
- DN dn = new DN( "dc=example,dc=com" );
- dn.normalize( schemaManager.getNormalizerMapping() );
-
- RDN rdn = new RDN( dn.getName() );
- rdn._setParentId( 1 );
- idx.add( rdn, 0l );
-
- RDN rdn2 = idx.reverseLookup( 0l );
- System.out.println( rdn2 );
- InternalRdnComparator rdnCom = new InternalRdnComparator( "" );
- assertEquals( 0, rdnCom.compare( rdn, rdn2 ) );
- }
+// @Test
+// public void testStoreRdnWithTwoATAVs() throws Exception
+// {
+// initIndex();
+//
+// DN dn = new DN( "dc=example,dc=com" );
+// dn.normalize( schemaManager.getNormalizerMapping() );
+//
+// RDN rdn = new RDN( dn.getName() );
+// rdn._setParentId( 1 );
+// idx.add( rdn, 0l );
+//
+// RDN rdn2 = idx.reverseLookup( 0l );
+// System.out.println( rdn2 );
+// InternalRdnComparator rdnCom = new InternalRdnComparator( "" );
+// assertEquals( 0, rdnCom.compare( rdn, rdn2 ) );
+// }
}
Modified: directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java (original)
+++ directory/apacheds/trunk/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java Thu Apr 29 21:21:14 2010
@@ -461,7 +461,7 @@ public class JdbmStoreTest
assertEquals( dn.getName(), store.getEntryUpdn( 1L ) );
// note that the suffix entry returns 0 for it's parent which does not exist
- assertEquals( 0L, ( long ) store.getParentId( dn.getNormName() ) );
+ assertEquals( 0L, ( long ) store.getParentId( store.getEntryId( dn ) ) );
assertNull( store.getParentId( 0L ) );
// should NOW be allowed
Modified: directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java (original)
+++ directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java Thu Apr 29 21:21:14 2010
@@ -841,20 +841,6 @@ public class LdifPartition extends BTree
@Override
- public Long getParentId( Long childId ) throws Exception
- {
- return wrappedPartition.getParentId( childId );
- }
-
-
- @Override
- public Long getParentId( String dn ) throws Exception
- {
- return wrappedPartition.getParentId( dn );
- }
-
-
- @Override
public Index<String, Entry, Long> getPresenceIndex()
{
return wrappedPartition.getPresenceIndex();
Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java (original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/core/partition/impl/btree/BTreePartition.java Thu Apr 29 21:21:14 2010
@@ -431,12 +431,6 @@ public abstract class BTreePartition<ID>
public abstract String getEntryDn( ID id ) throws Exception;
- public abstract ID getParentId( String dn ) throws Exception;
-
-
- public abstract ID getParentId( ID childId ) throws Exception;
-
-
/**
* Gets the user provided distinguished name.
*
Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java (original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/AbstractXdbmPartition.java Thu Apr 29 21:21:14 2010
@@ -205,18 +205,6 @@ public abstract class AbstractXdbmPartit
}
- public final ID getParentId( String dn ) throws Exception
- {
- return store.getParentId( dn );
- }
-
-
- public final ID getParentId( ID childId ) throws Exception
- {
- return store.getParentId( childId );
- }
-
-
public final String getEntryUpdn( ID id ) throws Exception
{
return store.getEntryUpdn( id );
Added: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java?rev=939483&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdn.java Thu Apr 29 21:21:14 2010
@@ -0,0 +1,158 @@
+/*
+ * 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.xdbm;
+
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+import org.apache.directory.shared.ldap.name.RDN;
+
+
+/**
+ * A wrapper for the tuple of parentId and RDN, used for the RDN index.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev: 917312 $
+ */
+public class ParentIdAndRdn<ID extends Comparable<ID>> implements Externalizable, Comparable<ParentIdAndRdn<ID>>
+{
+
+ protected ID parentId;
+ protected RDN rdn;
+
+
+ /**
+ * Serializable constructor.
+ */
+ public ParentIdAndRdn()
+ {
+ }
+
+
+ /**
+ * Creates a new instance of ParentIdAndRdn.
+ *
+ * @param parentId the parent ID
+ * @param rdn the RDN
+ */
+ public ParentIdAndRdn( ID parentId, RDN rdn )
+ {
+ this.parentId = parentId;
+ this.rdn = rdn;
+ }
+
+
+ /**
+ * Gets the parent ID.
+ *
+ * @return the parent ID
+ */
+ public ID getParentId()
+ {
+ return parentId;
+ }
+
+
+ /**
+ * Sets the parent ID.
+ *
+ * @param parentId the new parent ID
+ */
+ public void setParentId( ID parentId )
+ {
+ this.parentId = parentId;
+ }
+
+
+ /**
+ * Gets the RDN.
+ *
+ * @return the RDN
+ */
+ public RDN getRdn()
+ {
+ return rdn;
+ }
+
+
+ /**
+ * Sets the RDN.
+ *
+ * @param rdn the new RDN
+ */
+ public void setRdn( RDN rdn )
+ {
+ this.rdn = rdn;
+ }
+
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ( ( parentId == null ) ? 0 : parentId.hashCode() );
+ result = prime * result + ( ( rdn == null ) ? 0 : rdn.hashCode() );
+ return result;
+ }
+
+
+ @Override
+ @SuppressWarnings("unchecked")
+ public boolean equals( Object obj )
+ {
+ if ( !( obj instanceof ParentIdAndRdn<?> ) )
+ {
+ return false;
+ }
+
+ return compareTo( ( ParentIdAndRdn<ID> ) obj ) == 0;
+ }
+
+
+ public int compareTo( ParentIdAndRdn<ID> o )
+ {
+ int val = this.getRdn().compareTo( o.getRdn() );
+ if ( val == 0 )
+ {
+ val = this.getParentId().compareTo( o.getParentId() );
+ }
+
+ return val;
+ }
+
+
+ public void writeExternal( ObjectOutput out ) throws IOException
+ {
+ out.writeObject( parentId );
+ out.writeObject( rdn );
+ }
+
+
+ @SuppressWarnings("unchecked")
+ public void readExternal( ObjectInput in ) throws IOException, ClassNotFoundException
+ {
+ parentId = ( ID ) in.readObject();
+ rdn = ( RDN ) in.readObject();
+ }
+}
Added: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdnComparator.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdnComparator.java?rev=939483&view=auto
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdnComparator.java (added)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/ParentIdAndRdnComparator.java Thu Apr 29 21:21:14 2010
@@ -0,0 +1,60 @@
+/*
+ * 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.xdbm;
+
+
+import org.apache.directory.server.xdbm.ParentIdAndRdn;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.comparators.SerializableComparator;
+
+
+/**
+ * A comparator used to compare {@link ParentIdAndRdn} stored in the RDN index.
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class ParentIdAndRdnComparator<ID extends Comparable<ID>> extends SerializableComparator<ParentIdAndRdn<ID>>
+{
+
+ private static final long serialVersionUID = 5414960421568991202L;
+
+
+ public ParentIdAndRdnComparator( String matchingRuleOid )
+ {
+ super( matchingRuleOid );
+ }
+
+
+ @Override
+ public int compare( ParentIdAndRdn<ID> rdn1, ParentIdAndRdn<ID> rdn2 )
+ {
+ return rdn1.compareTo( rdn2 );
+ }
+
+
+ @Override
+ public void setSchemaManager( SchemaManager schemaManager )
+ {
+ // no need to deal with the schema manager
+ }
+
+}
\ No newline at end of file
Modified: directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java?rev=939483&r1=939482&r2=939483&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java (original)
+++ directory/apacheds/trunk/xdbm-base/src/main/java/org/apache/directory/server/xdbm/Store.java Thu Apr 29 21:21:14 2010
@@ -386,18 +386,13 @@ public interface Store<E, ID>
/**
- * Gets the Long id of an entry's parent using the child entry's
- * normalized dn. Note that the suffix entry returns 0, which does not
- * map to any entry.
- *
- * @param dn the normalized distinguished name of the child
- * @return the id of the parent entry or zero if the suffix entry the
- * normalized suffix dn string is used
+ * Gets the ID of an entry's parent using the child entry's ID.
+ * Note that the suffix entry returns 0, which does not map to any entry.
+ *
+ * @param childId the ID of the entry
+ * @return the id of the parent entry or zero if the suffix entry ID is used
* @throws Exception on failures to access the underlying store
*/
- ID getParentId( String dn ) throws Exception;
-
-
ID getParentId( ID childId ) throws Exception;