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

The following examples show how to use org.springframework.jdbc.datasource.init.DatabasePopulator. These examples are extracted from open source projects. 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 Project: Intro-to-Spring-Hadoop   Source File: Application.java    License: 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 Project: monolith   Source File: TeiidTestDataSources.java    License: 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 3
Source Project: monolith   Source File: TeiidTestDataSources.java    License: 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 4
@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 5
@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 6
@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 7
@Bean
DataSourceInitializer dataSourceInitializer(DataSource dataSource, DatabasePopulator databasePopulator) {
	DataSourceInitializer initializer = new DataSourceInitializer();
	initializer.setDataSource(dataSource);
	initializer.setDatabasePopulator(databasePopulator);
	return initializer;
}
 
Example 8
Source Project: EasyReport   Source File: MemberDataSourceConfig.java    License: 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 9
Source Project: batchers   Source File: TempConfigToInitDB.java    License: 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 10
Source Project: batchers   Source File: EmployeeJobTestConfig.java    License: 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
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 Project: Spring   Source File: TestDataConfig.java    License: 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 13
Source Project: Spring   Source File: TestDataConfig.java    License: 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 14
Source Project: Spring   Source File: TestDataConfig.java    License: 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 15
Source Project: Spring   Source File: TestDataConfig.java    License: 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 16
Source Project: oauth2lab   Source File: OAuth2AuthorizationServerConfig.java    License: 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 17
Source Project: activiti6-boot2   Source File: DatabaseInititializer.java    License: 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 18
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example 19
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example 20
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    return populator;
}
 
Example 21
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    return populator;
}
 
Example 22
private DatabasePopulator databasePopulator() {
    final ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(schemaScript);
    populator.addScript(dataScript);
    return populator;
}
 
Example 23
Source Project: flowable-engine   Source File: DatabaseInititializer.java    License: 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 Project: syncope   Source File: SchedulerDBInit.java    License: Apache License 2.0 4 votes vote down vote up
public void setDatabasePopulator(final DatabasePopulator databasePopulator) {
    this.databasePopulator = databasePopulator;
}
 
Example 25
Source Project: spring-analysis-note   Source File: EmbeddedDatabaseFactoryBean.java    License: 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 26
Source Project: spring-analysis-note   Source File: EmbeddedDatabaseFactory.java    License: MIT License 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 27
/**
 * 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 Project: java-technology-stack   Source File: EmbeddedDatabaseFactory.java    License: MIT License 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
/**
 * 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 Project: lams   Source File: EmbeddedDatabaseFactory.java    License: 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;
}