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

Matthew Swift
10.45.2015 8fee00d9880af3d06ff9f917fd3934141ef2135c
Minor code cleanup:

* removed listDatabases(), getConfiguration(), and substringKeys() in AttributeIndex
* added AttributeIndex.isIndexed() and modified BackendImpl.isIndexed() to delegate to AttributeIndex.
3 files modified
113 ■■■■ changed files
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java 77 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java 34 ●●●●● patch | view | raw | blame | history
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java 2 ●●● patch | view | raw | blame | history
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/AttributeIndex.java
@@ -390,12 +390,39 @@
  }
  /**
   * Get the JE index configuration used by this index.
   * @return The configuration in effect.
   * Returns {@code true} if this attribute index supports the provided index type.
   *
   * @param indexType
   *          The index type.
   * @return {@code true} if this attribute index supports the provided index type.
   */
  BackendIndexCfg getConfiguration()
  boolean isIndexed(org.opends.server.types.IndexType indexType)
  {
    return config;
    Set<IndexType> indexTypes = config.getIndexType();
    switch (indexType)
    {
    case PRESENCE:
      return indexTypes.contains(IndexType.PRESENCE);
    case EQUALITY:
      return indexTypes.contains(IndexType.EQUALITY);
    case SUBSTRING:
    case SUBINITIAL:
    case SUBANY:
    case SUBFINAL:
      return indexTypes.contains(IndexType.SUBSTRING);
    case GREATER_OR_EQUAL:
    case LESS_OR_EQUAL:
      return indexTypes.contains(IndexType.ORDERING);
    case APPROXIMATE:
      return indexTypes.contains(IndexType.APPROXIMATE);
    default:
      return false;
    }
  }
  /**
@@ -482,39 +509,6 @@
  }
  /**
   * Decompose an attribute value into a set of substring index keys.
   * The ID of the entry containing this value should be inserted
   * into the list of each of these keys.
   *
   * @param normValue A byte array containing the normalized attribute value.
   * @return A set of index keys.
   */
  Set<ByteString> substringKeys(ByteString normValue)
  { // FIXME replace this code with SDK's
    // AbstractSubstringMatchingRuleImpl.SubstringIndexer.createKeys()
    // Eliminate duplicates by putting the keys into a set.
    // Sorting the keys will ensure database record locks are acquired
    // in a consistent order and help prevent transaction deadlocks between
    // concurrent writers.
    Set<ByteString> set = new HashSet<ByteString>();
    int substrLength = config.getSubstringLength();
    // Example: The value is ABCDE and the substring length is 3.
    // We produce the keys ABC BCD CDE DE E
    // To find values containing a short substring such as DE,
    // iterate through keys with prefix DE. To find values
    // containing a longer substring such as BCDE, read keys BCD and CDE.
    for (int i = 0, remain = normValue.length(); remain > 0; i++, remain--)
    {
      int len = Math.min(substrLength, remain);
      set.add(normValue.subSequence(i, i + len));
    }
    return set;
  }
  /**
   * Retrieve the entry IDs that might match the provided assertion.
   *
   * @param indexQuery
@@ -674,15 +668,6 @@
  }
  /**
   * Get a list of the databases opened by this attribute index.
   * @param dbList A list of database containers.
   */
  void listDatabases(List<DatabaseContainer> dbList)
  {
    dbList.addAll(nameToIndexes.values());
  }
  /**
   * Get a string representation of this object.
   * @return return A string representation of this object.
   */
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/BackendImpl.java
@@ -45,7 +45,6 @@
import org.forgerock.opendj.ldap.ResultCode;
import org.forgerock.util.Reject;
import org.opends.server.admin.server.ConfigurationChangeListener;
import org.opends.server.admin.std.meta.BackendIndexCfgDefn;
import org.opends.server.admin.std.server.PluggableBackendCfg;
import org.opends.server.api.Backend;
import org.opends.server.api.MonitorProvider;
@@ -251,42 +250,11 @@
    {
      EntryContainer ec = rootContainer.getEntryContainer(baseDNs[0]);
      AttributeIndex ai = ec.getAttributeIndex(attributeType);
      if (ai == null)
      {
        return false;
      }
      Set<BackendIndexCfgDefn.IndexType> indexTypes =
           ai.getConfiguration().getIndexType();
      switch (indexType)
      {
        case PRESENCE:
          return indexTypes.contains(BackendIndexCfgDefn.IndexType.PRESENCE);
        case EQUALITY:
          return indexTypes.contains(BackendIndexCfgDefn.IndexType.EQUALITY);
        case SUBSTRING:
        case SUBINITIAL:
        case SUBANY:
        case SUBFINAL:
          return indexTypes.contains(BackendIndexCfgDefn.IndexType.SUBSTRING);
        case GREATER_OR_EQUAL:
        case LESS_OR_EQUAL:
          return indexTypes.contains(BackendIndexCfgDefn.IndexType.ORDERING);
        case APPROXIMATE:
          return indexTypes.contains(BackendIndexCfgDefn.IndexType.APPROXIMATE);
        default:
          return false;
      }
      return ai != null ? ai.isIndexed(indexType) : false;
    }
    catch (Exception e)
    {
      logger.traceException(e);
      return false;
    }
  }
opendj-sdk/opendj-server-legacy/src/main/java/org/opends/server/backends/pluggable/EntryContainer.java
@@ -2989,7 +2989,7 @@
    for (AttributeIndex index : attrIndexMap.values())
    {
      index.listDatabases(databases);
      databases.addAll(index.getNameToIndexes().values());
    }
    databases.addAll(vlvIndexMap.values());