in xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/btree/AbstractBTreePartition.java [1920:2068]
private void modifyRemove( PartitionTxn partitionTxn, String id, Entry entry, Attribute mods )
throws LdapException, IndexNotFoundException
{
if ( entry instanceof ClonedServerEntry )
{
throw new LdapOtherException( I18n.err( I18n.ERR_49007_CANNOT_STORE_CLONED_SERVER_ENTRY ) );
}
String modsOid = schemaManager.getAttributeTypeRegistry().getOidByName( mods.getId() );
AttributeType attributeType = mods.getAttributeType();
// Special case for the ObjectClass index
if ( attributeType.equals( objectClassAT ) )
{
/*
* 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 )
{
for ( Value value : entry.get( objectClassAT ) )
{
if ( value.equals( topOCValue ) )
{
continue;
}
String normalizedOc = objectClassNormalizer.normalize( value.getString() );
objectClassIdx.drop( partitionTxn, normalizedOc, id );
}
}
else
{
for ( Value value : mods )
{
if ( value.equals( topOCValue ) )
{
continue;
}
String normalizedOc = objectClassNormalizer.normalize( value.getString() );
objectClassIdx.drop( partitionTxn, normalizedOc, id );
}
}
}
else if ( hasUserIndexOn( attributeType ) )
{
Index<?, String> userIndex = getUserIndex( attributeType );
Attribute attribute = entry.get( attributeType ).clone();
int nbValues = 0;
if ( attribute != null )
{
nbValues = attribute.size();
}
/*
* 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 ) userIndex ).drop( partitionTxn, id );
nbValues = 0;
}
else if ( nbValues > 0 )
{
for ( Value value : mods )
{
if ( attribute.contains( value ) )
{
nbValues--;
attribute.remove( value );
}
String normalized = value.getNormalized();
( ( Index ) userIndex ).drop( partitionTxn, normalized, id );
}
}
/*
* If no attribute values exist for this entryId in the index then
* we remove the presence index entry for the removed attribute.
*/
if ( nbValues == 0 )
{
presenceIdx.drop( partitionTxn, modsOid, id );
}
}
// Special case for the AdministrativeRole index
else if ( modsOid.equals( SchemaConstants.ADMINISTRATIVE_ROLE_AT_OID ) )
{
// We may have more than one role
for ( Value value : mods )
{
adminRoleIdx.drop( partitionTxn, value.getString(), 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 == adminRoleIdx.reverseLookup( partitionTxn, id ) )
{
presenceIdx.drop( partitionTxn, modsOid, id );
}
}
/*
* 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() );
// Allow for null to fix DIRSERVER-2135
if ( entryAttr != null )
{
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( aliasedObjectNameAT ) )
{
dropAliasIndices( partitionTxn, id );
}
}