directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pamarce...@apache.org
Subject svn commit: r1401194 - in /directory/apacheds/trunk: core-api/src/main/java/org/apache/directory/server/core/api/partition/ jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ ldif-partition/src/main/java/org/apache...
Date Tue, 23 Oct 2012 08:14:51 GMT
Author: pamarcelot
Date: Tue Oct 23 08:14:50 2012
New Revision: 1401194

URL: http://svn.apache.org/viewvc?rev=1401194&view=rev
Log:
Fix for DIRSERVER-1752 (Adding a context entry (ads-contextentry attribute) in the configuration
of a partition has no effect).

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/partition/AbstractPartition.java
    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
    directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java
    directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/partition/AbstractPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/partition/AbstractPartition.java?rev=1401194&r1=1401193&r2=1401194&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/partition/AbstractPartition.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/partition/AbstractPartition.java
Tue Oct 23 08:14:50 2012
@@ -26,6 +26,7 @@ import java.io.OutputStream;
 import javax.naming.InvalidNameException;
 
 import org.apache.directory.server.i18n.I18n;
+import org.apache.directory.shared.ldap.model.entry.Entry;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
 import org.apache.directory.shared.ldap.model.exception.LdapOtherException;
@@ -46,6 +47,9 @@ public abstract class AbstractPartition 
     /** <tt>true</tt> if and only if this partition is initialized. */
     protected boolean initialized;
 
+    /** The partition ContextEntry */
+    protected Entry contextEntry;
+
     /** The SchemaManager instance */
     protected SchemaManager schemaManager;
 
@@ -212,4 +216,22 @@ public abstract class AbstractPartition 
             throw new IllegalStateException( I18n.err( I18n.ERR_576, property ) );
         }
     }
+
+
+    /**
+     * @return the contextEntry
+     */
+    public Entry getContextEntry()
+    {
+        return contextEntry;
+    }
+
+
+    /**
+     * @param contextEntry the contextEntry to set
+     */
+    public void setContextEntry( Entry contextEntry )
+    {
+        this.contextEntry = contextEntry;
+    }
 }

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=1401194&r1=1401193&r2=1401194&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
Tue Oct 23 08:14:50 2012
@@ -27,6 +27,7 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.UUID;
 
 import jdbm.RecordManager;
 import jdbm.helper.MRU;
@@ -34,6 +35,7 @@ import jdbm.recman.BaseRecordManager;
 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.partition.Partition;
 import org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition;
 import org.apache.directory.server.i18n.I18n;
@@ -43,9 +45,12 @@ import org.apache.directory.server.xdbm.
 import org.apache.directory.server.xdbm.search.impl.DefaultSearchEngine;
 import org.apache.directory.server.xdbm.search.impl.EvaluatorBuilder;
 import org.apache.directory.server.xdbm.search.impl.NoOpOptimizer;
+import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.csn.CsnFactory;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.cursor.Tuple;
 import org.apache.directory.shared.ldap.model.entry.Attribute;
+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.schema.AttributeType;
@@ -195,6 +200,34 @@ public class JdbmPartition extends Abstr
 
             deleteUnusedIndexFiles( allIndices, allIndexDbFiles );
 
+            // Initialization of the context entry
+            if ( 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 )
+                {
+                    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
+                AddOperationContext addContext = new AddOperationContext( null, contextEntry
);
+                add( addContext );
+            }
+
             // We are done !
             initialized = true;
         }

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=1401194&r1=1401193&r2=1401194&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
Tue Oct 23 08:14:50 2012
@@ -39,6 +39,7 @@ import org.apache.directory.server.xdbm.
 import org.apache.directory.server.xdbm.SingletonIndexCursor;
 import org.apache.directory.server.xdbm.search.cursor.DescendantCursor;
 import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.model.csn.CsnFactory;
 import org.apache.directory.shared.ldap.model.cursor.Cursor;
 import org.apache.directory.shared.ldap.model.entry.DefaultEntry;
 import org.apache.directory.shared.ldap.model.entry.Entry;
@@ -180,17 +181,39 @@ public class LdifPartition extends Abstr
 
                 LOG.info( "ldif file doesn't exist {}, creating it.", contextEntryFile.getAbsolutePath()
);
 
-                if ( contextEntryFile.exists() )
+                if ( contextEntry == null )
                 {
-                    LdifReader reader = new LdifReader( contextEntryFile );
-                    Entry contextEntry = new DefaultEntry( schemaManager, reader.next().getEntry()
);
-                    reader.close();
+                    if ( contextEntryFile.exists() )
+                    {
+                        LdifReader reader = new LdifReader( contextEntryFile );
+                        contextEntry = new DefaultEntry( schemaManager, reader.next().getEntry()
);
+                        reader.close();
+                    }
+                    else
+                    {
+                        // No context entry and no LDIF file exists.
+                        // Skip initialization of context entry here, it will be added later.
+                        return;
+                    }
+                }
+
+                // Initialization of the context entry
+                if ( 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 )
                     {
-                        contextEntry.add( SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString()
);
+                        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();

Modified: directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java?rev=1401194&r1=1401193&r2=1401194&view=diff
==============================================================================
--- directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java
(original)
+++ directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/SingleFileLdifPartition.java
Tue Oct 23 08:14:50 2012
@@ -142,7 +142,7 @@ public class SingleFileLdifPartition ext
 
         LdifEntry ldifEntry = itr.next();
 
-        Entry contextEntry = new DefaultEntry( schemaManager, ldifEntry.getEntry() );
+        contextEntry = new DefaultEntry( schemaManager, ldifEntry.getEntry() );
 
         if ( suffixDn.equals( contextEntry.getDn() ) )
         {
@@ -184,6 +184,16 @@ public class SingleFileLdifPartition ext
         {
             super.add( addContext );
 
+            if ( contextEntry == null )
+            {
+                Entry entry = addContext.getEntry();
+
+                if ( entry.getDn().equals( suffixDn ) )
+                {
+                    contextEntry = entry;
+                }
+            }
+
             dirty = true;
             rewritePartitionData();
         }
@@ -292,6 +302,7 @@ public class SingleFileLdifPartition ext
 
                 if ( suffixId == null )
                 {
+                    contextEntry = null;
                     return;
                 }
 

Modified: directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java?rev=1401194&r1=1401193&r2=1401194&view=diff
==============================================================================
--- directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java
(original)
+++ directory/apacheds/trunk/service-builder/src/main/java/org/apache/directory/server/config/builder/ServiceBuilder.java
Tue Oct 23 08:14:50 2012
@@ -1219,7 +1219,8 @@ public class ServiceBuilder
 
                 if ( ( entries != null ) && ( entries.size() > 0 ) )
                 {
-                    entries.get( 0 );
+                    LdifEntry entry = entries.get( 0 );
+                    jdbmPartition.setContextEntry( entry.getEntry() );
                 }
             }
             catch ( LdapLdifException lle )



Mime
View raw message