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 2012-2015 ForgeRock AS. 026 */ 027package org.opends.server.backends.jeb; 028 029import java.util.Comparator; 030import java.util.List; 031import java.util.Map; 032import java.util.Set; 033 034import org.forgerock.opendj.ldap.ByteSequence; 035import org.forgerock.opendj.ldap.ByteString; 036import org.opends.server.backends.jeb.AttributeIndex.KeyComparator; 037import org.opends.server.types.Entry; 038import org.opends.server.types.Modification; 039 040/** 041 * This class attempts to abstract the generation and comparison of keys 042 * for an index. It is subclassed for the specific type of indexing. 043 */ 044public abstract class Indexer 045{ 046 /** 047 * Get the comparator that must be used to compare index keys generated by 048 * this class. 049 * 050 * @return A byte array comparator. 051 */ 052 public final Comparator<byte[]> getComparator() 053 { 054 return KeyComparator.INSTANCE; 055 } 056 057 /** 058 * Get the comparator that must be used to compare index keys generated by 059 * this class. 060 * 061 * @return A byte string comparator. 062 */ 063 public final Comparator<ByteSequence> getBSComparator() 064 { 065 return ByteSequence.COMPARATOR; 066 } 067 068 /** 069 * Generate the set of index keys for an entry. 070 * 071 * @param entry The entry. 072 * @param keys The set into which the generated keys will be inserted. 073 */ 074 public abstract void indexEntry(Entry entry, Set<ByteString> keys); 075 076 /** 077 * Generate the set of index keys to be added and the set of index keys 078 * to be deleted for an entry that was modified. 079 * 080 * @param oldEntry The original entry contents. 081 * @param newEntry The new entry contents. 082 * @param mods The set of modifications that were applied to the entry. 083 * @param modifiedKeys The map into which the modified keys will be inserted. 084 */ 085 public abstract void modifyEntry(Entry oldEntry, Entry newEntry, 086 List<Modification> mods, Map<ByteString, Boolean> modifiedKeys); 087 088 /** 089 * Get a string representation of this object. The returned value is 090 * used to name an index created using this object. 091 * @return A string representation of this object. 092 */ 093 @Override 094 public abstract String toString(); 095}