From 4c6354275265e835bbab21af899df63b4dc0ebcb Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Wed, 26 Sep 2007 00:49:44 +0000
Subject: [PATCH] Update the backend API to include new isIndexed methods that can be used to determine whether a given attribute is indexed in a specified manner, or that can be used to determine whether a specified filter is indexed.  At present, all backends except the JE backend and the replication backend are considered always indexed for all operations.  The JE backend is only considered indexed based on its index configuration.  The replication backend is never considered indexed.

---
 opends/src/server/org/opends/server/plugins/UniqueAttributePlugin.java |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 46 insertions(+), 0 deletions(-)

diff --git a/opends/src/server/org/opends/server/plugins/UniqueAttributePlugin.java b/opends/src/server/org/opends/server/plugins/UniqueAttributePlugin.java
index 279164f..a9b2370 100644
--- a/opends/src/server/org/opends/server/plugins/UniqueAttributePlugin.java
+++ b/opends/src/server/org/opends/server/plugins/UniqueAttributePlugin.java
@@ -40,6 +40,7 @@
 import org.opends.server.admin.std.server.PluginCfg;
 import org.opends.server.admin.std.server.UniqueAttributePluginCfg;
 import org.opends.server.api.AlertGenerator;
+import org.opends.server.api.Backend;
 import org.opends.server.api.plugin.DirectoryServerPlugin;
 import org.opends.server.api.plugin.PluginType;
 import org.opends.server.api.plugin.PreOperationPluginResult;
@@ -57,6 +58,7 @@
 import org.opends.server.types.DirectoryException;
 import org.opends.server.types.DN;
 import org.opends.server.types.Entry;
+import org.opends.server.types.IndexType;
 import org.opends.server.types.Modification;
 import org.opends.server.types.RDN;
 import org.opends.server.types.ResultCode;
@@ -157,6 +159,27 @@
 
       }
     }
+
+    Set<DN> cfgBaseDNs = configuration.getUniqueAttributeBaseDN();
+    if ((cfgBaseDNs == null) || cfgBaseDNs.isEmpty())
+    {
+      cfgBaseDNs = DirectoryServer.getPublicNamingContexts().keySet();
+    }
+
+    for (AttributeType t : configuration.getUniqueAttributeType())
+    {
+      for (DN baseDN : cfgBaseDNs)
+      {
+        Backend b = DirectoryServer.getBackend(baseDN);
+        if ((b != null) && (! b.isIndexed(t, IndexType.EQUALITY)))
+        {
+          throw new ConfigException(ERR_PLUGIN_UNIQUEATTR_ATTR_UNINDEXED.get(
+                                         configuration.dn().toString(),
+                                         t.getNameOrOID(),
+                                         b.getBackendID()));
+        }
+      }
+    }
   }
 
 
@@ -836,6 +859,7 @@
                       List<Message> unacceptableReasons)
   {
     boolean configAcceptable = true;
+
     for (PluginCfgDefn.PluginType pluginType : configuration.getPluginType())
     {
       switch (pluginType)
@@ -856,6 +880,28 @@
           configAcceptable = false;
       }
     }
+
+    Set<DN> cfgBaseDNs = configuration.getUniqueAttributeBaseDN();
+    if ((cfgBaseDNs == null) || cfgBaseDNs.isEmpty())
+    {
+      cfgBaseDNs = DirectoryServer.getPublicNamingContexts().keySet();
+    }
+
+    for (AttributeType t : configuration.getUniqueAttributeType())
+    {
+      for (DN baseDN : cfgBaseDNs)
+      {
+        Backend b = DirectoryServer.getBackend(baseDN);
+        if ((b != null) && (! b.isIndexed(t, IndexType.EQUALITY)))
+        {
+          unacceptableReasons.add(ERR_PLUGIN_UNIQUEATTR_ATTR_UNINDEXED.get(
+                                       configuration.dn().toString(),
+                                       t.getNameOrOID(), b.getBackendID()));
+          configAcceptable = false;
+        }
+      }
+    }
+
     return configAcceptable;
   }
 

--
Gitblit v1.10.0