@Transactional
  public boolean reconcileCategory(String categoryName, Map<String, String> properties, boolean removeIfNotProvided) {
    boolean changesDetected = false;
    List<AmbariConfigurationEntity> existingEntities = findByCategory(categoryName);
    Map<String, String> propertiesToProcess = new HashMap<>();

    if (properties != null) {
      propertiesToProcess.putAll(properties);
    }

    if (existingEntities != null) {
      for (AmbariConfigurationEntity entity : existingEntities) {
        String propertyName = entity.getPropertyName();

        if (propertiesToProcess.containsKey(propertyName)) {
          String newPropertyValue = propertiesToProcess.get(propertyName);
          if (!StringUtils.equals(newPropertyValue, entity.getPropertyValue())) {
            // Update the entry...
            entity.setPropertyValue(newPropertyValue);
            merge(entity);
            changesDetected = true;
          }
        } else if (removeIfNotProvided) {
          // Remove the entry since it is not in the new set of properties...
          remove(entity);
          changesDetected = true;
        }

        // If already processed, remove it so we know no to add it later...
        propertiesToProcess.remove(propertyName);
      }
    }

    // Add the new entries...
    if (!propertiesToProcess.isEmpty()) {
      for (Map.Entry<String, String> property : propertiesToProcess.entrySet()) {
        AmbariConfigurationEntity entity = new AmbariConfigurationEntity();
        entity.setCategoryName(categoryName);
        entity.setPropertyName(property.getKey());
        entity.setPropertyValue(property.getValue());
        create(entity);
      }

      changesDetected = true;
    }

    if (changesDetected) {
      entityManagerProvider.get().flush();
    }

    return changesDetected;
  }
Reconciles the properties associted with an Ambari confgiration category (for example, ldap-configuration)
using persisted properties and the supplied properties.
<p>
if <code>removeIfNotProvided</code> is <code>true</code>, only properties that exist in the new set of
properties will be persisted; others will be removed.
<p>
If <code>removeIfNotProvided</code> is <code>false</code>, then the new properties will be used
to update or append to the set of persisted properties.

@param categoryName        the category name for the set of properties
@param properties          a map of name to value pairs
@param removeIfNotProvided <code>true</code> to explicitly set the set of properties for the category; <code>false</code> to upadate the set of properties for the category
@return <code>true</code> if changes were made; <code>false</code> if not changes were made.
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/AmbariConfigurationDAO.java