From decebf8d68ef3648d011e8ee478d8b33d318d0ec Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Mon, 18 Sep 2006 16:46:59 +0000
Subject: [PATCH] Update the memory-based backend to provide support for modify DN operations. It does not support operations that would cause the entry to be moved to another backend, nor does it support the subtree rename (i.e., changing the DN of a non-leaf entry).

---
 opends/src/server/org/opends/server/backends/MemoryBackend.java |   76 +++++++++++++++++++++++++++++++++++--
 1 files changed, 71 insertions(+), 5 deletions(-)

diff --git a/opends/src/server/org/opends/server/backends/MemoryBackend.java b/opends/src/server/org/opends/server/backends/MemoryBackend.java
index 2e565eb..8b7d080 100644
--- a/opends/src/server/org/opends/server/backends/MemoryBackend.java
+++ b/opends/src/server/org/opends/server/backends/MemoryBackend.java
@@ -409,11 +409,77 @@
                       String.valueOf(entry), String.valueOf(modifyDNOperation));
 
 
-    // FIXME -- Consider adding support for this in the future.
-    int    msgID   = MSGID_MEMORYBACKEND_MODDN_NOT_SUPPORTED;
-    String message = getMessage(msgID);
-    throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
-                                 msgID);
+    // Make sure that the target entry exists.
+    if (! entryMap.containsKey(currentDN))
+    {
+      int    msgID   = MSGID_MEMORYBACKEND_ENTRY_DOESNT_EXIST;
+      String message = getMessage(msgID, String.valueOf(currentDN));
+      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID);
+    }
+
+
+    // Make sure that the target entry doesn't have any children.
+    HashSet<DN> children  = childDNs.get(currentDN);
+    if (children != null)
+    {
+      if (children.isEmpty())
+      {
+        childDNs.remove(currentDN);
+      }
+      else
+      {
+        int    msgID   = MSGID_MEMORYBACKEND_CANNOT_RENAME_ENRY_WITH_CHILDREN;
+        String message = getMessage(msgID, String.valueOf(currentDN));
+        throw new DirectoryException(ResultCode.NOT_ALLOWED_ON_NONLEAF, message,
+                                     msgID);
+      }
+    }
+
+
+    // Make sure that no entry exists with the new DN.
+    if (entryMap.containsKey(entry.getDN()))
+    {
+      int    msgID   = MSGID_MEMORYBACKEND_ENTRY_ALREADY_EXISTS;
+      String message = getMessage(msgID, String.valueOf(entry.getDN()));
+      throw new DirectoryException(ResultCode.NO_SUCH_OBJECT, message, msgID);
+    }
+
+
+    // Make sure that the new DN is in this backend.
+    boolean matchFound = false;
+    for (DN dn : baseDNs)
+    {
+      if (dn.isAncestorOf(entry.getDN()))
+      {
+        matchFound = true;
+        break;
+      }
+    }
+
+    if (! matchFound)
+    {
+      int    msgID   = MSGID_MEMORYBACKEND_CANNOT_RENAME_TO_ANOTHER_BACKEND;
+      String message = getMessage(msgID, String.valueOf(currentDN));
+      throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+                                   msgID);
+    }
+
+
+    // Make sure that the parent of the new entry exists.
+    DN parentDN = entry.getDN().getParent();
+    if ((parentDN == null) || (! entryMap.containsKey(parentDN)))
+    {
+      int    msgID   = MSGID_MEMORYBACKEND_RENAME_PARENT_DOESNT_EXIST;
+      String message = getMessage(msgID, String.valueOf(currentDN),
+                                  String.valueOf(parentDN));
+      throw new DirectoryException(ResultCode.UNWILLING_TO_PERFORM, message,
+                                   msgID);
+    }
+
+
+    // Delete the current entry and add the new one.
+    deleteEntry(currentDN, null);
+    addEntry(entry, null);
   }
 
 

--
Gitblit v1.10.0