From 87ea6a1089819313e274c7954ec1cd5513503908 Mon Sep 17 00:00:00 2001
From: boli <boli@localhost>
Date: Wed, 31 Oct 2007 22:19:14 +0000
Subject: [PATCH] This set of fixes mainly address the issues where the JE backend does not handle attributes with options and subtypes correctly when they are being indexed.  With this fix: - All values of an indexed attribute type will be indexed correctly on modifies, adds, and deletes.  - Updates to subordinate types will now update the superior type if its indexed.  - Adding and deleting superior attribute types that are not allowed by any object classes (ie. name) will be correctly handled - Deleting all values from an attribute with no options will no longer delete the values from the same attribute but with options.  

---
 opendj-sdk/opends/src/server/org/opends/server/backends/jeb/OrderingIndexer.java |   93 ++++++++++++++++------------------------------
 1 files changed, 32 insertions(+), 61 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/OrderingIndexer.java b/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/OrderingIndexer.java
index 70d9b15..4c17058 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/OrderingIndexer.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/backends/jeb/OrderingIndexer.java
@@ -180,72 +180,43 @@
                           Set<ASN1OctetString> delKeys)
        throws DatabaseException
   {
-    List<Attribute> beforeList;
-    beforeList = oldEntry.getAttribute(attributeType);
+    List<Attribute> newAttributes = newEntry.getAttribute(attributeType, true);
+    List<Attribute> oldAttributes = oldEntry.getAttribute(attributeType, true);
+    HashSet<AttributeValue> newValues;
+    HashSet<AttributeValue> oldValues;
 
-    // Pick out the modifications that apply to this indexed attribute
-
-    /**
-     * FIXME unusual modifications can insert spurious index values
-     * The following sequence of modifications will insert A into the
-     * index, yet A is not a resulting value for the attribute.
-     *
-     * add: cn
-     * cn: A
-     * -
-     * replace: cn
-     * cn: B
-     * -
-     *
-     */
-
-    for (Modification mod : mods)
+    if(newAttributes == null)
     {
-      Attribute modAttr = mod.getAttribute();
-      AttributeType modAttrType = modAttr.getAttributeType();
-      if (modAttrType.equals(attributeType))
+      indexAttribute(oldAttributes, delKeys);
+    }
+    else
+    {
+      if(oldAttributes == null)
       {
-        switch (mod.getModificationType())
+        indexAttribute(newAttributes, addKeys);
+      }
+      else
+      {
+        newValues = new HashSet<AttributeValue>();
+        oldValues = new HashSet<AttributeValue>();
+        for(Attribute a : newAttributes)
         {
-          case REPLACE:
-          case INCREMENT:
-            if (beforeList != null)
-            {
-              for (Attribute attr : beforeList)
-              {
-                if (attr.hasOptions(modAttr.getOptions()))
-                {
-                  indexValues(attr.getValues(), delKeys);
-                }
-              }
-            }
-            indexValues(modAttr.getValues(), addKeys);
-            break;
-
-          case ADD:
-            indexValues(modAttr.getValues(), addKeys);
-            break;
-
-          case DELETE:
-            if (!modAttr.hasValue())
-            {
-              if (beforeList != null)
-              {
-                for (Attribute attr : beforeList)
-                {
-                  if (attr.hasOptions(modAttr.getOptions()))
-                  {
-                    indexValues(attr.getValues(), delKeys);
-                  }
-                }
-              }
-            }
-            else
-            {
-              indexValues(modAttr.getValues(), delKeys);
-            }
-            break;
+          newValues.addAll(a.getValues());
         }
+        for(Attribute a : oldAttributes)
+        {
+          oldValues.addAll(a.getValues());
+        }
+
+        HashSet<AttributeValue> valuesToAdd =
+            new HashSet<AttributeValue>(newValues);
+        HashSet<AttributeValue> valuesToDel =
+            new HashSet<AttributeValue>(oldValues);
+        valuesToAdd.removeAll(oldValues);
+        valuesToDel.removeAll(newValues);
+
+        indexValues(valuesToDel, delKeys);
+        indexValues(valuesToAdd, addKeys);
       }
     }
   }

--
Gitblit v1.10.0