Modified: directory/apacheds/branches/apacheds-txns/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java?rev=1296527&r1=1296526&r2=1296527&view=diff ============================================================================== --- directory/apacheds/branches/apacheds-txns/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java (original) +++ directory/apacheds/branches/apacheds-txns/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java Sat Mar 3 00:20:10 2012 @@ -52,7 +52,6 @@ import org.apache.directory.server.core. import org.apache.directory.server.core.api.interceptor.context.UnbindOperationContext; import org.apache.directory.server.core.api.partition.AbstractPartition; import org.apache.directory.server.core.api.partition.Partition; -import org.apache.directory.server.i18n.I18n; import org.apache.directory.server.core.api.partition.index.GenericIndex; import org.apache.directory.server.core.api.partition.index.Index; import org.apache.directory.server.core.api.partition.index.IndexCursor; @@ -64,6 +63,7 @@ import org.apache.directory.server.core. import org.apache.directory.server.core.shared.partition.EntryCursorAdaptor; import org.apache.directory.server.core.shared.partition.OperationExecutionManagerFactory; import org.apache.directory.server.core.shared.txn.TxnManagerFactory; +import org.apache.directory.server.i18n.I18n; import org.apache.directory.server.xdbm.Store; import org.apache.directory.server.xdbm.search.Optimizer; import org.apache.directory.server.xdbm.search.SearchEngine; @@ -102,10 +102,10 @@ public abstract class AbstractBTreeParti /** the search engine used to search the database */ protected SearchEngine searchEngine; - + /** The optimizer to use during search operation */ protected Optimizer optimizer; - + /** Tells if the Optimizer is enabled */ protected boolean optimizerEnabled = true; @@ -165,17 +165,18 @@ public abstract class AbstractBTreeParti /** the one level scope alias index */ protected Index oneAliasIdx; - + /** Cached attributes types to avoid lookup all over the code */ protected AttributeType OBJECT_CLASS_AT; protected AttributeType ENTRY_CSN_AT; protected AttributeType ENTRY_UUID_AT; protected AttributeType ALIASED_OBJECT_NAME_AT; - + /** Txn and Operation manager factories */ protected TxnManagerFactory txnManagerFactory; protected OperationExecutionManagerFactory executionManagerFactory; + // ------------------------------------------------------------------------ // C O N S T R U C T O R S // ------------------------------------------------------------------------ @@ -184,7 +185,7 @@ public abstract class AbstractBTreeParti * Creates a B-tree based context partition. */ protected AbstractBTreePartition( SchemaManager schemaManager, TxnManagerFactory txnManagerFactory, - OperationExecutionManagerFactory executionManagerFactory ) + OperationExecutionManagerFactory executionManagerFactory ) { this.schemaManager = schemaManager; this.txnManagerFactory = txnManagerFactory; @@ -212,8 +213,8 @@ public abstract class AbstractBTreeParti { return cacheSize; } - - + + /** * Used to specify the entry cache size for a Partition. Various Partition * implementations may interpret this value in different ways: i.e. total cache @@ -246,7 +247,7 @@ public abstract class AbstractBTreeParti this.optimizerEnabled = optimizerEnabled; } - + /** * Sets the path in which this Partition stores data. This may be an URL to * a file or directory, or an JDBC URL. @@ -268,6 +269,7 @@ public abstract class AbstractBTreeParti return isSyncOnWrite.get(); } + /** * {@inheritDoc} */ @@ -287,7 +289,7 @@ public abstract class AbstractBTreeParti // add missing system indices if ( getPresenceIndex() == null ) { - Index index = new GenericIndex( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID ) ; + Index index = new GenericIndex( ApacheSchemaConstants.APACHE_PRESENCE_AT_OID ); index.setWkDirPath( partitionPath ); addIndex( index ); } @@ -405,7 +407,7 @@ public abstract class AbstractBTreeParti userIndices = tmp; } - + /** * Gets the DefaultSearchEngine used by this ContextPartition to search the @@ -422,7 +424,7 @@ public abstract class AbstractBTreeParti // ----------------------------------------------------------------------- // Miscellaneous abstract methods // ----------------------------------------------------------------------- - + /** * Convert and initialize an index for a specific store implementation. * @@ -509,7 +511,7 @@ public abstract class AbstractBTreeParti } } - + /** * {@inheritDoc} */ @@ -521,6 +523,7 @@ public abstract class AbstractBTreeParti setupUserIndices(); } + //--------------------------------------------------------------------------------------------- // The Add operation //--------------------------------------------------------------------------------------------- @@ -529,156 +532,156 @@ public abstract class AbstractBTreeParti */ public void add( AddOperationContext addContext ) throws LdapException { -// try -// { -// Entry entry = ( ( ClonedServerEntry ) addContext.getEntry() ).getClonedEntry(); -// Dn entryDn = entry.getDn(); -// -// // check if the entry already exists -// if ( getEntryId( entryDn ) != null ) -// { -// LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( -// I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, entryDn.getName() ) ); -// throw ne; -// } -// -// UUID parentId = null; -// -// // -// // Suffix entry cannot have a parent since it is the root so it is -// // capped off using the zero value which no entry can have since -// // entry sequences start at 1. -// // -// Dn parentDn = null; -// ParentIdAndRdn key = null; -// -// if ( entryDn.equals( suffixDn ) ) -// { -// parentId = getRootId(); -// key = new ParentIdAndRdn( parentId, suffixDn.getRdns() ); -// } -// else -// { -// parentDn = entryDn.getParent(); -// parentId = getEntryId( parentDn ); -// -// key = new ParentIdAndRdn( parentId, entryDn.getRdn() ); -// } -// -// // don't keep going if we cannot find the parent Id -// if ( parentId == null ) -// { -// throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_216_ID_FOR_PARENT_NOT_FOUND, parentDn ) ); -// } -// -// // Get a new ID for the added entry -// UUID id = master.getNextId( entry ); -// -// // Update the RDN index -// rdnIdx.add( key, id ); -// -// // Update the ObjectClass index -// Attribute objectClass = entry.get( OBJECT_CLASS_AT ); -// -// if ( objectClass == null ) -// { -// String msg = I18n.err( I18n.ERR_217, entryDn.getName(), entry ); -// ResultCodeEnum rc = ResultCodeEnum.OBJECT_CLASS_VIOLATION; -// LdapSchemaViolationException e = new LdapSchemaViolationException( rc, msg ); -// //e.setResolvedName( entryDn ); -// throw e; -// } -// -// for ( Value value : objectClass ) -// { -// objectClassIdx.add( value.getString(), id ); -// } -// -// if ( objectClass.contains( SchemaConstants.ALIAS_OC ) ) -// { -// Attribute aliasAttr = entry.get( ALIASED_OBJECT_NAME_AT ); -// addAliasIndices( id, entryDn, aliasAttr.getString() ); -// } -// -// // Update the OneLevel index -// oneLevelIdx.add( parentId, id ); -// -// // Update the SubLevel index -// UUID tempId = parentId; -// -// while ( ( tempId != null ) && ( !tempId.equals( getRootId() ) ) && ( !tempId.equals( getSuffixId() ) ) ) -// { -// subLevelIdx.add( tempId, id ); -// tempId = getParentId( tempId ); -// } -// -// // making entry an ancestor/descendent of itself in sublevel index -// subLevelIdx.add( id, id ); -// -// // Update the EntryCsn index -// Attribute entryCsn = entry.get( ENTRY_CSN_AT ); -// -// if ( entryCsn == null ) -// { -// String msg = I18n.err( I18n.ERR_219, entryDn.getName(), entry ); -// throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg ); -// } -// -// entryCsnIdx.add( entryCsn.getString(), id ); -// -// // Update the EntryUuid index -// Attribute entryUuid = entry.get( ENTRY_UUID_AT ); -// -// if ( entryUuid == null ) -// { -// String msg = I18n.err( I18n.ERR_220, entryDn.getName(), entry ); -// throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg ); -// } -// -// entryUuidIdx.add( entryUuid.getString(), id ); -// -// // Now work on the user defined userIndices -// for ( Attribute attribute : entry ) -// { -// AttributeType attributeType = attribute.getAttributeType(); -// String attributeOid = attributeType.getOid(); -// -// if ( hasUserIndexOn( attributeType ) ) -// { -// Index idx = ( Index ) getUserIndex( attributeType ); -// -// // here lookup by attributeId is OK since we got attributeId from -// // the entry via the enumeration - it's in there as is for sure -// -// for ( Value value : attribute ) -// { -// idx.add( value.getValue(), id ); -// } -// -// // Adds only those attributes that are indexed -// presenceIdx.add( attributeOid, id ); -// } -// } -// -// // Add the parentId in the entry -// entry.put( SchemaConstants.ENTRY_PARENT_ID_AT, parentId.toString() ); -// -// // And finally add the entry into the master table -// master.put( id, entry ); -// -// if ( isSyncOnWrite.get() ) -// { -// sync(); -// } -// } -// catch ( LdapException le ) -// { -// throw le; -// } -// catch ( Exception e ) -// { -// throw new LdapException( e ); -// } + // try + // { + // Entry entry = ( ( ClonedServerEntry ) addContext.getEntry() ).getClonedEntry(); + // Dn entryDn = entry.getDn(); + // + // // check if the entry already exists + // if ( getEntryId( entryDn ) != null ) + // { + // LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( + // I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, entryDn.getName() ) ); + // throw ne; + // } + // + // UUID parentId = null; + // + // // + // // Suffix entry cannot have a parent since it is the root so it is + // // capped off using the zero value which no entry can have since + // // entry sequences start at 1. + // // + // Dn parentDn = null; + // ParentIdAndRdn key = null; + // + // if ( entryDn.equals( suffixDn ) ) + // { + // parentId = getRootId(); + // key = new ParentIdAndRdn( parentId, suffixDn.getRdns() ); + // } + // else + // { + // parentDn = entryDn.getParent(); + // parentId = getEntryId( parentDn ); + // + // key = new ParentIdAndRdn( parentId, entryDn.getRdn() ); + // } + // + // // don't keep going if we cannot find the parent Id + // if ( parentId == null ) + // { + // throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_216_ID_FOR_PARENT_NOT_FOUND, parentDn ) ); + // } + // + // // Get a new ID for the added entry + // UUID id = master.getNextId( entry ); + // + // // Update the RDN index + // rdnIdx.add( key, id ); + // + // // Update the ObjectClass index + // Attribute objectClass = entry.get( OBJECT_CLASS_AT ); + // + // if ( objectClass == null ) + // { + // String msg = I18n.err( I18n.ERR_217, entryDn.getName(), entry ); + // ResultCodeEnum rc = ResultCodeEnum.OBJECT_CLASS_VIOLATION; + // LdapSchemaViolationException e = new LdapSchemaViolationException( rc, msg ); + // //e.setResolvedName( entryDn ); + // throw e; + // } + // + // for ( Value value : objectClass ) + // { + // objectClassIdx.add( value.getString(), id ); + // } + // + // if ( objectClass.contains( SchemaConstants.ALIAS_OC ) ) + // { + // Attribute aliasAttr = entry.get( ALIASED_OBJECT_NAME_AT ); + // addAliasIndices( id, entryDn, aliasAttr.getString() ); + // } + // + // // Update the OneLevel index + // oneLevelIdx.add( parentId, id ); + // + // // Update the SubLevel index + // UUID tempId = parentId; + // + // while ( ( tempId != null ) && ( !tempId.equals( getRootId() ) ) && ( !tempId.equals( getSuffixId() ) ) ) + // { + // subLevelIdx.add( tempId, id ); + // tempId = getParentId( tempId ); + // } + // + // // making entry an ancestor/descendent of itself in sublevel index + // subLevelIdx.add( id, id ); + // + // // Update the EntryCsn index + // Attribute entryCsn = entry.get( ENTRY_CSN_AT ); + // + // if ( entryCsn == null ) + // { + // String msg = I18n.err( I18n.ERR_219, entryDn.getName(), entry ); + // throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg ); + // } + // + // entryCsnIdx.add( entryCsn.getString(), id ); + // + // // Update the EntryUuid index + // Attribute entryUuid = entry.get( ENTRY_UUID_AT ); + // + // if ( entryUuid == null ) + // { + // String msg = I18n.err( I18n.ERR_220, entryDn.getName(), entry ); + // throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, msg ); + // } + // + // entryUuidIdx.add( entryUuid.getString(), id ); + // + // // Now work on the user defined userIndices + // for ( Attribute attribute : entry ) + // { + // AttributeType attributeType = attribute.getAttributeType(); + // String attributeOid = attributeType.getOid(); + // + // if ( hasUserIndexOn( attributeType ) ) + // { + // Index idx = ( Index ) getUserIndex( attributeType ); + // + // // here lookup by attributeId is OK since we got attributeId from + // // the entry via the enumeration - it's in there as is for sure + // + // for ( Value value : attribute ) + // { + // idx.add( value.getValue(), id ); + // } + // + // // Adds only those attributes that are indexed + // presenceIdx.add( attributeOid, id ); + // } + // } + // + // // Add the parentId in the entry + // entry.put( SchemaConstants.ENTRY_PARENT_ID_AT, parentId.toString() ); + // + // // And finally add the entry into the master table + // master.put( id, entry ); + // + // if ( isSyncOnWrite.get() ) + // { + // sync(); + // } + // } + // catch ( LdapException le ) + // { + // throw le; + // } + // catch ( Exception e ) + // { + // throw new LdapException( e ); + // } } @@ -690,25 +693,25 @@ public abstract class AbstractBTreeParti */ public void delete( DeleteOperationContext deleteContext ) throws LdapException { -// Dn dn = deleteContext.getDn(); -// -// UUID id = getEntryId( dn ); -// -// // don't continue if id is null -// if ( id == null ) -// { -// throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_699, dn ) ); -// } -// -// if ( getChildCount( id ) > 0 ) -// { -// LdapContextNotEmptyException cnee = new LdapContextNotEmptyException( I18n.err( I18n.ERR_700, dn ) ); -// //cnee.setRemainingName( dn ); -// throw cnee; -// } -// -// // We now defer the deletion to the implementing class -// delete( id ); + // Dn dn = deleteContext.getDn(); + // + // UUID id = getEntryId( dn ); + // + // // don't continue if id is null + // if ( id == null ) + // { + // throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_699, dn ) ); + // } + // + // if ( getChildCount( id ) > 0 ) + // { + // LdapContextNotEmptyException cnee = new LdapContextNotEmptyException( I18n.err( I18n.ERR_700, dn ) ); + // //cnee.setRemainingName( dn ); + // throw cnee; + // } + // + // // We now defer the deletion to the implementing class + // delete( id ); } @@ -719,78 +722,78 @@ public abstract class AbstractBTreeParti */ public void delete( UUID id ) throws LdapException { -// try -// { -// // First get the entry -// Entry entry = master.get( id ); -// -// if ( entry == null ) -// { -// // Not allowed -// throw new LdapNoSuchObjectException( "Cannot find an entry for ID " + id ); -// } -// -// Attribute objectClass = entry.get( OBJECT_CLASS_AT ); -// -// if ( objectClass.contains( SchemaConstants.ALIAS_OC ) ) -// { -// dropAliasIndices( id ); -// } -// -// // Update the ObjectClass index -// for ( Value value : objectClass ) -// { -// objectClassIdx.drop( value.getString(), id ); -// } -// -// // Update the rdn, oneLevel, subLevel, entryCsn and entryUuid indexes -// rdnIdx.drop( id ); -// oneLevelIdx.drop( id ); -// subLevelIdx.drop( id ); -// entryCsnIdx.drop( id ); -// entryUuidIdx.drop( id ); -// -// // Update the user indexes -// for ( Attribute attribute : entry ) -// { -// AttributeType attributeType = attribute.getAttributeType(); -// String attributeOid = attributeType.getOid(); -// -// if ( hasUserIndexOn( attributeType ) ) -// { -// Index index = getUserIndex( attributeType ); -// -// // here lookup by attributeId is ok since we got attributeId from -// // the entry via the enumeration - it's in there as is for sure -// for ( Value value : attribute ) -// { -// ( ( Index ) index ).drop( value.getValue(), id ); -// } -// -// presenceIdx.drop( attributeOid, id ); -// } -// } -// -// master.remove( id ); -// -// // if this is a context entry reset the master table counter -// if ( id.equals( getDefaultId() ) ) -// { -// master.resetCounter(); -// } -// -// if ( isSyncOnWrite.get() ) -// { -// sync(); -// } -// } -// catch ( Exception e ) -// { -// throw new LdapOperationErrorException( e.getMessage(), e ); -// } + // try + // { + // // First get the entry + // Entry entry = master.get( id ); + // + // if ( entry == null ) + // { + // // Not allowed + // throw new LdapNoSuchObjectException( "Cannot find an entry for ID " + id ); + // } + // + // Attribute objectClass = entry.get( OBJECT_CLASS_AT ); + // + // if ( objectClass.contains( SchemaConstants.ALIAS_OC ) ) + // { + // dropAliasIndices( id ); + // } + // + // // Update the ObjectClass index + // for ( Value value : objectClass ) + // { + // objectClassIdx.drop( value.getString(), id ); + // } + // + // // Update the rdn, oneLevel, subLevel, entryCsn and entryUuid indexes + // rdnIdx.drop( id ); + // oneLevelIdx.drop( id ); + // subLevelIdx.drop( id ); + // entryCsnIdx.drop( id ); + // entryUuidIdx.drop( id ); + // + // // Update the user indexes + // for ( Attribute attribute : entry ) + // { + // AttributeType attributeType = attribute.getAttributeType(); + // String attributeOid = attributeType.getOid(); + // + // if ( hasUserIndexOn( attributeType ) ) + // { + // Index index = getUserIndex( attributeType ); + // + // // here lookup by attributeId is ok since we got attributeId from + // // the entry via the enumeration - it's in there as is for sure + // for ( Value value : attribute ) + // { + // ( ( Index ) index ).drop( value.getValue(), id ); + // } + // + // presenceIdx.drop( attributeOid, id ); + // } + // } + // + // master.remove( id ); + // + // // if this is a context entry reset the master table counter + // if ( id.equals( getDefaultId() ) ) + // { + // master.resetCounter(); + // } + // + // if ( isSyncOnWrite.get() ) + // { + // sync(); + // } + // } + // catch ( Exception e ) + // { + // throw new LdapOperationErrorException( e.getMessage(), e ); + // } } - + //--------------------------------------------------------------------------------------------- // The List operation //--------------------------------------------------------------------------------------------- @@ -801,9 +804,9 @@ public abstract class AbstractBTreeParti { try { - return new BaseEntryFilteringCursor( - new EntryCursorAdaptor( this, - list( getEntryId( listContext.getDn() ) ), txnManagerFactory ), listContext ); + return new BaseEntryFilteringCursor( + new EntryCursorAdaptor( this, + list( getEntryId( listContext.getDn() ) ), txnManagerFactory ), listContext ); } catch ( Exception e ) { @@ -811,21 +814,21 @@ public abstract class AbstractBTreeParti } } - + /** * {@inheritDoc} */ public final IndexCursor list( UUID id ) throws LdapException { try - { + { // We use the OneLevel index to get all the entries from a starting point // and below IndexCursor cursor = oneLevelIdx.forwardCursor( id ); cursor.beforeFirst(); - + return cursor; - } + } catch ( Exception e ) { throw new LdapOperationErrorException( e.getMessage(), e ); @@ -833,7 +836,6 @@ public abstract class AbstractBTreeParti } - //--------------------------------------------------------------------------------------------- // The Search operation //--------------------------------------------------------------------------------------------- @@ -852,7 +854,8 @@ public abstract class AbstractBTreeParti underlying = searchEngine.cursor( dn, derefMode, filter, searchCtls ); - return new BaseEntryFilteringCursor( new EntryCursorAdaptor( this, underlying, txnManagerFactory ), searchContext ); + return new BaseEntryFilteringCursor( new EntryCursorAdaptor( this, underlying, txnManagerFactory ), + searchContext ); } catch ( LdapException le ) { @@ -884,7 +887,8 @@ public abstract class AbstractBTreeParti Entry entry = lookup( id ); // Remove all the attributes if the NO_ATTRIBUTE flag is set and there is no requested attribute - if ( lookupContext.hasNoAttribute() && ( ( lookupContext.getAttrsId() == null ) || lookupContext.getAttrsId().size() == 0 ) ) + if ( lookupContext.hasNoAttribute() + && ( ( lookupContext.getAttrsId() == null ) || lookupContext.getAttrsId().size() == 0 ) ) { entry.clear(); @@ -899,12 +903,12 @@ public abstract class AbstractBTreeParti } else { - for ( Attribute attribute : ( ((ClonedServerEntry)entry).getOriginalEntry() ).getAttributes() ) + for ( Attribute attribute : ( ( ( ClonedServerEntry ) entry ).getOriginalEntry() ).getAttributes() ) { AttributeType attributeType = attribute.getAttributeType(); String oid = attributeType.getOid(); - if ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) + if ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) { if ( !lookupContext.getAttrsId().contains( oid ) ) { @@ -918,11 +922,11 @@ public abstract class AbstractBTreeParti { if ( lookupContext.hasAllOperational() ) { - for ( Attribute attribute : ( ((ClonedServerEntry)entry).getOriginalEntry() ).getAttributes() ) + for ( Attribute attribute : ( ( ( ClonedServerEntry ) entry ).getOriginalEntry() ).getAttributes() ) { AttributeType attributeType = attribute.getAttributeType(); - if ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) + if ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) { entry.removeAttributes( attributeType ); } @@ -932,11 +936,11 @@ public abstract class AbstractBTreeParti { if ( lookupContext.getAttrsId().size() == 0 ) { - for ( Attribute attribute : ( ((ClonedServerEntry)entry).getOriginalEntry() ).getAttributes() ) + for ( Attribute attribute : ( ( ( ClonedServerEntry ) entry ).getOriginalEntry() ).getAttributes() ) { AttributeType attributeType = attribute.getAttributeType(); - if ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) + if ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) { entry.removeAttributes( attributeType ); } @@ -944,11 +948,11 @@ public abstract class AbstractBTreeParti } else { - for ( Attribute attribute : ( ((ClonedServerEntry)entry).getOriginalEntry() ).getAttributes() ) + for ( Attribute attribute : ( ( ( ClonedServerEntry ) entry ).getOriginalEntry() ).getAttributes() ) { AttributeType attributeType = attribute.getAttributeType(); String oid = attributeType.getOid(); - + if ( !lookupContext.getAttrsId().contains( oid ) ) { entry.removeAttributes( attributeType ); @@ -974,16 +978,16 @@ public abstract class AbstractBTreeParti try { Entry entry = master.get( id ); - + if ( entry != null ) { // We have to store the DN in this entry Dn dn = buildEntryDn( id ); entry.setDn( dn ); - + return new ClonedServerEntry( schemaManager, entry ); } - + return null; } catch ( Exception e ) @@ -1001,323 +1005,325 @@ public abstract class AbstractBTreeParti */ public void modify( ModifyOperationContext modifyContext ) throws LdapException { -// try -// { -// Entry modifiedEntry = modify( modifyContext.getDn(), modifyContext.getModItems().toArray( new Modification[]{}) ); -// modifyContext.setAlteredEntry( modifiedEntry ); -// } -// catch ( Exception e ) -// { -// throw new LdapOperationErrorException( e.getMessage(), e ); -// } + // try + // { + // Entry modifiedEntry = modify( modifyContext.getDn(), modifyContext.getModItems().toArray( new Modification[]{}) ); + // modifyContext.setAlteredEntry( modifiedEntry ); + // } + // catch ( Exception e ) + // { + // throw new LdapOperationErrorException( e.getMessage(), e ); + // } } - - + + /** * {@inheritDoc} */ public synchronized final Entry modify( Dn dn, Modification... mods ) throws Exception { -// UUID id = getEntryId( dn ); -// Entry entry = master.get( id ); -// -// for ( Modification mod : mods ) -// { -// Attribute attrMods = mod.getAttribute(); -// -// switch ( mod.getOperation() ) -// { -// case ADD_ATTRIBUTE: -// modifyAdd( id, entry, attrMods ); -// break; -// -// case REMOVE_ATTRIBUTE: -// modifyRemove( id, entry, attrMods ); -// break; -// -// case REPLACE_ATTRIBUTE: -// modifyReplace( id, entry, attrMods ); -// break; -// -// default: -// throw new LdapException( I18n.err( I18n.ERR_221 ) ); -// } -// } -// -// updateCsnIndex( entry, id ); -// master.put( id, entry ); -// -// if ( isSyncOnWrite.get() ) -// { -// sync(); -// } -// -// return entry; + // UUID id = getEntryId( dn ); + // Entry entry = master.get( id ); + // + // for ( Modification mod : mods ) + // { + // Attribute attrMods = mod.getAttribute(); + // + // switch ( mod.getOperation() ) + // { + // case ADD_ATTRIBUTE: + // modifyAdd( id, entry, attrMods ); + // break; + // + // case REMOVE_ATTRIBUTE: + // modifyRemove( id, entry, attrMods ); + // break; + // + // case REPLACE_ATTRIBUTE: + // modifyReplace( id, entry, attrMods ); + // break; + // + // default: + // throw new LdapException( I18n.err( I18n.ERR_221 ) ); + // } + // } + // + // updateCsnIndex( entry, id ); + // master.put( id, entry ); + // + // if ( isSyncOnWrite.get() ) + // { + // sync(); + // } + // + // return entry; return null; } -// -// -// /** -// * Adds a set of attribute values while affecting the appropriate userIndices. -// * The entry is not persisted: it is only changed in anticipation for a put -// * into the master table. -// * -// * @param id the primary key of the entry -// * @param entry the entry to alter -// * @param mods the attribute and values to add -// * @throws Exception if index alteration or attribute addition fails -// */ -// @SuppressWarnings("unchecked") -// private void modifyAdd( UUID id, Entry entry, Attribute mods ) throws Exception -// { -// if ( entry instanceof ClonedServerEntry ) -// { -// throw new Exception( I18n.err( I18n.ERR_215 ) ); -// } -// -// String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() ); -// AttributeType attributeType = mods.getAttributeType(); -// -// // Special case for the ObjectClass index -// if ( modsOid.equals( SchemaConstants.OBJECT_CLASS_AT_OID ) ) -// { -// for ( Value value : mods ) -// { -// objectClassIdx.add( value.getString(), id ); -// } -// } -// else if ( hasUserIndexOn( attributeType ) ) -// { -// Index index = getUserIndex( attributeType ); -// -// for ( Value value : mods ) -// { -// ( ( Index ) index ).add( value.getValue(), id ); -// } -// -// // If the attr didn't exist for this id add it to presence index -// if ( !presenceIdx.forward( modsOid, id ) ) -// { -// presenceIdx.add( modsOid, id ); -// } -// } -// -// // add all the values in mods to the same attribute in the entry -// -// for ( Value value : mods ) -// { -// entry.add( mods.getAttributeType(), value ); -// } -// -// if ( modsOid.equals( SchemaConstants.ALIASED_OBJECT_NAME_AT_OID ) ) -// { -// Dn ndn = getEntryDn( id ); -// addAliasIndices( id, ndn, mods.getString() ); -// } -// } -// -// -// /** -// * Completely replaces the existing set of values for an attribute with the -// * modified values supplied affecting the appropriate userIndices. The entry -// * is not persisted: it is only changed in anticipation for a put into the -// * master table. -// * -// * @param id the primary key of the entry -// * @param entry the entry to alter -// * @param mods the replacement attribute and values -// * @throws Exception if index alteration or attribute modification -// * fails. -// */ -// @SuppressWarnings("unchecked") -// private void modifyReplace( UUID id, Entry entry, Attribute mods ) throws Exception -// { -// if ( entry instanceof ClonedServerEntry ) -// { -// throw new Exception( I18n.err( I18n.ERR_215 ) ); -// } -// -// String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() ); -// AttributeType attributeType = mods.getAttributeType(); -// -// // Special case for the ObjectClass index -// if ( attributeType.equals( OBJECT_CLASS_AT ) ) -// { -// // if the id exists in the index drop all existing attribute -// // value index entries and add new ones -// if ( objectClassIdx.reverse( id ) ) -// { -// objectClassIdx.drop( id ); -// } -// -// for ( Value value : mods ) -// { -// objectClassIdx.add( value.getString(), id ); -// } -// } -// else if ( hasUserIndexOn( attributeType ) ) -// { -// Index index = getUserIndex( attributeType ); -// -// // if the id exists in the index drop all existing attribute -// // value index entries and add new ones -// if ( index.reverse( id ) ) -// { -// ( ( Index ) index ).drop( id ); -// } -// -// for ( Value value : mods ) -// { -// ( ( Index ) index ).add( value.getValue(), id ); -// } -// -// /* -// * If no attribute values exist for this entryId in the index then -// * we remove the presence index entry for the removed attribute. -// */ -// if ( null == index.reverseLookup( id ) ) -// { -// presenceIdx.drop( modsOid, id ); -// } -// } -// -// String aliasAttributeOid = schemaManager.getAttributeTypeRegistry().getOidByName( -// SchemaConstants.ALIASED_OBJECT_NAME_AT ); -// -// if ( mods.getAttributeType().equals( ALIASED_OBJECT_NAME_AT ) ) -// { -// dropAliasIndices( id ); -// } -// -// // replaces old attributes with new modified ones if they exist -// if ( mods.size() > 0 ) -// { -// entry.put( mods ); -// } -// else -// // removes old attributes if new replacements do not exist -// { -// entry.remove( mods ); -// } -// -// if ( modsOid.equals( aliasAttributeOid ) && mods.size() > 0 ) -// { -// Dn entryDn = getEntryDn( id ); -// addAliasIndices( id, entryDn, mods.getString() ); -// } -// } -// -// -// /** -// * Completely removes the set of values for an attribute having the values -// * supplied while affecting the appropriate userIndices. The entry is not -// * persisted: it is only changed in anticipation for a put into the master -// * table. Note that an empty attribute w/o values will remove all the -// * values within the entry where as an attribute w/ values will remove those -// * attribute values it contains. -// * -// * @param id the primary key of the entry -// * @param entry the entry to alter -// * @param mods the attribute and its values to delete -// * @throws Exception if index alteration or attribute modification fails. -// */ -// @SuppressWarnings("unchecked") -// private void modifyRemove( UUID id, Entry entry, Attribute mods ) throws Exception -// { -// if ( entry instanceof ClonedServerEntry ) -// { -// throw new Exception( I18n.err( I18n.ERR_215 ) ); -// } -// -// String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() ); -// AttributeType attributeType = mods.getAttributeType(); -// -// // Special case for the ObjectClass index -// if ( attributeType.equals( OBJECT_CLASS_AT ) ) -// { -// /* -// * If there are no attribute values in the modifications then this -// * implies the complete removal of the attribute from the index. Else -// * we remove individual tuples from the index. -// */ -// if ( mods.size() == 0 ) -// { -// objectClassIdx.drop( id ); -// } -// else -// { -// for ( Value value : mods ) -// { -// objectClassIdx.drop( value.getString(), id ); -// } -// } -// } -// else if ( hasUserIndexOn( attributeType ) ) -// { -// Index index = getUserIndex( attributeType ); -// -// /* -// * If there are no attribute values in the modifications then this -// * implies the complete removal of the attribute from the index. Else -// * we remove individual tuples from the index. -// */ -// if ( mods.size() == 0 ) -// { -// ( ( Index ) index ).drop( id ); -// } -// else -// { -// for ( Value value : mods ) -// { -// ( ( Index ) index ).drop( value.getValue(), id ); -// } -// } -// -// /* -// * If no attribute values exist for this entryId in the index then -// * we remove the presence index entry for the removed attribute. -// */ -// if ( null == index.reverseLookup( id ) ) -// { -// presenceIdx.drop( modsOid, id ); -// } -// } -// -// AttributeType attrType = schemaManager.lookupAttributeTypeRegistry( modsOid ); -// -// /* -// * If there are no attribute values in the modifications then this -// * implies the complete removal of the attribute from the entry. Else -// * we remove individual attribute values from the entry in mods one -// * at a time. -// */ -// if ( mods.size() == 0 ) -// { -// entry.removeAttributes( mods.getAttributeType() ); -// } -// else -// { -// Attribute entryAttr = entry.get( mods.getAttributeType() ); -// -// for ( Value value : mods ) -// { -// entryAttr.remove( value ); -// } -// -// // if nothing is left just remove empty attribute -// if ( entryAttr.size() == 0 ) -// { -// entry.removeAttributes( entryAttr.getId() ); -// } -// } -// -// // Aliases->single valued comp/partial attr removal is not relevant here -// if ( mods.getAttributeType().equals( ALIASED_OBJECT_NAME_AT ) ) -// { -// dropAliasIndices( id ); -// } -// } -// + + + // + // + // /** + // * Adds a set of attribute values while affecting the appropriate userIndices. + // * The entry is not persisted: it is only changed in anticipation for a put + // * into the master table. + // * + // * @param id the primary key of the entry + // * @param entry the entry to alter + // * @param mods the attribute and values to add + // * @throws Exception if index alteration or attribute addition fails + // */ + // @SuppressWarnings("unchecked") + // private void modifyAdd( UUID id, Entry entry, Attribute mods ) throws Exception + // { + // if ( entry instanceof ClonedServerEntry ) + // { + // throw new Exception( I18n.err( I18n.ERR_215 ) ); + // } + // + // String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() ); + // AttributeType attributeType = mods.getAttributeType(); + // + // // Special case for the ObjectClass index + // if ( modsOid.equals( SchemaConstants.OBJECT_CLASS_AT_OID ) ) + // { + // for ( Value value : mods ) + // { + // objectClassIdx.add( value.getString(), id ); + // } + // } + // else if ( hasUserIndexOn( attributeType ) ) + // { + // Index index = getUserIndex( attributeType ); + // + // for ( Value value : mods ) + // { + // ( ( Index ) index ).add( value.getValue(), id ); + // } + // + // // If the attr didn't exist for this id add it to presence index + // if ( !presenceIdx.forward( modsOid, id ) ) + // { + // presenceIdx.add( modsOid, id ); + // } + // } + // + // // add all the values in mods to the same attribute in the entry + // + // for ( Value value : mods ) + // { + // entry.add( mods.getAttributeType(), value ); + // } + // + // if ( modsOid.equals( SchemaConstants.ALIASED_OBJECT_NAME_AT_OID ) ) + // { + // Dn ndn = getEntryDn( id ); + // addAliasIndices( id, ndn, mods.getString() ); + // } + // } + // + // + // /** + // * Completely replaces the existing set of values for an attribute with the + // * modified values supplied affecting the appropriate userIndices. The entry + // * is not persisted: it is only changed in anticipation for a put into the + // * master table. + // * + // * @param id the primary key of the entry + // * @param entry the entry to alter + // * @param mods the replacement attribute and values + // * @throws Exception if index alteration or attribute modification + // * fails. + // */ + // @SuppressWarnings("unchecked") + // private void modifyReplace( UUID id, Entry entry, Attribute mods ) throws Exception + // { + // if ( entry instanceof ClonedServerEntry ) + // { + // throw new Exception( I18n.err( I18n.ERR_215 ) ); + // } + // + // String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() ); + // AttributeType attributeType = mods.getAttributeType(); + // + // // Special case for the ObjectClass index + // if ( attributeType.equals( OBJECT_CLASS_AT ) ) + // { + // // if the id exists in the index drop all existing attribute + // // value index entries and add new ones + // if ( objectClassIdx.reverse( id ) ) + // { + // objectClassIdx.drop( id ); + // } + // + // for ( Value value : mods ) + // { + // objectClassIdx.add( value.getString(), id ); + // } + // } + // else if ( hasUserIndexOn( attributeType ) ) + // { + // Index index = getUserIndex( attributeType ); + // + // // if the id exists in the index drop all existing attribute + // // value index entries and add new ones + // if ( index.reverse( id ) ) + // { + // ( ( Index ) index ).drop( id ); + // } + // + // for ( Value value : mods ) + // { + // ( ( Index ) index ).add( value.getValue(), id ); + // } + // + // /* + // * If no attribute values exist for this entryId in the index then + // * we remove the presence index entry for the removed attribute. + // */ + // if ( null == index.reverseLookup( id ) ) + // { + // presenceIdx.drop( modsOid, id ); + // } + // } + // + // String aliasAttributeOid = schemaManager.getAttributeTypeRegistry().getOidByName( + // SchemaConstants.ALIASED_OBJECT_NAME_AT ); + // + // if ( mods.getAttributeType().equals( ALIASED_OBJECT_NAME_AT ) ) + // { + // dropAliasIndices( id ); + // } + // + // // replaces old attributes with new modified ones if they exist + // if ( mods.size() > 0 ) + // { + // entry.put( mods ); + // } + // else + // // removes old attributes if new replacements do not exist + // { + // entry.remove( mods ); + // } + // + // if ( modsOid.equals( aliasAttributeOid ) && mods.size() > 0 ) + // { + // Dn entryDn = getEntryDn( id ); + // addAliasIndices( id, entryDn, mods.getString() ); + // } + // } + // + // + // /** + // * Completely removes the set of values for an attribute having the values + // * supplied while affecting the appropriate userIndices. The entry is not + // * persisted: it is only changed in anticipation for a put into the master + // * table. Note that an empty attribute w/o values will remove all the + // * values within the entry where as an attribute w/ values will remove those + // * attribute values it contains. + // * + // * @param id the primary key of the entry + // * @param entry the entry to alter + // * @param mods the attribute and its values to delete + // * @throws Exception if index alteration or attribute modification fails. + // */ + // @SuppressWarnings("unchecked") + // private void modifyRemove( UUID id, Entry entry, Attribute mods ) throws Exception + // { + // if ( entry instanceof ClonedServerEntry ) + // { + // throw new Exception( I18n.err( I18n.ERR_215 ) ); + // } + // + // String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() ); + // AttributeType attributeType = mods.getAttributeType(); + // + // // Special case for the ObjectClass index + // if ( attributeType.equals( OBJECT_CLASS_AT ) ) + // { + // /* + // * If there are no attribute values in the modifications then this + // * implies the complete removal of the attribute from the index. Else + // * we remove individual tuples from the index. + // */ + // if ( mods.size() == 0 ) + // { + // objectClassIdx.drop( id ); + // } + // else + // { + // for ( Value value : mods ) + // { + // objectClassIdx.drop( value.getString(), id ); + // } + // } + // } + // else if ( hasUserIndexOn( attributeType ) ) + // { + // Index index = getUserIndex( attributeType ); + // + // /* + // * If there are no attribute values in the modifications then this + // * implies the complete removal of the attribute from the index. Else + // * we remove individual tuples from the index. + // */ + // if ( mods.size() == 0 ) + // { + // ( ( Index ) index ).drop( id ); + // } + // else + // { + // for ( Value value : mods ) + // { + // ( ( Index ) index ).drop( value.getValue(), id ); + // } + // } + // + // /* + // * If no attribute values exist for this entryId in the index then + // * we remove the presence index entry for the removed attribute. + // */ + // if ( null == index.reverseLookup( id ) ) + // { + // presenceIdx.drop( modsOid, id ); + // } + // } + // + // AttributeType attrType = schemaManager.lookupAttributeTypeRegistry( modsOid ); + // + // /* + // * If there are no attribute values in the modifications then this + // * implies the complete removal of the attribute from the entry. Else + // * we remove individual attribute values from the entry in mods one + // * at a time. + // */ + // if ( mods.size() == 0 ) + // { + // entry.removeAttributes( mods.getAttributeType() ); + // } + // else + // { + // Attribute entryAttr = entry.get( mods.getAttributeType() ); + // + // for ( Value value : mods ) + // { + // entryAttr.remove( value ); + // } + // + // // if nothing is left just remove empty attribute + // if ( entryAttr.size() == 0 ) + // { + // entry.removeAttributes( entryAttr.getId() ); + // } + // } + // + // // Aliases->single valued comp/partial attr removal is not relevant here + // if ( mods.getAttributeType().equals( ALIASED_OBJECT_NAME_AT ) ) + // { + // dropAliasIndices( id ); + // } + // } + // //--------------------------------------------------------------------------------------------- // The Move operation @@ -1327,25 +1333,25 @@ public abstract class AbstractBTreeParti */ public void move( MoveOperationContext moveContext ) throws LdapException { -// if ( moveContext.getNewSuperior().isDescendantOf( moveContext.getDn() ) ) -// { -// throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, -// "cannot place an entry below itself" ); -// } -// -// try -// { -// Dn oldDn = moveContext.getDn(); -// Dn newSuperior = moveContext.getNewSuperior(); -// Dn newDn = moveContext.getNewDn(); -// Entry modifiedEntry = moveContext.getModifiedEntry(); -// -// move( oldDn, newSuperior, newDn, modifiedEntry ); -// } -// catch ( Exception e ) -// { -// throw new LdapOperationErrorException( e.getMessage(), e ); -// } + // if ( moveContext.getNewSuperior().isDescendantOf( moveContext.getDn() ) ) + // { + // throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, + // "cannot place an entry below itself" ); + // } + // + // try + // { + // Dn oldDn = moveContext.getDn(); + // Dn newSuperior = moveContext.getNewSuperior(); + // Dn newDn = moveContext.getNewDn(); + // Entry modifiedEntry = moveContext.getModifiedEntry(); + // + // move( oldDn, newSuperior, newDn, modifiedEntry ); + // } + // catch ( Exception e ) + // { + // throw new LdapOperationErrorException( e.getMessage(), e ); + // } } @@ -1354,91 +1360,91 @@ public abstract class AbstractBTreeParti */ public synchronized final void move( Dn oldDn, Dn newSuperiorDn, Dn newDn, Entry modifiedEntry ) throws Exception { -// // Check that the parent Dn exists -// UUID newParentId = getEntryId( newSuperiorDn ); -// -// if ( newParentId == null ) -// { -// // This is not allowed : the parent must exist -// LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( -// I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, newSuperiorDn.getName() ) ); -// throw ne; -// } -// -// // Now check that the new entry does not exist -// UUID newId = getEntryId( newDn ); -// -// if ( newId != null ) -// { -// // This is not allowed : we should not be able to move an entry -// // to an existing position -// LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( -// I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newSuperiorDn.getName() ) ); -// throw ne; -// } -// -// // Get the entry and the old parent IDs -// UUID entryId = getEntryId( oldDn ); -// UUID oldParentId = getParentId( entryId ); -// -// /* -// * All aliases including and below oldChildDn, will be affected by -// * the move operation with respect to one and subtree userIndices since -// * their relationship to ancestors above oldChildDn will be -// * destroyed. For each alias below and including oldChildDn we will -// * drop the index tuples mapping ancestor ids above oldChildDn to the -// * respective target ids of the aliases. -// */ -// dropMovedAliasIndices( oldDn ); -// -// /* -// * Drop the old parent child relationship and add the new one -// * Set the new parent id for the child replacing the old parent id -// */ -// oneLevelIdx.drop( oldParentId, entryId ); -// oneLevelIdx.add( newParentId, entryId ); -// -// updateSubLevelIndex( entryId, oldParentId, newParentId ); -// -// // Update the Rdn index -// rdnIdx.drop( entryId ); -// ParentIdAndRdn key = new ParentIdAndRdn( newParentId, oldDn.getRdn() ); -// rdnIdx.add( key, entryId ); -// -// -// /* -// * Read Alias Index Tuples -// * -// * If this is a name change due to a move operation then the one and -// * subtree userIndices for aliases were purged before the aliases were -// * moved. Now we must add them for each alias entry we have moved. -// * -// * aliasTarget is used as a marker to tell us if we're moving an -// * alias. If it is null then the moved entry is not an alias. -// */ -// String aliasTarget = aliasIdx.reverseLookup( entryId ); -// -// if ( null != aliasTarget ) -// { -// addAliasIndices( entryId, buildEntryDn( entryId ), aliasTarget ); -// } -// -// // the below case arises only when the move( Dn oldDn, Dn newSuperiorDn, Dn newDn ) is called -// // directly using the Store API, in this case the value of modified entry will be null -// // we need to lookup the entry to update the parent ID -// if ( modifiedEntry == null ) -// { -// modifiedEntry = lookup( entryId ); -// } -// -// // Update the master table with the modified entry -// modifiedEntry.put( SchemaConstants.ENTRY_PARENT_ID_AT, newParentId.toString() ); -// master.put( entryId, modifiedEntry ); -// -// if ( isSyncOnWrite.get() ) -// { -// sync(); -// } + // // Check that the parent Dn exists + // UUID newParentId = getEntryId( newSuperiorDn ); + // + // if ( newParentId == null ) + // { + // // This is not allowed : the parent must exist + // LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( + // I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, newSuperiorDn.getName() ) ); + // throw ne; + // } + // + // // Now check that the new entry does not exist + // UUID newId = getEntryId( newDn ); + // + // if ( newId != null ) + // { + // // This is not allowed : we should not be able to move an entry + // // to an existing position + // LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( + // I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newSuperiorDn.getName() ) ); + // throw ne; + // } + // + // // Get the entry and the old parent IDs + // UUID entryId = getEntryId( oldDn ); + // UUID oldParentId = getParentId( entryId ); + // + // /* + // * All aliases including and below oldChildDn, will be affected by + // * the move operation with respect to one and subtree userIndices since + // * their relationship to ancestors above oldChildDn will be + // * destroyed. For each alias below and including oldChildDn we will + // * drop the index tuples mapping ancestor ids above oldChildDn to the + // * respective target ids of the aliases. + // */ + // dropMovedAliasIndices( oldDn ); + // + // /* + // * Drop the old parent child relationship and add the new one + // * Set the new parent id for the child replacing the old parent id + // */ + // oneLevelIdx.drop( oldParentId, entryId ); + // oneLevelIdx.add( newParentId, entryId ); + // + // updateSubLevelIndex( entryId, oldParentId, newParentId ); + // + // // Update the Rdn index + // rdnIdx.drop( entryId ); + // ParentIdAndRdn key = new ParentIdAndRdn( newParentId, oldDn.getRdn() ); + // rdnIdx.add( key, entryId ); + // + // + // /* + // * Read Alias Index Tuples + // * + // * If this is a name change due to a move operation then the one and + // * subtree userIndices for aliases were purged before the aliases were + // * moved. Now we must add them for each alias entry we have moved. + // * + // * aliasTarget is used as a marker to tell us if we're moving an + // * alias. If it is null then the moved entry is not an alias. + // */ + // String aliasTarget = aliasIdx.reverseLookup( entryId ); + // + // if ( null != aliasTarget ) + // { + // addAliasIndices( entryId, buildEntryDn( entryId ), aliasTarget ); + // } + // + // // the below case arises only when the move( Dn oldDn, Dn newSuperiorDn, Dn newDn ) is called + // // directly using the Store API, in this case the value of modified entry will be null + // // we need to lookup the entry to update the parent ID + // if ( modifiedEntry == null ) + // { + // modifiedEntry = lookup( entryId ); + // } + // + // // Update the master table with the modified entry + // modifiedEntry.put( SchemaConstants.ENTRY_PARENT_ID_AT, newParentId.toString() ); + // master.put( entryId, modifiedEntry ); + // + // if ( isSyncOnWrite.get() ) + // { + // sync(); + // } } @@ -1450,83 +1456,84 @@ public abstract class AbstractBTreeParti */ public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException { -// if ( moveAndRenameContext.getNewSuperiorDn().isDescendantOf( moveAndRenameContext.getDn() ) ) -// { -// throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, -// "cannot place an entry below itself" ); -// } -// -// try -// { -// Dn oldDn = moveAndRenameContext.getDn(); -// Dn newSuperiorDn = moveAndRenameContext.getNewSuperiorDn(); -// Rdn newRdn = moveAndRenameContext.getNewRdn(); -// boolean deleteOldRdn = moveAndRenameContext.getDeleteOldRdn(); -// Entry modifiedEntry = moveAndRenameContext.getModifiedEntry(); -// -// moveAndRename( oldDn, newSuperiorDn, newRdn, modifiedEntry, deleteOldRdn ); -// } -// catch ( LdapException le ) -// { -// // In case we get an LdapException, just rethrow it as is to -// // avoid having it lost -// throw le; -// } -// catch ( Exception e ) -// { -// throw new LdapOperationErrorException( e.getMessage(), e ); -// } + // if ( moveAndRenameContext.getNewSuperiorDn().isDescendantOf( moveAndRenameContext.getDn() ) ) + // { + // throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, + // "cannot place an entry below itself" ); + // } + // + // try + // { + // Dn oldDn = moveAndRenameContext.getDn(); + // Dn newSuperiorDn = moveAndRenameContext.getNewSuperiorDn(); + // Rdn newRdn = moveAndRenameContext.getNewRdn(); + // boolean deleteOldRdn = moveAndRenameContext.getDeleteOldRdn(); + // Entry modifiedEntry = moveAndRenameContext.getModifiedEntry(); + // + // moveAndRename( oldDn, newSuperiorDn, newRdn, modifiedEntry, deleteOldRdn ); + // } + // catch ( LdapException le ) + // { + // // In case we get an LdapException, just rethrow it as is to + // // avoid having it lost + // throw le; + // } + // catch ( Exception e ) + // { + // throw new LdapOperationErrorException( e.getMessage(), e ); + // } } /** * {@inheritDoc} */ - public synchronized final void moveAndRename( Dn oldDn, Dn newSuperiorDn, Rdn newRdn, Entry modifiedEntry, boolean deleteOldRdn ) throws Exception - { -// // Check that the old entry exists -// UUID oldId = getEntryId( oldDn ); -// -// if ( oldId == null ) -// { -// // This is not allowed : the old entry must exist -// LdapNoSuchObjectException nse = new LdapNoSuchObjectException( -// I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, oldDn ) ); -// throw nse; -// } -// -// // Check that the new superior exist -// UUID newSuperiorId = getEntryId( newSuperiorDn ); -// -// if ( newSuperiorId == null ) -// { -// // This is not allowed : the new superior must exist -// LdapNoSuchObjectException nse = new LdapNoSuchObjectException( -// I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, newSuperiorDn ) ); -// throw nse; -// } -// -// Dn newDn = newSuperiorDn.add( newRdn ); -// -// // Now check that the new entry does not exist -// UUID newId = getEntryId( newDn ); -// -// if ( newId != null ) -// { -// // This is not allowed : we should not be able to move an entry -// // to an existing position -// LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( -// I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newSuperiorDn.getName() ) ); -// throw ne; -// } -// -// rename( oldDn, newRdn, deleteOldRdn, modifiedEntry ); -// moveAndRename( oldDn, oldId, newSuperiorDn, newRdn, modifiedEntry ); -// -// if ( isSyncOnWrite.get() ) -// { -// sync(); -// } + public synchronized final void moveAndRename( Dn oldDn, Dn newSuperiorDn, Rdn newRdn, Entry modifiedEntry, + boolean deleteOldRdn ) throws Exception + { + // // Check that the old entry exists + // UUID oldId = getEntryId( oldDn ); + // + // if ( oldId == null ) + // { + // // This is not allowed : the old entry must exist + // LdapNoSuchObjectException nse = new LdapNoSuchObjectException( + // I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, oldDn ) ); + // throw nse; + // } + // + // // Check that the new superior exist + // UUID newSuperiorId = getEntryId( newSuperiorDn ); + // + // if ( newSuperiorId == null ) + // { + // // This is not allowed : the new superior must exist + // LdapNoSuchObjectException nse = new LdapNoSuchObjectException( + // I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, newSuperiorDn ) ); + // throw nse; + // } + // + // Dn newDn = newSuperiorDn.add( newRdn ); + // + // // Now check that the new entry does not exist + // UUID newId = getEntryId( newDn ); + // + // if ( newId != null ) + // { + // // This is not allowed : we should not be able to move an entry + // // to an existing position + // LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( + // I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newSuperiorDn.getName() ) ); + // throw ne; + // } + // + // rename( oldDn, newRdn, deleteOldRdn, modifiedEntry ); + // moveAndRename( oldDn, oldId, newSuperiorDn, newRdn, modifiedEntry ); + // + // if ( isSyncOnWrite.get() ) + // { + // sync(); + // } } @@ -1545,7 +1552,8 @@ public abstract class AbstractBTreeParti * @param modifiedEntry the modified entry * @throws Exception if something goes wrong */ - private void moveAndRename( Dn oldDn, UUID childId, Dn newSuperior, Rdn newRdn, Entry modifiedEntry ) throws Exception + private void moveAndRename( Dn oldDn, UUID childId, Dn newSuperior, Rdn newRdn, Entry modifiedEntry ) + throws Exception { // Get the child and the new parent to be entries and Ids UUID newParentId = getEntryId( newSuperior ); @@ -1615,26 +1623,26 @@ public abstract class AbstractBTreeParti */ public void rename( RenameOperationContext renameContext ) throws LdapException { -// try -// { -// Dn oldDn = renameContext.getDn(); -// Rdn newRdn = renameContext.getNewRdn(); -// boolean deleteOldRdn = renameContext.getDeleteOldRdn(); -// -// if ( renameContext.getEntry() != null ) -// { -// Entry modifiedEntry = renameContext.getModifiedEntry(); -// rename( oldDn, newRdn, deleteOldRdn, modifiedEntry ); -// } -// else -// { -// rename( oldDn, newRdn, deleteOldRdn, null ); -// } -// } -// catch ( Exception e ) -// { -// throw new LdapOperationErrorException( e.getMessage(), e ); -// } + // try + // { + // Dn oldDn = renameContext.getDn(); + // Rdn newRdn = renameContext.getNewRdn(); + // boolean deleteOldRdn = renameContext.getDeleteOldRdn(); + // + // if ( renameContext.getEntry() != null ) + // { + // Entry modifiedEntry = renameContext.getModifiedEntry(); + // rename( oldDn, newRdn, deleteOldRdn, modifiedEntry ); + // } + // else + // { + // rename( oldDn, newRdn, deleteOldRdn, null ); + // } + // } + // catch ( Exception e ) + // { + // throw new LdapOperationErrorException( e.getMessage(), e ); + // } } @@ -1644,128 +1652,128 @@ public abstract class AbstractBTreeParti @SuppressWarnings("unchecked") public synchronized final void rename( Dn dn, Rdn newRdn, boolean deleteOldRdn, Entry entry ) throws Exception { -// UUID id = getEntryId( dn ); -// -// if ( entry == null ) -// { -// entry = master.get( id ); -// } -// -// Dn updn = entry.getDn(); -// -// newRdn.apply( schemaManager ); -// -// /* -// * H A N D L E N E W R D N -// * ==================================================================== -// * Add the new Rdn attribute to the entry. If an index exists on the -// * new Rdn attribute we add the index for this attribute value pair. -// * Also we make sure that the presence index shows the existence of the -// * new Rdn attribute within this entry. -// */ -// -// for ( Ava newAtav : newRdn ) -// { -// String newNormType = newAtav.getNormType(); -// Object newNormValue = newAtav.getNormValue().getValue(); -// -// AttributeType newRdnAttrType = schemaManager.lookupAttributeTypeRegistry( newNormType ); -// -// entry.add( newRdnAttrType, newAtav.getNormValue() ); -// -// if ( hasUserIndexOn( newRdnAttrType ) ) -// { -// Index index = getUserIndex( newRdnAttrType ); -// ( ( Index ) index ).add( newNormValue, id ); -// -// // Make sure the altered entry shows the existence of the new attrib -// if ( !presenceIdx.forward( newNormType, id ) ) -// { -// presenceIdx.add( newNormType, id ); -// } -// } -// } -// -// /* -// * H A N D L E O L D R D N -// * ==================================================================== -// * If the old Rdn is to be removed we need to get the attribute and -// * value for it. Keep in mind the old Rdn need not be based on the -// * same attr as the new one. We remove the Rdn value from the entry -// * and remove the value/id tuple from the index on the old Rdn attr -// * if any. We also test if the delete of the old Rdn index tuple -// * removed all the attribute values of the old Rdn using a reverse -// * lookup. If so that means we blew away the last value of the old -// * Rdn attribute. In this case we need to remove the attrName/id -// * tuple from the presence index. -// * -// * We only remove an ATAV of the old Rdn if it is not included in the -// * new Rdn. -// */ -// -// if ( deleteOldRdn ) -// { -// Rdn oldRdn = updn.getRdn(); -// -// for ( Ava oldAtav : oldRdn ) -// { -// // check if the new ATAV is part of the old Rdn -// // if that is the case we do not remove the ATAV -// boolean mustRemove = true; -// -// for ( Ava newAtav : newRdn ) -// { -// if ( oldAtav.equals( newAtav ) ) -// { -// mustRemove = false; -// break; -// } -// } -// -// if ( mustRemove ) -// { -// String oldNormType = oldAtav.getNormType(); -// String oldNormValue = oldAtav.getNormValue().getString(); -// AttributeType oldRdnAttrType = schemaManager.lookupAttributeTypeRegistry( oldNormType ); -// entry.remove( oldRdnAttrType, oldNormValue ); -// -// if ( hasUserIndexOn( oldRdnAttrType ) ) -// { -// Index index = getUserIndex( oldRdnAttrType ); -// ( ( Index ) index ).drop( oldNormValue, id ); -// -// /* -// * If there is no value for id in this index due to our -// * drop above we remove the oldRdnAttr from the presence idx -// */ -// if ( null == index.reverseLookup( id ) ) -// { -// presenceIdx.drop( oldNormType, id ); -// } -// } -// } -// } -// } -// -// -// /* -// * H A N D L E D N C H A N G E -// * ==================================================================== -// * We only need to update the Rdn index. -// * No need to calculate the new Dn. -// */ -// -// UUID parentId = getParentId( id ); -// rdnIdx.drop( id ); -// ParentIdAndRdn key = new ParentIdAndRdn( parentId, newRdn ); -// rdnIdx.add( key, id ); -// -// master.put( id, entry ); -// -// if ( isSyncOnWrite.get() ) -// { -// sync(); -// } + // UUID id = getEntryId( dn ); + // + // if ( entry == null ) + // { + // entry = master.get( id ); + // } + // + // Dn updn = entry.getDn(); + // + // newRdn.apply( schemaManager ); + // + // /* + // * H A N D L E N E W R D N + // * ==================================================================== + // * Add the new Rdn attribute to the entry. If an index exists on the + // * new Rdn attribute we add the index for this attribute value pair. + // * Also we make sure that the presence index shows the existence of the + // * new Rdn attribute within this entry. + // */ + // + // for ( Ava newAtav : newRdn ) + // { + // String newNormType = newAtav.getNormType(); + // Object newNormValue = newAtav.getNormValue().getValue(); + // + // AttributeType newRdnAttrType = schemaManager.lookupAttributeTypeRegistry( newNormType ); + // + // entry.add( newRdnAttrType, newAtav.getNormValue() ); + // + // if ( hasUserIndexOn( newRdnAttrType ) ) + // { + // Index index = getUserIndex( newRdnAttrType ); + // ( ( Index ) index ).add( newNormValue, id ); + // + // // Make sure the altered entry shows the existence of the new attrib + // if ( !presenceIdx.forward( newNormType, id ) ) + // { + // presenceIdx.add( newNormType, id ); + // } + // } + // } + // + // /* + // * H A N D L E O L D R D N + // * ==================================================================== + // * If the old Rdn is to be removed we need to get the attribute and + // * value for it. Keep in mind the old Rdn need not be based on the + // * same attr as the new one. We remove the Rdn value from the entry + // * and remove the value/id tuple from the index on the old Rdn attr + // * if any. We also test if the delete of the old Rdn index tuple + // * removed all the attribute values of the old Rdn using a reverse + // * lookup. If so that means we blew away the last value of the old + // * Rdn attribute. In this case we need to remove the attrName/id + // * tuple from the presence index. + // * + // * We only remove an ATAV of the old Rdn if it is not included in the + // * new Rdn. + // */ + // + // if ( deleteOldRdn ) + // { + // Rdn oldRdn = updn.getRdn(); + // + // for ( Ava oldAtav : oldRdn ) + // { + // // check if the new ATAV is part of the old Rdn + // // if that is the case we do not remove the ATAV + // boolean mustRemove = true; + // + // for ( Ava newAtav : newRdn ) + // { + // if ( oldAtav.equals( newAtav ) ) + // { + // mustRemove = false; + // break; + // } + // } + // + // if ( mustRemove ) + // { + // String oldNormType = oldAtav.getNormType(); + // String oldNormValue = oldAtav.getNormValue().getString(); + // AttributeType oldRdnAttrType = schemaManager.lookupAttributeTypeRegistry( oldNormType ); + // entry.remove( oldRdnAttrType, oldNormValue ); + // + // if ( hasUserIndexOn( oldRdnAttrType ) ) + // { + // Index index = getUserIndex( oldRdnAttrType ); + // ( ( Index ) index ).drop( oldNormValue, id ); + // + // /* + // * If there is no value for id in this index due to our + // * drop above we remove the oldRdnAttr from the presence idx + // */ + // if ( null == index.reverseLookup( id ) ) + // { + // presenceIdx.drop( oldNormType, id ); + // } + // } + // } + // } + // } + // + // + // /* + // * H A N D L E D N C H A N G E + // * ==================================================================== + // * We only need to update the Rdn index. + // * No need to calculate the new Dn. + // */ + // + // UUID parentId = getParentId( id ); + // rdnIdx.drop( id ); + // ParentIdAndRdn key = new ParentIdAndRdn( parentId, newRdn ); + // rdnIdx.add( key, id ); + // + // master.put( id, entry ); + // + // if ( isSyncOnWrite.get() ) + // { + // sync(); + // } } @@ -1793,8 +1801,8 @@ public abstract class AbstractBTreeParti UUID id = getEntryId( entryContext.getDn() ); Entry entry = lookup( id ); - - return entry != null; + + return entry != null; } catch ( LdapException e ) { @@ -1852,7 +1860,7 @@ public abstract class AbstractBTreeParti } cursor.close(); - + // detach the childId and all its children from oldParentId and all it parents excluding the root for ( UUID pid : parentIds ) { @@ -1866,7 +1874,7 @@ public abstract class AbstractBTreeParti tempId = newParentId; // find all the parents of the newParentId - while ( ( tempId != null) && !tempId.equals( getRootId() ) && !tempId.equals( getSuffixId() ) ) + while ( ( tempId != null ) && !tempId.equals( getRootId() ) && !tempId.equals( getSuffixId() ) ) { parentIds.add( tempId ); tempId = getParentId( tempId ); @@ -1916,7 +1924,7 @@ public abstract class AbstractBTreeParti { upName.append( ',' ); } - + upName.append( rdn.getName() ); } @@ -1962,8 +1970,8 @@ public abstract class AbstractBTreeParti { return buildEntryDn( id ); } - - + + /** * {@inheritDoc} */ @@ -2026,7 +2034,7 @@ public abstract class AbstractBTreeParti if ( suffixId == null ) { ParentIdAndRdn key = new ParentIdAndRdn( getRootId(), suffixDn.getRdns() ); - + suffixId = rdnIdx.forwardLookup( key ); } @@ -2083,7 +2091,7 @@ public abstract class AbstractBTreeParti } } - + /** * Set the list of indexes for this partition * @param indexedAttributes The list of indexes @@ -2102,6 +2110,7 @@ public abstract class AbstractBTreeParti return indexedAttributes; } + /** * {@inheritDoc} */ @@ -2118,8 +2127,8 @@ public abstract class AbstractBTreeParti { return systemIndices.keySet().iterator(); } - - + + /** * {@inheritDoc} */ @@ -2128,7 +2137,7 @@ public abstract class AbstractBTreeParti return master; } - + /** * {@inheritDoc} */ @@ -2151,11 +2160,11 @@ public abstract class AbstractBTreeParti } String oid = attributeType.getOid(); - + return getUserIndex( oid ); } - - + + /** * {@inheritDoc} */ @@ -2167,11 +2176,11 @@ public abstract class AbstractBTreeParti } String oid = attributeType.getOid(); - - return getSystemIndex( oid ); + + return getSystemIndex( oid ); } - - + + /** * {@inheritDoc} */ @@ -2189,8 +2198,8 @@ public abstract class AbstractBTreeParti throw new IndexNotFoundException( I18n.err( I18n.ERR_3, oid, oid ) ); } - - + + /** * {@inheritDoc} */ @@ -2345,8 +2354,8 @@ public abstract class AbstractBTreeParti { return hasUserIndexOn( attributeType ) || hasSystemIndexOn( attributeType ); } - - + + /** * {@inheritDoc} */ @@ -2372,8 +2381,8 @@ public abstract class AbstractBTreeParti { return hasUserIndexOn( oid ) || hasSystemIndexOn( oid ); } - - + + //--------------------------------------------------------------------------------------------- // Alias index manipulation //--------------------------------------------------------------------------------------------- @@ -2492,8 +2501,8 @@ public abstract class AbstractBTreeParti ancestorId = getEntryId( ancestorDn ); } } - - + + /** * Removes the index entries for an alias before the entry is deleted from [... 56 lines stripped ...]