org.springframework.jdbc.datasource.init.DatabasePopulator Java Examples

The following examples show how to use org.springframework.jdbc.datasource.init.DatabasePopulator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Application.java    From Intro-to-Spring-Hadoop with Apache License 2.0 6 votes vote down vote up
@Bean
DataSourceInitializer hiveInitializer(final DataSource dataSource) {
	final String ddl = "create external table if not exists tweetdata (value STRING) LOCATION '" + input + "'";
	final DataSourceInitializer dsi = new DataSourceInitializer();
    dsi.setDataSource(dataSource);
	dsi.setDatabasePopulator(new DatabasePopulator() {
		@Override
		public void populate(Connection conn) throws SQLException,
				ScriptException {
			Statement st = conn.createStatement();
			st.execute(ddl);
			st.close();
		}
	});
	return dsi;
}
 
Example #2
Source File: TempConfigToInitDB.java    From batchers with Apache License 2.0 5 votes vote down vote up
private DatabasePopulator dataSourcePopulator() {
    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.setScripts(
            new ClassPathResource(dropScript),
            new ClassPathResource(schemaScript)
    );
    return databasePopulator;
}
 
Example #3
Source File: AbstractContainerJdbcIndexedSessionRepositoryITests.java    From spring-session with Apache License 2.0 5 votes vote down vote up
@Bean
DataSourceInitializer dataSourceInitializer(DataSource dataSource, DatabasePopulator databasePopulator) {
	DataSourceInitializer initializer = new DataSourceInitializer();
	initializer.setDataSource(dataSource);
	initializer.setDatabasePopulator(databasePopulator);
	return initializer;
}
 
Example #4
Source File: MemberDataSourceConfig.java    From EasyReport with Apache License 2.0 5 votes vote down vote up
@Primary
@Bean(name = "memberDataSource")
public DataSource dataSource() {
    DruidDataSource dsh = firstDataSourceProperties().initializeDataSourceBuilder().type
        (DruidDataSource.class).build();
    dsh.setValidationQuery("select 1");
    Resource initSchema = new ClassPathResource("schema.sql");
    Resource initData = new ClassPathResource("data.sql");
    DatabasePopulator databasePopulator = new ResourceDatabasePopulator(initSchema, initData);
    DatabasePopulatorUtils.execute(databasePopulator, dsh);
    return dsh;
}
 
Example #5
Source File: SqoopToolJobApplicationTests.java    From spring-cloud-task-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
DatabasePopulator databasePopulator(DataSource dataSource) throws SQLException, InterruptedException {
	DatabasePopulator dbp = new ResourceDatabasePopulator(false, false, "UTF-8",
			new ClassPathResource("sqoop-schema-ddl.sql"),
			new ClassPathResource("sqoop-root-data.sql"),
			new ClassPathResource("sqoop-sessions-data.sql"),
			new ClassPathResource("sqoop-test-schema-ddl.sql"),
			new ClassPathResource("sqoop-test-data.sql"));
	dbp.populate(DataSourceUtils.getConnection(dataSource));
	return dbp;
}
 
Example #6
Source File: SqoopToolTaskApplicationTests.java    From spring-cloud-task-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
DatabasePopulator databasePopulator(DataSource dataSource) throws SQLException, InterruptedException {
	DatabasePopulator dbp = new ResourceDatabasePopulator(false, false, "UTF-8",
			new ClassPathResource("sqoop-test-schema-ddl.sql"),
			new ClassPathResource("sqoop-test-data.sql"));
	dbp.populate(DataSourceUtils.getConnection(dataSource));
	return dbp;
}
 
Example #7
Source File: JdbcHdfsTaskIntegrationTests.java    From spring-cloud-task-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean
DatabasePopulator databasePopulator(DataSource dataSource) throws SQLException, InterruptedException {
	DatabasePopulator dbp = new ResourceDatabasePopulator(false, false, "UTF-8",
			new ClassPathResource("jdbchdfs-schema.sql"),
			new ClassPathResource("jdbchdfs-data.sql"));
	dbp.populate(DataSourceUtils.getConnection(dataSource));
	return dbp;
}
 
Example #8
Source File: TeiidTestDataSources.java    From monolith with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource ordersDS() {
    DataSource dataSource = DataSourceBuilder.create().driverClassName("org.h2.Driver").username("sa").password("").url("jdbc:h2:mem:ordersdb;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=FALSE;MODE=MYSQL").build();

    Resource initSchema = new ClassPathResource("h2/scripts/ordersdb-schema.sql");
    Resource initData = new ClassPathResource("h2/scripts/ordersdb-data.sql");
    DatabasePopulator databasePopulator = new ResourceDatabasePopulator(initSchema, initData);
    DatabasePopulatorUtils.execute(databasePopulator, dataSource);
    return dataSource;
}
 
Example #9
Source File: TeiidTestDataSources.java    From monolith with Apache License 2.0 5 votes vote down vote up
@Bean
public DataSource legacyDS() {

    DataSource dataSource = DataSourceBuilder.create().driverClassName("org.h2.Driver").username("sa").password("").url("jdbc:h2:mem:legacydb;DB_CLOSE_ON_EXIT=FALSE;DATABASE_TO_UPPER=FALSE;MODE=MYSQL").build();

    Resource initSchema = new ClassPathResource("h2/scripts/legacydb-schema.sql");
    Resource initData = new ClassPathResource("h2/scripts/legacydb-data.sql");
    DatabasePopulator databasePopulator = new ResourceDatabasePopulator(initSchema, initData);
    DatabasePopulatorUtils.execute(databasePopulator, dataSource);
    return dataSource;
}
 
Example #10
Source File: EmployeeJobTestConfig.java    From batchers with Apache License 2.0 5 votes vote down vote up
private DatabasePopulator dataSourcePopulator() {
    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.setScripts(
            new ClassPathResource("org/springframework/batch/core/schema-drop-hsqldb.sql"),
            new ClassPathResource("org/springframework/batch/core/schema-hsqldb.sql")
    );
    return databasePopulator;
}
 
Example #11
Source File: Application.java    From Vaadin4Spring-MVP-Sample-SpringSecurity with Apache License 2.0 5 votes vote down vote up
private DatabasePopulator databasePopulator() {
	ResourceDatabasePopulator populator = new ResourceDatabasePopulator();		
	populator.addScript(new ClassPathResource("Account.sql", JdbcAccountRepository.class));
	populator.addScript(new ClassPathResource("data.sql", JdbcAccountRepository.class));
	populator.addScript(new ClassPathResource("rememberme.sql", JdbcAccountRepository.class));
	return populator;
}
 
Example #12
Source File: AppConfig.java    From Building-Web-Apps-with-Spring-5-and-Angular with MIT License 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example #13
Source File: DatabaseInititializer.java    From flowable-engine with Apache License 2.0 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example #14
Source File: OAuth2AuthorizationServerConfig.java    From spring-security-oauth with MIT License 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example #15
Source File: OAuth2AuthorizationServerConfigInMemory.java    From spring-security-oauth with MIT License 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    return populator;
}
 
Example #16
Source File: OAuth2AuthorizationServerConfig.java    From spring-boot with Apache License 2.0 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    return populator;
}
 
Example #17
Source File: SchedulerDBInit.java    From syncope with Apache License 2.0 4 votes vote down vote up
public void setDatabasePopulator(final DatabasePopulator databasePopulator) {
    this.databasePopulator = databasePopulator;
}
 
Example #18
Source File: TestDataConfig.java    From Spring with Apache License 2.0 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example #19
Source File: TestDataConfig.java    From Spring with Apache License 2.0 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example #20
Source File: TestDataConfig.java    From Spring with Apache License 2.0 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
	final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
	populator.addScript(schemaScript);
	populator.addScript(dataScript);
	return populator;
}
 
Example #21
Source File: TestDataConfig.java    From Spring with Apache License 2.0 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example #22
Source File: OAuth2AuthorizationServerConfig.java    From oauth2lab with MIT License 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example #23
Source File: DatabaseInititializer.java    From activiti6-boot2 with Apache License 2.0 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
  ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
  populator.addScript(schemaScript);
  populator.addScript(dataScript);
  return populator;
}
 
Example #24
Source File: AppConfig.java    From Building-Web-Apps-with-Spring-5-and-Angular with MIT License 4 votes vote down vote up
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example #25
Source File: EmbeddedDatabaseFactory.java    From effectivejava with Apache License 2.0 2 votes vote down vote up
/**
 * Set the strategy that will be used to initialize or populate the embedded
 * database.
 * <p>Defaults to {@code null}.
 */
public void setDatabasePopulator(DatabasePopulator populator) {
	this.databasePopulator = populator;
}
 
Example #26
Source File: EmbeddedDatabaseFactoryBean.java    From effectivejava with Apache License 2.0 2 votes vote down vote up
/**
 * Set a script execution to be run in the bean destruction callback,
 * cleaning up the database and leaving it in a known state for others.
 * @param databaseCleaner the database script executor to run on destroy
 * @see #setDatabasePopulator
 * @see org.springframework.jdbc.datasource.init.DataSourceInitializer#setDatabaseCleaner
 */
public void setDatabaseCleaner(DatabasePopulator databaseCleaner) {
	this.databaseCleaner = databaseCleaner;
}
 
Example #27
Source File: EmbeddedDatabaseFactoryBean.java    From spring-analysis-note with MIT License 2 votes vote down vote up
/**
 * Set a script execution to be run in the bean destruction callback,
 * cleaning up the database and leaving it in a known state for others.
 * @param databaseCleaner the database script executor to run on destroy
 * @see #setDatabasePopulator
 * @see org.springframework.jdbc.datasource.init.DataSourceInitializer#setDatabaseCleaner
 */
public void setDatabaseCleaner(DatabasePopulator databaseCleaner) {
	this.databaseCleaner = databaseCleaner;
}
 
Example #28
Source File: EmbeddedDatabaseFactory.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Set the strategy that will be used to initialize or populate the embedded
 * database.
 * <p>Defaults to {@code null}.
 */
public void setDatabasePopulator(DatabasePopulator populator) {
	this.databasePopulator = populator;
}
 
Example #29
Source File: EmbeddedDatabaseFactoryBean.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Set a script execution to be run in the bean destruction callback,
 * cleaning up the database and leaving it in a known state for others.
 * @param databaseCleaner the database script executor to run on destroy
 * @see #setDatabasePopulator
 * @see org.springframework.jdbc.datasource.init.DataSourceInitializer#setDatabaseCleaner
 */
public void setDatabaseCleaner(DatabasePopulator databaseCleaner) {
	this.databaseCleaner = databaseCleaner;
}
 
Example #30
Source File: EmbeddedDatabaseFactory.java    From lams with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Set the strategy that will be used to initialize or populate the embedded
 * database.
 * <p>Defaults to {@code null}.
 */
public void setDatabasePopulator(DatabasePopulator populator) {
	this.databasePopulator = populator;
}