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 children index.
039 */
040public class ID2CIndexer extends Indexer
041{
042  /**
043   * Create a new indexer for a children index.
044   */
045  public ID2CIndexer()
046  {
047    // No implementation required.
048  }
049
050  /** {@inheritDoc} */
051  @Override
052  public String toString()
053  {
054    return "id2children";
055  }
056
057  /** {@inheritDoc} */
058  @Override
059  public void indexEntry(Entry entry, Set<ByteString> addKeys)
060  {
061    // The superior entry IDs are in the entry attachment.
062    ArrayList<EntryID> ids = (ArrayList<EntryID>) entry.getAttachment();
063
064    // Skip the entry's own ID.
065    Iterator<EntryID> iter = ids.iterator();
066    iter.next();
067
068    // Get the parent ID.
069    if (iter.hasNext())
070    {
071      DatabaseEntry nodeIDData = iter.next().getDatabaseEntry();
072      addKeys.add(ByteString.wrap(nodeIDData.getData()));
073    }
074  }
075
076  /** {@inheritDoc} */
077  @Override
078  public void modifyEntry(Entry oldEntry, Entry newEntry,
079                          List<Modification> mods,
080                          Map<ByteString, Boolean> modifiedKeys)
081  {
082    // Nothing to do.
083  }
084}