@SuppressWarnings("unchecked")
  @Override
  public void updateSettings(SettingsCommand command) {
    // group all updates by provider+instance, to reduce the number of CA updates
    // when multiple settings are changed
    if (command.getProviderKey() == null) {
      Map<String, SettingsCommand> groups = new LinkedHashMap<String, SettingsCommand>(8);
      Map<String, SettingsCommand> indexedGroups = null;
      for (SettingValueBean bean : command.getValues()) {
        String groupKey =
            bean.getProviderKey() + (bean.getInstanceKey() == null ? "" : bean.getInstanceKey());
        final boolean indexed = INDEXED_PROP_PATTERN.matcher(bean.getKey()).find();
        SettingsCommand cmd = null;
        if (indexed) {
          // indexed property, add in indexed groups
          if (indexedGroups == null) {
            indexedGroups = new LinkedHashMap<String, SettingsCommand>(8);
          }
          cmd = indexedGroups.get(groupKey);
        } else {
          cmd = groups.get(groupKey);
        }

        if (cmd == null) {
          cmd = new SettingsCommand();
          cmd.setProviderKey(bean.getProviderKey());
          cmd.setInstanceKey(bean.getInstanceKey());
          if (indexed) {
            indexedGroups.put(groupKey, cmd);
          } else {
            groups.put(groupKey, cmd);
          }
        }
        cmd.getValues().add(bean);
      }
      for (SettingsCommand cmd : groups.values()) {
        updateSettings(cmd);
      }
      if (indexedGroups != null) {
        for (SettingsCommand cmd : indexedGroups.values()) {
          updateSettings(cmd);
        }
      }
      return;
    }

    try {
      Configuration conf = getConfiguration(command.getProviderKey(), command.getInstanceKey());
      Dictionary<String, Object> props = conf.getProperties();
      if (props == null) {
        props = new Hashtable<String, Object>();
      }
      for (SettingValueBean bean : command.getValues()) {
        String settingKey = command.getProviderKey();
        String instanceKey = command.getInstanceKey();
        if (instanceKey != null) {
          settingKey = getFactoryInstanceSettingKey(settingKey, instanceKey);
        }
        if (bean.isRemove()) {
          props.remove(bean.getKey());
        } else {
          props.put(bean.getKey(), bean.getValue());
        }

        if (!bean.isTransient()) {
          if (bean.isRemove()) {
            settingDao.deleteSetting(settingKey, bean.getKey());
          } else {
            settingDao.storeSetting(settingKey, bean.getKey(), bean.getValue());
          }
        }
      }
      if (conf != null && props != null) {
        if (command.getInstanceKey() != null) {
          props.put(OSGI_PROPERTY_KEY_FACTORY_INSTANCE_KEY, command.getInstanceKey());
        }
        conf.update(props);
      }

    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (InvalidSyntaxException e) {
      throw new RuntimeException(e);
    }
  }