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 2008 Sun Microsystems, Inc. 026 */ 027 028 package org.opends.server.synchronization.plugin; 029 030 import org.opends.server.api.OrderingMatchingRule; 031 import org.opends.server.core.DirectoryServer; 032 033 import java.util.Comparator; 034 035 /** 036 * This class maintains compatibility with databases created before the 037 * org.opends.server.synchronization package was renamed. The class 038 * was used as a JE custom btree comparator in the ds-sync-hist attribute 039 * index, so older databases expect it to exist. This class now just 040 * implements the comparator interface and delegates to the matching rule 041 * comparator found in the replication package. 042 */ 043 public class HistoricalCsnOrderingMatchingRule implements Comparator<byte[]> 044 { 045 /** 046 * The historicalCsnOrderingMatch matching rule in the replication package. 047 */ 048 private static OrderingMatchingRule rule = null; 049 050 051 /** 052 * Compares its two arguments for order. Returns a negative integer, 053 * zero, or a positive integer as the first argument is less than, equal 054 * to, or greater than the second.<p> 055 * <p/> 056 * The implementor must ensure that <tt>sgn(compare(x, y)) == 057 * -sgn(compare(y, x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This 058 * implies that <tt>compare(x, y)</tt> must throw an exception if and only 059 * if <tt>compare(y, x)</tt> throws an exception.)<p> 060 * <p/> 061 * The implementor must also ensure that the relation is transitive: 062 * <tt>((compare(x, y)>0) && (compare(y, z)>0))</tt> implies 063 * <tt>compare(x, z)>0</tt>.<p> 064 * <p/> 065 * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt> 066 * implies that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all 067 * <tt>z</tt>.<p> 068 * <p/> 069 * It is generally the case, but <i>not</i> strictly required that 070 * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking, 071 * any comparator that violates this condition should clearly indicate 072 * this fact. The recommended language is "Note: this comparator 073 * imposes orderings that are inconsistent with equals." 074 * 075 * @param o1 the first object to be compared. 076 * @param o2 the second object to be compared. 077 * @return a negative integer, zero, or a positive integer as the 078 * first argument is less than, equal to, or greater than the 079 * second. 080 */ 081 public int compare(byte[] o1, byte[] o2) 082 { 083 if (rule == null) 084 { 085 rule = DirectoryServer. 086 getOrderingMatchingRule("historicalCsnOrderingMatch"); 087 } 088 return rule.compare(o1, o2); 089 } 090 091 }