You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by pa...@apache.org on 2012/10/24 11:37:30 UTC

svn commit: r1401598 - in /directory/apacheds/trunk: jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java

Author: pamarcelot
Date: Wed Oct 24 09:37:30 2012
New Revision: 1401598

URL: http://svn.apache.org/viewvc?rev=1401598&view=rev
Log:
Fix for DIRSERVER-1752 (Adding a context entry (ads-contextentry attribute) in the configuration of a partition has no effect).
Fixed a bug when the context entry was already there (typically when restarting).

Modified:
    directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
    directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/LdifPartition.java

Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java?rev=1401598&r1=1401597&r2=1401598&view=diff
==============================================================================
--- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java (original)
+++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmPartition.java Wed Oct 24 09:37:30 2012
@@ -36,6 +36,7 @@ import jdbm.recman.CacheRecordManager;
 
 import org.apache.directory.server.constants.ApacheSchemaConstants;
 import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
 import org.apache.directory.server.core.api.partition.Partition;
 import org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition;
 import org.apache.directory.server.i18n.I18n;
@@ -53,6 +54,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.entry.Value;
+import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.AttributeType;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
 import org.apache.directory.shared.util.exception.MultiException;
@@ -201,31 +203,50 @@ public class JdbmPartition extends Abstr
             deleteUnusedIndexFiles( allIndices, allIndexDbFiles );
 
             // Initialization of the context entry
-            if ( contextEntry != null )
+            if ( ( suffixDn != null ) && ( contextEntry != null ) )
             {
-                // Checking of the context entry is schema aware
-                if ( !contextEntry.isSchemaAware() )
-                {
-                    // Making the context entry schema aware
-                    contextEntry = new DefaultEntry( schemaManager, contextEntry );
-                }
-                
-                // Adding the 'entryCsn' attribute
-                if ( contextEntry.get( SchemaConstants.ENTRY_CSN_AT ) == null )
+                Dn contextEntryDn = contextEntry.getDn();
+
+                // Checking if the context entry DN is schema aware
+                if ( !contextEntryDn.isSchemaAware() )
                 {
-                    contextEntry.add( SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance().toString() );
+                    contextEntryDn.apply( schemaManager );
                 }
 
-                // Adding the 'entryUuid' attribute
-                if ( contextEntry.get( SchemaConstants.ENTRY_UUID_AT ) == null )
+                // We're only adding the entry if the two DNs are equal
+                if ( suffixDn.equals( contextEntryDn ) )
                 {
-                    String uuid = UUID.randomUUID().toString();
-                    contextEntry.add( SchemaConstants.ENTRY_UUID_AT, uuid );
-                }
+                    // Looking for the current context entry
+                    Entry suffixEntry = lookup( new LookupOperationContext( null, suffixDn ) );
+
+                    // We're only adding the context entry if it doesn't already exist
+                    if ( suffixEntry == null )
+                    {
+                        // Checking of the context entry is schema aware
+                        if ( !contextEntry.isSchemaAware() )
+                        {
+                            // Making the context entry schema aware
+                            contextEntry = new DefaultEntry( schemaManager, contextEntry );
+                        }
 
-                // And add this entry to the underlying partition
-                AddOperationContext addContext = new AddOperationContext( null, contextEntry );
-                add( addContext );
+                        // Adding the 'entryCsn' attribute
+                        if ( contextEntry.get( SchemaConstants.ENTRY_CSN_AT ) == null )
+                        {
+                            contextEntry.add( SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance()
+                                .toString() );
+                        }
+
+                        // Adding the 'entryUuid' attribute
+                        if ( contextEntry.get( SchemaConstants.ENTRY_UUID_AT ) == null )
+                        {
+                            String uuid = UUID.randomUUID().toString();
+                            contextEntry.add( SchemaConstants.ENTRY_UUID_AT, uuid );
+                        }
+
+                        // And add this entry to the underlying partition
+                        add( new AddOperationContext( null, contextEntry ) );
+                    }
+                }
             }
 
             // We are done !

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=1401598&r1=1401597&r2=1401598&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 Wed Oct 24 09:37:30 2012
@@ -29,6 +29,7 @@ import java.util.List;
 import java.util.UUID;
 
 import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.MoveAndRenameOperationContext;
 import org.apache.directory.server.core.api.interceptor.context.MoveOperationContext;
@@ -198,31 +199,50 @@ public class LdifPartition extends Abstr
                 }
 
                 // Initialization of the context entry
-                if ( contextEntry == null )
+                if ( ( suffixDn != null ) && ( contextEntry != null ) )
                 {
-                    // Checking of the context entry is schema aware
-                    if ( !contextEntry.isSchemaAware() )
-                    {
-                        // Making the context entry schema aware
-                        contextEntry = new DefaultEntry( schemaManager, contextEntry );
-                    }
+                    Dn contextEntryDn = contextEntry.getDn();
 
-                    // Adding the 'entryCsn' attribute
-                    if ( contextEntry.get( SchemaConstants.ENTRY_CSN_AT ) == null )
+                    // Checking if the context entry DN is schema aware
+                    if ( !contextEntryDn.isSchemaAware() )
                     {
-                        contextEntry.add( SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance().toString() );
+                        contextEntryDn.apply( schemaManager );
                     }
 
-                    // Adding the 'entryUuid' attribute
-                    if ( contextEntry.get( SchemaConstants.ENTRY_UUID_AT ) == null )
+                    // We're only adding the entry if the two DNs are equal
+                    if ( suffixDn.equals( contextEntryDn ) )
                     {
-                        String uuid = UUID.randomUUID().toString();
-                        contextEntry.add( SchemaConstants.ENTRY_UUID_AT, uuid );
-                    }
+                        // Looking for the current context entry
+                        Entry suffixEntry = lookup( new LookupOperationContext( null, suffixDn ) );
 
-                    // And add this entry to the underlying partition
-                    AddOperationContext addContext = new AddOperationContext( null, contextEntry );
-                    add( addContext );
+                        // We're only adding the context entry if it doesn't already exist
+                        if ( suffixEntry == null )
+                        {
+                            // Checking of the context entry is schema aware
+                            if ( !contextEntry.isSchemaAware() )
+                            {
+                                // Making the context entry schema aware
+                                contextEntry = new DefaultEntry( schemaManager, contextEntry );
+                            }
+
+                            // Adding the 'entryCsn' attribute
+                            if ( contextEntry.get( SchemaConstants.ENTRY_CSN_AT ) == null )
+                            {
+                                contextEntry.add( SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance()
+                                    .toString() );
+                            }
+
+                            // Adding the 'entryUuid' attribute
+                            if ( contextEntry.get( SchemaConstants.ENTRY_UUID_AT ) == null )
+                            {
+                                String uuid = UUID.randomUUID().toString();
+                                contextEntry.add( SchemaConstants.ENTRY_UUID_AT, uuid );
+                            }
+
+                            // And add this entry to the underlying partition
+                            add( new AddOperationContext( null, contextEntry ) );
+                        }
+                    }
                 }
             }
         }