Return-Path: X-Original-To: apmail-directory-commits-archive@www.apache.org Delivered-To: apmail-directory-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 2D127D73F for ; Tue, 23 Oct 2012 08:15:49 +0000 (UTC) Received: (qmail 30658 invoked by uid 500); 23 Oct 2012 08:15:49 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 30337 invoked by uid 500); 23 Oct 2012 08:15:38 -0000 Mailing-List: contact commits-help@directory.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@directory.apache.org Delivered-To: mailing list commits@directory.apache.org Received: (qmail 30113 invoked by uid 99); 23 Oct 2012 08:15:36 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Oct 2012 08:15:36 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 23 Oct 2012 08:15:35 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 6593E23888E3 for ; Tue, 23 Oct 2012 08:14:51 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: commits@directory.apache.org From: pamarcelot@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20121023081451.6593E23888E3@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 /** true 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 )