com.flipkart.polyguice.config.YamlConfiguration.subset()方法的使用及代码示例

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

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

YamlConfiguration.subset介绍

暂无

代码示例

代码示例来源: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 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类方法