| | |
| | | */ |
| | | package org.opends.server.backends.jeb; |
| | | |
| | | import java.util.Collections; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | import java.util.Set; |
| | |
| | | */ |
| | | public class PresenceIndexer extends Indexer |
| | | { |
| | | /** The key bytes used for the presence index. */ |
| | | static final byte[] presenceKeyBytes = "+".getBytes(); |
| | | |
| | | /** |
| | | * The attribute type for which this instance will |
| | | * generate index keys. |
| | | */ |
| | | /** The key bytes used for the presence index as a {@link ByteString}. */ |
| | | static final ByteString presenceKey = ByteString.wrap(presenceKeyBytes); |
| | | |
| | | /** The attribute type for which this instance will generate index keys. */ |
| | | private AttributeType attributeType; |
| | | |
| | | /** |
| | |
| | | @Override |
| | | public void indexEntry(Entry entry, Set<ByteString> keys, IndexingOptions options) |
| | | { |
| | | List<Attribute> attrList = |
| | | entry.getAttribute(attributeType); |
| | | List<Attribute> attrList = entry.getAttribute(attributeType); |
| | | if (attrList != null) |
| | | { |
| | | if (!attrList.isEmpty()) |
| | | { |
| | | keys.add(getPresenceKeyData()); |
| | | keys.add(presenceKey); |
| | | } |
| | | } |
| | | } |
| | |
| | | public void replaceEntry(Entry oldEntry, Entry newEntry, |
| | | Map<ByteString, Boolean> modifiedKeys, IndexingOptions options) |
| | | { |
| | | List<Attribute> newAttributes = newEntry.getAttribute(attributeType, true); |
| | | List<Attribute> oldAttributes = oldEntry.getAttribute(attributeType, true); |
| | | if(oldAttributes == null) |
| | | { |
| | | if(newAttributes != null) |
| | | { |
| | | modifiedKeys.put(getPresenceKeyData(), true); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if(newAttributes == null) |
| | | { |
| | | modifiedKeys.put(getPresenceKeyData(), false); |
| | | } |
| | | } |
| | | modifyEntry(oldEntry, newEntry, Collections.<Modification>emptyList(), modifiedKeys, options); |
| | | } |
| | | |
| | | /** {@inheritDoc} */ |
| | |
| | | { |
| | | if(newAttributes != null) |
| | | { |
| | | modifiedKeys.put(getPresenceKeyData(), true); |
| | | modifiedKeys.put(presenceKey, true); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if(newAttributes == null) |
| | | { |
| | | modifiedKeys.put(getPresenceKeyData(), false); |
| | | modifiedKeys.put(presenceKey, false); |
| | | } |
| | | } |
| | | } |
| | | |
| | | private ByteString getPresenceKeyData() |
| | | { |
| | | return ByteString.wrap(AttributeIndex.presenceKey.getData()); |
| | | } |
| | | } |