directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r1209595 - /directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java
Date Fri, 02 Dec 2011 17:30:08 GMT
Author: elecharny
Date: Fri Dec  2 17:30:07 2011
New Revision: 1209595

URL: http://svn.apache.org/viewvc?rev=1209595&view=rev
Log:
Added a check on the delete operation done on schema entries to deal with entries with children

Modified:
    directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java

Modified: directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java?rev=1209595&r1=1209594&r2=1209595&view=diff
==============================================================================
--- directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java
(original)
+++ directory/apacheds/trunk/core-api/src/main/java/org/apache/directory/server/core/api/schema/SchemaPartition.java
Fri Dec  2 17:30:07 2011
@@ -51,6 +51,10 @@ import org.apache.directory.shared.ldap.
 import org.apache.directory.shared.ldap.model.entry.ModificationOperation;
 import org.apache.directory.shared.ldap.model.exception.LdapException;
 import org.apache.directory.shared.ldap.model.exception.LdapInvalidDnException;
+import org.apache.directory.shared.ldap.model.exception.LdapUnwillingToPerformException;
+import org.apache.directory.shared.ldap.model.message.SearchRequest;
+import org.apache.directory.shared.ldap.model.message.SearchRequestImpl;
+import org.apache.directory.shared.ldap.model.message.SearchScope;
 import org.apache.directory.shared.ldap.model.message.controls.Cascade;
 import org.apache.directory.shared.ldap.model.name.Dn;
 import org.apache.directory.shared.ldap.model.schema.SchemaManager;
@@ -64,13 +68,13 @@ import org.slf4j.LoggerFactory;
  * A special partition designed to contain the portion of the DIT where schema
  * information for the server is stored.
  * 
- * In an effort to make sure that all Partition implementations are equal 
- * citizens to ApacheDS we want to be able to swap in and out any kind of 
+ * In an effort to make sure that all Partition implementations are equal
+ * citizens to ApacheDS we want to be able to swap in and out any kind of
  * Partition to store schema.  This also has the added advantage of making
- * sure the core, and hence the server is not dependent on any specific 
+ * sure the core, and hence the server is not dependent on any specific
  * partition, which reduces coupling in the server's modules.
  * 
- * The SchemaPartition achieves this by not really being a backing store 
+ * The SchemaPartition achieves this by not really being a backing store
  * itself for the schema entries.  It instead delegates to another Partition
  * via containment.  It delegates all calls to this contained Partition. While
  * doing so it also manages certain things:
@@ -80,21 +84,21 @@ import org.slf4j.LoggerFactory;
  *   <li>Updates the schema Registries on valid schema changes making sure
  *       the schema on disk is in sync with the schema in memory.
  *   </li>
- *   <li>Will eventually manage transaction based changes to schema where 
+ *   <li>Will eventually manage transaction based changes to schema where
  *       between some sequence of operations the schema may be inconsistent.
  *   </li>
  *   <li>Delegates read/write operations to contained Partition.</li>
  *   <li>
  *       Responsible for initializing schema for the entire server.  ApacheDS
- *       cannot start up other partitions until this Partition is started 
+ *       cannot start up other partitions until this Partition is started
  *       without having access to the Registries.  This Partition supplies the
  *       Registries on initialization for the server.  That's one of it's core
  *       responsibilities.
  *   </li>
- *   
- * So by containing another Partition, we abstract the storage mechanism away 
+ * 
+ * So by containing another Partition, we abstract the storage mechanism away
  * from the management responsibilities while decoupling the server from a
- * specific partition implementation and removing complexity in the Schema 
+ * specific partition implementation and removing complexity in the Schema
  * interceptor service which before managed synchronization.
  * </ol>
  *
@@ -139,7 +143,7 @@ public final class SchemaPartition exten
     
     
     /**
-     * Sets the wrapped {@link Partition} which must be supplied or 
+     * Sets the wrapped {@link Partition} which must be supplied or
      * {@link Partition#initialize()} will fail with a NullPointerException.
      *
      * @param wrapped the Partition being wrapped
@@ -272,13 +276,45 @@ public final class SchemaPartition exten
         updateSchemaModificationAttributes( addContext );
     }
 
+   
+    public void bind( BindOperationContext bindContext ) throws LdapException 
+    {
+        wrapped.bind( bindContext );
+    }
+
 
     /**
      * {@inheritDoc}
      */
-    public void bind( BindOperationContext bindContext ) throws LdapException
+    public final int getChildCount( DeleteOperationContext deleteContext ) throws LdapException
     {
-        wrapped.bind( bindContext );
+        try
+        {
+            Dn dn = deleteContext.getDn();
+            SearchRequest searchRequest = new SearchRequestImpl();
+            searchRequest.setBase( dn );
+            searchRequest.setFilter( "ObjectClass=*)" );
+            searchRequest.setTypesOnly( true );
+            searchRequest.setScope( SearchScope.ONELEVEL );
+            
+            SearchOperationContext searchContext = new SearchOperationContext( deleteContext.getSession(),
searchRequest );
+            
+            EntryFilteringCursor cursor = wrapped.search( searchContext );
+            
+            cursor.beforeFirst();
+            int nbEntry = 0;
+            
+            while ( cursor.next() && ( nbEntry < 2 ) )
+            {
+                nbEntry++;
+            }
+            
+            return nbEntry;
+        }
+        catch ( Exception e )
+        {
+            return 0;
+        }
     }
 
 
@@ -288,7 +324,15 @@ public final class SchemaPartition exten
     public void delete( DeleteOperationContext deleteContext ) throws LdapException
     {
         boolean cascade = deleteContext.hasRequestControl( Cascade.OID );
+        
+        // We have to check if the entry we want to delete has children, or not
+        int nbChild = getChildCount( deleteContext );
 
+        if ( nbChild > 1 )
+        {
+            throw new LdapUnwillingToPerformException();
+        }
+        
         // The SchemaObject always exist when we reach this method.
         synchronizer.delete( deleteContext, cascade );
 
@@ -338,7 +382,7 @@ public final class SchemaPartition exten
             modifyContext.setEntry( entry );
         }
 
-        Entry targetEntry = ( Entry ) SchemaUtils.getTargetEntry( modifyContext.getModItems(),
entry );
+        Entry targetEntry = SchemaUtils.getTargetEntry( modifyContext.getModItems(), entry
);
 
         boolean cascade = modifyContext.hasRequestControl( Cascade.OID );
 
@@ -434,8 +478,8 @@ public final class SchemaPartition exten
 
     /**
      * Updates the schemaModifiersName and schemaModifyTimestamp attributes of
-     * the schemaModificationAttributes entry for the global schema at 
-     * ou=schemaModifications,ou=schema.  This entry is hardcoded at that 
+     * the schemaModificationAttributes entry for the global schema at
+     * ou=schemaModifications,ou=schema.  This entry is hardcoded at that
      * position for now.
      * 
      * The current time is used to set the timestamp and the Dn of current user



Mime
View raw message