001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2006-2010 Sun Microsystems, Inc.
015 * Portions Copyright 2013-2016 ForgeRock AS.
016 */
017package org.opends.server.replication.plugin;
018
019import java.util.Iterator;
020import java.util.Set;
021
022import org.forgerock.opendj.ldap.ByteString;
023import org.forgerock.opendj.ldap.schema.AttributeType;
024import org.opends.server.replication.common.CSN;
025import org.opends.server.types.Entry;
026import org.opends.server.types.Modification;
027
028/** This class store historical information for a provided attribute. */
029public abstract class AttrHistorical
030{
031  /**
032   * This method will be called when replaying an operation.
033   * It should use whatever historical information is stored in this class
034   * to solve the conflict and modify the mod and the mods iterator accordingly
035   *
036   * @param modsIterator  The iterator on the mods from which the mod is extracted.
037   * @param csn  The CSN associated to the operation.
038   * @param modifiedEntry The entry modified by this operation.
039   * @param mod           The modification.
040   * @return {@code true} if a conflict was detected, {@code false} otherwise.
041   */
042  public abstract boolean replayOperation(
043      Iterator<Modification> modsIterator, CSN csn, Entry modifiedEntry, Modification mod);
044
045  /**
046   * This method calculates the historical information and update the hist
047   * attribute to store the historical information for modify operation that
048   * does not conflict with previous operation.
049   * This is the usual path and should therefore be optimized.
050   * <p>
051   * It does not check if the operation to process is conflicting or not with
052   * previous operations. The caller is responsible for this.
053   *
054   * @param csn The CSN of the operation to process
055   * @param mod The modify operation to process.
056   */
057  public abstract void processLocalOrNonConflictModification(CSN csn, Modification mod);
058
059  /**
060   * Create a new object from a provided attribute type. Historical is empty.
061   *
062   * @param attrType the provided attribute type.
063   * @return a new AttributeInfo object.
064   */
065  public static AttrHistorical createAttributeHistorical(AttributeType attrType)
066  {
067    return attrType.isSingleValue() ? new AttrHistoricalSingle(attrType) : new AttrHistoricalMultiple();
068  }
069
070  /**
071   * Get the historical informations for this attribute Info.
072   *
073   * @return the historical informations
074   */
075  public abstract Set<AttrValueHistorical> getValuesHistorical();
076
077  /**
078   * Returns the last time when this attribute was deleted.
079   *
080   * @return the last time when this attribute was deleted
081   */
082  public abstract CSN getDeleteTime();
083
084  /**
085   * Assign the provided information to this object.
086   *
087   * @param histKey the key to assign.
088   * @param attrType the associated attribute type.
089   * @param value   the associated value or null if there is no value;
090   * @param csn     the associated CSN.
091   */
092  public abstract void assign(HistAttrModificationKey histKey, AttributeType attrType, ByteString value, CSN csn);
093}