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

Jean-Noel Rouvignac
11.32.2014 2f8ddecb5c2234bb90f6879100656cbfa6c1f5fe
Code cleanup.


JebFormat.java:
In dnFromDNKey() and findDNKeyParent() removed parameters offset and length since they are never relevant and we can directly use the byte array.

Changed client code to only pass the byte array.
4 files modified
48 ■■■■■ changed files
opendj3-server-dev/src/server/org/opends/server/backends/jeb/DN2URI.java 6 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java 4 ●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/jeb/JebFormat.java 33 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java 5 ●●●●● patch | view | raw | blame | history
opendj3-server-dev/src/server/org/opends/server/backends/jeb/DN2URI.java
@@ -46,6 +46,7 @@
import static com.sleepycat.je.OperationStatus.*;
import static org.opends.messages.JebMessages.*;
import static org.opends.server.backends.jeb.JebFormat.*;
import static org.opends.server.util.ServerConstants.*;
/**
@@ -621,12 +622,11 @@
          }
          // We have found a subordinate referral.
          DN dn = JebFormat.dnFromDNKey(key.getData(), 0, key.getSize(),
                                        entryContainer.getBaseDN());
          DN dn = dnFromDNKey(key.getData(), entryContainer.getBaseDN());
          // Make sure the referral is within scope.
          if (searchOp.getScope() == SearchScope.SINGLE_LEVEL
              && JebFormat.findDNKeyParent(key.getData(), 0, key.getSize()) != baseDN.length)
              && findDNKeyParent(key.getData()) != baseDN.length)
          {
            continue;
          }
opendj3-server-dev/src/server/org/opends/server/backends/jeb/EntryContainer.java
@@ -1160,7 +1160,7 @@
          boolean isInScope =
              searchScope != SearchScope.SINGLE_LEVEL
                  // Check if this entry is an immediate child.
                  || findDNKeyParent(key.getData(), 0, key.getSize()) == baseDNKey.length;
                  || findDNKeyParent(key.getData()) == baseDNKey.length;
          if (isInScope)
          {
            // Process the candidate entry.
@@ -1678,7 +1678,7 @@
            {
              LocalizableMessage message =
                      ERR_JEB_DELETE_ABORTED_BY_SUBORDINATE_PLUGIN.get(
                      dnFromDNKey(key.getData(), 0, 0, getBaseDN()));
                      dnFromDNKey(key.getData(), getBaseDN()));
              throw new DirectoryException(
                  DirectoryServer.getServerErrorResultCode(), message);
            }
opendj3-server-dev/src/server/org/opends/server/backends/jeb/JebFormat.java
@@ -257,34 +257,31 @@
   * Decode a DN value from its database key representation.
   *
   * @param dnKey The database key value of the DN.
   * @param offset Starting position in the database key data.
   * @param length The length of the database key data.
   * @param prefix The DN to prefix the deocded DN value.
   * @param prefix The DN to prefix the decoded DN value.
   * @return The decoded DN value.
   * @throws DirectoryException if an error occurs while decoding the DN value.
   * @see #dnToDNKey(DN, int)
   */
  public static DN dnFromDNKey(byte[] dnKey, int offset, int length, DN prefix)
  public static DN dnFromDNKey(byte[] dnKey, DN prefix)
      throws DirectoryException
  {
    DN dn = prefix;
    int start = offset;
    boolean escaped = false;
    ByteStringBuilder buffer = new ByteStringBuilder();
    for(int i = start; i < length; i++)
    for (byte b : dnKey)
    {
      if(dnKey[i] == 0x5C)
      if (b == 0x5C)
      {
        escaped = true;
        continue;
      }
      else if(!escaped && dnKey[i] == 0x01)
      else if (!escaped && b == 0x01)
      {
        buffer.append(0x01);
        escaped = false;
        continue;
      }
      else if(!escaped && dnKey[i] == 0x00)
      else if (!escaped && b == 0x00)
      {
        if(buffer.length() > 0)
        {
@@ -299,7 +296,7 @@
          buffer.append(0x5C);
          escaped = false;
        }
        buffer.append(dnKey[i]);
        buffer.append(b);
      }
    }
@@ -311,6 +308,20 @@
    return dn;
  }
  /**
   * Find the length of bytes that represents the superior DN of the given
   * DN key. The superior DN is represented by the initial bytes of the DN key.
   *
   * @param dnKey The database key value of the DN.
   * @return The length of the superior DN or -1 if the given dn is the
   *         root DN or 0 if the superior DN is removed.
   */
  public static int findDNKeyParent(byte[] dnKey)
  {
    return findDNKeyParent(dnKey, 0, dnKey.length);
  }
  /**
   * Find the length of bytes that represents the superior DN of the given
   * DN key. The superior DN is represented by the initial bytes of the DN key.
@@ -347,7 +358,7 @@
   * @param prefixRDNs The number of prefix RDNs to remove from the encoded
   *                   representation.
   * @return A DatabaseEntry containing the key.
   * @see #dnFromDNKey(byte[], int, int, DN)
   * @see #dnFromDNKey(byte[], DN)
   */
  public static byte[] dnToDNKey(DN dn, int prefixRDNs)
  {
opendj3-server-dev/src/server/org/opends/server/tools/DBTest.java
@@ -74,6 +74,7 @@
import static com.forgerock.opendj.cli.Utils.*;
import static org.opends.messages.ToolMessages.*;
import static org.opends.server.backends.jeb.JebFormat.*;
import static org.opends.server.util.StaticUtils.*;
/**
@@ -1252,9 +1253,7 @@
              {
                try
                {
                  formatedKey = JebFormat.dnFromDNKey(
                      key.getData(), 0, key.getSize(), ec.getBaseDN()).
                      toNormalizedString();
                  formatedKey = dnFromDNKey(key.getData(), ec.getBaseDN()).toNormalizedString();
                  keyLabel = INFO_LABEL_DBTEST_ENTRY_DN.get();
                }
                catch(Exception e)