com.flipkart.polyguice.config.YamlConfiguration类的使用及代码示例

x33g5p2x  于2022-02-05 转载在 其他  
字(3.9k)|赞(0)|评价(0)|浏览(128)

本文整理了Java中com.flipkart.polyguice.config.YamlConfiguration类的一些代码示例,展示了YamlConfiguration类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。YamlConfiguration类的具体详情如下:
包路径:com.flipkart.polyguice.config.YamlConfiguration
类名称:YamlConfiguration

YamlConfiguration介绍

暂无

代码示例

代码示例来源:origin: flipkart-incubator/flux

/**
 * Binds individual flattened key-value properties in the configuration yml
 * file. So one can directly inject something like this:
 *
 * @Named("Hibernate.hibernate.jdbcDriver") String jdbcDriver OR
 * @Named("Dashboard.service.port") int port
 */
@SuppressWarnings({"rawtypes", "unchecked"})
private void bindConfigProperties() {
  bind(YamlConfiguration.class).toInstance(yamlConfiguration);
  Iterator<String> propertyKeys = yamlConfiguration.getKeys();
  while (propertyKeys.hasNext()) {
    String propertyKey = propertyKeys.next();
    Object propertyValue = yamlConfiguration.getProperty(propertyKey);
    LinkedBindingBuilder annotatedWith = bind(propertyValue.getClass()).annotatedWith(Names.named(propertyKey));
    annotatedWith.toInstance(propertyValue);
  }
}

代码示例来源:origin: flipkart-incubator/flux

/**
 * Creates hibernate configuration from the configuration yaml properties.
 * Since the yaml properties are already flattened in input param <code>yamlConfiguration</code>
 * the method loops over them to selectively pick Hibernate specific properties.
 */
@Provides
@Singleton
@Named("schedulerHibernateConfiguration")
public Configuration getConfiguration(YamlConfiguration yamlConfiguration) {
  Configuration configuration = new Configuration();
  addAnnotatedClassesAndTypes(configuration);
  org.apache.commons.configuration.Configuration hibernateConfig = yamlConfiguration.subset(FLUX_SCHEDULER_HIBERNATE_CONFIG_NAME_SPACE);
  Iterator<String> propertyKeys = hibernateConfig.getKeys();
  Properties configProperties = new Properties();
  while (propertyKeys.hasNext()) {
    String propertyKey = propertyKeys.next();
    Object propertyValue = hibernateConfig.getProperty(propertyKey);
    configProperties.put(propertyKey, propertyValue);
  }
  configuration.addProperties(configProperties);
  return configuration;
}

代码示例来源:origin: flipkart-incubator/flux

public ConfigModule(FluxRuntimeRole role) {
  try {
    URL configUrl = null;
    String fluxConfigFile = null;
    switch (role) {
      case ORCHESTRATION:
        fluxConfigFile = System.getProperty("flux.orchestration.configurationFile");
        if (fluxConfigFile != null) {
          configUrl = new File(fluxConfigFile).toURI().toURL();
        } else {
          configUrl = this.getClass().getClassLoader().getResource(ORCHESTRATION_NODE_CONFIGURATION_YML);
        }
        break;
      case EXECUTION:
        configUrl = loadExecutinNodeConfiguration(fluxConfigFile);
        break;
      default:
        configUrl = loadExecutinNodeConfiguration(fluxConfigFile);
        break;
    }
    configProvider = new ApacheCommonsConfigProvider().location(configUrl);
    yamlConfiguration = new YamlConfiguration(configUrl);
  } catch (IOException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: flipkart-incubator/flux

public void migrate(String dbName) {
    try {
      Configuration configuration = yamlConfiguration.subset(dbName + ".Hibernate");
      Properties properties = new Properties();
      properties.put("user", configuration.getProperty("hibernate.connection.username"));
      properties.put("password", configuration.getProperty("hibernate.connection.password"));
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      String url = (String) configuration.getProperty("hibernate.connection.url");
      java.sql.Connection connection = DriverManager.getConnection(url, properties);
      Database database = DatabaseFactory.getInstance().findCorrectDatabaseImplementation(new JdbcConnection(connection));
      ClassLoader classLoader = getClass().getClassLoader();
      File file = new File(classLoader.getResource(dbName +  "/migrations.xml").getFile());
      Liquibase liquibase = new Liquibase(file.getCanonicalPath(), new FileSystemResourceAccessor(), database);
      liquibase.update(new Contexts());
    } catch (Exception e) {
      System.err.println("Unable to perform database migration.");
      e.printStackTrace();
    }
  }
}

相关文章

YamlConfiguration类方法