directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r954931 - in /directory/apacheds/trunk: core-api/src/main/java/org/apache/directory/server/core/interceptor/ core/src/main/java/org/apache/directory/server/core/exception/ i18n/src/main/java/org/apache/directory/server/i18n/ i18n/src/main/r...
Date Tue, 15 Jun 2010 15:25:05 GMT
Author: elecharny
Date: Tue Jun 15 15:25:04 2010
New Revision: 954931

URL: http://svn.apache.org/viewvc?rev=954931&view=rev
Log:
o Renamed some error codes
o Added some check in AbstractStore.moveAndRename operation
o code refactoring in Excetion interceptor for M&R op

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
    directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
    directory/apacheds/trunk/i18n/src/main/java/org/apache/directory/server/i18n/I18n.java
    directory/apacheds/trunk/i18n/src/main/resources/org/apache/directory/server/i18n/errors.properties
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/xdbm/AbstractXdbmPartition.java
    directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java?rev=954931&r1=954930&r2=954931&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/interceptor/InterceptorChain.java
Tue Jun 15 15:25:04 2010
@@ -586,7 +586,7 @@ public class InterceptorChain
             else
             {
                 // This is an error : we *must* have an entry if we want to be able to rename.
-                LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err(
I18n.ERR_256, opContext.getDn() ) );
+                LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err(
I18n.ERR_256_NO_SUCH_OBJECT, opContext.getDn() ) );
 
                 throw ldnfe;
             }
@@ -610,7 +610,7 @@ public class InterceptorChain
         else
         {
             // This is an error : we *must* have an entry if we want to be able to rename.
-            LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err( I18n.ERR_256,
opContext.getDn() ) );
+            LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err( I18n.ERR_256_NO_SUCH_OBJECT,
opContext.getDn() ) );
 
             throw ldnfe;
         }

Modified: directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java?rev=954931&r1=954930&r2=954931&view=diff
==============================================================================
--- directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
(original)
+++ directory/apacheds/trunk/core/src/main/java/org/apache/directory/server/core/exception/ExceptionInterceptor.java
Tue Jun 15 15:25:04 2010
@@ -73,7 +73,6 @@ import org.apache.directory.shared.ldap.
 public class ExceptionInterceptor extends BaseInterceptor
 {
     private PartitionNexus nexus;
-    private DirectoryService directoryService;
     private DN subschemSubentryDn;
 
     /**
@@ -110,7 +109,6 @@ public class ExceptionInterceptor extend
 
     public void init( DirectoryService directoryService ) throws LdapException
     {
-        this.directoryService = directoryService;
         nexus = directoryService.getPartitionNexus();
         Value<?> attr = nexus.getRootDSE( null ).get( SchemaConstants.SUBSCHEMA_SUBENTRY_AT
).get();
         subschemSubentryDn = new DN( attr.getString() );
@@ -359,7 +357,7 @@ public class ExceptionInterceptor extend
         if ( nextInterceptor.hasEntry( new EntryOperationContext( opContext.getSession(),
newDn ) ) )
         {
             LdapEntryAlreadyExistsException e;
-            e = new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_257, newDn.getName()
) );
+            e = new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS,
newDn.getName() ) );
             //e.setResolvedName( new DN( newDn.getName() ) );
             throw e;
         }
@@ -410,10 +408,10 @@ public class ExceptionInterceptor extend
     public void moveAndRename( NextInterceptor nextInterceptor, MoveAndRenameOperationContext
moveAndRenameContext )
         throws LdapException
     {
-        DN oriChildName = moveAndRenameContext.getDn();
-        DN parent = moveAndRenameContext.getNewSuperiorDn();
+        DN oldDn = moveAndRenameContext.getDn();
+        DN newSuperiorDn = moveAndRenameContext.getNewSuperiorDn();
 
-        if ( oriChildName.getNormName().equalsIgnoreCase( subschemSubentryDn.getNormName()
) )
+        if ( oldDn.equals( subschemSubentryDn ) )
         {
             throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM,
I18n.err( I18n.ERR_258,
                 subschemSubentryDn, subschemSubentryDn ) );
@@ -421,24 +419,20 @@ public class ExceptionInterceptor extend
 
         // check if child to move exists
         String msg = "Attempt to move to non-existant parent: ";
-        assertHasEntry( moveAndRenameContext, msg, oriChildName );
+        assertHasEntry( moveAndRenameContext, msg, oldDn );
 
         // check if parent to move to exists
         msg = "Attempt to move to non-existant parent: ";
-        assertHasEntry( moveAndRenameContext, msg, parent );
+        assertHasEntry( moveAndRenameContext, msg, newSuperiorDn );
 
         // check to see if target entry exists
-        DN target = ( DN ) parent.clone();
-        target.add( moveAndRenameContext.getNewRdn() );
+        DN newDn = moveAndRenameContext.getNewDn();
 
-        if ( nextInterceptor.hasEntry( new EntryOperationContext( moveAndRenameContext.getSession(),
target ) ) )
+        if ( nextInterceptor.hasEntry( new EntryOperationContext( moveAndRenameContext.getSession(),
newDn ) ) )
         {
             // we must calculate the resolved name using the user provided Rdn value
-            DN upTarget = ( DN ) parent.clone();
-            upTarget.add( moveAndRenameContext.getNewRdn() );
-
             LdapEntryAlreadyExistsException e;
-            e = new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_257, upTarget.getName()
) );
+            e = new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS,
newDn ) );
             //e.setResolvedName( new DN( upTarget.getName() ) );
             throw e;
         }
@@ -446,9 +440,9 @@ public class ExceptionInterceptor extend
         // Remove the original entry from the NotAlias cache, if needed
         synchronized ( notAliasCache )
         {
-            if ( notAliasCache.containsKey( oriChildName.getNormName() ) )
+            if ( notAliasCache.containsKey( oldDn.getNormName() ) )
             {
-                notAliasCache.remove( oriChildName.getNormName() );
+                notAliasCache.remove( oldDn.getNormName() );
             }
         }
 

Modified: directory/apacheds/trunk/i18n/src/main/java/org/apache/directory/server/i18n/I18n.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/i18n/src/main/java/org/apache/directory/server/i18n/I18n.java?rev=954931&r1=954930&r2=954931&view=diff
==============================================================================
--- directory/apacheds/trunk/i18n/src/main/java/org/apache/directory/server/i18n/I18n.java
(original)
+++ directory/apacheds/trunk/i18n/src/main/java/org/apache/directory/server/i18n/I18n.java
Tue Jun 15 15:25:04 2010
@@ -289,8 +289,8 @@ public enum I18n
     ERR_253("ERR_253"),
     ERR_254_ADD_EXISTING_VALUE("ERR_254_ADD_EXISTING_VALUE"),
     ERR_255("ERR_255"),
-    ERR_256("ERR_256"),
-    ERR_257("ERR_257"),
+    ERR_256_NO_SUCH_OBJECT("ERR_256_NO_SUCH_OBJECT"),
+    //ERR_257("ERR_257"), --> ERR_250
     ERR_258("ERR_258"),
     ERR_259("ERR_259"),
     ERR_260("ERR_260"),

Modified: directory/apacheds/trunk/i18n/src/main/resources/org/apache/directory/server/i18n/errors.properties
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/i18n/src/main/resources/org/apache/directory/server/i18n/errors.properties?rev=954931&r1=954930&r2=954931&view=diff
==============================================================================
--- directory/apacheds/trunk/i18n/src/main/resources/org/apache/directory/server/i18n/errors.properties
(original)
+++ directory/apacheds/trunk/i18n/src/main/resources/org/apache/directory/server/i18n/errors.properties
Tue Jun 15 15:25:04 2010
@@ -277,8 +277,8 @@ ERR_252=Attempt to add entry to alias ''
 ERR_253=Can not allow the deletion of the subschemaSubentry ({0}) for the global schema.
 ERR_254_ADD_EXISTING_VALUE=Trying to add existing value ''{0}'' to attribute {1}
 ERR_255=Can not allow the renaming of the subschemaSubentry ({0}) for the global schema:
it is fixed at {1}
-ERR_256=target entry {0} does not exist!
-ERR_257=target entry {0} already exists!
+ERR_256_NO_SUCH_OBJECT=Entry {0} does not exist!
+#ERR_257=Entry {0} already exists!
 ERR_258=Can not allow the move of the subschemaSubentry ({0}) for the global schema\: it
is fixed at {1} 
 ERR_259=Attempt to search under non-existant entry\:  
 ERR_260=Unknown assertion type: {0}

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/xdbm/AbstractXdbmPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/xdbm/AbstractXdbmPartition.java?rev=954931&r1=954930&r2=954931&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/xdbm/AbstractXdbmPartition.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/core/partition/impl/xdbm/AbstractXdbmPartition.java
Tue Jun 15 15:25:04 2010
@@ -44,6 +44,7 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.exception.LdapUnwillingToPerformException;
 import org.apache.directory.shared.ldap.message.ResultCodeEnum;
 import org.apache.directory.shared.ldap.name.DN;
+import org.apache.directory.shared.ldap.name.RDN;
 
 
 /**
@@ -343,8 +344,18 @@ public abstract class AbstractXdbmPartit
 
         try
         {
-            store.moveAndRename( moveAndRenameContext.getDn(), moveAndRenameContext.getNewSuperiorDn(),
moveAndRenameContext.getNewRdn(),
-                null, moveAndRenameContext.getDeleteOldRdn() );
+        	DN oldDn = moveAndRenameContext.getDn();
+        	DN newSuperiorDn = moveAndRenameContext.getNewSuperiorDn();
+        	RDN newRdn = moveAndRenameContext.getNewRdn();
+        	boolean deleteOldRdn = moveAndRenameContext.getDeleteOldRdn();
+        	
+            store.moveAndRename( oldDn, newSuperiorDn, newRdn, null, deleteOldRdn );
+        }
+        catch ( LdapException le )
+        {
+        	// In case we get an LdapException, just rethrow it as is to 
+        	// avoid having it lost
+        	throw le;
         }
         catch ( Exception e )
         {

Modified: directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java?rev=954931&r1=954930&r2=954931&view=diff
==============================================================================
--- directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
(original)
+++ directory/apacheds/trunk/xdbm-partition/src/main/java/org/apache/directory/server/xdbm/AbstractStore.java
Tue Jun 15 15:25:04 2010
@@ -1201,11 +1201,46 @@ public abstract class AbstractStore<E, I
     /**
      * {@inheritDoc}
      */
-    public synchronized void moveAndRename( DN oldDn, DN newSuperior, RDN newRdn, Entry modifiedEntry,
boolean deleteOldRdn ) throws Exception
+    public synchronized void moveAndRename( DN oldDn, DN newSuperiorDn, RDN newRdn, Entry
modifiedEntry, boolean deleteOldRdn ) throws Exception
     {
-        ID childId = getEntryId( oldDn );
+    	// Check that the old entry exists, that the new superior exists and
+    	// that the new DN does not exist
+        ID oldId = getEntryId( oldDn );
+        
+        if ( oldId == null )
+        {
+            // This is not allowed : the old entry must exist
+        	LdapNoSuchObjectException nse = new LdapNoSuchObjectException( 
+                I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, oldDn ) );
+            throw nse;
+        }
+        
+        ID newSuperiorId = getEntryId( newSuperiorDn );
+        
+        if ( newSuperiorId == null )
+        {
+            // This is not allowed : the new superior must exist
+        	LdapNoSuchObjectException nse = new LdapNoSuchObjectException( 
+                I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, newSuperiorDn ) );
+            throw nse;
+        }
+        
+        DN newDn = ((DN)newSuperiorDn.clone()).add( newRdn );
+        
+        // Now check that the new entry does not exist
+        ID newId = getEntryId( newDn );
+        
+        if ( newId != null )
+        {
+            // This is not allowed : we should not be able to move an entry
+            // to an existing position
+            LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( 
+                I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newSuperiorDn.getName() ) );
+            throw ne;
+        }
+
         rename( oldDn, newRdn, deleteOldRdn );
-        moveAndRename( oldDn, childId, newSuperior, newRdn );
+        moveAndRename( oldDn, oldId, newSuperiorDn, newRdn );
 
         if ( isSyncOnWrite )
         {
@@ -1235,7 +1270,7 @@ public abstract class AbstractStore<E, I
         {
             // This is not allowed : the parent must exist
             LdapEntryAlreadyExistsException ne = new LdapEntryAlreadyExistsException( 
-                I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newSuperiorDn.getName() ) );
+                I18n.err( I18n.ERR_256_NO_SUCH_OBJECT, newSuperiorDn.getName() ) );
             throw ne;
         }
         
@@ -1250,7 +1285,6 @@ public abstract class AbstractStore<E, I
                 I18n.err( I18n.ERR_250_ENTRY_ALREADY_EXISTS, newSuperiorDn.getName() ) );
             throw ne;
         }
-        
 
         // Get the entry and the old parent IDs
         ID entryId = getEntryId( oldDn );



Mime
View raw message