protected void populateConfiguration(Date date, Configurable configurable) {
    if (_configured.contains(configurable)) return;

    s_logger.debug("Retrieving keys from " + configurable.getClass().getSimpleName());

    for (ConfigKey<?> key : configurable.getConfigKeys()) {
      Pair<String, ConfigKey<?>> previous = _allKeys.get(key.key());
      if (previous != null && !previous.first().equals(configurable.getConfigComponentName())) {
        throw new CloudRuntimeException(
            "Configurable "
                + configurable.getConfigComponentName()
                + " is adding a key that has been added before by "
                + previous.first()
                + ": "
                + key.toString());
      }
      _allKeys.put(
          key.key(), new Pair<String, ConfigKey<?>>(configurable.getConfigComponentName(), key));

      createOrupdateConfigObject(date, configurable.getConfigComponentName(), key, null);

      if ((key.scope() != null) && (key.scope() != ConfigKey.Scope.Global)) {
        Set<ConfigKey<?>> currentConfigs = _scopeLevelConfigsMap.get(key.scope());
        currentConfigs.add(key);
      }
    }

    _configured.add(configurable);
  }
 private void createOrupdateConfigObject(
     Date date, String componentName, ConfigKey<?> key, String value) {
   ConfigurationVO vo = _configDao.findById(key.key());
   if (vo == null) {
     vo = new ConfigurationVO(componentName, key);
     vo.setUpdated(date);
     if (value != null) {
       vo.setValue(value);
     }
     _configDao.persist(vo);
   } else {
     if (vo.isDynamic() != key.isDynamic()
         || !ObjectUtils.equals(vo.getDescription(), key.description())
         || !ObjectUtils.equals(vo.getDefaultValue(), key.defaultValue())
         || !ObjectUtils.equals(vo.getScope(), key.scope().toString())
         || !ObjectUtils.equals(vo.getComponent(), componentName)) {
       vo.setDynamic(key.isDynamic());
       vo.setDescription(key.description());
       vo.setDefaultValue(key.defaultValue());
       vo.setScope(key.scope().toString());
       vo.setComponent(componentName);
       vo.setUpdated(date);
       _configDao.persist(vo);
     }
   }
 }
 @Override
 public <T> void set(ConfigKey<T> key, T value) {
   _configDao.update(key.key(), value.toString());
 }
  public ScopedConfigStorage scoped(ConfigKey<?> config) {
    for (ScopedConfigStorage storage : _scopedStorages) {
      if (storage.getScope() == config.scope()) {
        return storage;
      }
    }

    throw new CloudRuntimeException(
        "Unable to find config storage for this scope: " + config.scope() + " for " + config.key());
  }