From commits-return-32128-apmail-directory-commits-archive=directory.apache.org@directory.apache.org Fri Jul 22 00:02:54 2011 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 C2C9A63C5 for ; Fri, 22 Jul 2011 00:02:54 +0000 (UTC) Received: (qmail 5970 invoked by uid 500); 22 Jul 2011 00:02:54 -0000 Delivered-To: apmail-directory-commits-archive@directory.apache.org Received: (qmail 5854 invoked by uid 500); 22 Jul 2011 00:02:54 -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 5814 invoked by uid 99); 22 Jul 2011 00:02:54 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 22 Jul 2011 00:02:54 +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; Fri, 22 Jul 2011 00:02:45 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 9401C2388994 for ; Fri, 22 Jul 2011 00:02:22 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1149411 [2/6] - in /directory/apacheds/trunk: core-annotations/src/main/java/org/apache/directory/server/core/factory/ core-annotations/src/test/java/org/apache/directory/server/core/factory/ core-api/src/main/java/org/apache/directory/ser... Date: Fri, 22 Jul 2011 00:02:18 -0000 To: commits@directory.apache.org From: elecharny@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110722000222.9401C2388994@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java?rev=1149411&r1=1149410&r2=1149411&view=diff ============================================================================== --- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java (original) +++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/partition/DefaultPartitionNexus.java Fri Jul 22 00:02:02 2011 @@ -85,7 +85,6 @@ import org.apache.directory.shared.ldap. import org.apache.directory.shared.ldap.util.tree.DnNode; import org.apache.directory.shared.util.DateUtils; import org.apache.directory.shared.util.exception.MultiException; -import org.apache.directory.shared.util.exception.NotImplementedException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -103,6 +102,9 @@ public class DefaultPartitionNexus exten /** A logger for this class */ private static final Logger LOG = LoggerFactory.getLogger( DefaultPartitionNexus.class ); + /** the fixed id: 'NEXUS' */ + private static final String ID = "NEXUS"; + /** Speedup for logs */ private static final boolean IS_DEBUG = LOG.isDebugEnabled(); @@ -122,10 +124,7 @@ public class DefaultPartitionNexus exten private DnNode partitionLookupTree = new DnNode(); /** the system partition */ - private Partition system; - - /** the closed state of this partition */ - private boolean initialized; + //private Partition system; /** A reference to the EntryCSN attributeType */ private static AttributeType ENTRY_CSN_AT; @@ -133,7 +132,7 @@ public class DefaultPartitionNexus exten /** A reference to the ObjectClass attributeType */ private static AttributeType OBJECT_CLASS_AT; - final List mods = new ArrayList( 2 ); + private final List mods = new ArrayList( 2 ); private String lastSyncedCtxCsn = null; @@ -154,6 +153,9 @@ public class DefaultPartitionNexus exten */ public DefaultPartitionNexus( Entry rootDSE ) throws Exception { + id = ID; + suffixDn = null; + // setup that root DSE this.rootDSE = rootDSE; @@ -193,67 +195,69 @@ public class DefaultPartitionNexus exten protected void doInit() throws Exception { // NOTE: We ignore ContextPartitionConfiguration parameter here. - if ( initialized ) - { - return; - } - - // Add the supported controls - Iterator ctrlOidItr = directoryService.getLdapCodecService().registeredControls(); - while ( ctrlOidItr.hasNext() ) - { - rootDSE.add( SchemaConstants.SUPPORTED_CONTROL_AT, ctrlOidItr.next() ); - } - - schemaManager = directoryService.getSchemaManager(); - ENTRY_CSN_AT = schemaManager.getAttributeType( SchemaConstants.ENTRY_CSN_AT ); - OBJECT_CLASS_AT = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT ); - - // Initialize and normalize the localy used DNs - Dn adminDn = directoryService.getDnFactory().create( ServerDNConstants.ADMIN_SYSTEM_DN ); - adminDn.apply( schemaManager ); - - Value attr = rootDSE.get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get(); - subschemSubentryDn = directoryService.getDnFactory().create( attr.getString() ); - - initializeSystemPartition( directoryService ); - - List initializedPartitions = new ArrayList(); - initializedPartitions.add( 0, this.system ); - - try + if ( !initialized ) { - for ( Partition partition : directoryService.getPartitions() ) + // Add the supported controls + Iterator ctrlOidItr = directoryService.getLdapCodecService().registeredControls(); + + while ( ctrlOidItr.hasNext() ) { - partition.setSchemaManager( schemaManager ); - addContextPartition( partition ); - initializedPartitions.add( partition ); + rootDSE.add( SchemaConstants.SUPPORTED_CONTROL_AT, ctrlOidItr.next() ); } - - createContextCsnModList(); - - initialized = true; - } - finally - { - if ( !initialized ) + + schemaManager = directoryService.getSchemaManager(); + ENTRY_CSN_AT = schemaManager.getAttributeType( SchemaConstants.ENTRY_CSN_AT ); + OBJECT_CLASS_AT = schemaManager.getAttributeType( SchemaConstants.OBJECT_CLASS_AT ); + + // Initialize and normalize the localy used DNs + Dn adminDn = directoryService.getDnFactory().create( ServerDNConstants.ADMIN_SYSTEM_DN ); + adminDn.apply( schemaManager ); + + Value attr = rootDSE.get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT ).get(); + subschemSubentryDn = directoryService.getDnFactory().create( attr.getString() ); + + //initializeSystemPartition( directoryService ); + + List initializedPartitions = new ArrayList(); + + initializedPartitions.add( 0, directoryService.getSystemPartition() ); + addContextPartition( directoryService.getSystemPartition() ); + + try { - Iterator i = initializedPartitions.iterator(); - while ( i.hasNext() ) + for ( Partition partition : directoryService.getPartitions() ) { - Partition partition = i.next(); - i.remove(); - try - { - partition.destroy(); - } - catch ( Exception e ) - { - LOG.warn( "Failed to destroy a partition: " + partition.getSuffix(), e ); - } - finally + addContextPartition( partition ); + initializedPartitions.add( partition ); + } + + createContextCsnModList(); + + initialized = true; + } + finally + { + if ( !initialized ) + { + Iterator i = initializedPartitions.iterator(); + + while ( i.hasNext() ) { - unregister( partition ); + Partition partition = i.next(); + i.remove(); + + try + { + partition.destroy(); + } + catch ( Exception e ) + { + LOG.warn( "Failed to destroy a partition: " + partition.getSuffixDn(), e ); + } + finally + { + unregister( partition ); + } } } } @@ -264,29 +268,7 @@ public class DefaultPartitionNexus exten private Partition initializeSystemPartition( DirectoryService directoryService ) throws Exception { // initialize system partition first - Partition override = directoryService.getSystemPartition(); - - if ( override != null ) - { - - // --------------------------------------------------------------- - // check a few things to make sure users configured it properly - // --------------------------------------------------------------- - - if ( !override.getId().equals( "system" ) ) - { - throw new ConfigurationException( I18n.err( I18n.ERR_262, override.getId() ) ); - } - - system = override; - } - else - { - // TODO : we have to deal with this case ! - } - - system.setSchemaManager( schemaManager ); - system.initialize(); + Partition system = directoryService.getSystemPartition(); // Add root context entry for system partition Dn systemSuffixDn = directoryService.getDnFactory().create( ServerDNConstants.SYSTEM_DN ); @@ -312,7 +294,7 @@ public class DefaultPartitionNexus exten system.add( addOperationContext ); } - String key = system.getSuffix().getNormName(); + String key = system.getSuffixDn().getNormName(); if ( partitions.containsKey( key ) ) { @@ -322,18 +304,18 @@ public class DefaultPartitionNexus exten synchronized ( partitionLookupTree ) { partitions.put( key, system ); - partitionLookupTree.add( system.getSuffix(), system ); + partitionLookupTree.add( system.getSuffixDn(), system ); Attribute namingContexts = rootDSE.get( SchemaConstants.NAMING_CONTEXTS_AT ); if ( namingContexts == null ) { namingContexts = new DefaultAttribute( schemaManager - .getAttributeType( SchemaConstants.NAMING_CONTEXTS_AT ), system.getSuffix().getName() ); + .getAttributeType( SchemaConstants.NAMING_CONTEXTS_AT ), system.getSuffixDn().getName() ); rootDSE.put( namingContexts ); } else { - namingContexts.add( system.getSuffix().getName() ); + namingContexts.add( system.getSuffixDn().getName() ); } } @@ -369,17 +351,8 @@ public class DefaultPartitionNexus exten } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#getId() - */ - public String getId() - { - return "NEXUS"; - } - - - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#setId(java.lang.String) + /** + * {@inheritDoc} */ public void setId( String id ) { @@ -387,25 +360,16 @@ public class DefaultPartitionNexus exten } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#setSuffix(java.lang.String) + /** + * {@inheritDoc} */ - public void setSuffix( Dn suffix ) + public void setSuffixDn( Dn suffix ) { throw new UnsupportedOperationException(); } /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#isInitialized() - */ - public boolean isInitialized() - { - return initialized; - } - - - /* (non-Javadoc) * @see org.apache.directory.server.core.partition.PartitionNexus#sync() */ public void sync() throws Exception @@ -431,8 +395,8 @@ public class DefaultPartitionNexus exten timeStampAt.add( DateUtils.getGeneralizedTime() ); ModifyOperationContext csnModContext = new ModifyOperationContext( directoryService.getAdminSession(), - system.getSuffix(), mods ); - system.modify( csnModContext ); + directoryService.getSystemPartition().getSuffixDn(), mods ); + directoryService.getSystemPartition().modify( csnModContext ); } } catch ( Exception e ) @@ -481,8 +445,8 @@ public class DefaultPartitionNexus exten */ public void add( AddOperationContext addContext ) throws LdapException { - Partition backend = getPartition( addContext.getDn() ); - backend.add( addContext ); + Partition partition = getPartition( addContext.getDn() ); + partition.add( addContext ); Attribute at = addContext.getEntry().get( SchemaConstants.ENTRY_CSN_AT ); directoryService.setContextCsn( at.getString() ); @@ -547,13 +511,13 @@ public class DefaultPartitionNexus exten */ public void delete( DeleteOperationContext deleteContext ) throws LdapException { - Partition backend = getPartition( deleteContext.getDn() ); - backend.delete( deleteContext ); + Partition partition = getPartition( deleteContext.getDn() ); + partition.delete( deleteContext ); } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#hasEntry(org.apache.directory.server.core.interceptor.context.EntryOperationContext) + /** + * {@inheritDoc} */ public boolean hasEntry( EntryOperationContext hasEntryContext ) throws LdapException { @@ -569,23 +533,25 @@ public class DefaultPartitionNexus exten return true; } - Partition backend = getPartition( dn ); - return backend.hasEntry( hasEntryContext ); + Partition partition = getPartition( dn ); + + return partition.hasEntry( hasEntryContext ); } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#list(org.apache.directory.server.core.interceptor.context.ListOperationContext) + /** + * {@inheritDoc} */ public EntryFilteringCursor list( ListOperationContext listContext ) throws LdapException { - Partition backend = getPartition( listContext.getDn() ); - return backend.list( listContext ); + Partition partition = getPartition( listContext.getDn() ); + + return partition.list( listContext ); } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#lookup(org.apache.directory.server.core.interceptor.context.LookupOperationContext) + /** + * {@inheritDoc} */ public Entry lookup( LookupOperationContext lookupContext ) throws LdapException { @@ -613,6 +579,7 @@ public class DefaultPartitionNexus exten retval.removeAttributes( attributeType ); } } + return retval; } else @@ -621,8 +588,8 @@ public class DefaultPartitionNexus exten } } - Partition backend = getPartition( dn ); - Entry entry = backend.lookup( lookupContext ); + Partition partition = getPartition( dn ); + Entry entry = partition.lookup( lookupContext ); if ( entry == null ) { @@ -636,19 +603,8 @@ public class DefaultPartitionNexus exten } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#lookup(java.lang.Long) - */ - public Entry lookup( Long id ) throws LdapException - { - // TODO not implemented until we can use id to figure out the partition using - // the partition ID component of the 64 bit Long identifier - throw new NotImplementedException(); - } - - - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#modify(org.apache.directory.server.core.interceptor.context.ModifyOperationContext) + /** + * {@inheritDoc} */ public void modify( ModifyOperationContext modifyContext ) throws LdapException { @@ -658,9 +614,9 @@ public class DefaultPartitionNexus exten return; } - Partition backend = getPartition( modifyContext.getDn() ); + Partition partition = getPartition( modifyContext.getDn() ); - backend.modify( modifyContext ); + partition.modify( modifyContext ); Entry alteredEntry = modifyContext.getAlteredEntry(); @@ -671,38 +627,38 @@ public class DefaultPartitionNexus exten } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#move(org.apache.directory.server.core.interceptor.context.MoveOperationContext) + /** + * {@inheritDoc} */ public void move( MoveOperationContext moveContext ) throws LdapException { // Get the current partition - Partition backend = getPartition( moveContext.getDn() ); + Partition partition = getPartition( moveContext.getDn() ); // We also have to get the new partition as it can be different //Partition newBackend = getPartition( opContext.getNewDn() ); - backend.move( moveContext ); + partition.move( moveContext ); } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#moveAndRename(org.apache.directory.server.core.interceptor.context.MoveAndRenameOperationContext) + /** + * {@inheritDoc} */ public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException { - Partition backend = getPartition( moveAndRenameContext.getDn() ); - backend.moveAndRename( moveAndRenameContext ); + Partition partition = getPartition( moveAndRenameContext.getDn() ); + partition.moveAndRename( moveAndRenameContext ); } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#rename(org.apache.directory.server.core.interceptor.context.RenameOperationContext) + /** + * {@inheritDoc} */ public void rename( RenameOperationContext renameContext ) throws LdapException { - Partition backend = getPartition( renameContext.getDn() ); - backend.rename( renameContext ); + Partition partition = getPartition( renameContext.getDn() ); + partition.rename( renameContext ); } @@ -836,7 +792,7 @@ public class DefaultPartitionNexus exten for ( Partition partition : partitions.values() ) { - Dn contextDn = partition.getSuffix(); + Dn contextDn = partition.getSuffixDn(); EntryOperationContext hasEntryContext = new EntryOperationContext( null, contextDn ); // search only if the context entry exists if( partition.hasEntry( hasEntryContext ) ) @@ -856,7 +812,7 @@ public class DefaultPartitionNexus exten for ( Partition partition : partitions.values() ) { Entry entry = partition.lookup( new LookupOperationContext( directoryService.getAdminSession(), - partition.getSuffix() ) ); + partition.getSuffixDn() ) ); if ( entry != null ) { @@ -910,7 +866,7 @@ public class DefaultPartitionNexus exten public synchronized void addContextPartition( Partition partition ) throws LdapException { // Turn on default indices - String key = partition.getSuffix().getNormName(); + String key = partition.getSuffixDn().getNormName(); if ( partitions.containsKey( key ) ) { @@ -924,7 +880,7 @@ public class DefaultPartitionNexus exten synchronized ( partitionLookupTree ) { - Dn partitionSuffix = partition.getSuffix(); + Dn partitionSuffix = partition.getSuffixDn(); if ( partitionSuffix == null ) { @@ -932,7 +888,7 @@ public class DefaultPartitionNexus exten } partitions.put( partitionSuffix.getNormName(), partition ); - partitionLookupTree.add( partition.getSuffix(), partition ); + partitionLookupTree.add( partition.getSuffixDn(), partition ); Attribute namingContexts = rootDSE.get( SchemaConstants.NAMING_CONTEXTS_AT ); @@ -969,7 +925,7 @@ public class DefaultPartitionNexus exten throw new LdapNoSuchObjectException( msg ); } - String partitionSuffix = partition.getSuffix().getName(); + String partitionSuffix = partition.getSuffixDn().getName(); // Retrieve the namingContexts from the RootDSE : the partition // suffix must be present in those namingContexts @@ -990,7 +946,7 @@ public class DefaultPartitionNexus exten } // Update the partition tree - partitionLookupTree.remove( partition.getSuffix() ); + partitionLookupTree.remove( partition.getSuffixDn() ); partitions.remove( key ); try @@ -1005,15 +961,6 @@ public class DefaultPartitionNexus exten /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#getSystemPartition() - */ - public Partition getSystemPartition() - { - return system; - } - - - /* (non-Javadoc) * @see org.apache.directory.server.core.partition.PartitionNexus#getPartition(org.apache.directory.shared.ldap.model.name.Dn) */ public Partition getPartition( Dn dn ) throws LdapException @@ -1031,20 +978,14 @@ public class DefaultPartitionNexus exten } - /* (non-Javadoc) - * @see org.apache.directory.server.core.partition.PartitionNexus#getSuffix(org.apache.directory.server.core.interceptor.context.GetSuffixOperationContext) + /** + * {@inheritDoc} */ - public Dn findSuffix( Dn dn ) throws LdapException + public Dn getSuffixDn( Dn dn ) throws LdapException { - Partition backend = getPartition( dn ); - - return backend.getSuffix(); - } - + Partition partition = getPartition( dn ); - public Dn getSuffix() - { - return null; + return partition.getSuffixDn(); } @@ -1113,10 +1054,10 @@ public class DefaultPartitionNexus exten if ( namingContexts != null ) { - namingContexts.remove( partition.getSuffix().getName() ); + namingContexts.remove( partition.getSuffixDn().getName() ); } - partitions.remove( partition.getSuffix().getName() ); + partitions.remove( partition.getSuffixDn().getName() ); } Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DefaultSchemaService.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DefaultSchemaService.java?rev=1149411&r1=1149410&r2=1149411&view=diff ============================================================================== --- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DefaultSchemaService.java (original) +++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/schema/DefaultSchemaService.java Fri Jul 22 00:02:02 2011 @@ -71,13 +71,13 @@ public class DefaultSchemaService implem private Object schemaSubentrLock = new Object(); - public DefaultSchemaService() throws Exception + public DefaultSchemaService( SchemaManager schemaManager ) throws Exception { - schemaPartition = new SchemaPartition(); + schemaPartition = new SchemaPartition( schemaManager ); + schemaModificationAttributesDn = new Dn( getSchemaManager(), SchemaConstants.SCHEMA_MODIFICATIONS_DN ); } - /** * {@inheritDoc} */ @@ -350,24 +350,6 @@ public class DefaultSchemaService implem } - /** - * Initializes the SchemaService - * - * @throws Exception If the initializaion fails - */ - public void initialize() throws LdapException - { - try - { - schemaModificationAttributesDn = new Dn( getSchemaManager(), SchemaConstants.SCHEMA_MODIFICATIONS_DN ); - } - catch ( LdapException e ) - { - throw new RuntimeException( e ); - } - } - - /* (non-Javadoc) * @see org.apache.directory.server.core.schema.SchemaService#getSubschemaEntryCloned() */ Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java?rev=1149411&r1=1149410&r2=1149411&view=diff ============================================================================== --- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java (original) +++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/subtree/SubentryInterceptor.java Fri Jul 22 00:02:02 2011 @@ -384,7 +384,7 @@ public class SubentryInterceptor extends */ private boolean isNamingContext( Dn dn ) throws LdapException { - Dn namingContext = nexus.findSuffix( dn ); + Dn namingContext = nexus.getSuffixDn( dn ); return dn.equals( namingContext ); } 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=1149411&r1=1149410&r2=1149411&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 Fri Jul 22 00:02:02 2011 @@ -20,15 +20,38 @@ package org.apache.directory.server.core.partition.impl.btree.jdbm; +import java.io.File; +import java.io.FilenameFilter; +import java.net.URI; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import jdbm.RecordManager; +import jdbm.helper.MRU; +import jdbm.recman.BaseRecordManager; +import jdbm.recman.CacheRecordManager; + +import org.apache.directory.server.constants.ApacheSchemaConstants; import org.apache.directory.server.core.partition.Partition; import org.apache.directory.server.core.partition.impl.xdbm.AbstractXdbmPartition; +import org.apache.directory.server.i18n.I18n; import org.apache.directory.server.xdbm.Index; import org.apache.directory.server.xdbm.search.impl.CursorBuilder; import org.apache.directory.server.xdbm.search.impl.DefaultOptimizer; 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.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.Entry; +import org.apache.directory.shared.ldap.model.entry.Value; +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; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -39,75 +62,360 @@ import org.apache.directory.shared.ldap. */ public class JdbmPartition extends AbstractXdbmPartition { + /** static logger */ + private static final Logger LOG = LoggerFactory.getLogger( JdbmPartition.class ); + + private static final String JDBM_DB_FILE_EXTN = ".db"; + + private static final FilenameFilter DB_FILTER = new FilenameFilter() + { + + public boolean accept( File dir, String name ) + { + // really important to filter master.db and master.lg files + return ( name.endsWith( JDBM_DB_FILE_EXTN ) && !name.startsWith( "master." ) ); + } + }; + + /** the JDBM record manager used by this database */ + private RecordManager recMan; /** * Creates a store based on JDBM B+Trees. */ - public JdbmPartition() + public JdbmPartition( SchemaManager schemaManager ) { - super( new JdbmStore() ); + super( schemaManager ); + + // Initialize the cache size + if ( cacheSize < 0 ) + { + cacheSize = DEFAULT_CACHE_SIZE; + LOG.debug( "Using the default entry cache size of {} for {} partition", cacheSize, id ); + } + else + { + LOG.debug( "Using the custom configured cache size of {} for {} partition", cacheSize, id ); + } } protected void doInit() throws Exception { - store.setPartitionPath( getPartitionPath() ); + if ( !initialized ) + { + // setup optimizer and registries for parent + if ( !optimizerEnabled ) + { + optimizer = new NoOpOptimizer(); + } + else + { + optimizer = new DefaultOptimizer( this ); + } + + EvaluatorBuilder evaluatorBuilder = new EvaluatorBuilder( this, schemaManager ); + CursorBuilder cursorBuilder = new CursorBuilder( this, evaluatorBuilder ); + + searchEngine = new DefaultSearchEngine( this, cursorBuilder, evaluatorBuilder, optimizer ); + + // Create the underlying directories (only if needed) + getPartitionDir().mkdirs(); + + // Initialize the indexes + setupSystemIndices(); + setupUserIndices(); + + // First, check if the file storing the data exists + String path = getPartitionDir().getPath() + File.separator + "master"; + BaseRecordManager baseRecordManager = new BaseRecordManager( path ); + baseRecordManager.disableTransactions(); + + if ( cacheSize < 0 ) + { + cacheSize = DEFAULT_CACHE_SIZE; + LOG.debug( "Using the default entry cache size of {} for {} partition", cacheSize, id ); + } + else + { + LOG.debug( "Using the custom configured cache size of {} for {} partition", cacheSize, id ); + } + + // Now, create the entry cache for this partition + recMan = new CacheRecordManager( baseRecordManager, new MRU( cacheSize ) ); + + // Create the master table (the table containing all the entries) + master = new JdbmMasterTable( recMan, schemaManager ); + + // get all index db files first + File[] allIndexDbFiles = getPartitionDir().listFiles( DB_FILTER ); + + // get the names of the db files also + List indexDbFileNameList = Arrays.asList( getPartitionDir().list( DB_FILTER ) ); + + // then add all index objects to a list + List allIndices = new ArrayList(); + + for( Index index : systemIndices.values() ) + { + allIndices.add( index.getAttribute().getOid() ); + } + + // this loop is used for two purposes + // one for collecting all user indices + // two for finding a new index to be built + // just to avoid another iteration for determining which is the new index + for( Index index : userIndices.values() ) + { + allIndices.add( index.getAttributeId() ); + + // take the part after removing .db from the + String name = index.getAttributeId() + JDBM_DB_FILE_EXTN; + + // if the name doesn't exist in the list of index DB files + // this is a new index and we need to build it + if ( !indexDbFileNameList.contains( name ) ) + { + buildUserIndex( index ); + } + } + + deleteUnusedIndexFiles( allIndices, allIndexDbFiles ); + + // We are done ! + initialized = true; + } + } + + + /** + * {@inheritDoc}} + */ + public Long getDefaultId() + { + return 1L; + } - EvaluatorBuilder evaluatorBuilder = new EvaluatorBuilder( store, schemaManager ); - CursorBuilder cursorBuilder = new CursorBuilder( store, evaluatorBuilder ); - // setup optimizer and registries for parent - if ( !optimizerEnabled ) + /** + * {@inheritDoc} + */ + public Long getRootId() + { + return 0L; + } + + + /** + * This method is called when the synch thread is waking up, to write + * the modified data. + * + * @throws Exception on failures to sync database files to disk + */ + public synchronized void sync() throws Exception + { + if ( !initialized ) { - optimizer = new NoOpOptimizer(); + return; } - else + + // Sync all system indices + for ( Index idx : systemIndices.values() ) { - optimizer = new DefaultOptimizer( store ); + idx.sync(); + } + + // Sync all user defined userIndices + for ( Index idx : userIndices.values() ) + { + idx.sync(); } - searchEngine = new DefaultSearchEngine( store, cursorBuilder, evaluatorBuilder, optimizer ); - - // initialize the store - store.setCacheSize( cacheSize ); - store.setId( id ); - - // Normalize the suffix - suffix.apply( schemaManager ); - store.setSuffixDn( suffix ); - store.setPartitionPath( getPartitionPath() ); + ( ( JdbmMasterTable ) master ).sync(); + recMan.commit(); + } + + + /** + * builds a user defined index on a attribute by browsing all the entries present in master db + * + * @param userIdx then user defined index + * @throws Exception in case of any problems while building the index + */ + private void buildUserIndex( Index userIdx ) throws Exception + { + AttributeType atType = userIdx.getAttribute(); - for ( Index index : getIndexedAttributes() ) + LOG.info( "building the index for attribute type {}", atType ); + + Cursor> cursor = master.cursor(); + cursor.beforeFirst(); + + String attributeOid = userIdx.getAttribute().getOid(); + + while ( cursor.next() ) { - String oid = schemaManager.getAttributeTypeRegistry().getOidByName( index.getAttributeId() ); + Tuple tuple = cursor.get(); - if ( !index.getAttributeId().equals( oid ) ) + Long id = tuple.getKey(); + Entry entry = tuple.getValue(); + + Attribute entryAttr = entry.get( atType ); + + if ( entryAttr != null ) { - index.setAttributeId( oid ); + for ( Value value : entryAttr ) + { + userIdx.add( value.getValue(), id ); + } + + // Adds only those attributes that are indexed + presenceIdx.add( attributeOid, id ); } + } + + cursor.close(); + } + /** + * removes any unused/removed attribute index files present under the partition's + * working directory + */ + private void deleteUnusedIndexFiles( List allIndices, File[] dbFiles ) + { + for ( File file : dbFiles ) + { + String name = file.getName(); + // take the part after removing .db from the + name = name.substring( 0, name.lastIndexOf( JDBM_DB_FILE_EXTN ) ); - store.addIndex( index ); + // remove the file if not found in the list of names of indices + if( !allIndices.contains( name ) ) + { + boolean deleted = file.delete(); + + if( deleted ) + { + LOG.info( "Deleted unused index file {}", file.getAbsolutePath() ); + + try + { + String atName = schemaManager.lookupAttributeTypeRegistry( name ).getName(); + File txtFile = new File( file.getParent(), name + "-" + atName + ".txt" ); + + deleted = txtFile.delete(); + + if( !deleted ) + { + LOG.info( "couldn't delete the index name helper file {}", txtFile ); + } + } + catch( Exception e ) + { + LOG.warn( "couldn't find the attribute's name with oid {}", name ); + LOG.warn( "", e ); + } + } + else + { + LOG.warn( "Failed to delete unused index file {}", file.getAbsolutePath() ); + } + } } - - store.init( schemaManager ); } + + + /** + * {@inheritDoc} + */ + protected Index convertAndInit( Index index ) throws Exception + { + JdbmIndex jdbmIndex; + + if ( index.getAttributeId().equals( ApacheSchemaConstants.APACHE_RDN_AT_OID ) ) + { + jdbmIndex = new JdbmRdnIndex(); + jdbmIndex.setAttributeId( ApacheSchemaConstants.APACHE_RDN_AT_OID ); + jdbmIndex.setCacheSize( index.getCacheSize() ); + jdbmIndex.setNumDupLimit( JdbmIndex.DEFAULT_DUPLICATE_LIMIT ); + jdbmIndex.setWkDirPath( index.getWkDirPath() ); + } + else if ( index instanceof JdbmIndex ) + { + jdbmIndex = ( JdbmIndex ) index; + + if ( jdbmIndex.getWkDirPath() == null ) + { + jdbmIndex.setWkDirPath( partitionPath ); + } + } + else + { + LOG.debug( "Supplied index {} is not a JdbmIndex. " + + "Will create new JdbmIndex using copied configuration parameters.", index ); + jdbmIndex = new JdbmIndex( index.getAttributeId() ); + jdbmIndex.setCacheSize( index.getCacheSize() ); + jdbmIndex.setNumDupLimit( JdbmIndex.DEFAULT_DUPLICATE_LIMIT ); + jdbmIndex.setWkDirPath( index.getWkDirPath() ); + } + jdbmIndex.init( schemaManager, schemaManager.lookupAttributeTypeRegistry( index.getAttributeId() ) ); - public Index getObjectClassIndex() - { - return store.getObjectClassIndex(); + return jdbmIndex; } - public Index getEntryCsnIndex() + private File getPartitionDir() { - return store.getEntryCsnIndex(); + return new File( getPartitionPath() ); } - public Index getEntryUuidIndex() + /** + * {@inheritDoc} + */ + public URI getPartitionPath() { - return store.getEntryUuidIndex(); + return partitionPath; } + + /** + * {@inheritDoc} + */ + protected synchronized void doDestroy() throws Exception + { + MultiException errors = new MultiException( I18n.err( I18n.ERR_577 ) ); + + if ( !initialized ) + { + return; + } + + try + { + super.doDestroy(); + } + catch ( Exception e ) + { + errors.addThrowable( e ); + } + + // This is specific to the JDBM store : close the record manager + try + { + recMan.close(); + LOG.debug( "Closed record manager for {} partition.", suffixDn ); + } + catch ( Throwable t ) + { + t.printStackTrace(); + LOG.error( I18n.err( I18n.ERR_127 ), t ); + errors.addThrowable( t ); + } + + if ( errors.size() > 0 ) + { + throw errors; + } + } } Modified: directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ServerEntrySerializer.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ServerEntrySerializer.java?rev=1149411&r1=1149410&r2=1149411&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ServerEntrySerializer.java (original) +++ directory/apacheds/trunk/jdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/jdbm/ServerEntrySerializer.java Fri Jul 22 00:02:02 2011 @@ -102,7 +102,7 @@ public class ServerEntrySerializer imple */ public byte[] serialize( Object object ) throws IOException { - Entry entry = (DefaultEntry) object; + Entry entry = (Entry) object; ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream( baos ); Modified: directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java?rev=1149411&r1=1149410&r2=1149411&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java (original) +++ directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/impl/btree/jdbm/JdbmStoreTest.java Fri Jul 22 00:02:02 2011 @@ -32,14 +32,15 @@ import java.lang.reflect.Method; import java.util.Iterator; import java.util.UUID; -import javax.naming.directory.Attributes; - import org.apache.commons.io.FileUtils; import org.apache.directory.server.constants.ApacheSchemaConstants; +import org.apache.directory.server.core.interceptor.context.AddOperationContext; +import org.apache.directory.server.core.partition.Partition; import org.apache.directory.server.xdbm.GenericIndex; import org.apache.directory.server.xdbm.Index; import org.apache.directory.server.xdbm.IndexEntry; import org.apache.directory.server.xdbm.IndexNotFoundException; +import org.apache.directory.server.xdbm.Store; import org.apache.directory.server.xdbm.StoreUtils; import org.apache.directory.shared.ldap.model.constants.SchemaConstants; import org.apache.directory.shared.ldap.model.csn.CsnFactory; @@ -81,7 +82,7 @@ public class JdbmStoreTest private static final Logger LOG = LoggerFactory.getLogger( JdbmStoreTest.class.getSimpleName() ); File wkdir; - JdbmStore store; + JdbmPartition store; private static SchemaManager schemaManager = null; private static LdifSchemaLoader loader; private static Dn EXAMPLE_COM; @@ -135,8 +136,6 @@ public class JdbmStoreTest @Before public void createStore() throws Exception { - destroyStore(); - // setup the working directory for the store wkdir = File.createTempFile( getClass().getSimpleName(), "db" ); wkdir.delete(); @@ -144,8 +143,7 @@ public class JdbmStoreTest wkdir.mkdirs(); // initialize the store - store = new JdbmStore(); - store.setSchemaManager( schemaManager ); + store = new JdbmPartition( schemaManager ); store.setId( "example" ); store.setCacheSize( 10 ); store.setPartitionPath( wkdir.toURI() ); @@ -159,6 +157,11 @@ public class JdbmStoreTest uidIndex.setWkDirPath( wkdir.toURI() ); store.addIndex( uidIndex ); + Dn suffixDn = new Dn( schemaManager, "o=Good Times Co." ); + ((Partition)store).setSuffixDn( suffixDn ); + + ((Partition)store).initialize(); + StoreUtils.loadExampleData( store, schemaManager ); LOG.debug( "Created new store" ); } @@ -199,8 +202,7 @@ public class JdbmStoreTest wkdir2.mkdirs(); // initialize the 2nd store - JdbmStore store2 = new JdbmStore(); - store2.setSchemaManager( schemaManager ); + JdbmPartition store2 = new JdbmPartition( schemaManager ); store2.setId( "example2" ); store2.setCacheSize( 10 ); store2.setPartitionPath( wkdir2.toURI() ); @@ -208,7 +210,7 @@ public class JdbmStoreTest store2.addIndex( new JdbmIndex( SchemaConstants.OU_AT_OID ) ); store2.addIndex( new JdbmIndex( SchemaConstants.UID_AT_OID ) ); store2.setSuffixDn( EXAMPLE_COM ); - store2.init( schemaManager ); + store2.initialize(); // inject context entry Dn suffixDn = new Dn( schemaManager, "dc=example,dc=com" ); @@ -217,7 +219,7 @@ public class JdbmStoreTest entry.add( "dc", "example" ); entry.add( SchemaConstants.ENTRY_CSN_AT, new CsnFactory( 0 ).newInstance().toString() ); entry.add( SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString() ); - store2.add( entry ); + store2.add( new AddOperationContext( null, entry ) ); // lookup the context entry Long id = store2.getEntryId( suffixDn ); @@ -232,69 +234,68 @@ public class JdbmStoreTest @Test public void testSimplePropertiesUnlocked() throws Exception { - JdbmStore store = new JdbmStore(); - store.setSchemaManager( schemaManager ); - store.setSyncOnWrite( true ); // for code coverage - - assertNull( store.getAliasIndex() ); - Index index = new JdbmIndex( ApacheSchemaConstants.APACHE_ALIAS_AT_OID ); - store.addIndex( index ); - assertNotNull( store.getAliasIndex() ); - - assertEquals( JdbmStore.DEFAULT_CACHE_SIZE, store.getCacheSize() ); - store.setCacheSize( 24 ); - assertEquals( 24, store.getCacheSize() ); - - assertNull( store.getPresenceIndex() ); - store.addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID ) ); - assertNotNull( store.getPresenceIndex() ); + JdbmPartition jdbmPartition = new JdbmPartition( schemaManager ); + jdbmPartition.setSyncOnWrite( true ); // for code coverage - assertNull( store.getOneLevelIndex() ); - store.addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_ONE_LEVEL_AT_OID ) ); - assertNotNull( store.getOneLevelIndex() ); - - assertNull( store.getSubLevelIndex() ); - store.addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID ) ); - assertNotNull( store.getSubLevelIndex() ); - - assertNull( store.getId() ); - store.setId( "foo" ); - assertEquals( "foo", store.getId() ); - - assertNull( store.getRdnIndex() ); - store.addIndex( new JdbmRdnIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID ) ); - assertNotNull( store.getRdnIndex() ); - - assertNull( store.getOneAliasIndex() ); - store.addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID ) ); - assertNotNull( store.getOneAliasIndex() ); + assertNull( jdbmPartition.getAliasIndex() ); + Index index = new JdbmIndex( ApacheSchemaConstants.APACHE_ALIAS_AT_OID ); + ((Store)jdbmPartition).addIndex( index ); + assertNotNull( jdbmPartition.getAliasIndex() ); + + assertEquals( JdbmPartition.DEFAULT_CACHE_SIZE, jdbmPartition.getCacheSize() ); + jdbmPartition.setCacheSize( 24 ); + assertEquals( 24, jdbmPartition.getCacheSize() ); + + assertNull( jdbmPartition.getPresenceIndex() ); + jdbmPartition.addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID ) ); + assertNotNull( jdbmPartition.getPresenceIndex() ); + + assertNull( jdbmPartition.getOneLevelIndex() ); + ((Store)jdbmPartition).addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_ONE_LEVEL_AT_OID ) ); + assertNotNull( jdbmPartition.getOneLevelIndex() ); + + assertNull( jdbmPartition.getSubLevelIndex() ); + ((Store)jdbmPartition).addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_SUB_LEVEL_AT_OID ) ); + assertNotNull( jdbmPartition.getSubLevelIndex() ); + + assertNull( jdbmPartition.getId() ); + jdbmPartition.setId( "foo" ); + assertEquals( "foo", jdbmPartition.getId() ); + + assertNull( jdbmPartition.getRdnIndex() ); + jdbmPartition.addIndex( new JdbmRdnIndex( ApacheSchemaConstants.APACHE_RDN_AT_OID ) ); + assertNotNull( jdbmPartition.getRdnIndex() ); + + assertNull( jdbmPartition.getOneAliasIndex() ); + ((Store)jdbmPartition).addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_ONE_ALIAS_AT_OID ) ); + assertNotNull( jdbmPartition.getOneAliasIndex() ); + + assertNull( jdbmPartition.getSubAliasIndex() ); + jdbmPartition.addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID ) ); + assertNotNull( jdbmPartition.getSubAliasIndex() ); + + assertNull( jdbmPartition.getSuffixDn() ); + jdbmPartition.setSuffixDn( EXAMPLE_COM ); + assertEquals( "dc=example,dc=com", jdbmPartition.getSuffixDn().getName() ); + + assertNotNull( jdbmPartition.getSuffixDn() ); + + assertFalse( jdbmPartition.getUserIndices().hasNext() ); + jdbmPartition.addIndex( new JdbmIndex( "2.5.4.3" ) ); + assertEquals( true, jdbmPartition.getUserIndices().hasNext() ); + + assertNull( jdbmPartition.getPartitionPath() ); + jdbmPartition.setPartitionPath( new File( "." ).toURI() ); + assertEquals( new File( "." ).toURI(), jdbmPartition.getPartitionPath() ); + + assertFalse( jdbmPartition.isInitialized() ); + assertTrue( jdbmPartition.isSyncOnWrite() ); + jdbmPartition.setSyncOnWrite( false ); + assertFalse( jdbmPartition.isSyncOnWrite() ); - assertNull( store.getSubAliasIndex() ); - store.addIndex( new JdbmIndex( ApacheSchemaConstants.APACHE_SUB_ALIAS_AT_OID ) ); - assertNotNull( store.getSubAliasIndex() ); - - assertNull( store.getSuffixDn() ); - store.setSuffixDn( EXAMPLE_COM ); - assertEquals( "dc=example,dc=com", store.getSuffixDn().getName() ); - - assertNotNull( store.getSuffixDn() ); - - assertFalse( store.getUserIndices().hasNext() ); - store.addIndex( new JdbmIndex( "2.5.4.3" ) ); - assertEquals( true, store.getUserIndices().hasNext() ); - - assertNull( store.getPartitionPath() ); - store.setPartitionPath( new File( "." ).toURI() ); - assertEquals( new File( "." ).toURI(), store.getPartitionPath() ); - - assertFalse( store.isInitialized() ); - assertTrue( store.isSyncOnWrite() ); - store.setSyncOnWrite( false ); - assertFalse( store.isSyncOnWrite() ); - - store.sync(); + jdbmPartition.sync(); // make sure all files are closed so that they can be deleted on Windows. - store.destroy(); + jdbmPartition.destroy(); } @@ -531,7 +532,9 @@ public class JdbmStoreTest entry.add( "aliasedObjectName", "cn=Jack Daniels,ou=Engineering,o=Good Times Co." ); entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() ); entry.add( "entryUUID", UUID.randomUUID().toString() ); - store.add( entry ); + + AddOperationContext addContext = new AddOperationContext( null, entry ); + store.add( addContext ); store.delete( 12L ); // drops the alias indices @@ -545,7 +548,7 @@ public class JdbmStoreTest assertEquals( 19, idx.count() ); - Cursor> cursor = idx.forwardCursor( 2L ); + Cursor> cursor = idx.forwardCursor( 2L ); assertTrue( cursor.next() ); assertEquals( 2, ( long ) cursor.get().getId() ); @@ -578,7 +581,8 @@ public class JdbmStoreTest entry.add( "cn", "Martin King" ); entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() ); entry.add( "entryUUID", UUID.randomUUID().toString() ); - store.add( entry ); + AddOperationContext addContext = new AddOperationContext( null, entry ); + store.add( addContext ); cursor = idx.forwardCursor( 2L ); cursor.afterLast(); @@ -602,7 +606,8 @@ public class JdbmStoreTest entry.add( "ou", "Marketing" ); entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() ); entry.add( "entryUUID", UUID.randomUUID().toString() ); - store.add( entry ); + addContext = new AddOperationContext( null, entry ); + store.add( addContext ); // dn id 14 Dn jimmyDn = new Dn( schemaManager, "cn=Jimmy Wales,ou=Marketing, ou=Sales,o=Good Times Co." ); @@ -612,7 +617,8 @@ public class JdbmStoreTest entry.add( "cn", "Jimmy Wales" ); entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() ); entry.add( "entryUUID", UUID.randomUUID().toString() ); - store.add( entry ); + addContext = new AddOperationContext( null, entry ); + store.add( addContext ); newDn = newParentDn.add( marketingDn.getRdn() ); @@ -675,7 +681,8 @@ public class JdbmStoreTest entry.add( "objectClass", "top", "person", "organizationalPerson" ); entry.add( "ou", "Not Present" ); entry.add( "cn", "Martin King" ); - store.add( entry ); + AddOperationContext addContext = new AddOperationContext( null, entry ); + store.add( addContext ); } @@ -686,7 +693,8 @@ public class JdbmStoreTest Entry entry = new DefaultEntry( schemaManager, dn ); entry.add( "ou", "Sales" ); entry.add( "cn", "Martin King" ); - store.add( entry ); + AddOperationContext addContext = new AddOperationContext( null, entry ); + store.add( addContext ); } @@ -715,7 +723,8 @@ public class JdbmStoreTest entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() ); entry.add( "entryUUID", UUID.randomUUID().toString() ); - store.add( entry ); + AddOperationContext addContext = new AddOperationContext( null, entry ); + store.add( addContext ); Rdn rdn = new Rdn( "sn=James" ); @@ -734,7 +743,8 @@ public class JdbmStoreTest entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() ); entry.add( "entryUUID", UUID.randomUUID().toString() ); - store.add( entry ); + AddOperationContext addContext = new AddOperationContext( null, entry ); + store.add( addContext ); Rdn rdn = new Rdn( "sn=Ja\\+es" ); @@ -759,7 +769,8 @@ public class JdbmStoreTest childEntry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() ); childEntry.add( "entryUUID", UUID.randomUUID().toString() ); - store.add( childEntry ); + AddOperationContext addContext = new AddOperationContext( null, childEntry ); + store.add( addContext ); Dn parentDn = new Dn( schemaManager, "ou=Sales,o=Good Times Co." ); @@ -817,13 +828,13 @@ public class JdbmStoreTest assertEquals( "WAlkeR", lookedup.get( "sn" ).get().getString() ); // before replacing - store.modify( dn, add ); + lookedup = store.modify( dn, add ); assertEquals( attribVal, lookedup.get( "sn" ).get().getString() ); // testing the store.modify( dn, mod, entry ) API Modification replace = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, SN_AT, "JWalker" ); - store.modify( dn, replace ); + lookedup = store.modify( dn, replace ); assertEquals( "JWalker", lookedup.get( "sn" ).get().getString() ); assertEquals( 1, lookedup.get( "sn" ).size() ); } @@ -842,16 +853,16 @@ public class JdbmStoreTest assertNotNull( lookedup.get( "sn" ).get() ); - store.modify( dn, add ); + lookedup = store.modify( dn, add ); assertNull( lookedup.get( "sn" ) ); // add an entry for the sake of testing the remove operation add = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, SN_AT, "JWalker" ); - store.modify( dn, add ); + lookedup = store.modify( dn, add ); assertNotNull( lookedup.get( "sn" ) ); Modification remove = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, SN_AT ); - store.modify( dn, remove ); + lookedup = store.modify( dn, remove ); assertNull( lookedup.get( "sn" ) ); } @@ -866,7 +877,8 @@ public class JdbmStoreTest entry.add( "entryCSN", new CsnFactory( 1 ).newInstance().toString() ); entry.add( "entryUUID", UUID.randomUUID().toString() ); - store.add( entry ); + AddOperationContext addContext = new AddOperationContext( null, entry ); + store.add( addContext ); Attribute attrib = new DefaultAttribute( SchemaConstants.OU_AT, OU_AT ); @@ -879,7 +891,7 @@ public class JdbmStoreTest assertNull( lookedup.get( "ou" ) ); // before replacing - store.modify( dn, add ); + lookedup = store.modify( dn, add ); assertEquals( attribVal, lookedup.get( "ou" ).get().getString() ); } @@ -907,8 +919,7 @@ public class JdbmStoreTest assertTrue( uuidIndexDbFile.exists() ); assertTrue( uuidIndexTxtFile.exists() ); - store = new JdbmStore(); - store.setSchemaManager( schemaManager ); + store = new JdbmPartition( schemaManager ); store.setId( "example" ); store.setCacheSize( 10 ); store.setPartitionPath( wkdir.toURI() ); @@ -919,7 +930,7 @@ public class JdbmStoreTest Dn suffixDn = new Dn( schemaManager, "o=Good Times Co." ); store.setSuffixDn( suffixDn ); // init the store to call deleteUnusedIndexFiles() method - store.init( schemaManager ); + store.initialize(); assertFalse( ouIndexDbFile.exists() ); assertFalse( ouIndexTxtFile.exists() ); Modified: directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java?rev=1149411&r1=1149410&r2=1149411&view=diff ============================================================================== --- directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java (original) +++ directory/apacheds/trunk/jdbm-partition/src/test/java/org/apache/directory/server/core/partition/tree/PartitionTreeTest.java Fri Jul 22 00:02:02 2011 @@ -23,13 +23,24 @@ package org.apache.directory.server.core import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.File; import org.apache.directory.server.core.partition.Partition; +import org.apache.directory.server.core.partition.impl.btree.jdbm.DupsContainerCursorTest; import org.apache.directory.server.core.partition.impl.btree.jdbm.JdbmPartition; import org.apache.directory.shared.ldap.model.exception.LdapException; import org.apache.directory.shared.ldap.model.name.Dn; import org.apache.directory.shared.ldap.model.name.Rdn; +import org.apache.directory.shared.ldap.model.schema.SchemaManager; +import org.apache.directory.shared.ldap.schemaextractor.SchemaLdifExtractor; +import org.apache.directory.shared.ldap.schemaextractor.impl.DefaultSchemaLdifExtractor; +import org.apache.directory.shared.ldap.schemaloader.LdifSchemaLoader; +import org.apache.directory.shared.ldap.schemamanager.impl.DefaultSchemaManager; import org.apache.directory.shared.ldap.util.tree.DnNode; +import org.apache.directory.shared.util.exception.Exceptions; +import org.junit.BeforeClass; import org.junit.Test; @@ -40,111 +51,144 @@ import org.junit.Test; */ public class PartitionTreeTest { + private static SchemaManager schemaManager; + + + @BeforeClass + public static void init() throws Exception + { + String workingDirectory = System.getProperty( "workingDirectory" ); + + if ( workingDirectory == null ) + { + String path = DupsContainerCursorTest.class.getResource( "" ).getPath(); + int targetPos = path.indexOf( "target" ); + workingDirectory = path.substring( 0, targetPos + 6 ); + } + + File schemaRepository = new File( workingDirectory, "schema" ); + SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) ); + extractor.extractOrCopy( true ); + LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository ); + schemaManager = new DefaultSchemaManager( loader ); + + boolean loaded = schemaManager.loadAllEnabled(); + + if ( !loaded ) + { + fail( "Schema load failed : " + Exceptions.printErrors(schemaManager.getErrors()) ); + } + } + + /** * Test the addition of a single partition */ - @Test public void testNewPartitionTree() throws LdapException + @Test + public void testNewPartitionTree() throws LdapException { /** A structure to hold all the partitions */ DnNode partitionLookupTree = new DnNode(); - Dn suffix = new Dn( "dc=example, dc=com" ); - Partition partition = new JdbmPartition(); - partition.setSuffix( suffix ); + Dn suffix = new Dn( schemaManager, "dc=example, dc=com" ); + Partition partition = new JdbmPartition( schemaManager ); + partition.setSuffixDn( suffix ); partitionLookupTree.add( suffix, partition ); assertNotNull( partitionLookupTree ); assertTrue( partitionLookupTree.hasChildren() ); - assertTrue( partitionLookupTree.contains( new Rdn( "dc=com" ) ) ); + assertTrue( partitionLookupTree.contains( new Rdn( schemaManager, "dc=com" ) ) ); - DnNode child = partitionLookupTree.getChild( new Rdn( "dc=com" ) ); + DnNode child = partitionLookupTree.getChild( new Rdn( schemaManager, "dc=com" ) ); assertTrue( child.hasChildren() ); - assertTrue( child.contains( new Rdn( "dc=example" ) ) ); + assertTrue( child.contains( new Rdn( schemaManager, "dc=example" ) ) ); - child = child.getChild( new Rdn( "dc=example" ) ); - assertEquals( "dc=example, dc=com", child.getElement().getSuffix().getName() ); + child = child.getChild( new Rdn( schemaManager, "dc=example" ) ); + assertEquals( "dc=example, dc=com", child.getElement().getSuffixDn().getName() ); } /** * Test the addition of a two disjointed partition */ - @Test public void testNewPartitionTree2Nodes() throws LdapException + @Test + public void testNewPartitionTree2Nodes() throws LdapException { /** A structure to hold all the partitions */ DnNode partitionLookupTree = new DnNode(); - Dn suffix1 = new Dn( "dc=example, dc=com" ); - Partition partition1 = new JdbmPartition(); - partition1.setSuffix( suffix1 ); + Dn suffix1 = new Dn( schemaManager, "dc=example, dc=com" ); + Partition partition1 = new JdbmPartition( schemaManager ); + partition1.setSuffixDn( suffix1 ); partitionLookupTree.add( suffix1, partition1 ); - Dn suffix2 = new Dn( "ou=system" ); - Partition partition2 = new JdbmPartition(); - partition2.setSuffix( suffix2 ); + Dn suffix2 = new Dn( schemaManager, "ou=system" ); + Partition partition2 = new JdbmPartition( schemaManager ); + partition2.setSuffixDn( suffix2 ); partitionLookupTree.add( suffix2, partition2 ); assertNotNull( partitionLookupTree ); assertTrue( partitionLookupTree.hasChildren() ); - assertTrue( partitionLookupTree.contains( new Rdn( "ou=system" ) ) ); - assertTrue( partitionLookupTree.contains( new Rdn( "dc=com" ) ) ); + assertTrue( partitionLookupTree.contains( new Rdn( schemaManager, "ou=system" ) ) ); + assertTrue( partitionLookupTree.contains( new Rdn( schemaManager, "dc=com" ) ) ); - DnNode child = partitionLookupTree.getChild( new Rdn( "ou=system" ) ); + DnNode child = partitionLookupTree.getChild( new Rdn( schemaManager, "ou=system" ) ); assertTrue( child.isLeaf() ); - assertEquals( "ou=system", child.getElement().getSuffix().getName() ); + assertEquals( "ou=system", child.getElement().getSuffixDn().getName() ); - child = partitionLookupTree.getChild( new Rdn( "dc=com" ) ); + child = partitionLookupTree.getChild( new Rdn( schemaManager, "dc=com" ) ); assertTrue( child.hasChildren() ); - assertTrue( child.contains( new Rdn( "dc=example" ) ) ); + assertTrue( child.contains( new Rdn( schemaManager, "dc=example" ) ) ); - child = child.getChild( new Rdn( "dc=example" ) ); + child = child.getChild( new Rdn( schemaManager, "dc=example" ) ); assertTrue( child.isLeaf() ); - assertEquals( "dc=example, dc=com", child.getElement().getSuffix().getName() ); + assertEquals( "dc=example, dc=com", child.getElement().getSuffixDn().getName() ); } /** * Test the addition of a two partitions with the same root */ - @Test public void testNewPartitionTree2NodesWithSameRoot() throws LdapException + @Test + public void testNewPartitionTree2NodesWithSameRoot() throws LdapException { /** A structure to hold all the partitions */ DnNode partitionLookupTree = new DnNode(); - Dn suffix1 = new Dn( "dc=example1, dc=com" ); - Partition partition1 = new JdbmPartition(); - partition1.setSuffix( suffix1 ); + Dn suffix1 = new Dn( schemaManager, "dc=example1, dc=com" ); + Partition partition1 = new JdbmPartition( schemaManager ); + partition1.setSuffixDn( suffix1 ); partitionLookupTree.add( suffix1, partition1 ); - Dn suffix2 = new Dn( "dc=example2, dc=com" ); - Partition partition2 = new JdbmPartition(); - partition2.setSuffix( suffix2 ); + Dn suffix2 = new Dn( schemaManager, "dc=example2, dc=com" ); + Partition partition2 = new JdbmPartition( schemaManager ); + partition2.setSuffixDn( suffix2 ); partitionLookupTree.add( suffix2, partition2 ); assertNotNull( partitionLookupTree ); assertTrue( partitionLookupTree.hasChildren() ); - assertTrue( partitionLookupTree.contains( new Rdn( "dc=com" ) ) ); + assertTrue( partitionLookupTree.contains( new Rdn( schemaManager, "dc=com" ) ) ); - DnNode child = partitionLookupTree.getChild( new Rdn( "dc=com" ) ); + DnNode child = partitionLookupTree.getChild( new Rdn( schemaManager, "dc=com" ) ); assertTrue( child.hasChildren() ); - child = partitionLookupTree.getChild( new Rdn( "dc=com" ) ); + child = partitionLookupTree.getChild( new Rdn( schemaManager, "dc=com" ) ); assertTrue( child.hasChildren() ); - assertTrue( child.contains( new Rdn( "dc=example1" ) ) ); - assertTrue( child.contains( new Rdn( "dc=example2" ) ) ); + assertTrue( child.contains( new Rdn( schemaManager, "dc=example1" ) ) ); + assertTrue( child.contains( new Rdn( schemaManager, "dc=example2" ) ) ); - DnNode child1 = child.getChild( new Rdn( "dc=example1" ) ); + DnNode child1 = child.getChild( new Rdn( schemaManager, "dc=example1" ) ); assertTrue( child1.isLeaf() ); - assertEquals( "dc=example1, dc=com", child1.getElement().getSuffix().getName() ); + assertEquals( "dc=example1, dc=com", child1.getElement().getSuffixDn().getName() ); - DnNode child2 = child.getChild( new Rdn( "dc=example1" ) ); + DnNode child2 = child.getChild( new Rdn( schemaManager, "dc=example1" ) ); assertTrue( child2.isLeaf() ); - assertEquals( "dc=example1, dc=com", child2.getElement().getSuffix().getName() ); + assertEquals( "dc=example1, dc=com", child2.getElement().getSuffixDn().getName() ); } } Modified: directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/AbstractLdifPartition.java URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/AbstractLdifPartition.java?rev=1149411&r1=1149410&r2=1149411&view=diff ============================================================================== --- directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/AbstractLdifPartition.java (original) +++ directory/apacheds/trunk/ldif-partition/src/main/java/org/apache/directory/server/core/partition/ldif/AbstractLdifPartition.java Fri Jul 22 00:02:02 2011 @@ -21,20 +21,10 @@ package org.apache.directory.server.core.partition.ldif; -import java.util.Iterator; +import java.net.URI; -import org.apache.directory.server.core.interceptor.context.UnbindOperationContext; -import org.apache.directory.server.core.partition.Partition; import org.apache.directory.server.core.partition.impl.avl.AvlPartition; -import org.apache.directory.server.core.partition.impl.btree.AbstractBTreePartition; -import org.apache.directory.server.xdbm.Index; -import org.apache.directory.server.xdbm.IndexCursor; import org.apache.directory.shared.ldap.model.csn.CsnFactory; -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.name.Dn; -import org.apache.directory.shared.ldap.model.schema.AttributeType; import org.apache.directory.shared.ldap.model.schema.SchemaManager; @@ -43,11 +33,8 @@ import org.apache.directory.shared.ldap. * * @author Apache Directory Project */ -public abstract class AbstractLdifPartition extends AbstractBTreePartition +public abstract class AbstractLdifPartition extends AvlPartition { - /** We use a partition to manage searches on this partition */ - protected AvlPartition wrappedPartition; - /** The extension used for LDIF entry files */ protected static final String CONF_FILE_EXTN = ".ldif"; @@ -55,26 +42,26 @@ public abstract class AbstractLdifPartit protected static CsnFactory defaultCSNFactory; - public AbstractLdifPartition() + public AbstractLdifPartition( SchemaManager schemaManager ) { + super( schemaManager ); + // Create the CsnFactory with a invalid ReplicaId // @TODO : inject a correct ReplicaId defaultCSNFactory = new CsnFactory( 0 ); } - /** - * @return the contextEntry - */ - public Entry getContextEntry() + @Override + protected void doDestroy() throws Exception { - return contextEntry; + // Nothing to do : we don't have index } - + /** * @return the wrappedPartition - */ + * public Partition getWrappedPartition() { return wrappedPartition; @@ -83,7 +70,7 @@ public abstract class AbstractLdifPartit /** * @param wrappedPartition the wrappedPartition to set - */ + * public void setWrappedPartition( AvlPartition wrappedPartition ) { this.wrappedPartition = wrappedPartition; @@ -92,7 +79,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public void addIndexOn( Index index ) throws Exception { wrappedPartition.addIndexOn( index ); @@ -101,7 +88,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public int count() throws Exception { return wrappedPartition.count(); @@ -110,7 +97,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * @Override protected void doDestroy() throws Exception { @@ -120,7 +107,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public Index getAliasIndex() { return wrappedPartition.getAliasIndex(); @@ -129,7 +116,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * @Override public int getChildCount( Long id ) throws LdapException { @@ -139,7 +126,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public Dn getEntryDn( Long id ) throws Exception { return wrappedPartition.getEntryDn( id ); @@ -148,7 +135,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * @Override public Long getEntryId( Dn dn ) throws LdapException { @@ -158,7 +145,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public Index getOneAliasIndex() { return wrappedPartition.getOneAliasIndex(); @@ -167,7 +154,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public Index getOneLevelIndex() { return wrappedPartition.getOneLevelIndex(); @@ -176,7 +163,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public Index getPresenceIndex() { return wrappedPartition.getPresenceIndex(); @@ -185,7 +172,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public Index getSubAliasIndex() { return wrappedPartition.getSubAliasIndex(); @@ -194,7 +181,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public Index getSubLevelIndex() { return wrappedPartition.getSubLevelIndex(); @@ -203,8 +190,8 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ - public Index getSystemIndex( AttributeType attributeType ) throws Exception + * + public Index getSystemIndex( AttributeType attributeType ) throws IndexNotFoundException { return wrappedPartition.getSystemIndex( attributeType ); } @@ -212,7 +199,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public Iterator getSystemIndices() { return wrappedPartition.getSystemIndices(); @@ -221,8 +208,8 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ - public Index getUserIndex( AttributeType attributeType ) throws Exception + * + public Index getUserIndex( AttributeType attributeType ) throws IndexNotFoundException { return wrappedPartition.getUserIndex( attributeType ); } @@ -230,7 +217,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * public Iterator getUserIndices() { return wrappedPartition.getUserIndices(); @@ -239,8 +226,8 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ - public boolean hasSystemIndexOn( AttributeType attributeType ) throws Exception + * + public boolean hasSystemIndexOn( AttributeType attributeType ) throws LdapException { return wrappedPartition.hasSystemIndexOn( attributeType ); } @@ -248,8 +235,8 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ - public boolean hasUserIndexOn( AttributeType attributeType ) throws Exception + * + public boolean hasUserIndexOn( AttributeType attributeType ) throws LdapException { return wrappedPartition.hasUserIndexOn( attributeType ); } @@ -257,7 +244,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * @Override public boolean isInitialized() { @@ -267,7 +254,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * @Override public IndexCursor list( Long id ) throws LdapException { @@ -277,17 +264,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ - @Override - public Entry lookup( Long id ) throws LdapException - { - return wrappedPartition.lookup( id ); - } - - - /** - * {@inheritDoc} - */ + * @Override public void setSchemaManager( SchemaManager schemaManager ) { @@ -298,7 +275,7 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * @Override public void sync() throws Exception { @@ -314,32 +291,40 @@ public abstract class AbstractLdifPartit /** * {@inheritDoc} - */ + * @Override - public String getId() + public void setId( String id ) { - return super.getId(); + super.setId( id ); + wrappedPartition.setId( id ); } /** * {@inheritDoc} - */ + * @Override - public void setId( String id ) + public void setSuffixDn( Dn suffix ) throws LdapInvalidDnException { - super.setId( id ); - wrappedPartition.setId( id ); + super.setSuffixDn( suffix ); + wrappedPartition.setSuffixDn( suffix ); } /** * {@inheritDoc} */ - @Override - public void setSuffix( Dn suffix ) throws LdapInvalidDnException + public Long getDefaultId() + { + return 1L; + } + + + /** + * {@inheritDoc} + */ + public URI getPartitionPath() { - super.setSuffix( suffix ); - wrappedPartition.setSuffix( suffix ); + return partitionPath; } }