in core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java [725:904]
public void delete( DeleteOperationContext deleteContext ) throws LdapException
{
if ( IS_DEBUG )
{
OPERATION_LOG.debug( ">> DeleteOperation : {}", deleteContext );
}
long opStart = 0L;
if ( IS_TIME )
{
opStart = System.nanoTime();
}
ensureStarted();
// Normalize the deleteContext Dn
Dn dn = deleteContext.getDn();
Partition partition = directoryService.getPartitionNexus().getPartition( dn );
deleteContext.setPartition( partition );
if ( !dn.isSchemaAware() )
{
dn = new Dn( directoryService.getSchemaManager(), dn );
deleteContext.setDn( dn );
}
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
try
{
Entry parentEntry = directoryService.getReferralManager().getParentReferral( dn );
if ( parentEntry != null )
{
// We have found a parent referral for the current Dn
Dn childDn = dn.getDescendantOf( parentEntry.getDn() );
if ( directoryService.getReferralManager().isReferral( dn ) )
{
// This is a referral. We can delete it if the ManageDsaIt flag is true
// Otherwise, we just throw a LdapReferralException
if ( !deleteContext.isReferralIgnored() )
{
// Throw a Referral Exception
throw buildReferralException( parentEntry, childDn );
}
}
else if ( directoryService.getReferralManager().hasParentReferral( dn ) )
{
// We can't delete an entry which has an ancestor referral
// Depending on the Context.REFERRAL property value, we will throw
// a different exception.
if ( deleteContext.isReferralIgnored() )
{
throw buildLdapPartialResultException( childDn );
}
else
{
throw buildReferralException( parentEntry, childDn );
}
}
}
}
finally
{
// Unlock the ReferralManager
directoryService.getReferralManager().unlock();
}
// populate the context with the old entry
lockWrite();
// Start a Write transaction right away
PartitionTxn transaction = deleteContext.getSession().getTransaction( partition );
try
{
if ( transaction == null )
{
transaction = partition.beginWriteTransaction();
if ( deleteContext.getSession().hasSessionTransaction() )
{
deleteContext.getSession().addTransaction( partition, transaction );
}
}
deleteContext.setTransaction( transaction );
// Check if the TreeDelete control is used
if ( deleteContext.hasRequestControl( TreeDelete.OID ) )
{
try
{
processTreeDelete( deleteContext, deleteContext.getDn() );
if ( !deleteContext.getSession().hasSessionTransaction() )
{
transaction.commit();
}
}
catch ( CursorException ce )
{
try
{
if ( transaction != null )
{
transaction.abort();
}
throw new LdapOtherException( ce.getMessage(), ce );
}
catch ( IOException ioe )
{
throw new LdapOtherException( ioe.getMessage(), ioe );
}
}
}
else
{
eagerlyPopulateFields( deleteContext );
// Call the Delete method
Interceptor head = directoryService.getInterceptor( deleteContext.getNextInterceptor() );
head.delete( deleteContext );
if ( !deleteContext.getSession().hasSessionTransaction() )
{
transaction.commit();
}
}
}
catch ( LdapException le )
{
try
{
if ( transaction != null )
{
transaction.abort();
}
throw le;
}
catch ( IOException ioe )
{
throw new LdapOtherException( ioe.getMessage(), ioe );
}
}
catch ( IOException ioe )
{
try
{
transaction.abort();
throw new LdapOtherException( ioe.getMessage(), ioe );
}
catch ( IOException ioe2 )
{
throw new LdapOtherException( ioe2.getMessage(), ioe2 );
}
}
finally
{
unlockWrite();
}
if ( IS_DEBUG )
{
OPERATION_LOG.debug( "<< DeleteOperation successful" );
}
if ( IS_TIME )
{
OPERATION_TIME.debug( "Delete operation took {} ns", ( System.nanoTime() - opStart ) );
}
}