mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Jean-Noel Rouvignac
16.28.2015 9b24ea04b84ecd1cdf7c1f07d9460729c6b5e5e2
In pluggable backend, renamed all "EntryIDList" to "EntryIDSet".
5 files modified
117 ■■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryIDSet.java 79 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/ImportIDSet.java 11 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Index.java 5 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/SortValuesSet.java 6 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/EntryIDSetTest.java 16 ●●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryIDSet.java
@@ -26,7 +26,7 @@
 */
package org.opends.server.backends.pluggable;
import static org.forgerock.util.Reject.checkNotNull;
import static org.forgerock.util.Reject.*;
import java.util.Arrays;
import java.util.Iterator;
@@ -45,9 +45,10 @@
 * Represents a set of Entry IDs. It can represent a set where the IDs are not defined, for example when the index entry
 * limit has been exceeded.
 */
@SuppressWarnings("javadoc")
final class EntryIDSet implements Iterable<EntryID>
{
  public static final ByteSequence NO_KEY = ByteString.valueOf("<none>");
  private static final ByteSequence NO_KEY = ByteString.valueOf("<none>");
  /**
   * Interface for EntryIDSet concrete implementations
@@ -273,13 +274,13 @@
    @Override
    public long[] getRange()
    {
      if (entryIDs.length == 0)
      if (entryIDs.length != 0)
      {
        return new long[] { 0, 0 };
        return new long[] { entryIDs[0], entryIDs[entryIDs.length - 1] };
      }
      else
      {
        return new long[] { entryIDs[0], entryIDs[entryIDs.length - 1] };
        return new long[] { 0, 0 };
      }
    }
@@ -429,24 +430,24 @@
   */
  private static final class IDSetIterator implements Iterator<EntryID>
  {
    private final long[] entryIDList;
    private final long[] entryIDSet;
    private int currentIndex;
    IDSetIterator(long[] entryIDList)
    IDSetIterator(long[] entryIDSet)
    {
      this.entryIDList = entryIDList;
      this.entryIDSet = entryIDSet;
    }
    IDSetIterator(long[] entryIDList, long begin)
    IDSetIterator(long[] entryIDSet, long begin)
    {
      this(entryIDList);
      currentIndex = Math.max(0, Arrays.binarySearch(entryIDList, begin));
      this(entryIDSet);
      currentIndex = Math.max(0, Arrays.binarySearch(entryIDSet, begin));
    }
    @Override
    public boolean hasNext()
    {
      return currentIndex < entryIDList.length;
      return currentIndex < entryIDSet.length;
    }
    @Override
@@ -454,7 +455,7 @@
    {
      if (hasNext())
      {
        return new EntryID(entryIDList[currentIndex++]);
        return new EntryID(entryIDSet[currentIndex++]);
      }
      throw new NoSuchElementException();
    }
@@ -466,58 +467,46 @@
    }
  }
  /**
   * Create a new undefined set
   */
  public static EntryIDSet newUndefinedSet()
  static EntryIDSet newUndefinedSet()
  {
    return new EntryIDSet(new UndefinedImpl(NO_KEY, Long.MAX_VALUE));
  }
  /**
   * Create a new undefined set
   */
  public static EntryIDSet newUndefinedSetWithKey(ByteSequence key)
  static EntryIDSet newUndefinedSetWithKey(ByteSequence key)
  {
    return newUndefinedSetWithSize(key, Long.MAX_VALUE);
  }
  /**
   * Create a new undefined set with a initial size.
   *
   * @param size
   *          The undefined size for this set.
   */
  public static EntryIDSet newUndefinedSetWithSize(ByteSequence key, long undefinedSize)
  static EntryIDSet newUndefinedSetWithSize(ByteSequence key, long undefinedSize)
  {
    return new EntryIDSet(new UndefinedImpl(key, undefinedSize));
  }
  /**
   * Create a new defined entry ID set with the specified ids.
   * Creates a new defined entry ID set with the specified ids.
   *
   * @param ids
   *          Entry IDs contained in the set.
   * @throws NullPointerException
   *           if ids is null
   */
  public static EntryIDSet newDefinedSet(long... ids)
  static EntryIDSet newDefinedSet(long... ids)
  {
    checkNotNull(ids, "ids must not be null");
    return new EntryIDSet(new DefinedImpl(ids));
  }
  /**
   * Create a new entry ID set from the raw database value.
   * Creates a new entry ID set from the raw database value.
   *
   * @param key
   *          The database key that contains this value.
   * @param bytes
   * @param value
   *          The database value, or null if there are no entry IDs.
   * @throws NullPointerException
   *           if either key or value is null
   */
  public static EntryIDSet newSetFromBytes(ByteSequence key, ByteString value)
  static EntryIDSet newSetFromBytes(ByteSequence key, ByteString value)
  {
    checkNotNull(key, "key must not be null");
    checkNotNull(value, "value must not be null");
@@ -535,7 +524,7 @@
    else
    {
      // Seems like entry limit has not been exceeded and the bytes is a list of entry IDs.
      return newDefinedSet(decodeEntryIDList(value));
      return newDefinedSet(decodeEntryIDSet(value));
    }
  }
@@ -569,13 +558,13 @@
  }
  /**
   * Create a new set of entry IDs that is the union of several entry ID sets.
   * Creates a new set of entry IDs that is the union of several entry ID sets.
   *
   * @param sets
   *          A list of entry ID sets.
   * @return The union of the provided entry ID sets.
   */
  public static EntryIDSet newSetFromUnion(List<EntryIDSet> sets)
  static EntryIDSet newSetFromUnion(List<EntryIDSet> sets)
  {
    checkNotNull(sets, "sets must not be null");
@@ -648,16 +637,16 @@
   *          the encoded entryID list
   * @return a long array representing the entryID list
   */
  public static long[] decodeEntryIDList(ByteSequence bytes)
  static long[] decodeEntryIDSet(ByteSequence bytes)
  {
    final ByteSequenceReader reader = bytes.asReader();
    final int count = bytes.length() / 8;
    final long[] entryIDList = new long[count];
    final long[] entryIDSet = new long[count];
    for (int i = 0; i < count; i++)
    {
      entryIDList[i] = reader.getLong();
      entryIDSet[i] = reader.getLong();
    }
    return entryIDList;
    return entryIDSet;
  }
  /**
@@ -667,9 +656,11 @@
   *          the encoded undefined size
   * @return the undefined size
   */
  public static long decodeUndefinedSize(ByteString bytes)
  static long decodeUndefinedSize(ByteString bytes)
  {
    return bytes.length() == 8 ? bytes.toLong() & Long.MAX_VALUE : Long.MAX_VALUE; // remove top bit
    return bytes.length() == 8
        ? bytes.toLong() & Long.MAX_VALUE
        : Long.MAX_VALUE; // remove top bit
  }
  private EntryIDSetImplementor concreteImpl;
@@ -850,7 +841,7 @@
  }
  /**
   * Create an iterator over the set or an empty iterator if the set is not defined.
   * Creates an iterator over the set or an empty iterator if the set is not defined.
   *
   * @return An EntryID iterator.
   */
@@ -861,7 +852,7 @@
  }
  /**
   * Create an iterator over the set or an empty iterator if the set is not defined.
   * Creates an iterator over the set or an empty iterator if the set is not defined.
   *
   * @param begin
   *          The entry ID of the first entry to return in the list.
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/ImportIDSet.java
@@ -26,8 +26,7 @@
 */
package org.opends.server.backends.pluggable;
import static org.opends.server.backends.pluggable.EntryIDSet.decodeEntryIDList;
import static org.opends.server.backends.pluggable.EntryIDSet.decodeUndefinedSize;
import static org.opends.server.backends.pluggable.EntryIDSet.*;
import org.forgerock.opendj.ldap.ByteSequence;
import org.forgerock.opendj.ldap.ByteString;
@@ -156,12 +155,12 @@
      undefinedSize = decodeUndefinedSize(dBbytes) + importIdSet.size();
      isDefined=false;
    } else if(!importIdSet.isDefined()) {
      int dbSize = decodeEntryIDList(dBbytes).length;
      int dbSize = decodeEntryIDSet(dBbytes).length;
      undefinedSize = dbSize + importIdSet.undefinedSize;
      isDefined = false;
      incrementLimitCount = true;
    } else {
      array = decodeEntryIDList(dBbytes);
      array = decodeEntryIDSet(dBbytes);
      if (array.length + importIdSet.size() > indexEntryLimit) {
        undefinedSize = array.length + importIdSet.size();
        isDefined=false;
@@ -190,7 +189,7 @@
      isDefined=false;
      undefinedSize = Long.MAX_VALUE;
    } else {
      array = decodeEntryIDList(bytes);
      array = decodeEntryIDSet(bytes);
      if (array.length - importIdSet.size() > indexEntryLimit) {
        isDefined=false;
        count = 0;
@@ -229,7 +228,7 @@
      undefinedSize = Long.MAX_VALUE;
      count = 0;
    } else {
      array = decodeEntryIDList(bytes);
      array = decodeEntryIDSet(bytes);
      if (array.length + importIdSet.size() > indexEntryLimit) {
        isDefined = false;
        incrementLimitCount = true;
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/Index.java
@@ -290,7 +290,7 @@
    final ByteString value = txn.getRMW(getName(), key);
    if (value != null)
    {
      EntryIDSet entryIDSet = computeEntryIDList(key, value, deletedIDs, addedIDs);
      EntryIDSet entryIDSet = computeEntryIDSet(key, value, deletedIDs, addedIDs);
      ByteString after = entryIDSet.toByteString();
      if (!after.isEmpty())
      {
@@ -318,8 +318,7 @@
    }
  }
  private EntryIDSet computeEntryIDList(ByteString key, ByteString value, EntryIDSet deletedIDs,
      EntryIDSet addedIDs)
  private EntryIDSet computeEntryIDSet(ByteString key, ByteString value, EntryIDSet deletedIDs, EntryIDSet addedIDs)
  {
    EntryIDSet entryIDSet = newSetFromBytes(key, value);
    if(addedIDs != null)
opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/SortValuesSet.java
@@ -370,12 +370,12 @@
  {
    final ByteSequenceReader reader = bytes.asReader();
    final int length = reader.getInt();
    final long[] entryIDList = new long[length];
    final long[] entryIDSet = new long[length];
    for (int i = 0; i < length; i++)
    {
      entryIDList[i] = reader.getLong();
      entryIDSet[i] = reader.getLong();
    }
    return entryIDList;
    return entryIDSet;
  }
  /**
opendj-server-legacy/src/test/java/org/opends/server/backends/pluggable/EntryIDSetTest.java
@@ -25,15 +25,9 @@
 */
package org.opends.server.backends.pluggable;
import static org.assertj.core.api.Assertions.assertThat;
import static org.opends.server.backends.pluggable.EntryIDSet.decodeEntryIDList;
import static org.opends.server.backends.pluggable.EntryIDSet.newDefinedSet;
import static org.opends.server.backends.pluggable.EntryIDSet.newSetFromBytes;
import static org.opends.server.backends.pluggable.EntryIDSet.newSetFromUnion;
import static org.opends.server.backends.pluggable.EntryIDSet.newUndefinedSetWithKey;
import static org.opends.server.backends.pluggable.EntryIDSet.newUndefinedSetWithSize;
import static org.opends.server.backends.pluggable.EntryIDSet.newUndefinedSet;
import static org.opends.server.backends.pluggable.Utils.assertIdsEquals;
import static org.assertj.core.api.Assertions.*;
import static org.opends.server.backends.pluggable.EntryIDSet.*;
import static org.opends.server.backends.pluggable.Utils.*;
import java.util.Arrays;
@@ -182,10 +176,10 @@
  public void testDefinedByteString()
  {
    ByteString string = newDefinedSet(4, 6, 8, 10, 12).toByteString();
    assertThat(decodeEntryIDList(string)).containsExactly(4, 6, 8, 10, 12);
    assertThat(decodeEntryIDSet(string)).containsExactly(4, 6, 8, 10, 12);
    string = newDefinedSet().toByteString();
    assertThat(decodeEntryIDList(string)).isEmpty();
    assertThat(decodeEntryIDSet(string)).isEmpty();
  }
  @Test(expectedExceptions = NullPointerException.class)