From 722804c719bc56ab6bc08283abcde3fa0d61ee62 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Mon, 09 Oct 2006 01:12:28 +0000
Subject: [PATCH] Update the memory-based backend to provide support for the subtree delete control.

---
 opendj-sdk/opends/src/server/org/opends/server/backends/MemoryBackend.java |   55 +++++++++++++++++++++++++++++++++++++++++++++++--------
 1 files changed, 47 insertions(+), 8 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/MemoryBackend.java b/opendj-sdk/opends/src/server/org/opends/server/backends/MemoryBackend.java
index 25707d4..8bc12d4 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/MemoryBackend.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/MemoryBackend.java
@@ -61,6 +61,7 @@
 import static org.opends.server.loggers.Debug.*;
 import static org.opends.server.messages.BackendMessages.*;
 import static org.opends.server.messages.MessageHandler.*;
+import static org.opends.server.util.ServerConstants.*;
 
 
 
@@ -177,6 +178,8 @@
     childDNs = new HashMap<DN,HashSet<DN>>();
 
     supportedControls = new HashSet<String>();
+    supportedControls.add(OID_SUBTREE_DELETE_CONTROL);
+
     supportedFeatures = new HashSet<String>();
 
     for (DN dn : baseDNs)
@@ -337,15 +340,51 @@
     }
 
 
-    // Make sure the entry doesn't have any children.  If it does, then throw an
-    // exception.
-    HashSet<DN> children = childDNs.get(entryDN);
-    if ((children != null) && (! children.isEmpty()))
+    // Check to see if the entry contains a subtree delete control.
+    boolean subtreeDelete = false;
+    if (deleteOperation != null)
     {
-      int    msgID   = MSGID_MEMORYBACKEND_CANNOT_DELETE_ENTRY_WITH_CHILDREN;
-      String message = getMessage(msgID, String.valueOf(entryDN));
-      throw new DirectoryException(ResultCode.NOT_ALLOWED_ON_NONLEAF, message,
-                                   msgID);
+      for (Control c : deleteOperation.getRequestControls())
+      {
+        if (c.getOID().equals(OID_SUBTREE_DELETE_CONTROL))
+        {
+          subtreeDelete = true;
+        }
+      }
+    }
+
+    HashSet<DN> children = childDNs.get(entryDN);
+    if (subtreeDelete)
+    {
+      if (children != null)
+      {
+        HashSet<DN> childrenCopy = new HashSet<DN>(children);
+        for (DN childDN : childrenCopy)
+        {
+          try
+          {
+            deleteEntry(childDN, null);
+          }
+          catch (Exception e)
+          {
+            // This shouldn't happen, but we want the delete to continue anyway
+            // so just ignore it if it does for some reason.
+            assert debugException(CLASS_NAME, "deleteEntry", e);
+          }
+        }
+      }
+    }
+    else
+    {
+      // Make sure the entry doesn't have any children.  If it does, then throw
+      // an exception.
+      if ((children != null) && (! children.isEmpty()))
+      {
+        int    msgID   = MSGID_MEMORYBACKEND_CANNOT_DELETE_ENTRY_WITH_CHILDREN;
+        String message = getMessage(msgID, String.valueOf(entryDN));
+        throw new DirectoryException(ResultCode.NOT_ALLOWED_ON_NONLEAF, message,
+                                     msgID);
+      }
     }
 
 

--
Gitblit v1.10.0