in core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java [352:481]
public void add( AddOperationContext addContext ) throws LdapException
{
if ( IS_DEBUG )
{
OPERATION_LOG.debug( ">> AddOperation : {}", addContext );
}
long addStart = 0L;
if ( IS_TIME )
{
addStart = System.nanoTime();
}
ensureStarted();
// Normalize the addContext Dn
Dn dn = addContext.getDn();
if ( !dn.isSchemaAware() )
{
dn = new Dn( directoryService.getSchemaManager(), dn );
addContext.setDn( dn );
}
// Find the working partition
Partition partition = directoryService.getPartitionNexus().getPartition( dn );
addContext.setPartition( partition );
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
try
{
if ( directoryService.getReferralManager().hasParentReferral( dn ) )
{
Entry parentEntry = directoryService.getReferralManager().getParentReferral( dn );
Dn childDn = dn.getDescendantOf( parentEntry.getDn() );
// Depending on the Context.REFERRAL property value, we will throw
// a different exception.
if ( addContext.isReferralIgnored() )
{
throw buildLdapPartialResultException( childDn );
}
else
{
throw buildReferralException( parentEntry, childDn );
}
}
}
finally
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
}
// Call the Add method
Interceptor head = directoryService.getInterceptor( addContext.getNextInterceptor() );
lockWrite();
// Start a Write transaction right away
PartitionTxn transaction = addContext.getSession().getTransaction( partition );
try
{
if ( transaction == null )
{
transaction = partition.beginWriteTransaction();
if ( addContext.getSession().hasSessionTransaction() )
{
addContext.getSession().addTransaction( partition, transaction );
}
}
addContext.setTransaction( transaction );
head.add( addContext );
if ( !addContext.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( "<< AddOperation successful" );
}
if ( IS_TIME )
{
OPERATION_TIME.debug( "Add operation took {} ns", ( System.nanoTime() - addStart ) );
}
}