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 subtree index. 038 */ 039 public class ID2SIndexer 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 subtree index. 049 */ 050 public ID2SIndexer() 051 { 052 } 053 054 /** 055 * Get a string representation of this object. The returned value is 056 * used to name an index created using this object. 057 * @return A string representation of this object. 058 */ 059 public String toString() 060 { 061 return "id2subtree"; 062 } 063 064 /** 065 * Get the comparator that must be used to compare index keys 066 * generated by this class. 067 * 068 * @return A byte array comparator. 069 */ 070 public Comparator<byte[]> getComparator() 071 { 072 return comparator; 073 } 074 075 /** 076 * Generate the set of index keys for an entry. 077 * 078 * @param entry The entry. 079 * @param addKeys The set into which the generated keys will be inserted. 080 */ 081 public void indexEntry(Entry entry, Set<byte[]> addKeys) 082 { 083 // The superior entry IDs are in the entry attachment. 084 ArrayList ids = (ArrayList)entry.getAttachment(); 085 086 // Skip the entry's own ID. 087 Iterator iter = ids.iterator(); 088 iter.next(); 089 090 // Iterate through the superior IDs. 091 while (iter.hasNext()) 092 { 093 DatabaseEntry nodeIDData = ((EntryID)iter.next()).getDatabaseEntry(); 094 addKeys.add(nodeIDData.getData()); 095 } 096 } 097 098 /** 099 * Generate the set of index keys to be added and the set of index keys 100 * to be deleted for an entry that has been replaced. 101 * 102 * @param oldEntry The original entry contents. 103 * @param newEntry The new entry contents. 104 * @param modifiedKeys The map into which the modified keys will be inserted. 105 */ 106 public void replaceEntry(Entry oldEntry, Entry newEntry, 107 Map<byte[], Boolean> modifiedKeys) 108 { 109 // Nothing to do. 110 } 111 112 113 114 /** 115 * Generate the set of index keys to be added and the set of index keys 116 * to be deleted for an entry that was modified. 117 * 118 * @param oldEntry The original entry contents. 119 * @param newEntry The new entry contents. 120 * @param mods The set of modifications that were applied to the entry. 121 * @param modifiedKeys The map into which the modified keys will be inserted. 122 */ 123 public void modifyEntry(Entry oldEntry, Entry newEntry, 124 List<Modification> mods, 125 Map<byte[], Boolean> modifiedKeys) 126 { 127 // Nothing to do. 128 } 129 }