in core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java [1449:1618]
public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
{
if ( IS_DEBUG )
{
OPERATION_LOG.debug( ">> MoveAndRenameOperation : {}", moveAndRenameContext );
}
long opStart = 0L;
if ( IS_TIME )
{
opStart = System.nanoTime();
}
ensureStarted();
// Normalize the moveAndRenameContext Dn
Dn dn = moveAndRenameContext.getDn();
if ( !dn.isSchemaAware() )
{
dn = new Dn( directoryService.getSchemaManager(), dn );
moveAndRenameContext.setDn( dn );
}
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
try
{
// Check if we have an ancestor for this Dn
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 ( !moveAndRenameContext.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 ( moveAndRenameContext.isReferralIgnored() )
{
throw buildLdapPartialResultException( childDn );
}
else
{
throw buildReferralException( parentEntry, childDn );
}
}
}
// Now, check the destination
// Normalize the moveAndRenameContext Dn
Dn newSuperiorDn = moveAndRenameContext.getNewSuperiorDn();
if ( !newSuperiorDn.isSchemaAware() )
{
newSuperiorDn = new Dn( directoryService.getSchemaManager(), newSuperiorDn );
moveAndRenameContext.setNewSuperiorDn( newSuperiorDn );
}
// If he parent Dn is a referral, or has a referral ancestor, we have to issue a AffectMultipleDsas result
// as stated by RFC 3296 Section 5.6.2
if ( directoryService.getReferralManager().isReferral( newSuperiorDn )
|| directoryService.getReferralManager().hasParentReferral( newSuperiorDn ) )
{
// The parent Dn is a referral, we have to issue a AffectMultipleDsas result
// as stated by RFC 3296 Section 5.6.2
throw new LdapAffectMultipleDsaException();
}
}
finally
{
// Unlock the ReferralManager
directoryService.getReferralManager().unlock();
}
// Find the working partition
Partition partition = directoryService.getPartitionNexus().getPartition( dn );
moveAndRenameContext.setPartition( partition );
lockWrite();
// Start a Write transaction right away
PartitionTxn transaction = moveAndRenameContext.getSession().getTransaction( partition );
try
{
if ( transaction == null )
{
transaction = partition.beginWriteTransaction();
if ( moveAndRenameContext.getSession().hasSessionTransaction() )
{
moveAndRenameContext.getSession().addTransaction( partition, transaction );
}
}
moveAndRenameContext.setOriginalEntry( getOriginalEntry( moveAndRenameContext ) );
moveAndRenameContext.setModifiedEntry( moveAndRenameContext.getOriginalEntry().clone() );
moveAndRenameContext.setTransaction( transaction );
// Call the MoveAndRename method
Interceptor head = directoryService.getInterceptor( moveAndRenameContext.getNextInterceptor() );
head.moveAndRename( moveAndRenameContext );
if ( !moveAndRenameContext.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( "<< MoveAndRenameOperation successful" );
}
if ( IS_TIME )
{
OPERATION_TIME.debug( "MoveAndRename operation took {} ns", ( System.nanoTime() - opStart ) );
}
}