From e28ddc3ed27d4352ddc7c476f4e5208b2eb27251 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 06 Mar 2014 23:25:34 +0000
Subject: [PATCH] OPENDJ-1308 Migrate schema support
---
opendj3-server-dev/src/server/org/opends/server/api/ExtensibleIndexer.java | 82 +++++++++++++++++++++++++++++------------
1 files changed, 58 insertions(+), 24 deletions(-)
diff --git a/opendj3-server-dev/src/server/org/opends/server/api/ExtensibleIndexer.java b/opendj3-server-dev/src/server/org/opends/server/api/ExtensibleIndexer.java
index 124460b..304d7f8 100644
--- a/opendj3-server-dev/src/server/org/opends/server/api/ExtensibleIndexer.java
+++ b/opendj3-server-dev/src/server/org/opends/server/api/ExtensibleIndexer.java
@@ -22,18 +22,23 @@
*
*
* Copyright 2009 Sun Microsystems, Inc.
+ * Portions Copyright 2014 ForgeRock AS
*/
package org.opends.server.api;
-
-
+import java.util.Collection;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.forgerock.opendj.ldap.ByteSequence;
+import org.forgerock.opendj.ldap.ByteString;
+import org.forgerock.opendj.ldap.DecodeException;
+import org.forgerock.opendj.ldap.schema.Schema;
+import org.forgerock.opendj.ldap.spi.Indexer;
+import org.forgerock.opendj.ldap.spi.IndexingOptions;
import org.opends.server.types.AttributeValue;
-
-
/**
* This class is registered with a Backend and it provides call- backs
* for indexing attribute values. An index implementation will use
@@ -44,19 +49,8 @@
mayInstantiate = false,
mayExtend = true,
mayInvoke = false)
-public abstract class ExtensibleIndexer
+public abstract class ExtensibleIndexer implements Indexer
{
- /**
- * Returns the index name preferred by this indexer. This name
- * appended with the identifier returned from
- * {@link #getExtensibleIndexID()} will be used as the index
- * database name.
- *
- * @return The name of the index for this indexer.
- */
- public abstract String getPreferredIndexName();
-
-
/**
* Returns an index identifier associated with this indexer. An
@@ -81,27 +75,67 @@
* @param keys
* The set into which the generated keys will be inserted.
*/
- public abstract void getKeys(AttributeValue value,
- Set<byte[]> keys);
+ public abstract void getKeys(AttributeValue value, Set<byte[]> keys);
-
+ /** {@inheritDoc} */
+ @Override
+ public void createKeys(Schema schema, ByteSequence value,
+ IndexingOptions options, Collection<ByteString> keys)
+ throws DecodeException
+ {
+ throw new RuntimeException("Not implemented yet");
+ }
/**
* Generates a map of index keys and a boolean flag indicating
* whether the corresponding key will be inserted or deleted.
*
- * @param value
+ * @param attrValue
* The attribute for which keys are required.
* @param modifiedKeys
* A map containing the keys and a boolean. Keys
- * corresponding to the boolean value <code>true
- * </code>
+ * corresponding to the boolean value <code>true</code>
* should be inserted and <code>false</code> should be
* deleted.
* @param insert
* <code>true</code> if generated keys should be inserted
* or <code>false</code> otherwise.
*/
- public abstract void getKeys(AttributeValue value,
- Map<byte[], Boolean> modifiedKeys, Boolean insert);
+ public void getKeys(AttributeValue attrValue, Map<byte[], Boolean> modifiedKeys, Boolean insert)
+ {
+ final Set<byte[]> keys = new HashSet<byte[]>();
+ getKeys(attrValue, keys);
+ computeModifiedKeys(modifiedKeys, insert, keys);
+ }
+
+ /**
+ * Computes the modified keys by an indexer.
+ *
+ * @param modifiedKeys
+ * A map containing the keys and a boolean. Keys
+ * corresponding to the boolean value <code>true</code>
+ * should be inserted and <code>false</code> should be
+ * deleted.
+ * @param insert
+ * <code>true</code> if generated keys should be inserted
+ * or <code>false</code> otherwise.
+ * @param keys
+ * the newly generated keys that will be added or removed from the Map
+ */
+ public static void computeModifiedKeys(Map<byte[], Boolean> modifiedKeys,
+ Boolean insert, final Set<byte[]> keys)
+ {
+ for (byte[] key : keys)
+ {
+ Boolean cInsert = modifiedKeys.get(key);
+ if (cInsert == null)
+ {
+ modifiedKeys.put(key, insert);
+ }
+ else if (!cInsert.equals(insert))
+ {
+ modifiedKeys.remove(key);
+ }
+ }
+ }
}
\ No newline at end of file
--
Gitblit v1.10.0