You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by el...@apache.org on 2011/12/30 00:54:20 UTC
svn commit: r1225696 [5/5] - in /directory/apacheds/branches/apacheds-txns:
core-api/src/main/java/org/apache/directory/server/core/api/
core-api/src/main/java/org/apache/directory/server/core/api/filtering/
core-api/src/main/java/org/apache/directory/...
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultDirectoryService.java Thu Dec 29 23:54:19 2011
@@ -1154,7 +1154,6 @@ public class DefaultDirectoryService imp
throw new IllegalArgumentException( I18n.err( I18n.ERR_314 ) );
}
- TxnManager txnManager = txnManagerFactory.txnManagerInstance();
Cursor<ChangeLogEvent> cursor = null;
/*
@@ -1189,13 +1188,9 @@ public class DefaultDirectoryService imp
boolean startedTxn = false;
List<ChangeLogEvent> events = new LinkedList();
-
+
try
{
- txnManager.beginTransaction( true );
-
- startedTxn = true;
-
cursor = changeLog.getChangeLogStore().findAfter( revision );
cursor.afterLast();
@@ -1204,13 +1199,6 @@ public class DefaultDirectoryService imp
events.add( cursor.get() );
}
}
- catch ( Exception e )
- {
- if ( startedTxn )
- {
- txnManager.abortTransaction();
- }
- }
finally
{
try
@@ -1226,8 +1214,6 @@ public class DefaultDirectoryService imp
}
}
- txnManager.commitTransaction();
-
Iterator<ChangeLogEvent> it = events.iterator();
boolean inTxn = false;
@@ -1238,9 +1224,6 @@ public class DefaultDirectoryService imp
ChangeLogEvent event = it.next();
List<LdifEntry> reverses = event.getReverseLdifs();
- txnManager.beginTransaction( false );
- inTxn = true;
-
for ( LdifEntry reverse : reverses )
{
switch ( reverse.getChangeType().getChangeType() )
@@ -1276,18 +1259,10 @@ public class DefaultDirectoryService imp
throw new NotImplementedException( I18n.err( I18n.ERR_76, reverse.getChangeType() ) );
}
}
-
- inTxn = false;
- txnManager.commitTransaction();
}
}
catch ( Exception e )
{
- if ( inTxn )
- {
- txnManager.abortTransaction();
- }
-
throw e;
}
@@ -1324,8 +1299,6 @@ public class DefaultDirectoryService imp
}
}
- txnManager.applyPendingTxns();
-
return changeLog.getCurrentRevision();
}
Modified: directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java (original)
+++ directory/apacheds/branches/apacheds-txns/core/src/main/java/org/apache/directory/server/core/DefaultOperationManager.java Thu Dec 29 23:54:19 2011
@@ -44,6 +44,7 @@ import org.apache.directory.server.core.
import org.apache.directory.server.core.api.interceptor.context.RenameOperationContext;
import org.apache.directory.server.core.api.interceptor.context.SearchOperationContext;
import org.apache.directory.server.core.api.interceptor.context.UnbindOperationContext;
+import org.apache.directory.server.core.api.txn.TxnManager;
import org.apache.directory.server.i18n.I18n;
import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
import org.apache.directory.shared.ldap.model.entry.Attribute;
@@ -53,6 +54,7 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.model.exception.LdapException;
import org.apache.directory.shared.ldap.model.exception.LdapNoSuchObjectException;
import org.apache.directory.shared.ldap.model.exception.LdapOperationErrorException;
+import org.apache.directory.shared.ldap.model.exception.LdapOtherException;
import org.apache.directory.shared.ldap.model.exception.LdapPartialResultException;
import org.apache.directory.shared.ldap.model.exception.LdapReferralException;
import org.apache.directory.shared.ldap.model.exception.LdapServiceUnavailableException;
@@ -107,8 +109,9 @@ public class DefaultOperationManager imp
// trouble reading the entry due to insufficient access rights
CoreSession adminSession = opContext.getSession().getDirectoryService().getAdminSession();
- LookupOperationContext lookupContext = new LookupOperationContext( adminSession, opContext.getDn(), SchemaConstants.ALL_ATTRIBUTES_ARRAY );
-
+ LookupOperationContext lookupContext = new LookupOperationContext( adminSession, opContext.getDn(),
+ SchemaConstants.ALL_ATTRIBUTES_ARRAY );
+
Entry foundEntry = opContext.getSession().getDirectoryService().getPartitionNexus().lookup( lookupContext );
if ( foundEntry != null )
@@ -133,7 +136,11 @@ public class DefaultOperationManager imp
// trouble reading the entry due to insufficient access rights
CoreSession adminSession = opContext.getSession().getDirectoryService().getAdminSession();
- Entry foundEntry = adminSession.lookup( opContext.getDn(), SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES, SchemaConstants.ALL_USER_ATTRIBUTES );
+ LookupOperationContext lookupOperationContext = new LookupOperationContext( adminSession, opContext.getDn(),
+ new String[]
+ { SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES, SchemaConstants.ALL_USER_ATTRIBUTES } );
+ Entry foundEntry = opContext.getSession().getDirectoryService().getPartitionNexus()
+ .lookup( lookupOperationContext );
if ( foundEntry != null )
{
@@ -191,7 +198,8 @@ public class DefaultOperationManager imp
}
- private LdapReferralException buildReferralExceptionForSearch( Entry parentEntry, Dn childDn, SearchScope scope ) throws LdapException
+ private LdapReferralException buildReferralExceptionForSearch( Entry parentEntry, Dn childDn, SearchScope scope )
+ throws LdapException
{
// Get the Ref attributeType
Attribute refs = parentEntry.get( SchemaConstants.REF_AT );
@@ -272,6 +280,71 @@ public class DefaultOperationManager imp
/**
+ * Starts a Read only transaction
+ */
+ private void beginTransactionR( TxnManager txnManager ) throws LdapException
+ {
+ try
+ {
+ txnManager.beginTransaction( true );
+ }
+ catch ( Exception e )
+ {
+ throw new LdapOtherException( e.getMessage() );
+ }
+ }
+
+
+ /**
+ * Starts a RW transaction
+ */
+ private void beginTransactionRW( TxnManager txnManager ) throws LdapException
+ {
+ try
+ {
+ txnManager.beginTransaction( false );
+ }
+ catch ( Exception e )
+ {
+ throw new LdapOtherException( e.getMessage() );
+ }
+ }
+
+
+ /**
+ * Rollback a transaction
+ */
+ private void abortTransaction( TxnManager txnManager, LdapException exception ) throws LdapException
+ {
+ try
+ {
+ txnManager.abortTransaction();
+ }
+ catch ( Exception txne )
+ {
+ throw new LdapOtherException( txne.getMessage(), exception );
+ }
+ }
+
+
+ /**
+ * Commit a transaction
+ */
+ private void commitTransaction( TxnManager txnManager ) throws LdapException
+ {
+ try
+ {
+ txnManager.commitTransaction();
+ }
+ catch ( Exception e )
+ {
+ // TODO check for conflict
+ throw new LdapOtherException( e.getMessage(), e );
+ }
+ }
+
+
+ /**
* {@inheritDoc}
*/
public void add( AddOperationContext addContext ) throws LdapException
@@ -283,26 +356,26 @@ public class DefaultOperationManager imp
// Normalize the addContext Dn
Dn dn = addContext.getDn();
-
+
if ( !dn.isSchemaAware() )
{
dn.apply( directoryService.getSchemaManager() );
}
-
+
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
-
+
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() )
{
directoryService.getReferralManager().unlock();
-
+
LdapPartialResultException exception = buildLdapPartialResultException( childDn );
throw exception;
}
@@ -310,7 +383,7 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
@@ -319,11 +392,35 @@ public class DefaultOperationManager imp
{
// Unlock the ReferralManager
directoryService.getReferralManager().unlock();
-
+
// Call the Add method
Interceptor head = directoryService.getInterceptor( addContext.getNextInterceptor() );
-
- head.add( addContext );
+
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ boolean done = false;
+
+ do
+ {
+ beginTransactionRW( txnManager );
+
+ try
+ {
+ head.add( addContext );
+
+ done = true;
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw le;
+ }
+
+ commitTransaction( txnManager );
+ txnManager.applyPendingTxns();
+ }
+ while ( !done );
}
LOG.debug( "<< AddOperation successful" );
@@ -342,8 +439,31 @@ public class DefaultOperationManager imp
// Call the Bind method
Interceptor head = directoryService.getInterceptor( bindContext.getNextInterceptor() );
-
- head.bind( bindContext );
+
+ boolean done = false;
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ do
+ {
+ beginTransactionR( txnManager );
+
+ try
+ {
+ head.bind( bindContext );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw ( le );
+ }
+
+ // If here then we are done.
+ commitTransaction( txnManager );
+
+ done = true;
+ }
+ while ( !done );
LOG.debug( "<< BindOperation successful" );
}
@@ -360,18 +480,18 @@ public class DefaultOperationManager imp
// Normalize the compareContext Dn
Dn dn = compareContext.getDn();
dn.apply( directoryService.getSchemaManager() );
-
+
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
-
+
// 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
@@ -381,7 +501,7 @@ public class DefaultOperationManager imp
// Throw a Referral Exception
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
@@ -393,7 +513,7 @@ public class DefaultOperationManager imp
if ( compareContext.isReferralIgnored() )
{
directoryService.getReferralManager().unlock();
-
+
LdapPartialResultException exception = buildLdapPartialResultException( childDn );
throw exception;
}
@@ -401,26 +521,42 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
}
}
-
+
// Unlock the ReferralManager
directoryService.getReferralManager().unlock();
-
- // populate the context with the old entry
- compareContext.setOriginalEntry( getOriginalEntry( compareContext ) );
-
- // Call the Compare method
- Interceptor head = directoryService.getInterceptor( compareContext.getNextInterceptor() );
-
- boolean result = head.compare( compareContext );
+
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ beginTransactionR( txnManager );
+ boolean result = false;
+
+ try
+ {
+ // populate the context with the old entry
+ compareContext.setOriginalEntry( getOriginalEntry( compareContext ) );
+
+ // Call the Compare method
+ Interceptor head = directoryService.getInterceptor( compareContext.getNextInterceptor() );
+
+ result = head.compare( compareContext );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw le;
+ }
+
+ commitTransaction( txnManager );
LOG.debug( "<< CompareOperation successful" );
-
+
return result;
}
@@ -438,17 +574,17 @@ public class DefaultOperationManager imp
// Normalize the deleteContext Dn
Dn dn = deleteContext.getDn();
dn.apply( directoryService.getSchemaManager() );
-
+
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
-
+
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
@@ -458,7 +594,7 @@ public class DefaultOperationManager imp
// Throw a Referral Exception
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
@@ -466,13 +602,13 @@ public class DefaultOperationManager imp
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() )
{
directoryService.getReferralManager().unlock();
-
+
LdapPartialResultException exception = buildLdapPartialResultException( childDn );
throw exception;
}
@@ -480,23 +616,48 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
}
}
-
+
// Unlock the ReferralManager
directoryService.getReferralManager().unlock();
-
- // populate the context with the old entry
- eagerlyPopulateFields( deleteContext );
-
- // Call the Delete method
- Interceptor head = directoryService.getInterceptor( deleteContext.getNextInterceptor() );
-
- head.delete( deleteContext );
+
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ boolean done = false;
+
+ do
+ {
+ beginTransactionRW( txnManager );
+
+ try
+ {
+ // populate the context with the old entry
+ eagerlyPopulateFields( deleteContext );
+
+ // Call the Delete method
+ Interceptor head = directoryService.getInterceptor( deleteContext.getNextInterceptor() );
+
+ head.delete( deleteContext );
+
+ // If here then we are done.
+ done = true;
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw le;
+ }
+
+ commitTransaction( txnManager );
+ txnManager.applyPendingTxns();
+ }
+ while ( !done );
LOG.debug( "<< DeleteOperation successful" );
LOG_CHANGES.debug( "<< DeleteOperation successful" );
@@ -513,12 +674,12 @@ public class DefaultOperationManager imp
ensureStarted();
Interceptor head = directoryService.getInterceptor( getRootDseContext.getNextInterceptor() );
-
+
// Call the getRootDSE method
Entry root = head.getRootDse( getRootDseContext );
-
+
LOG.debug( "<< getRootDseOperation successful" );
-
+
return root;
}
@@ -533,12 +694,28 @@ public class DefaultOperationManager imp
ensureStarted();
Interceptor head = directoryService.getInterceptor( hasEntryContext.getNextInterceptor() );
-
- // Call the hasEntry method
- boolean result = head.hasEntry( hasEntryContext );
-
+
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ beginTransactionR( txnManager );
+ boolean result = false;
+
+ try
+ {
+ // Call the hasEntry method
+ result = head.hasEntry( hasEntryContext );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ return false;
+ }
+
+ commitTransaction( txnManager );
+
LOG.debug( "<< HasEntryOperation successful" );
-
+
return result;
}
@@ -553,12 +730,28 @@ public class DefaultOperationManager imp
ensureStarted();
Interceptor head = directoryService.getInterceptor( listContext.getNextInterceptor() );
-
+
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ beginTransactionR( txnManager );
+ EntryFilteringCursor cursor = null;
+
// Call the list method
- EntryFilteringCursor cursor = head.list( listContext );
-
+ try
+ {
+ cursor = head.list( listContext );
+
+ cursor.setTxnManager( txnManager );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw le;
+ }
+
LOG.debug( "<< ListOperation successful" );
-
+
return cursor;
}
@@ -573,12 +766,28 @@ public class DefaultOperationManager imp
ensureStarted();
Interceptor head = directoryService.getInterceptor( lookupContext.getNextInterceptor() );
-
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ beginTransactionR( txnManager );
+
// Call the lookup method
- Entry entry = head.lookup( lookupContext );
-
+ Entry entry = null;
+
+ try
+ {
+ entry = head.lookup( lookupContext );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw le;
+ }
+
+ commitTransaction( txnManager );
+
LOG.debug( "<< LookupOperation successful" );
-
+
return entry;
}
@@ -596,15 +805,15 @@ public class DefaultOperationManager imp
// Normalize the modifyContext Dn
Dn dn = modifyContext.getDn();
dn.apply( directoryService.getSchemaManager() );
-
+
ReferralManager referralManager = directoryService.getReferralManager();
-
+
// We have to deal with the referral first
referralManager.lockRead();
-
+
// Check if we have an ancestor for this Dn
Entry parentEntry = referralManager.getParentReferral( dn );
-
+
if ( parentEntry != null )
{
if ( referralManager.isReferral( dn ) )
@@ -616,10 +825,10 @@ public class DefaultOperationManager imp
// Throw a Referral Exception
// Unlock the referral manager
referralManager.unlock();
-
+
// We have found a parent referral for the current Dn
Dn childDn = dn.getDescendantOf( parentEntry.getDn() );
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
@@ -627,16 +836,16 @@ public class DefaultOperationManager imp
else if ( referralManager.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 ( modifyContext.isReferralIgnored() )
{
referralManager.unlock();
-
+
// We have found a parent referral for the current Dn
Dn childDn = dn.getDescendantOf( parentEntry.getDn() );
-
+
LdapPartialResultException exception = buildLdapPartialResultException( childDn );
throw exception;
}
@@ -644,26 +853,50 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
referralManager.unlock();
-
+
// We have found a parent referral for the current Dn
Dn childDn = dn.getDescendantOf( parentEntry.getDn() );
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
}
}
-
+
// Unlock the ReferralManager
referralManager.unlock();
-
- // populate the context with the old entry
- eagerlyPopulateFields( modifyContext );
-
- // Call the Modify method
- Interceptor head = directoryService.getInterceptor( modifyContext.getNextInterceptor() );
-
- head.modify( modifyContext );
+
+ boolean done = false;
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ do
+ {
+ beginTransactionRW( txnManager );
+
+ try
+ {
+ // populate the context with the old entry
+ eagerlyPopulateFields( modifyContext );
+
+ // Call the Modify method
+ Interceptor head = directoryService.getInterceptor( modifyContext.getNextInterceptor() );
+
+ head.modify( modifyContext );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw ( le );
+ }
+
+ // If here then we are done.
+ done = true;
+
+ commitTransaction( txnManager );
+ txnManager.applyPendingTxns();
+ }
+ while ( !done );
LOG.debug( "<< ModifyOperation successful" );
LOG_CHANGES.debug( "<< ModifyOperation successful" );
@@ -683,22 +916,22 @@ public class DefaultOperationManager imp
// Normalize the moveContext Dn
Dn dn = moveContext.getDn();
dn.apply( directoryService.getSchemaManager() );
-
+
// Normalize the moveContext superior Dn
Dn newSuperiorDn = moveContext.getNewSuperior();
newSuperiorDn.apply( directoryService.getSchemaManager() );
-
+
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
-
+
// 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
@@ -708,7 +941,7 @@ public class DefaultOperationManager imp
// Throw a Referral Exception
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
@@ -716,13 +949,13 @@ public class DefaultOperationManager imp
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() )
{
directoryService.getReferralManager().unlock();
-
+
LdapPartialResultException exception = buildLdapPartialResultException( childDn );
throw exception;
}
@@ -730,13 +963,13 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
}
}
-
+
// 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
@@ -745,25 +978,49 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapAffectMultipleDsaException exception = new LdapAffectMultipleDsaException();
//exception.setRemainingName( dn );
-
+
throw exception;
}
-
+
// Unlock the ReferralManager
directoryService.getReferralManager().unlock();
-
- Entry originalEntry = getOriginalEntry( moveContext );
-
- moveContext.setOriginalEntry( originalEntry );
-
- // Call the Move method
- Interceptor head = directoryService.getInterceptor( moveContext.getNextInterceptor() );
-
- head.move( moveContext );
-
+
+ boolean done = false;
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ do
+ {
+ beginTransactionRW( txnManager );
+
+ try
+ {
+ Entry originalEntry = getOriginalEntry( moveContext );
+
+ moveContext.setOriginalEntry( originalEntry );
+
+ // Call the Move method
+ Interceptor head = directoryService.getInterceptor( moveContext.getNextInterceptor() );
+
+ head.move( moveContext );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw ( le );
+ }
+
+ // If here then we are done.
+ done = true;
+
+ commitTransaction( txnManager );
+ txnManager.applyPendingTxns();
+ }
+ while ( !done );
+
LOG.debug( "<< MoveOperation successful" );
LOG_CHANGES.debug( "<< MoveOperation successful" );
}
@@ -782,18 +1039,18 @@ public class DefaultOperationManager imp
// Normalize the moveAndRenameContext Dn
Dn dn = moveAndRenameContext.getDn();
dn.apply( directoryService.getSchemaManager() );
-
+
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
-
+
// 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
@@ -803,7 +1060,7 @@ public class DefaultOperationManager imp
// Throw a Referral Exception
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
@@ -811,13 +1068,13 @@ public class DefaultOperationManager imp
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() )
{
directoryService.getReferralManager().unlock();
-
+
LdapPartialResultException exception = buildLdapPartialResultException( childDn );
throw exception;
}
@@ -825,18 +1082,18 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
}
}
-
+
// Now, check the destination
// Normalize the moveAndRenameContext Dn
Dn newSuperiorDn = moveAndRenameContext.getNewSuperiorDn();
newSuperiorDn.apply( directoryService.getSchemaManager() );
-
+
// 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 )
@@ -844,26 +1101,50 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
// The parent Dn is a referral, we have to issue a AffectMultipleDsas result
// as stated by RFC 3296 Section 5.6.2
LdapAffectMultipleDsaException exception = new LdapAffectMultipleDsaException();
//exception.setRemainingName( dn );
-
+
throw exception;
}
-
+
// Unlock the ReferralManager
directoryService.getReferralManager().unlock();
-
- moveAndRenameContext.setOriginalEntry( getOriginalEntry( moveAndRenameContext ) );
- moveAndRenameContext.setModifiedEntry( moveAndRenameContext.getOriginalEntry().clone() );
-
- // Call the MoveAndRename method
- Interceptor head = directoryService.getInterceptor( moveAndRenameContext.getNextInterceptor() );
-
- head.moveAndRename( moveAndRenameContext );
-
+
+ boolean done = false;
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ do
+ {
+ beginTransactionRW( txnManager );
+
+ try
+ {
+ moveAndRenameContext.setOriginalEntry( getOriginalEntry( moveAndRenameContext ) );
+ moveAndRenameContext.setModifiedEntry( moveAndRenameContext.getOriginalEntry().clone() );
+
+ // Call the MoveAndRename method
+ Interceptor head = directoryService.getInterceptor( moveAndRenameContext.getNextInterceptor() );
+
+ head.moveAndRename( moveAndRenameContext );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw ( le );
+ }
+
+ // If here then we are done.
+ done = true;
+
+ commitTransaction( txnManager );
+ txnManager.applyPendingTxns();
+ }
+ while ( !done );
+
LOG.debug( "<< MoveAndRenameOperation successful" );
LOG_CHANGES.debug( "<< MoveAndRenameOperation successful" );
}
@@ -882,7 +1163,7 @@ public class DefaultOperationManager imp
// Normalize the renameContext Dn
Dn dn = renameContext.getDn();
dn.apply( directoryService.getSchemaManager() );
-
+
// Inject the newDn into the operation context
// Inject the new Dn into the context
if ( !dn.isEmpty() )
@@ -891,18 +1172,18 @@ public class DefaultOperationManager imp
newDn = newDn.add( renameContext.getNewRdn() );
renameContext.setNewDn( newDn );
}
-
+
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
-
+
// 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
@@ -912,7 +1193,7 @@ public class DefaultOperationManager imp
// Throw a Referral Exception
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
@@ -920,13 +1201,13 @@ public class DefaultOperationManager imp
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 ( renameContext.isReferralIgnored() )
{
directoryService.getReferralManager().unlock();
-
+
LdapPartialResultException exception = buildLdapPartialResultException( childDn );
throw exception;
}
@@ -934,28 +1215,52 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralException( parentEntry, childDn );
throw exception;
}
}
}
-
+
// Unlock the ReferralManager
directoryService.getReferralManager().unlock();
-
- // Call the rename method
- // populate the context with the old entry
- eagerlyPopulateFields( renameContext );
- Entry originalEntry = getOriginalEntry( renameContext );
- renameContext.setOriginalEntry( originalEntry );
- renameContext.setModifiedEntry( originalEntry.clone() );
-
- // Call the Rename method
- Interceptor head = directoryService.getInterceptor( renameContext.getNextInterceptor() );
-
- head.rename( renameContext );
-
+
+ boolean done = false;
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ do
+ {
+ beginTransactionRW( txnManager );
+
+ try
+ {
+ // Call the rename method
+ // populate the context with the old entry
+ eagerlyPopulateFields( renameContext );
+ Entry originalEntry = getOriginalEntry( renameContext );
+ renameContext.setOriginalEntry( originalEntry );
+ renameContext.setModifiedEntry( originalEntry.clone() );
+
+ // Call the Rename method
+ Interceptor head = directoryService.getInterceptor( renameContext.getNextInterceptor() );
+
+ head.rename( renameContext );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw ( le );
+ }
+
+ // If here then we are done.
+ done = true;
+
+ commitTransaction( txnManager );
+ txnManager.applyPendingTxns();
+ }
+ while ( !done );
+
LOG.debug( "<< RenameOperation successful" );
LOG_CHANGES.debug( "<< RenameOperation successful" );
}
@@ -973,18 +1278,18 @@ public class DefaultOperationManager imp
// Normalize the searchContext Dn
Dn dn = searchContext.getDn();
dn.apply( directoryService.getSchemaManager() );
-
+
// We have to deal with the referral first
directoryService.getReferralManager().lockRead();
-
+
// 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 return it if the ManageDsaIt flag is true
@@ -994,7 +1299,7 @@ public class DefaultOperationManager imp
// Throw a Referral Exception
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralExceptionForSearch( parentEntry, childDn,
searchContext.getScope() );
throw exception;
@@ -1003,13 +1308,13 @@ public class DefaultOperationManager imp
else if ( directoryService.getReferralManager().hasParentReferral( dn ) )
{
// We can't search an entry which has an ancestor referral
-
+
// Depending on the Context.REFERRAL property value, we will throw
// a different exception.
if ( searchContext.isReferralIgnored() )
{
directoryService.getReferralManager().unlock();
-
+
LdapPartialResultException exception = buildLdapPartialResultException( childDn );
throw exception;
}
@@ -1017,24 +1322,40 @@ public class DefaultOperationManager imp
{
// Unlock the referral manager
directoryService.getReferralManager().unlock();
-
+
LdapReferralException exception = buildReferralExceptionForSearch( parentEntry, childDn,
searchContext.getScope() );
throw exception;
}
}
}
-
+
// Unlock the ReferralManager
directoryService.getReferralManager().unlock();
-
+
// Call the Search method
Interceptor head = directoryService.getInterceptor( searchContext.getNextInterceptor() );
-
- EntryFilteringCursor cursor = head.search( searchContext );
-
+
+ TxnManager txnManager = directoryService.getTxnManager();
+
+ beginTransactionR( txnManager );
+ EntryFilteringCursor cursor = null;
+
+ try
+ {
+ cursor = head.search( searchContext );
+
+ cursor.setTxnManager( txnManager );
+ }
+ catch ( LdapException le )
+ {
+ abortTransaction( txnManager, le );
+
+ throw le;
+ }
+
LOG.debug( "<< SearchOperation successful" );
-
+
return cursor;
}
Modified: directory/apacheds/branches/apacheds-txns/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java (original)
+++ directory/apacheds/branches/apacheds-txns/interceptors/schema/src/main/java/org/apache/directory/server/core/schema/SchemaSubentryModifier.java Thu Dec 29 23:54:19 2011
@@ -20,10 +20,12 @@
package org.apache.directory.server.core.schema;
+import org.apache.directory.server.core.api.CoreSession;
import org.apache.directory.server.core.api.DnFactory;
import org.apache.directory.server.core.api.interceptor.Interceptor;
import org.apache.directory.server.core.api.interceptor.context.AddOperationContext;
import org.apache.directory.server.core.api.interceptor.context.DeleteOperationContext;
+import org.apache.directory.server.core.api.interceptor.context.LookupOperationContext;
import org.apache.directory.server.core.api.interceptor.context.ModifyOperationContext;
import org.apache.directory.shared.ldap.model.constants.MetaSchemaConstants;
import org.apache.directory.shared.ldap.model.constants.SchemaConstants;
@@ -43,8 +45,8 @@ import org.apache.directory.shared.ldap.
import org.apache.directory.shared.ldap.model.schema.SchemaManager;
import org.apache.directory.shared.ldap.model.schema.SchemaObject;
import org.apache.directory.shared.ldap.model.schema.parsers.LdapComparatorDescription;
-import org.apache.directory.shared.ldap.model.schema.parsers.SyntaxCheckerDescription;
import org.apache.directory.shared.ldap.model.schema.parsers.NormalizerDescription;
+import org.apache.directory.shared.ldap.model.schema.parsers.SyntaxCheckerDescription;
import org.apache.directory.shared.ldap.model.schema.registries.Schema;
import org.apache.directory.shared.util.Base64;
@@ -78,8 +80,8 @@ public class SchemaSubentryModifier
this.schemaManager = schemaManager;
this.dnFactory = dnFactory;
}
-
-
+
+
private Dn getDn( SchemaObject obj ) throws LdapInvalidDnException
{
StringBuffer buf = new StringBuffer();
@@ -121,9 +123,10 @@ public class SchemaSubentryModifier
buf.append( ",cn=" ).append( obj.getSchemaName() ).append( ",ou=schema" );
return dnFactory.create( buf.toString() );
}
-
- public void add( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext, LdapComparatorDescription comparatorDescription ) throws LdapException
+
+ public void add( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext,
+ LdapComparatorDescription comparatorDescription ) throws LdapException
{
String schemaName = getSchema( comparatorDescription );
Dn dn = dnFactory.create(
@@ -131,7 +134,7 @@ public class SchemaSubentryModifier
SchemaConstants.COMPARATORS_PATH,
"cn=" + schemaName,
SchemaConstants.OU_SCHEMA );
-
+
Entry entry = getEntry( dn, comparatorDescription );
AddOperationContext addContext = new AddOperationContext( modifyContext.getSession(), entry );
@@ -139,17 +142,18 @@ public class SchemaSubentryModifier
nextInterceptor.add( addContext );
}
-
-
- public void add( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext, NormalizerDescription normalizerDescription ) throws LdapException
+
+
+ public void add( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext,
+ NormalizerDescription normalizerDescription ) throws LdapException
{
String schemaName = getSchema( normalizerDescription );
Dn dn = dnFactory.create(
"m-oid=" + normalizerDescription.getOid(),
- SchemaConstants.NORMALIZERS_PATH ,
+ SchemaConstants.NORMALIZERS_PATH,
"cn=" + schemaName,
SchemaConstants.OU_SCHEMA );
-
+
Entry entry = getEntry( dn, normalizerDescription );
AddOperationContext addContext = new AddOperationContext( modifyContext.getSession(), entry );
@@ -157,9 +161,10 @@ public class SchemaSubentryModifier
nextInterceptor.add( addContext );
}
-
-
- public void add( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext, SyntaxCheckerDescription syntaxCheckerDescription ) throws LdapException
+
+
+ public void add( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext,
+ SyntaxCheckerDescription syntaxCheckerDescription ) throws LdapException
{
String schemaName = getSchema( syntaxCheckerDescription );
Dn dn = dnFactory.create(
@@ -167,7 +172,7 @@ public class SchemaSubentryModifier
SchemaConstants.SYNTAX_CHECKERS_PATH,
"cn=" + schemaName,
SchemaConstants.OU_SCHEMA );
-
+
Entry entry = getEntry( dn, syntaxCheckerDescription );
AddOperationContext addContext = new AddOperationContext( modifyContext.getSession(), entry );
@@ -175,15 +180,16 @@ public class SchemaSubentryModifier
nextInterceptor.add( addContext );
}
-
-
- public void addSchemaObject( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext, SchemaObject obj ) throws LdapException
+
+
+ public void addSchemaObject( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext,
+ SchemaObject obj ) throws LdapException
{
Schema schema = schemaManager.getLoadedSchema( obj.getSchemaName() );
Dn dn = getDn( obj );
Entry entry = factory.getAttributes( obj, schema, schemaManager );
entry.setDn( dn );
-
+
AddOperationContext addContext = new AddOperationContext( modifyContext.getSession(), entry );
addContext.setCurrentInterceptor( position );
@@ -191,19 +197,23 @@ public class SchemaSubentryModifier
}
- public void deleteSchemaObject( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext, SchemaObject obj ) throws LdapException
+ public void deleteSchemaObject( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext,
+ SchemaObject obj ) throws LdapException
{
Dn dn = getDn( obj );
- DeleteOperationContext deleteContext = new DeleteOperationContext( modifyContext.getSession(), dn );
- deleteContext.setEntry( modifyContext.getSession().lookup( dn ) );
+ CoreSession session = modifyContext.getSession();
+ DeleteOperationContext deleteContext = new DeleteOperationContext( session, dn );
+ LookupOperationContext lookupContext = new LookupOperationContext( session, dn );
+ deleteContext.setEntry( session.getDirectoryService().getPartitionNexus().lookup( lookupContext ) );
deleteContext.setCurrentInterceptor( position );
nextInterceptor.delete( deleteContext );
}
-
- public void delete( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext, NormalizerDescription normalizerDescription ) throws LdapException
+
+ public void delete( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext,
+ NormalizerDescription normalizerDescription ) throws LdapException
{
String schemaName = getSchema( normalizerDescription );
Dn dn = dnFactory.create(
@@ -211,16 +221,19 @@ public class SchemaSubentryModifier
SchemaConstants.NORMALIZERS_PATH,
"cn=" + schemaName,
SchemaConstants.OU_SCHEMA );
-
- DeleteOperationContext deleteContext = new DeleteOperationContext( modifyContext.getSession(), dn );
- deleteContext.setEntry( modifyContext.getSession().lookup( dn ) );
+
+ CoreSession session = modifyContext.getSession();
+ DeleteOperationContext deleteContext = new DeleteOperationContext( session, dn );
+ LookupOperationContext lookupContext = new LookupOperationContext( session, dn );
+ deleteContext.setEntry( session.getDirectoryService().getPartitionNexus().lookup( lookupContext ) );
deleteContext.setCurrentInterceptor( position );
nextInterceptor.delete( deleteContext );
}
- public void delete( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext, SyntaxCheckerDescription syntaxCheckerDescription ) throws LdapException
+ public void delete( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext,
+ SyntaxCheckerDescription syntaxCheckerDescription ) throws LdapException
{
String schemaName = getSchema( syntaxCheckerDescription );
Dn dn = dnFactory.create(
@@ -229,15 +242,18 @@ public class SchemaSubentryModifier
"cn=" + schemaName,
SchemaConstants.OU_SCHEMA );
- DeleteOperationContext deleteContext = new DeleteOperationContext( modifyContext.getSession(), dn );
- deleteContext.setEntry( modifyContext.getSession().lookup( dn ) );
+ CoreSession session = modifyContext.getSession();
+ DeleteOperationContext deleteContext = new DeleteOperationContext( session, dn );
+ LookupOperationContext lookupContext = new LookupOperationContext( session, dn );
+ deleteContext.setEntry( session.getDirectoryService().getPartitionNexus().lookup( lookupContext ) );
deleteContext.setCurrentInterceptor( position );
nextInterceptor.delete( deleteContext );
}
- public void delete( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext, LdapComparatorDescription comparatorDescription ) throws LdapException
+ public void delete( Interceptor nextInterceptor, int position, ModifyOperationContext modifyContext,
+ LdapComparatorDescription comparatorDescription ) throws LdapException
{
String schemaName = getSchema( comparatorDescription );
Dn dn = dnFactory.create(
@@ -245,9 +261,11 @@ public class SchemaSubentryModifier
SchemaConstants.COMPARATORS_PATH,
"cn=" + schemaName,
SchemaConstants.OU_SCHEMA );
-
- DeleteOperationContext deleteContext = new DeleteOperationContext( modifyContext.getSession(), dn );
- deleteContext.setEntry( modifyContext.getSession().lookup( dn ) );
+
+ CoreSession session = modifyContext.getSession();
+ DeleteOperationContext deleteContext = new DeleteOperationContext( session, dn );
+ LookupOperationContext lookupContext = new LookupOperationContext( session, dn );
+ deleteContext.setEntry( session.getDirectoryService().getPartitionNexus().lookup( lookupContext ) );
deleteContext.setCurrentInterceptor( position );
nextInterceptor.delete( deleteContext );
@@ -257,12 +275,12 @@ public class SchemaSubentryModifier
private Entry getEntry( Dn dn, LdapComparatorDescription comparatorDescription )
{
Entry entry = new DefaultEntry( schemaManager, dn );
-
+
entry.put( SchemaConstants.OBJECT_CLASS_AT,
- SchemaConstants.TOP_OC,
- MetaSchemaConstants.META_TOP_OC,
- MetaSchemaConstants.META_COMPARATOR_OC );
-
+ SchemaConstants.TOP_OC,
+ MetaSchemaConstants.META_TOP_OC,
+ MetaSchemaConstants.META_COMPARATOR_OC );
+
entry.put( MetaSchemaConstants.M_OID_AT, comparatorDescription.getOid() );
entry.put( MetaSchemaConstants.M_FQCN_AT, comparatorDescription.getFqcn() );
@@ -271,12 +289,12 @@ public class SchemaSubentryModifier
entry.put( MetaSchemaConstants.M_BYTECODE_AT,
Base64.decode( comparatorDescription.getBytecode().toCharArray() ) );
}
-
+
if ( comparatorDescription.getDescription() != null )
{
entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, comparatorDescription.getDescription() );
}
-
+
return entry;
}
@@ -289,7 +307,7 @@ public class SchemaSubentryModifier
SchemaConstants.TOP_OC,
MetaSchemaConstants.META_TOP_OC,
MetaSchemaConstants.META_NORMALIZER_OC );
-
+
entry.put( MetaSchemaConstants.M_OID_AT, normalizerDescription.getOid() );
entry.put( MetaSchemaConstants.M_FQCN_AT, normalizerDescription.getFqcn() );
@@ -298,12 +316,12 @@ public class SchemaSubentryModifier
entry.put( MetaSchemaConstants.M_BYTECODE_AT,
Base64.decode( normalizerDescription.getBytecode().toCharArray() ) );
}
-
+
if ( normalizerDescription.getDescription() != null )
{
entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, normalizerDescription.getDescription() );
}
-
+
return entry;
}
@@ -314,15 +332,15 @@ public class SchemaSubentryModifier
{
return desc.getExtensions().get( MetaSchemaConstants.X_SCHEMA ).get( 0 );
}
-
+
return MetaSchemaConstants.SCHEMA_OTHER;
}
-
-
+
+
private Entry getEntry( Dn dn, SyntaxCheckerDescription syntaxCheckerDescription )
{
Entry entry = new DefaultEntry( schemaManager, dn );
-
+
entry.put( SchemaConstants.OBJECT_CLASS_AT,
SchemaConstants.TOP_OC,
MetaSchemaConstants.META_TOP_OC,
@@ -334,14 +352,14 @@ public class SchemaSubentryModifier
if ( syntaxCheckerDescription.getBytecode() != null )
{
entry.put( MetaSchemaConstants.M_BYTECODE_AT,
- Base64.decode(syntaxCheckerDescription.getBytecode().toCharArray()) );
+ Base64.decode( syntaxCheckerDescription.getBytecode().toCharArray() ) );
}
-
+
if ( syntaxCheckerDescription.getDescription() != null )
{
entry.put( MetaSchemaConstants.M_DESCRIPTION_AT, syntaxCheckerDescription.getDescription() );
}
-
+
return entry;
}
}
Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java (original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/AddHandler.java Thu Dec 29 23:54:19 2011
@@ -51,38 +51,9 @@ public class AddHandler extends LdapRequ
try
{
- boolean done = false;
-
- do
- {
- txnManager.beginTransaction( false );
-
- try
- {
- // Call the underlying layer to inject the new entry
- CoreSession coreSession = session.getCoreSession();
- coreSession.add( req );
- }
- catch ( Exception e )
- {
- txnManager.abortTransaction();
-
- handleException( session, req, e );
- }
-
- // If here then we are done.
- done = true;
-
- try
- {
- txnManager.commitTransaction();
- }
- catch( Exception e )
- {
- handleException( session, req, e );
- }
- }
- while ( !done );
+ // Call the underlying layer to inject the new entry
+ CoreSession coreSession = session.getCoreSession();
+ coreSession.add( req );
// If success, here now, otherwise, we would have an exception.
result.setResultCode( ResultCodeEnum.SUCCESS );
Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java (original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/BindHandler.java Thu Dec 29 23:54:19 2011
@@ -159,6 +159,7 @@ public class BindHandler extends LdapReq
result.setDiagnosticMessage( "Bind principalDn points to referral." );
result.setResultCode( ResultCodeEnum.INVALID_CREDENTIALS );
ldapSession.getIoSession().write( bindRequest.getResultResponse() );
+
return;
}
@@ -602,40 +603,14 @@ public class BindHandler extends LdapReq
return;
}
- boolean done = false;
-
- do
+ // Deal with the two kinds of authentication : Simple and SASL
+ if ( bindRequest.isSimple() )
{
- txnManager.beginTransaction( false );
-
- try
- {
- // Deal with the two kinds of authentication : Simple and SASL
- if ( bindRequest.isSimple() )
- {
- handleSimpleAuth( ldapSession, bindRequest );
- }
- else
- {
- handleSaslAuth( ldapSession, bindRequest );
- }
- }
- catch ( Exception e )
- {
- e.printStackTrace();
- txnManager.abortTransaction();
-
- // TODO Instead of rethrowing the exception here all the time, check
- // if the root cause if conflictexception and retry by going to he
- // beginning of the loop if necessary.
-
- throw ( e );
- }
-
- // If here then we are done.
- txnManager.commitTransaction();
- done = true;
+ handleSimpleAuth( ldapSession, bindRequest );
+ }
+ else
+ {
+ handleSaslAuth( ldapSession, bindRequest );
}
- while ( !done );
}
}
Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java (original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/CompareHandler.java Thu Dec 29 23:54:19 2011
@@ -24,7 +24,6 @@ import org.apache.directory.server.ldap.
import org.apache.directory.shared.ldap.model.message.CompareRequest;
import org.apache.directory.shared.ldap.model.message.LdapResult;
import org.apache.directory.shared.ldap.model.message.ResultCodeEnum;
-
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -38,7 +37,7 @@ public class CompareHandler extends Ldap
{
private static final Logger LOG = LoggerFactory.getLogger( CompareHandler.class );
-
+
/**
* @see LdapRequestHandler#handle(LdapSession, org.apache.directory.shared.ldap.model.message.Request)
*/
@@ -47,32 +46,18 @@ public class CompareHandler extends Ldap
{
LOG.debug( "Handling compare request while ignoring referrals: {}", req );
LdapResult result = req.getResultResponse().getLdapResult();
-
- try
- {
- txnManager.beginTransaction( true );
- try
+ try
+ {
+ if ( session.getCoreSession().compare( req ) )
{
- if ( session.getCoreSession().compare( req ) )
- {
- result.setResultCode( ResultCodeEnum.COMPARE_TRUE );
- }
- else
- {
- result.setResultCode( ResultCodeEnum.COMPARE_FALSE );
- }
+ result.setResultCode( ResultCodeEnum.COMPARE_TRUE );
}
- catch ( Exception e )
+ else
{
- txnManager.abortTransaction();
- throw ( e );
+ result.setResultCode( ResultCodeEnum.COMPARE_FALSE );
}
- // If here then we are done.
- txnManager.commitTransaction();
-
-
result.setMatchedDn( req.getName() );
session.getIoSession().write( req.getResultResponse() );
}
Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java (original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/DeleteHandler.java Thu Dec 29 23:54:19 2011
@@ -50,39 +50,9 @@ public class DeleteHandler extends LdapR
try
{
- boolean done = false;
-
- do
- {
- txnManager.beginTransaction( false );
-
- try
- {
- // Call the underlying layer to delete the entry
- CoreSession coreSession = session.getCoreSession();
- coreSession.delete( req );
- }
- catch ( Exception e )
- {
- txnManager.abortTransaction();
-
- throw ( e );
- }
-
- // If here then we are done.
- done = true;
-
- try
- {
- txnManager.commitTransaction();
- }
- catch( Exception e )
- {
- // TODO check for conflict
- throw e;
- }
- }
- while ( !done );
+ // Call the underlying layer to delete the entry
+ CoreSession coreSession = session.getCoreSession();
+ coreSession.delete( req );
// If success, here now, otherwise, we would have an exception.
result.setResultCode( ResultCodeEnum.SUCCESS );
Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java (original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyDnHandler.java Thu Dec 29 23:54:19 2011
@@ -19,7 +19,7 @@
*/
package org.apache.directory.server.ldap.handlers;
-
+
import org.apache.directory.server.core.api.CoreSession;
import org.apache.directory.server.ldap.LdapSession;
import org.apache.directory.shared.ldap.model.message.LdapResult;
@@ -40,7 +40,7 @@ public class ModifyDnHandler extends Lda
{
private static final Logger LOG = LoggerFactory.getLogger( ModifyDnHandler.class );
-
+
/**
* Deal with a ModifyDN request received from a client.
*
@@ -71,89 +71,34 @@ public class ModifyDnHandler extends Lda
session.getIoSession().write( req.getResultResponse() );
return;
}
-
+
try
{
SchemaManager schemaManager = session.getCoreSession().getDirectoryService().getSchemaManager();
Dn newRdn = new Dn( schemaManager, req.getNewRdn().getName() );
-
+
Dn oldRdn = new Dn( schemaManager, req.getName().getRdn().getName() );
-
- boolean rdnChanged = req.getNewRdn() != null &&
- ! newRdn.getNormName().equals( oldRdn.getNormName() );
-
+
+ boolean rdnChanged = req.getNewRdn() != null &&
+ !newRdn.getNormName().equals( oldRdn.getNormName() );
+
CoreSession coreSession = session.getCoreSession();
-
+
if ( rdnChanged )
- {
- boolean done = false;
-
- do
+ {
+ if ( req.getNewSuperior() != null )
+ {
+ coreSession.moveAndRename( req );
+ }
+ else
{
- txnManager.beginTransaction( false );
-
- try
- {
- if ( req.getNewSuperior() != null )
- {
- coreSession.moveAndRename( req );
- }
- else
- {
- coreSession.rename( req );
- }
- }
- catch ( Exception e )
- {
- txnManager.abortTransaction();
-
- // TODO Instead of rethrowing the exception here all the time, check
- // if the root cause if conflictexception and retry by going to he
- // beginning of the loop if necessary.
-
- throw ( e );
- }
-
- // If here then we are done.
- txnManager.commitTransaction();
- done = true;
+ coreSession.rename( req );
}
- while ( !done );
}
else if ( req.getNewSuperior() != null )
{
- boolean done = false;
-
- do
- {
- txnManager.beginTransaction( false );
-
- try
- {
- req.setNewRdn( null );
- coreSession.move( req );
- }
- catch ( Exception e )
- {
- txnManager.abortTransaction();
-
- throw ( e );
- }
-
- // If here then we are done.
- done = true;
-
- try
- {
- txnManager.commitTransaction();
- }
- catch( Exception e )
- {
- // TODO check for conflict
- throw e;
- }
- }
- while ( !done );
+ req.setNewRdn( null );
+ coreSession.move( req );
}
else
{
@@ -161,6 +106,7 @@ public class ModifyDnHandler extends Lda
result.setResultCode( ResultCodeEnum.ENTRY_ALREADY_EXISTS );
result.setMatchedDn( req.getName() );
session.getIoSession().write( req.getResultResponse() );
+
return;
}
Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java (original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/ModifyHandler.java Thu Dec 29 23:54:19 2011
@@ -50,39 +50,9 @@ public class ModifyHandler extends LdapR
try
{
- boolean done = false;
-
- do
- {
- txnManager.beginTransaction( false );
-
- try
- {
- // Call the underlying layer to delete the entry
- CoreSession coreSession = session.getCoreSession();
- coreSession.modify( req );
- }
- catch ( Exception e )
- {
- txnManager.abortTransaction();
-
- throw ( e );
- }
-
- // If here then we are done.
- done = true;
-
- try
- {
- txnManager.commitTransaction();
- }
- catch( Exception e )
- {
- // TODO check for conflict
- throw e;
- }
- }
- while ( !done );
+ // Call the underlying layer to delete the entry
+ CoreSession coreSession = session.getCoreSession();
+ coreSession.modify( req );
// If success, here now, otherwise, we would have an exception.
result.setResultCode( ResultCodeEnum.SUCCESS );
Modified: directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java
URL: http://svn.apache.org/viewvc/directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java?rev=1225696&r1=1225695&r2=1225696&view=diff
==============================================================================
--- directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java (original)
+++ directory/apacheds/branches/apacheds-txns/protocol-ldap/src/main/java/org/apache/directory/server/ldap/handlers/SearchHandler.java Thu Dec 29 23:54:19 2011
@@ -190,11 +190,11 @@ public class SearchHandler extends LdapR
LOG.warn( "This server does not allow replication" );
// Replication is not allowed on this server. generate a error message
LdapResult result = req.getResultResponse().getLdapResult();
-
+
result.setDiagnosticMessage( "Replicztion is not allowed on this server" );
result.setResultCode( ResultCodeEnum.OTHER );
session.getIoSession().write( req.getResultResponse() );
-
+
return;
}
}
@@ -208,28 +208,28 @@ public class SearchHandler extends LdapR
// SearchResponseEntry elements instead of
// SearchResponseReference elements.
LOG.debug( "ManageDsaITControl detected." );
- boolean txnStarted = false;
-
+ //boolean txnStarted = false;
+
try
{
- beginTxnForSearch( session, req );
- txnStarted = true;
-
+ //beginTxnForSearch( session, req );
+ //txnStarted = true;
+
handleIgnoringReferrals( session, req );
-
+
}
catch ( Exception e )
{
- if ( txnStarted )
- {
- endTxnForSearch( true );
- }
-
+ //if ( txnStarted )
+ //{
+ // endTxnForSearch( true );
+ //}
+
throw e;
}
-
+
// if here, we are done
- endTxnForSearch( false );
+ //endTxnForSearch( false );
}
else
{
@@ -240,29 +240,29 @@ public class SearchHandler extends LdapR
switch ( req.getType() )
{
case SEARCH_REQUEST:
-
- boolean txnStarted = false;
-
+
+ //boolean txnStarted = false;
+
try
{
- beginTxnForSearch( session, req );
- txnStarted = true;
-
+ //beginTxnForSearch( session, req );
+ //txnStarted = true;
+
handleWithReferrals( session, req );
}
catch ( Exception e )
{
- if ( txnStarted )
- {
- endTxnForSearch( true );
- }
-
+ //if ( txnStarted )
+ //{
+ // endTxnForSearch( true );
+ //}
+
throw e;
}
-
+
// if here, we are done
- endTxnForSearch( false );
-
+ //endTxnForSearch( false );
+
break;
default:
@@ -445,7 +445,7 @@ public class SearchHandler extends LdapR
LOG.debug( "Sending {}", entry.getDn() );
count++;
}
-
+
// DO NOT WRITE THE RESPONSE - JUST RETURN IT
ldapResult.setResultCode( ResultCodeEnum.SUCCESS );
@@ -536,11 +536,11 @@ public class SearchHandler extends LdapR
// Stores the cursor current position
pagedContext.incrementCurrentPosition( pageCount );
-
+
// Suspend the current txn
TxnHandle txnHandle = txnManager.suspendCurTxn();
pagedContext.setTxnHandle( txnHandle );
-
+
return;
}
else
@@ -567,10 +567,10 @@ public class SearchHandler extends LdapR
*/
private SearchResultDone abandonPagedSearch( LdapSession session, SearchRequest req ) throws Exception
{
- PagedResults pagedSearchControl = (PagedResults)req.getControls().get( PagedResults.OID );
+ PagedResults pagedSearchControl = ( PagedResults ) req.getControls().get( PagedResults.OID );
byte[] cookie = pagedSearchControl.getCookie();
- if ( !Strings.isEmpty(cookie) )
+ if ( !Strings.isEmpty( cookie ) )
{
// If the cookie is not null, we have to destroy the associated
// cursor stored into the session (if any)
@@ -664,7 +664,7 @@ public class SearchHandler extends LdapR
byte[] cookie = pagedSearchControl.getCookie();
LdapResult ldapResult = req.getResultResponse().getLdapResult();
- if ( Strings.isEmpty(cookie) )
+ if ( Strings.isEmpty( cookie ) )
{
// This is a new search. We have a special case when the paged size
// is above the server size limit : in this case, we default to a
@@ -697,6 +697,7 @@ public class SearchHandler extends LdapR
// If we had a cookie in the session, remove it
removeContext( session, pagedContext );
+
return ( SearchResultDone ) req.getResultResponse();
}
else
@@ -833,7 +834,7 @@ public class SearchHandler extends LdapR
}
EntryFilteringCursor cursor = null;
-
+
try
{
// A normal search
@@ -915,7 +916,7 @@ public class SearchHandler extends LdapR
}
LdapUrl ldapUrl = null;
-
+
try
{
ldapUrl = new LdapUrl( url );
@@ -1085,7 +1086,7 @@ public class SearchHandler extends LdapR
// Handle psearch differently
// ===============================================================
- PersistentSearch psearch = (PersistentSearch)req.getControls().get( PersistentSearch.OID );
+ PersistentSearch psearch = ( PersistentSearch ) req.getControls().get( PersistentSearch.OID );
if ( psearch != null )
{
@@ -1122,7 +1123,7 @@ public class SearchHandler extends LdapR
*
* SO DON'T SEND BACK ANYTHING!!!!!
*/
- if ( e instanceof OperationAbandonedException)
+ if ( e instanceof OperationAbandonedException )
{
return;
}
@@ -1300,7 +1301,7 @@ public class SearchHandler extends LdapR
result.setDiagnosticMessage( "Encountered referral attempting to handle request." );
result.setMatchedDn( req.getBase() );
- Attribute refAttr = ((ClonedServerEntry)entry).getOriginalEntry().get( SchemaConstants.REF_AT );
+ Attribute refAttr = ( ( ClonedServerEntry ) entry ).getOriginalEntry().get( SchemaConstants.REF_AT );
for ( Value<?> refval : refAttr )
{
@@ -1315,7 +1316,7 @@ public class SearchHandler extends LdapR
// parse the ref value and normalize the Dn
LdapUrl ldapUrl = null;
-
+
try
{
ldapUrl = new LdapUrl( refstr );
@@ -1361,7 +1362,7 @@ public class SearchHandler extends LdapR
if ( filter.isSchemaAware() )
{
- AttributeType attributeType = ( (PresenceNode) req.getFilter() ).getAttributeType();
+ AttributeType attributeType = ( ( PresenceNode ) req.getFilter() ).getAttributeType();
isRootDseFilter = attributeType.equals( OBJECT_CLASS_AT );
}
else
@@ -1427,7 +1428,7 @@ public class SearchHandler extends LdapR
{
LOG.debug( "Inside getReferralOnAncestor()" );
- Attribute refAttr = ((ClonedServerEntry)referralAncestor).getOriginalEntry().get( SchemaConstants.REF_AT );
+ Attribute refAttr = ( ( ClonedServerEntry ) referralAncestor ).getOriginalEntry().get( SchemaConstants.REF_AT );
Referral referral = new ReferralImpl();
for ( Value<?> value : refAttr )
@@ -1445,7 +1446,7 @@ public class SearchHandler extends LdapR
// Parse the ref value
LdapUrl ldapUrl = null;
-
+
try
{
ldapUrl = new LdapUrl( ref );
@@ -1475,7 +1476,7 @@ public class SearchHandler extends LdapR
*/
Dn suffix = req.getBase().getDescendantOf( referralAncestor.getDn() );
Dn refDn = urlDn.add( suffix );
-
+
ldapUrl.setDn( refDn );
ldapUrl.setForceScopeRendering( true );
ldapUrl.setAttributes( req.getAttributes() );
@@ -1500,7 +1501,7 @@ public class SearchHandler extends LdapR
{
LOG.debug( "Inside getReferralOnAncestor()" );
- Attribute refAttr = ((ClonedServerEntry)referralAncestor).getOriginalEntry().get( SchemaConstants.REF_AT );
+ Attribute refAttr = ( ( ClonedServerEntry ) referralAncestor ).getOriginalEntry().get( SchemaConstants.REF_AT );
Referral referral = new ReferralImpl();
for ( Value<?> value : refAttr )
@@ -1518,7 +1519,7 @@ public class SearchHandler extends LdapR
// parse the ref value and normalize the Dn
LdapUrl ldapUrl = null;
-
+
try
{
ldapUrl = new LdapUrl( ref );
@@ -1589,7 +1590,7 @@ public class SearchHandler extends LdapR
if ( e instanceof LdapOperationException )
{
- code = ( (LdapOperationException) e ).getResultCode();
+ code = ( ( LdapOperationException ) e ).getResultCode();
}
else
{
@@ -1691,23 +1692,23 @@ public class SearchHandler extends LdapR
{
this.replicationReqHandler = replicationReqHandler;
}
-
-
+
+
private boolean checkPagedSearchTxnResume( LdapSession session, SearchRequest req )
{
boolean resumedTxn = false;
-
- PagedResultsDecorator pagedSearchControl = ( PagedResultsDecorator )req.getControls().get( PagedResults.OID );
-
+
+ PagedResultsDecorator pagedSearchControl = ( PagedResultsDecorator ) req.getControls().get( PagedResults.OID );
+
if ( pagedSearchControl != null )
{
byte[] cookie = pagedSearchControl.getCookie();
-
+
if ( !Strings.isEmpty( cookie ) )
{
int cookieValue = pagedSearchControl.getCookieValue();
PagedSearchContext pagedContext = session.getPagedSearchContext( cookieValue );
-
+
if ( pagedContext != null )
{
TxnHandle txnHandle = pagedContext.getTxnHandle();
@@ -1717,36 +1718,36 @@ public class SearchHandler extends LdapR
}
}
}
-
+
return resumedTxn;
}
-
-
+
+
private void beginTxnForSearch( LdapSession session, SearchRequest req ) throws Exception
{
boolean resumedTxn = checkPagedSearchTxnResume( session, req );
-
+
// If resumed an existing txn then just return
-
+
if ( resumedTxn )
{
return;
}
-
+
txnManager.beginTransaction( true );
}
-
-
+
+
private void endTxnForSearch( boolean abort ) throws Exception
{
// Paged search might have suspended the execution of the txn
TxnHandle txnHandle = txnManager.getCurTxn();
-
+
if ( txnHandle == null )
{
return;
}
-
+
if ( abort == false )
{
txnManager.commitTransaction();
@@ -1755,6 +1756,6 @@ public class SearchHandler extends LdapR
{
txnManager.abortTransaction();
}
-
+
}
}