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

Nicolas Capponi
19.24.2016 6ac20cf528ddcbf44b14f0df63f0af1d0cdafb69
OPENDJ-2987 Adapt CompressedSchema to change on object classes
1 files modified
54 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/api/CompressedSchema.java 54 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/api/CompressedSchema.java
@@ -41,6 +41,7 @@
import org.forgerock.opendj.ldap.ByteString;
import org.forgerock.opendj.ldap.ByteStringBuilder;
import org.forgerock.opendj.ldap.schema.AttributeType;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.forgerock.opendj.ldap.schema.Schema;
import org.opends.server.core.DirectoryServer;
import org.opends.server.core.ServerContext;
@@ -48,8 +49,6 @@
import org.opends.server.types.AttributeBuilder;
import org.opends.server.types.Attributes;
import org.opends.server.types.DirectoryException;
import org.forgerock.opendj.ldap.schema.ObjectClass;
import org.opends.server.util.RemoveOnceSDKSchemaIsUsed;
/**
 * This class provides a utility for interacting with compressed representations
@@ -124,22 +123,21 @@
    }
  }
  private Mappings reloadMappingsIfSchemaChanged(boolean force)
  private Mappings reloadMappingsIfSchemaChanged()
  {
    // @RemoveOnceSDKSchemaIsUsed remove the "force" parameter
    sharedLock.lock();
    boolean shared = true;
    try
    {
      Schema currentSchema = serverContext.getSchemaNG();
      if (force || schemaNG != currentSchema)
      if (schemaNG != currentSchema)
      {
        sharedLock.unlock();
        exclusiveLock.lock();
        shared = false;
        currentSchema = serverContext.getSchemaNG();
        if (force || schemaNG != currentSchema)
        if (schemaNG != currentSchema)
        {
          // build new maps from existing ones
          Mappings newMappings = new Mappings(mappings.adEncodeMap.size(), mappings.ocEncodeMap.size());
@@ -200,15 +198,15 @@
      throws DirectoryException
  {
    // First decode the encoded attribute description id.
    final int id = decodeId(reader);
    final int adId = decodeId(reader);
    // Before returning the attribute, make sure that the attribute type is not stale.
    final Mappings mappings = reloadMappingsIfSchemaChanged(false);
    final AttributeDescription ad = mappings.adDecodeMap.get(id);
    final Mappings mappings = reloadMappingsIfSchemaChanged();
    final AttributeDescription ad = mappings.adDecodeMap.get(adId);
    if (ad == null)
    {
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
          ERR_COMPRESSEDSCHEMA_UNRECOGNIZED_AD_TOKEN.get(id));
          ERR_COMPRESSEDSCHEMA_UNRECOGNIZED_AD_TOKEN.get(adId));
    }
    AttributeType attrType = ad.getAttributeType();
@@ -253,45 +251,19 @@
      final ByteSequenceReader reader) throws DirectoryException
  {
    // First decode the encoded object class id.
    final int id = decodeId(reader);
    final int ocId = decodeId(reader);
    // Look up the object classes.
    final Mappings mappings = getMappings();
    Map<ObjectClass, String> ocMap = mappings.ocDecodeMap.get(id);
    // Before returning the object classes, make sure that none of them are stale.
    final Mappings mappings = reloadMappingsIfSchemaChanged();
    Map<ObjectClass, String> ocMap = mappings.ocDecodeMap.get(ocId);
    if (ocMap == null)
    {
      // @RemoveOnceSDKSchemaIsUsed remove this first check (check is performed again later)
      throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
          ERR_COMPRESSEDSCHEMA_UNKNOWN_OC_TOKEN.get(id));
    }
    // Before returning the object classes, make sure that none of them are stale.
    boolean forceReload = isAnyObjectClassDirty(ocMap.keySet());
    final Mappings newMappings = reloadMappingsIfSchemaChanged(forceReload);
    if (mappings != newMappings)
    {
      ocMap = newMappings.ocDecodeMap.get(id);
      if (ocMap == null)
      {
        throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
            ERR_COMPRESSEDSCHEMA_UNKNOWN_OC_TOKEN.get(id));
      }
          ERR_COMPRESSEDSCHEMA_UNKNOWN_OC_TOKEN.get(ocId));
    }
    return ocMap;
  }
  @RemoveOnceSDKSchemaIsUsed
  private boolean isAnyObjectClassDirty(Set<ObjectClass> objectClasses)
  {
    for (final ObjectClass oc : objectClasses)
    {
      if (oc.isDirty())
      {
        return true;
      }
    }
    return false;
  }
  /**
   * Encodes the information in the provided attribute to a byte array.
   *