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/21 03:24:13 UTC

svn commit: r639517 - in /directory/sandbox/akarasulu/bigbang: apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ s...

Author: akarasulu
Date: Thu Mar 20 19:24:08 2008
New Revision: 639517

URL: http://svn.apache.org/viewvc?rev=639517&view=rev
Log:
more tests and fixed bug which prevents stuffing things besides byte[] and Strings into attributes

Modified:
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java
    directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java
    directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.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/JdbmStore.java?rev=639517&r1=639516&r2=639517&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStore.java Thu Mar 20 19:24:08 2008
@@ -40,6 +40,7 @@
 import org.apache.directory.shared.ldap.entry.Value;
 import org.apache.directory.shared.ldap.exception.LdapNameNotFoundException;
 import org.apache.directory.shared.ldap.exception.LdapSchemaViolationException;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
 import org.apache.directory.shared.ldap.message.AttributeImpl;
 import org.apache.directory.shared.ldap.message.AttributesImpl;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
@@ -733,6 +734,16 @@
     }
 
 
+    /**
+     * 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
     {
         Long childId = ndnIdx.forwardLookup( dn );
@@ -1048,6 +1059,12 @@
 
     public void delete( Long id ) throws Exception
     {
+        if ( id == 1 )
+        {
+            throw new LdapOperationNotSupportedException(
+                "Deletion of the suffix entry is not permitted.", ResultCodeEnum.UNWILLING_TO_PERFORM );
+        }
+
         Attributes entry = lookup( id );
         Long parentId = getParentId( id );
         NamingEnumeration<String> attrs = entry.getIDs();
@@ -1100,10 +1117,17 @@
     }
 
 
+    /**
+     * Gets an IndexEntry Cursor over the child nodes of an entry.
+     *
+     * @param id the id of the parent entry
+     * @return an IndexEntry Cursor over the child entries
+     * @throws Exception on failures to access the underlying store
+     */
     public Cursor<IndexEntry<Long,E>> list( Long id ) throws Exception
     {
-        Cursor<IndexEntry<Long,E>> cursor = hierarchyIdx.forwardCursor();
-        ForwardIndexEntry recordForward = new ForwardIndexEntry();
+        Cursor<IndexEntry<Long,E>> cursor = hierarchyIdx.forwardCursor( id );
+        ForwardIndexEntry<Long,E> recordForward = new ForwardIndexEntry<Long,E>();
         recordForward.setId( id );
         cursor.before( recordForward );
         return cursor;
@@ -1153,6 +1177,14 @@
     }
 
 
+    /**
+     * This is primarily a convenience method used to extract all the indices
+     * associated with an entry.
+     *
+     * @param id the id of the entry to get index information for
+     * @return the index names and values as an Attributes object
+     * @throws Exception if there are failures accessing the underlying store
+     */
     public Attributes getIndices( Long id ) throws Exception
     {
         Attributes attributes = new AttributesImpl();
@@ -1163,17 +1195,17 @@
         attributes.put( "_parent", getParentId( id ) );
 
         // Get all standard index attribute to value mappings
-        for ( Index index:this.userIndices.values() )
+        for ( Index index : userIndices.values() )
         {
-            Cursor<ForwardIndexEntry> list = index.reverseCursor();
-            ForwardIndexEntry recordForward = new ForwardIndexEntry();
+            Cursor<ForwardIndexEntry<Long,E>> list = index.reverseCursor();
+            ForwardIndexEntry<Long,E> recordForward = new ForwardIndexEntry<Long,E>();
             recordForward.setId( id );
             list.before( recordForward );
 
             while ( list.next() )
             {
-                IndexEntry rec = list.get();
-                Object val = rec.getValue();
+                IndexEntry<Long,E> rec = list.get();
+                String val = rec.getValue().toString();
                 String attrId = index.getAttribute().getName();
                 Attribute attr = attributes.get( attrId );
 
@@ -1190,7 +1222,7 @@
         // Get all existance mappings for this id creating a special key
         // that looks like so 'existance[attribute]' and the value is set to id
         Cursor<IndexEntry<String,E>> list = existanceIdx.reverseCursor();
-        ForwardIndexEntry recordForward = new ForwardIndexEntry();
+        ForwardIndexEntry<String,E> recordForward = new ForwardIndexEntry<String,E>();
         recordForward.setId( id );
         list.before( recordForward );
         StringBuffer val = new StringBuffer();
@@ -1199,7 +1231,7 @@
         {
             IndexEntry rec = list.get();
             val.append( "_existance[" );
-            val.append( rec.getValue() );
+            val.append( rec.getValue().toString() );
             val.append( "]" );
 
             String valStr = val.toString();
@@ -1210,7 +1242,7 @@
                 attr = new AttributeImpl( valStr );
             }
             
-            attr.add( rec.getId() );
+            attr.add( rec.getId().toString() );
             attributes.put( attr );
             val.setLength( 0 );
         }
@@ -1218,17 +1250,17 @@
         // Get all parent child mappings for this entry as the parent using the
         // key 'child' with many entries following it.
         Cursor<IndexEntry<Long,E>> children = hierarchyIdx.forwardCursor();
-        recordForward = new ForwardIndexEntry();
+        ForwardIndexEntry<Long,E> longRecordForward = new ForwardIndexEntry<Long,E>();
         recordForward.setId( id );
-        children.before( recordForward );
+        children.before( longRecordForward );
 
         Attribute childAttr = new AttributeImpl( "_child" );
         attributes.put( childAttr );
         
         while ( children.next() )
         {
-            IndexEntry rec = children.get();
-            childAttr.add( rec.getId() );
+            IndexEntry<Long,E> rec = children.get();
+            childAttr.add( rec.getId().toString() );
         }
 
         return attributes;

Modified: directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.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/JdbmStoreTest.java?rev=639517&r1=639516&r2=639517&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java (original)
+++ directory/sandbox/akarasulu/bigbang/apacheds/jdbm-store/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java Thu Mar 20 19:24:08 2008
@@ -33,9 +33,13 @@
 import org.apache.directory.server.core.entry.DefaultServerEntry;
 import org.apache.directory.server.core.entry.ServerEntryUtils;
 import org.apache.directory.server.core.partition.impl.btree.IndexNotFoundException;
+import org.apache.directory.server.core.partition.impl.btree.IndexEntry;
+import org.apache.directory.server.core.cursor.Cursor;
 import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.shared.ldap.name.LdapDN;
 import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.exception.LdapOperationNotSupportedException;
+import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 
 import javax.naming.directory.Attributes;
 import java.io.File;
@@ -290,24 +294,71 @@
 
 
     @Test
+    public void testGetIndicies() throws Exception
+    {
+        Attributes attrs = store.getIndices( 1L );
+        assertNotNull( attrs );
+        assertNotNull( attrs.get( "_nDn" ) );
+        assertNotNull( attrs.get( "_upDn" ) );
+        assertNotNull( attrs.get( "_parent" ) );
+        LOG.debug( attrs.toString() );
+    }
+
+
+    @Test
+    public void testPersistentProperties() throws Exception
+    {
+        assertNull( store.getProperty( "foo" ) );
+        store.setProperty( "foo", "bar" );
+        assertEquals( "bar", store.getProperty( "foo" ) );
+    }
+
+
+    @Test
     public void testFreshStore() throws Exception
     {
         LdapDN dn = new LdapDN( "dc=example,dc=com" );
         dn.normalize( attributeRegistry.getNormalizerMapping() );
         assertEquals( 1L, ( long ) store.getEntryId( dn.toNormName() ) );
         assertEquals( 1, store.count() );
-//        assertEquals( "dc=example,dc=com", store.getEntryUpdn( "dc=example,dc=com" ) );
+        assertEquals( "dc=example,dc=com", store.getEntryUpdn( dn.toNormName() ) );
+        assertEquals( dn.toNormName(), store.getEntryDn( 1L ) );
+        assertEquals( dn.getUpName(), store.getEntryUpdn( 1L ) );
+        assertNotNull( store.getSuffixEntry() );
+
+        // note that the suffix entry returns 0 for it's parent which does not exist
+        assertEquals( 0L, ( long ) store.getParentId( dn.toNormName() ) );
+        assertNull( store.getParentId( 0L ) );
+
+        // should not be allowed
+        try { store.delete( 1L ); fail(); } catch( LdapOperationNotSupportedException e )
+        {
+            assertEquals( ResultCodeEnum.UNWILLING_TO_PERFORM, e.getResultCode() );
+        }
     }
 
 
     @Test
     public void testEntryOperations() throws Exception
     {
+        assertEquals( 0, store.getChildCount( 1L ) );
         LdapDN dn = new LdapDN( "ou=Engineering,dc=example,dc=com" );
         dn.normalize( attributeRegistry.getNormalizerMapping() );
         DefaultServerEntry entry = new DefaultServerEntry( registries, dn );
         entry.add( "objectClass", "top", "organizationalUnit" );
         entry.add( "ou", "Engineering" );
         store.add( dn, ServerEntryUtils.toAttributesImpl( entry ) );
+
+        Cursor<IndexEntry<Long,Attributes>> cursor = store.list( 1L );
+        assertNotNull( cursor );
+        cursor.beforeFirst();
+        assertTrue( cursor.next() );
+        assertEquals( 2L, ( long ) cursor.get().getId() );
+        assertFalse( cursor.next() );
+        assertEquals( 1, store.getChildCount( 1L ) );
+
+        store.delete( 2L );
+        assertEquals( 0, store.getChildCount( 1L ) );
+        assertEquals( 1, store.count() );
     }
 }

Modified: directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java
URL: http://svn.apache.org/viewvc/directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java?rev=639517&r1=639516&r2=639517&view=diff
==============================================================================
--- directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java (original)
+++ directory/sandbox/akarasulu/bigbang/shared/ldap/src/main/java/org/apache/directory/shared/ldap/message/AttributeImpl.java Thu Mar 20 19:24:08 2008
@@ -124,7 +124,7 @@
      * instance of a BasicAttribute instance
      * 
      * @param attribute the Attribute instace to copy
-     * @throws
+     * @throws NamingException if attribute values cannot be accessed
      */
     public AttributeImpl( Attribute attribute ) throws NamingException
     {
@@ -263,11 +263,10 @@
                 return AttributeUtils.equals( value, attrVal );
 
             default:
-                Iterator<Object> values = list.iterator();
 
-                while ( values.hasNext() )
+                for ( Object candidate : list )
                 {
-                    if ( AttributeUtils.equals( values.next(), attrVal ) )
+                    if ( AttributeUtils.equals( candidate, attrVal ) )
                     {
                         return true;
                     }
@@ -289,7 +288,7 @@
      */
     public boolean add( Object attrVal )
     {
-        boolean exists = false;
+        boolean exists;
 
         if ( contains( attrVal ) )
         {
@@ -451,7 +450,6 @@
             default:
                 list = null;
                 size = 0;
-                return;
         }
     }
 
@@ -637,7 +635,6 @@
             default:
                 list.add( index, attrVal );
                 size++;
-                return;
         }
     }
 
@@ -785,7 +782,7 @@
 
             for ( Object v : list )
             {
-                int h = 0;
+                int h;
 
                 if ( v instanceof String )
                 {
@@ -801,7 +798,7 @@
                     return false;
                 }
 
-                hash.put( Integer.valueOf( h ), v );
+                hash.put( h, v );
             }
 
             try
@@ -814,7 +811,7 @@
 
                     if ( val instanceof String )
                     {
-                        Integer h = Integer.valueOf( val.hashCode() );
+                        Integer h = val.hashCode();
 
                         if ( !hash.containsKey( h ) )
                         {
@@ -832,7 +829,7 @@
                     }
                     else if ( val instanceof byte[] )
                     {
-                        Integer h = Integer.valueOf( Arrays.hashCode( ( byte[] ) val ) );
+                        Integer h = Arrays.hashCode( ( byte[] ) val );
 
                         if ( !hash.containsKey( h ) )
                         {
@@ -854,14 +851,7 @@
                     }
                 }
 
-                if ( hash.size() != 0 )
-                {
-                    return false;
-                }
-                else
-                {
-                    return true;
-                }
+                return hash.size() == 0;
             }
             catch ( NamingException ne )
             {
@@ -893,10 +883,14 @@
                 {
                     sb.append( '\'' ).append( value ).append( '\'' );
                 }
-                else
+                else if ( value instanceof byte[] )
                 {
                     sb.append( StringTools.dumpBytes( ( byte[] ) value ) );
                 }
+                else
+                {
+                    sb.append( value.toString() );
+                }
 
                 sb.append( "]\n" );
                 break;
@@ -904,13 +898,9 @@
             default:
                 boolean isFirst = true;
 
-                Iterator<Object> values = list.iterator();
-
-                while ( values.hasNext() )
+                for ( Object v : list )
                 {
-                    Object v = values.next();
-
-                    if ( isFirst == false )
+                    if ( !isFirst )
                     {
                         sb.append( ", " );
                     }