Package org.springframework.jdbc.datasource.init

Examples of org.springframework.jdbc.datasource.init.DataSourceInitializer


  private String initDB;

  @Bean
  public DataSourceInitializer dataSourceInitializer()
  {
    DataSourceInitializer dsInitializer = new DataSourceInitializer();
    dsInitializer.setDataSource(dataSource);
    String scripts = env.getProperty("scripts", "");
    logger.debug("Init-db :"+initDB+", scripts: "+scripts);
    if(Boolean.parseBoolean(initDB) && StringUtils.hasLength(scripts))
    {
      ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
      String[] files = scripts.split(",");
      for (String file : files) {
        databasePopulator.addScript(new ClassPathResource(file));
      }
      dsInitializer.setDatabasePopulator(databasePopulator);
    }
   
    return dsInitializer;
  }
View Full Code Here


  @Autowired
  protected DataSource dataSource;

  @Bean
  public DataSourceInitializer dataSourceInitializer() {
    DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDataSource(dataSource);
    initializer.setDatabasePopulator(databasePopulator());
    return initializer;
  }
View Full Code Here

    }
   
    @Bean
    public DataSourceInitializer dataSourceInitializer(DataSource dataSource)
    {
        DataSourceInitializer dataSourceInitializer = new DataSourceInitializer();
        String dbInitializationEnabled = env.resolvePlaceholders("${jdbc.init-db}");
        dataSourceInitializer.setEnabled(Boolean.parseBoolean(dbInitializationEnabled));
        dataSourceInitializer.setDataSource(dataSource);
        ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
        String dbInitScriptLocation = env.resolvePlaceholders("${jdbc.initLocation}");
        if(StringUtils.isNotEmpty(dbInitScriptLocation))
        {
            databasePopulator.setScripts(new Resource[]{
                    new ClassPathResource(dbInitScriptLocation)
            });
        }
        dataSourceInitializer.setDatabasePopulator(databasePopulator);
        return dataSourceInitializer;
    }
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.datasource.init.DataSourceInitializer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.