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
010     * trunk/opends/resource/legal-notices/OpenDS.LICENSE
011     * or https://OpenDS.dev.java.net/OpenDS.LICENSE.
012     * See the License for the specific language governing permissions
013     * and limitations under the License.
014     *
015     * When distributing Covered Code, include this CDDL HEADER in each
016     * file and include the License file at
017     * trunk/opends/resource/legal-notices/OpenDS.LICENSE.  If applicable,
018     * add the following below this CDDL HEADER, with the fields enclosed
019     * by brackets "[]" replaced with your own identifying information:
020     *      Portions Copyright [yyyy] [name of copyright owner]
021     *
022     * CDDL HEADER END
023     *
024     *
025     *      Copyright 2006-2008 Sun Microsystems, Inc.
026     */
027    package org.opends.server.backends.jeb;
028    
029    import org.opends.server.types.Entry;
030    import org.opends.server.types.Modification;
031    
032    import com.sleepycat.je.DatabaseEntry;
033    
034    import java.util.*;
035    
036    /**
037     * Implementation of an Indexer for the children index.
038     */
039    public class ID2CIndexer extends Indexer
040    {
041      /**
042       * The comparator for keys generated by this class.
043       */
044      private static final Comparator<byte[]> comparator =
045           new AttributeIndex.KeyComparator();
046    
047      /**
048       * Create a new indexer for a children index.
049       */
050      public ID2CIndexer()
051      {
052        // No implementation required.
053      }
054    
055      /**
056       * Get a string representation of this object.  The returned value is
057       * used to name an index created using this object.
058       * @return A string representation of this object.
059       */
060      public String toString()
061      {
062        return "id2children";
063      }
064    
065      /**
066       * Get the comparator that must be used to compare index keys
067       * generated by this class.
068       *
069       * @return A byte array comparator.
070       */
071      public Comparator<byte[]> getComparator()
072      {
073        return comparator;
074      }
075    
076      /**
077       * Generate the set of index keys for an entry.
078       *
079       * @param entry The entry.
080       * @param addKeys The set into which the generated keys will be inserted.
081       */
082      public void indexEntry(Entry entry, Set<byte[]> addKeys)
083      {
084        // The superior entry IDs are in the entry attachment.
085        ArrayList ids = (ArrayList)entry.getAttachment();
086    
087        // Skip the entry's own ID.
088        Iterator iter = ids.iterator();
089        iter.next();
090    
091        // Get the parent ID.
092        if (iter.hasNext())
093        {
094          DatabaseEntry nodeIDData = ((EntryID)iter.next()).getDatabaseEntry();
095          addKeys.add(nodeIDData.getData());
096        }
097      }
098    
099      /**
100       * Generate the set of index keys to be added and the set of index keys
101       * to be deleted for an entry that has been replaced.
102       *
103       * @param oldEntry The original entry contents.
104       * @param newEntry The new entry contents.
105       * @param modifiedKeys The map into which the modified keys will be inserted.
106       */
107      public void replaceEntry(Entry oldEntry, Entry newEntry,
108                               Map<byte[], Boolean> modifiedKeys)
109      {
110        // Nothing to do.
111      }
112    
113    
114    
115      /**
116       * Generate the set of index keys to be added and the set of index keys
117       * to be deleted for an entry that was modified.
118       *
119       * @param oldEntry The original entry contents.
120       * @param newEntry The new entry contents.
121       * @param mods The set of modifications that were applied to the entry.
122       * @param modifiedKeys The map into which the modified keys will be inserted.
123       */
124      public void modifyEntry(Entry oldEntry, Entry newEntry,
125                              List<Modification> mods,
126                              Map<byte[], Boolean> modifiedKeys)
127      {
128        // Nothing to do.
129      }
130    }