in core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java [1271:1443]
public void move( MoveOperationContext moveContext ) throws LdapException
{
if ( IS_DEBUG )
{
OPERATION_LOG.debug( ">> MoveOperation : {}", moveContext );
}
long opStart = 0L;
if ( IS_TIME )
{
opStart = System.nanoTime();
}
ensureStarted();
// Normalize the moveContext Dn
Dn dn = moveContext.getDn();
if ( !dn.isSchemaAware() )
{
dn = new Dn( directoryService.getSchemaManager(), dn );
moveContext.setDn( dn );
}
// Normalize the moveContext superior Dn
Dn newSuperiorDn = moveContext.getNewSuperior();
if ( !newSuperiorDn.isSchemaAware() )
{
newSuperiorDn = new Dn( directoryService.getSchemaManager(), newSuperiorDn );
moveContext.setNewSuperior( newSuperiorDn );
}
// 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 ( !moveContext.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 ( moveContext.isReferralIgnored() )
{
throw buildLdapPartialResultException( childDn );
}
else
{
throw buildReferralException( parentEntry, childDn );
}
}
}
// Now, check the destination
// 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 ) )
{
throw new LdapAffectMultipleDsaException();
}
}
finally
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
}
lockWrite();
// Find the working partition
Partition partition = directoryService.getPartitionNexus().getPartition( dn );
moveContext.setPartition( partition );
// Start a Write transaction right away
PartitionTxn transaction = moveContext.getSession().getTransaction( partition );
try
{
if ( transaction == null )
{
transaction = partition.beginWriteTransaction();
if ( moveContext.getSession().hasSessionTransaction() )
{
moveContext.getSession().addTransaction( partition, transaction );
}
}
moveContext.setTransaction( transaction );
Entry originalEntry = getOriginalEntry( moveContext );
moveContext.setOriginalEntry( originalEntry );
// Call the Move method
Interceptor head = directoryService.getInterceptor( moveContext.getNextInterceptor() );
head.move( moveContext );
if ( !moveContext.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
{
if ( transaction != null )
{
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( "<< MoveOperation successful" );
}
if ( IS_TIME )
{
OPERATION_TIME.debug( "Move operation took {} ns", ( System.nanoTime() - opStart ) );
}
}