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

Nicolas Capponi
27.14.2016 0149a25c5a0aea9d63e409cb7a9492eaaa09d956
OPENDJ-2987 Replace an attribute type in Schema in one step to prevent error when validating schema
2 files modified
74 ■■■■ changed files
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java 5 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java 69 ●●●● patch | view | raw | blame | history
opendj-server-legacy/src/main/java/org/opends/server/backends/SchemaBackend.java
@@ -1161,12 +1161,9 @@
    }
    else
    {
      schema.deregisterAttributeType(existingType);
      String schemaFile = replaceExistingSchemaElement(
          modifiedSchemaFiles, new SomeSchemaElement(attributeType), new SomeSchemaElement(existingType));
      schema.registerAttributeType(attributeType, schemaFile, false);
      schema.rebuildDependentElements(existingType);
      schema.replaceAttributeType(attributeType, existingType, schemaFile);
    }
  }
opendj-server-legacy/src/main/java/org/opends/server/types/Schema.java
@@ -478,19 +478,7 @@
    try
    {
      SchemaBuilder builder = new SchemaBuilder(schemaNG);
      AttributeType.Builder b = builder.buildAttributeType(attributeType);
      if (schemaFile != null)
      {
        b.removeExtraProperty(SCHEMA_PROPERTY_FILENAME).extraProperties(SCHEMA_PROPERTY_FILENAME, schemaFile);
      }
      if (overwriteExisting)
      {
        b.addToSchemaOverwrite();
      }
      else
      {
        b.addToSchema();
      }
      registerAttributeType0(builder, attributeType, schemaFile, overwriteExisting);
      switchSchema(builder.toSchema());
      updateSubordinateTypes(attributeType);
@@ -505,6 +493,61 @@
    }
  }
  private void registerAttributeType0(SchemaBuilder builder, final AttributeType attributeType,
      final String schemaFile, final boolean overwriteExisting)
  {
    AttributeType.Builder b = builder.buildAttributeType(attributeType);
    if (schemaFile != null)
    {
      b.removeExtraProperty(SCHEMA_PROPERTY_FILENAME).extraProperties(SCHEMA_PROPERTY_FILENAME, schemaFile);
    }
    if (overwriteExisting)
    {
      b.addToSchemaOverwrite();
    }
    else
    {
      b.addToSchema();
    }
  }
  /**
   * Replaces an existing attribute type by the provided new attribute type.
   *
   * @param newAttributeType
   *          Attribute type to register to the schema.
   * @param existingAttributeType
   *          Attribute type to remove from the schema.
   * @param schemaFile
   *          The schema file which the new object class belongs to.
   * @throws DirectoryException
   *            If an errors occurs.
   */
  public void replaceAttributeType(AttributeType newAttributeType, AttributeType existingAttributeType,
      String schemaFile) throws DirectoryException
  {
    exclusiveLock.lock();
    try
    {
      SchemaBuilder builder = new SchemaBuilder(schemaNG);
      builder.removeAttributeType(existingAttributeType.getNameOrOID());
      registerAttributeType0(builder, newAttributeType, schemaFile, false);
      switchSchema(builder.toSchema());
      AttributeType superiorType = existingAttributeType.getSuperiorType();
      if (superiorType != null)
      {
        deregisterSubordinateType(existingAttributeType, superiorType);
      }
      updateSubordinateTypes(newAttributeType);
    }
    finally
    {
      exclusiveLock.unlock();
    }
    rebuildDependentElements(existingAttributeType);
  }
  /**
   * Retrieves the OID of the provided object class definition.
   *