001/*
002 * CDDL HEADER START
003 *
004 * The contents of this file are subject to the terms of the
005 * Common Development and Distribution License, Version 1.0 only
006 * (the "License").  You may not use this file except in compliance
007 * with the License.
008 *
009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt
010 * or http://forgerock.org/license/CDDLv1.0.html.
011 * See the License for the specific language governing permissions
012 * and limitations under the License.
013 *
014 * When distributing Covered Code, include this CDDL HEADER in each
015 * file and include the License file at legal-notices/CDDLv1_0.txt.
016 * If applicable, add the following below this CDDL HEADER, with the
017 * fields enclosed by brackets "[]" replaced with your own identifying
018 * information:
019 *      Portions Copyright [yyyy] [name of copyright owner]
020 *
021 * CDDL HEADER END
022 *
023 *
024 *      Copyright 2006-2008 Sun Microsystems, Inc.
025 *      Portions Copyright 2014-2015 ForgeRock AS
026 */
027package org.opends.server.backends.jeb;
028
029import java.util.*;
030
031import org.forgerock.opendj.ldap.ByteString;
032import org.opends.server.types.Entry;
033import org.opends.server.types.Modification;
034
035import com.sleepycat.je.DatabaseEntry;
036
037/**
038 * Implementation of an Indexer for the subtree index.
039 */
040public class ID2SIndexer extends Indexer
041{
042  /**
043   * Create a new indexer for a subtree index.
044   */
045  public ID2SIndexer()
046  {
047  }
048
049  /** {@inheritDoc} */
050  @Override
051  public String toString()
052  {
053    return "id2subtree";
054  }
055
056  /** {@inheritDoc} */
057  @Override
058  public void indexEntry(Entry entry, Set<ByteString> addKeys)
059  {
060    // The superior entry IDs are in the entry attachment.
061    ArrayList<EntryID> ids = (ArrayList<EntryID>) entry.getAttachment();
062
063    // Skip the entry's own ID.
064    Iterator<EntryID> iter = ids.iterator();
065    iter.next();
066
067    // Iterate through the superior IDs.
068    while (iter.hasNext())
069    {
070      DatabaseEntry nodeIDData = iter.next().getDatabaseEntry();
071      addKeys.add(ByteString.wrap(nodeIDData.getData()));
072    }
073  }
074
075  /** {@inheritDoc} */
076  @Override
077  public void modifyEntry(Entry oldEntry, Entry newEntry,
078                          List<Modification> mods,
079                          Map<ByteString, Boolean> modifiedKeys)
080  {
081    // Nothing to do.
082  }
083}