| | |
| | | */ |
| | | package org.opends.server.backends.jeb; |
| | | |
| | | import java.util.Comparator; |
| | | import java.util.HashSet; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | | import java.util.TreeSet; |
| | | |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.ByteString; |
| | |
| | | private static final LocalizedLogger logger = LocalizedLogger.getLoggerForThisClass(); |
| | | |
| | | /** |
| | | * The comparator for index keys generated by this class. |
| | | */ |
| | | private static final Comparator<byte[]> comparator = |
| | | new AttributeIndex.KeyComparator(); |
| | | |
| | | |
| | | |
| | | /** |
| | | * The attribute type for which this instance will |
| | | * generate index keys. |
| | | */ |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Gets the comparator that must be used to compare index keys |
| | | * generated by this class. |
| | | * |
| | | * @return A byte array comparator. |
| | | */ |
| | | @Override |
| | | public Comparator<byte[]> getComparator() |
| | | { |
| | | return comparator; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | */ |
| | | @Override |
| | | public void indexEntry(Entry entry, Set<byte[]> keys) |
| | | public void indexEntry(Entry entry, Set<ByteString> keys) |
| | | { |
| | | List<Attribute> attrList = |
| | | entry.getAttribute(attributeType); |
| | |
| | | */ |
| | | @Override |
| | | public void replaceEntry(Entry oldEntry, Entry newEntry, |
| | | Map<byte[], Boolean> modifiedKeys) |
| | | Map<ByteString, Boolean> modifiedKeys) |
| | | { |
| | | List<Attribute> newAttributes = newEntry.getAttribute(attributeType, true); |
| | | List<Attribute> oldAttributes = oldEntry.getAttribute(attributeType, true); |
| | |
| | | @Override |
| | | public void modifyEntry(Entry oldEntry, Entry newEntry, |
| | | List<Modification> mods, |
| | | Map<byte[], Boolean> modifiedKeys) |
| | | Map<ByteString, Boolean> modifiedKeys) |
| | | { |
| | | List<Attribute> newAttributes = newEntry.getAttribute(attributeType, true); |
| | | List<Attribute> oldAttributes = oldEntry.getAttribute(attributeType, true); |
| | |
| | | * @param keys The set into which the generated keys will be inserted. |
| | | */ |
| | | private void indexAttribute(List<Attribute> attrList, |
| | | Set<byte[]> keys) |
| | | Set<ByteString> keys) |
| | | { |
| | | if (attrList == null) return; |
| | | |
| | | Set<ByteString> keysBS = new TreeSet<ByteString>(); |
| | | for (Attribute attr : attrList) |
| | | { |
| | | if (!attr.isVirtual()) |
| | |
| | | { |
| | | try |
| | | { |
| | | extensibleIndexer.createKeys(null, value.getValue(), null, keysBS); |
| | | extensibleIndexer.createKeys(null, value.getValue(), null, keys); |
| | | } |
| | | catch (DecodeException e) |
| | | { |
| | |
| | | } |
| | | } |
| | | } |
| | | for (ByteString key : keysBS) |
| | | { |
| | | keys.add(key.toByteArray()); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | * be inserted or <code>false</code> otherwise. |
| | | */ |
| | | private void indexAttribute(List<Attribute> attrList, |
| | | Map<byte[], Boolean> modifiedKeys, |
| | | Map<ByteString, Boolean> modifiedKeys, |
| | | Boolean insert) |
| | | { |
| | | if (attrList == null) return; |
| | | |
| | | final Set<byte[]> keys = new HashSet<byte[]>(); |
| | | final Set<ByteString> keys = new HashSet<ByteString>(); |
| | | indexAttribute(attrList, keys); |
| | | computeModifiedKeys(modifiedKeys, insert, keys); |
| | | } |
| | |
| | | * @param keys |
| | | * The index keys to map. |
| | | */ |
| | | private static void computeModifiedKeys(Map<byte[], Boolean> modifiedKeys, |
| | | Boolean insert, final Set<byte[]> keys) |
| | | private static void computeModifiedKeys(Map<ByteString, Boolean> modifiedKeys, |
| | | Boolean insert, Set<ByteString> keys) |
| | | { |
| | | for (byte[] key : keys) |
| | | for (ByteString key : keys) |
| | | { |
| | | Boolean cInsert = modifiedKeys.get(key); |
| | | if (cInsert == null) |