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

The following examples show how to use org.springframework.jdbc.datasource.init.DatabasePopulatorUtils. 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
private void runScripts(DataSource dataSource, List<Resource> resources, String username, String password) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(this.properties.isContinueOnError());
    populator.setSeparator(this.properties.getSeparator());
    if (this.properties.getSqlScriptEncoding() != null) {
        populator.setSqlScriptEncoding(this.properties.getSqlScriptEncoding().name());
    }
    for (Resource resource : resources) {
        populator.addScript(resource);
    }
    if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
        dataSource = DataSourceBuilder.create(this.properties.getClassLoader())
                .driverClassName(this.properties.determineDriverClassName())
                .url(this.properties.determineUrl())
                .username(username)
                .password(password)
                .build();
    }
    DatabasePopulatorUtils.execute(populator, dataSource);
}
 
Example 2
private void runScripts(List<Resource> resources, String username, String password) {
    if (resources.isEmpty()) {
        return;
    }
    boolean continueOnError = Boolean.parseBoolean(getProperty("continue-on-error"));
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(continueOnError);
    populator.setSeparator(getProperty("seperator"));

    if (getProperty("sql-script-encoding") != null) {
        populator.setSqlScriptEncoding(getProperty("sql-script-encoding"));
    }
    for (Resource resource : resources) {
        populator.addScript(resource);
    }
    DataSource dataSource = this.dataSource;
    if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
        String driver = getProperty("driver-class-name");
        String url = getProperty("url");
        dataSource = DataSourceBuilder.create(this.getClass().getClassLoader()).driverClassName(driver).url(url)
                .username(username).password(password).build();
    }
    DatabasePopulatorUtils.execute(populator, dataSource);
}
 
Example 3
Source Project: multitenant   Source File: ScriptServiceImpl.java    License: Apache License 2.0 6 votes vote down vote up
private void runScripts(List<Resource> resources, DataSource dataSource, Map<String, Object> vars) {
	if (resources.isEmpty()) {
		return;
	}
	DynamicResourceDatabasePopulator populator = new DynamicResourceDatabasePopulator();
	populator.setContinueOnError(this.properties.isContinueOnError());
	populator.setSeparator(this.properties.getSeparator());
	if (this.properties.getSqlScriptEncoding() != null) {
		populator.setSqlScriptEncoding(this.properties.getSqlScriptEncoding().name());
	}
	for (Resource resource : resources) {
		populator.addScript(resource);
	}
	populator.setVars(vars);
	DatabasePopulatorUtils.execute(populator, dataSource);
}
 
Example 4
public DataSource toDataSource() {
  DataSource dataSource;

  if (url == null || url.contains("hsqldb:mem")) {
    log.debug("Creating in memory HSQL database");
    // Start an in-process, in-memory HSQL server
    dataSource = new EmbeddedDatabaseBuilder().setType(HSQL).setName("c2mondb").build();
  } else {
    log.debug("Creating HSQL database at URL {}",url);
    dataSource = DataSourceBuilder.create().url(url).username(username).password(password).build();
  }

  if (!scripts.isEmpty()) {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator(scripts.toArray(new Resource[scripts.size()]));
    populator.setContinueOnError(true);
    DatabasePopulatorUtils.execute(populator, dataSource);
  }

  return dataSource;
}
 
Example 5
Source Project: herd   Source File: DaoEnvTestSpringModuleConfig.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Get a new herd data source based on an in-memory HSQLDB database. This data source is used for loading the configuration table as an environment property
 * source as well as for the JPA entity manager. It will therefore create/re-create the configuration table which is required for the former. It also
 * inserts required values for both scenarios.
 *
 * @return the test herd data source.
 */
@Bean
public static DataSource herdDataSource()
{
    // Create and return a data source that can connect directly to a JDBC URL.
    BasicDataSource basicDataSource = new BasicDataSource();
    basicDataSource.setDriverClassName(org.h2.Driver.class.getName());
    basicDataSource.setUsername("");
    basicDataSource.setPassword("");
    basicDataSource.setUrl("jdbc:h2:mem:herdTestDb");

    // Create and populate the configuration table.
    // This is needed for all data source method calls since it is used to create the environment property source which happens before
    // JPA and other non-static beans are initialized.
    ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
    resourceDatabasePopulator.addScript(new ClassPathResource("createConfigurationTableAndData.sql"));
    DatabasePopulatorUtils.execute(resourceDatabasePopulator, basicDataSource); // This is what the DataSourceInitializer does.

    return basicDataSource;
}
 
Example 6
Source Project: syncope   Source File: SchedulerDBInit.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void afterPropertiesSet() throws Exception {
    Assert.state(this.dataSource != null, "DataSource must be set");
    Assert.state(this.databasePopulator != null, "DatabasePopulator must be set");

    JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
    boolean existingData;
    try {
        existingData = jdbcTemplate.queryForObject("SELECT COUNT(0) FROM QRTZ_SCHEDULER_STATE", Integer.class) > 0;
    } catch (BadSqlGrammarException e) {
        LOG.debug("Could not access to table QRTZ_SCHEDULER_STATE", e);
        existingData = false;
    }

    if (existingData) {
        LOG.info("Quartz tables found in the database, leaving untouched");
    } else {
        LOG.info("No Quartz tables found, creating");

        DatabasePopulatorUtils.execute(databasePopulator, this.dataSource);
    }
}
 
Example 7
Source Project: effectivejava   Source File: EmbeddedDatabaseFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Hook to initialize the embedded database. Subclasses may call this method
 * to force initialization.
 * <p>After calling this method, {@link #getDataSource()} returns the
 * {@link DataSource} providing connectivity to the database.
 */
protected void initDatabase() {
	// Create the embedded database source first
	if (logger.isInfoEnabled()) {
		logger.info("Creating embedded database '" + this.databaseName + "'");
	}
	if (this.databaseConfigurer == null) {
		this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(EmbeddedDatabaseType.HSQL);
	}
	this.databaseConfigurer.configureConnectionProperties(
			this.dataSourceFactory.getConnectionProperties(), this.databaseName);
	this.dataSource = this.dataSourceFactory.getDataSource();

	// Now populate the database
	if (this.databasePopulator != null) {
		try {
			DatabasePopulatorUtils.execute(this.databasePopulator, this.dataSource);
		}
		catch (RuntimeException ex) {
			// failed to populate, so leave it as not initialized
			shutdownDatabase();
			throw ex;
		}
	}
}
 
Example 8
Source Project: double-entry-bookkeeping-api   Source File: BankFactoryImpl.java    License: MIT License 6 votes vote down vote up
@Override
public void configureDataSource(ConnectionOptions options) {
  try {
    DriverManagerDataSource dataSource = BankContextUtil.getBean("dataSource");
    dataSource.setDriverClassName(options.driverClassName());
    dataSource.setUrl(options.url());
    dataSource.setUsername(options.username());
    dataSource.setPassword(options.password());

    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.setContinueOnError(true);
    databasePopulator.addScript(new ClassPathResource("db/" + options.schema()));

    DatabasePopulatorUtils.execute(databasePopulator, dataSource);
  } catch (Exception e) {
    throw new InfrastructureException(e);
  }
}
 
Example 9
Source Project: spring-analysis-note   Source File: EmbeddedDatabaseFactoryBean.java    License: MIT License 5 votes vote down vote up
@Override
public void destroy() {
	if (this.databaseCleaner != null && getDataSource() != null) {
		DatabasePopulatorUtils.execute(this.databaseCleaner, getDataSource());
	}
	shutdownDatabase();
}
 
Example 10
Source Project: spring-analysis-note   Source File: EmbeddedDatabaseFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Hook to initialize the embedded database.
 * <p>If the {@code generateUniqueDatabaseName} flag has been set to {@code true},
 * the current value of the {@linkplain #setDatabaseName database name} will
 * be overridden with an auto-generated name.
 * <p>Subclasses may call this method to force initialization; however,
 * this method should only be invoked once.
 * <p>After calling this method, {@link #getDataSource()} returns the
 * {@link DataSource} providing connectivity to the database.
 */
protected void initDatabase() {
	if (this.generateUniqueDatabaseName) {
		setDatabaseName(UUID.randomUUID().toString());
	}

	// Create the embedded database first
	if (this.databaseConfigurer == null) {
		this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(EmbeddedDatabaseType.HSQL);
	}
	this.databaseConfigurer.configureConnectionProperties(
			this.dataSourceFactory.getConnectionProperties(), this.databaseName);
	this.dataSource = this.dataSourceFactory.getDataSource();

	if (logger.isInfoEnabled()) {
		if (this.dataSource instanceof SimpleDriverDataSource) {
			SimpleDriverDataSource simpleDriverDataSource = (SimpleDriverDataSource) this.dataSource;
			logger.info(String.format("Starting embedded database: url='%s', username='%s'",
					simpleDriverDataSource.getUrl(), simpleDriverDataSource.getUsername()));
		}
		else {
			logger.info(String.format("Starting embedded database '%s'", this.databaseName));
		}
	}

	// Now populate the database
	if (this.databasePopulator != null) {
		try {
			DatabasePopulatorUtils.execute(this.databasePopulator, this.dataSource);
		}
		catch (RuntimeException ex) {
			// failed to populate, so leave it as not initialized
			shutdownDatabase();
			throw ex;
		}
	}
}
 
Example 11
@Override
public void destroy() {
	if (this.databaseCleaner != null && getDataSource() != null) {
		DatabasePopulatorUtils.execute(this.databaseCleaner, getDataSource());
	}
	shutdownDatabase();
}
 
Example 12
Source Project: java-technology-stack   Source File: EmbeddedDatabaseFactory.java    License: MIT License 5 votes vote down vote up
/**
 * Hook to initialize the embedded database.
 * <p>If the {@code generateUniqueDatabaseName} flag has been set to {@code true},
 * the current value of the {@linkplain #setDatabaseName database name} will
 * be overridden with an auto-generated name.
 * <p>Subclasses may call this method to force initialization; however,
 * this method should only be invoked once.
 * <p>After calling this method, {@link #getDataSource()} returns the
 * {@link DataSource} providing connectivity to the database.
 */
protected void initDatabase() {
	if (this.generateUniqueDatabaseName) {
		setDatabaseName(UUID.randomUUID().toString());
	}

	// Create the embedded database first
	if (this.databaseConfigurer == null) {
		this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(EmbeddedDatabaseType.HSQL);
	}
	this.databaseConfigurer.configureConnectionProperties(
			this.dataSourceFactory.getConnectionProperties(), this.databaseName);
	this.dataSource = this.dataSourceFactory.getDataSource();

	if (logger.isInfoEnabled()) {
		if (this.dataSource instanceof SimpleDriverDataSource) {
			SimpleDriverDataSource simpleDriverDataSource = (SimpleDriverDataSource) this.dataSource;
			logger.info(String.format("Starting embedded database: url='%s', username='%s'",
					simpleDriverDataSource.getUrl(), simpleDriverDataSource.getUsername()));
		}
		else {
			logger.info(String.format("Starting embedded database '%s'", this.databaseName));
		}
	}

	// Now populate the database
	if (this.databasePopulator != null) {
		try {
			DatabasePopulatorUtils.execute(this.databasePopulator, this.dataSource);
		}
		catch (RuntimeException ex) {
			// failed to populate, so leave it as not initialized
			shutdownDatabase();
			throw ex;
		}
	}
}
 
Example 13
@Before
public void loadDataFixtures() {
	if (loadDataFixtures) {
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator(context.getResource("classpath:/test-data.sql"));
		DatabasePopulatorUtils.execute(populator, ds);
		loadDataFixtures = false;
	}
}
 
Example 14
@Before
public void loadDataFixtures() {
	if (loadDataFixtures) {
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator(context.getResource("classpath:/test-data.sql"));
		DatabasePopulatorUtils.execute(populator, ds);
		loadDataFixtures = false;
	}
}
 
Example 15
@Before
public void loadDataFixtures() {
	if (loadDataFixtures) {
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator(context.getResource("classpath:/test-data.sql"));
		DatabasePopulatorUtils.execute(populator, ds);
		loadDataFixtures = false;
	}
}
 
Example 16
@Before
public void loadDataFixtures() {
	if (loadDataFixtures) {
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator(context.getResource("classpath:/test-data.sql"));
		DatabasePopulatorUtils.execute(populator, ds);
		loadDataFixtures = false;
	}
}
 
Example 17
@Before
public void loadDataFixtures() {
	if (loadDataFixtures) {
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator(context.getResource("classpath:/test-data.sql"));
		DatabasePopulatorUtils.execute(populator, ds);
		loadDataFixtures = false;
	}
}
 
Example 18
@Override
public void destroy() {
	if (this.databaseCleaner != null) {
		DatabasePopulatorUtils.execute(this.databaseCleaner, getDataSource());
	}
	shutdownDatabase();
}
 
Example 19
Source Project: lams   Source File: EmbeddedDatabaseFactory.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * Hook to initialize the embedded database.
 * <p>If the {@code generateUniqueDatabaseName} flag has been set to {@code true},
 * the current value of the {@linkplain #setDatabaseName database name} will
 * be overridden with an auto-generated name.
 * <p>Subclasses may call this method to force initialization; however,
 * this method should only be invoked once.
 * <p>After calling this method, {@link #getDataSource()} returns the
 * {@link DataSource} providing connectivity to the database.
 */
protected void initDatabase() {
	if (this.generateUniqueDatabaseName) {
		setDatabaseName(UUID.randomUUID().toString());
	}

	// Create the embedded database first
	if (this.databaseConfigurer == null) {
		this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(EmbeddedDatabaseType.HSQL);
	}
	this.databaseConfigurer.configureConnectionProperties(
			this.dataSourceFactory.getConnectionProperties(), this.databaseName);
	this.dataSource = this.dataSourceFactory.getDataSource();

	if (logger.isInfoEnabled()) {
		if (this.dataSource instanceof SimpleDriverDataSource) {
			SimpleDriverDataSource simpleDriverDataSource = (SimpleDriverDataSource) this.dataSource;
			logger.info(String.format("Starting embedded database: url='%s', username='%s'",
				simpleDriverDataSource.getUrl(), simpleDriverDataSource.getUsername()));
		}
		else {
			logger.info(String.format("Starting embedded database '%s'", this.databaseName));
		}
	}

	// Now populate the database
	if (this.databasePopulator != null) {
		try {
			DatabasePopulatorUtils.execute(this.databasePopulator, this.dataSource);
		}
		catch (RuntimeException ex) {
			// failed to populate, so leave it as not initialized
			shutdownDatabase();
			throw ex;
		}
	}
}
 
Example 20
@Override
public void afterPropertiesSet() throws Exception {
	if (dataSource != null && definitionInitializationEnable) {
		String platform = getDatabaseType(dataSource);
		if ("hsql".equals(platform)) {
			platform = "hsqldb";
		}
		if ("postgres".equals(platform)) {
			platform = "postgresql";
		}
		if ("oracle".equals(platform)) {
			platform = "oracle10g";
		}
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
		String schemaLocation = schema;
		schemaLocation = schemaLocation.replace("@@[email protected]@", platform);
		String commonSchemaLocation = schemaLocation;
		commonSchemaLocation = commonSchemaLocation.replace("@@[email protected]@", COMMON_SCHEMA_SUFFIX);
		logger.info(String.format("Adding dataflow schema %s for %s database", commonSchemaLocation,
				platform));
		populator.addScript(resourceLoader.getResource(commonSchemaLocation));

		String applicationssSchemaLocation = schemaLocation;
		applicationssSchemaLocation = applicationssSchemaLocation.replace("@@[email protected]@", APPLICATIONS_SCHEMA_SUFFIX);
		logger.info(String.format("Adding dataflow schema %s for %s database", applicationssSchemaLocation,
				platform));
		populator.addScript(resourceLoader.getResource(applicationssSchemaLocation));

		String deploymentSchemaLocation = schemaLocation;
		deploymentSchemaLocation = deploymentSchemaLocation.replace("@@[email protected]@", DEPLOYMENT_SCHEMA_SUFFIX);
		logger.info(String.format("Adding dataflow schema %s for %s database", deploymentSchemaLocation,
				platform));
		populator.addScript(resourceLoader.getResource(deploymentSchemaLocation));

		populator.setContinueOnError(true);
		logger.debug(String.format("Initializing dataflow schema for %s database", platform));
		DatabasePopulatorUtils.execute(populator, dataSource);
	}
}
 
Example 21
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 22
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 23
@Override
public void destroy() {
	if (this.databaseCleaner != null) {
		DatabasePopulatorUtils.execute(this.databaseCleaner, getDataSource());
	}
	shutdownDatabase();
}
 
Example 24
/**
 * Hook to initialize the embedded database.
 * <p>If the {@code generateUniqueDatabaseName} flag has been set to {@code true},
 * the current value of the {@linkplain #setDatabaseName database name} will
 * be overridden with an auto-generated name.
 * <p>Subclasses may call this method to force initialization; however,
 * this method should only be invoked once.
 * <p>After calling this method, {@link #getDataSource()} returns the
 * {@link DataSource} providing connectivity to the database.
 */
protected void initDatabase() {
	if (this.generateUniqueDatabaseName) {
		setDatabaseName(UUID.randomUUID().toString());
	}

	// Create the embedded database first
	if (this.databaseConfigurer == null) {
		this.databaseConfigurer = EmbeddedDatabaseConfigurerFactory.getConfigurer(EmbeddedDatabaseType.HSQL);
	}
	this.databaseConfigurer.configureConnectionProperties(
			this.dataSourceFactory.getConnectionProperties(), this.databaseName);
	this.dataSource = this.dataSourceFactory.getDataSource();

	if (logger.isInfoEnabled()) {
		if (this.dataSource instanceof SimpleDriverDataSource) {
			SimpleDriverDataSource simpleDriverDataSource = (SimpleDriverDataSource) this.dataSource;
			logger.info(String.format("Starting embedded database: url='%s', username='%s'",
				simpleDriverDataSource.getUrl(), simpleDriverDataSource.getUsername()));
		}
		else {
			logger.info(String.format("Starting embedded database '%s'", this.databaseName));
		}
	}

	// Now populate the database
	if (this.databasePopulator != null) {
		try {
			DatabasePopulatorUtils.execute(this.databasePopulator, this.dataSource);
		}
		catch (RuntimeException ex) {
			// failed to populate, so leave it as not initialized
			shutdownDatabase();
			throw ex;
		}
	}
}
 
Example 25
@Override
protected void before() {
  ResourceDatabasePopulator populator = new ResourceDatabasePopulator(
      new ClassPathResource("sql/config-test-data.sql")
  );
  DatabasePopulatorUtils.execute(populator, configurationDataSource);
}
 
Example 26
@Override
protected void before() throws SQLException {
  ResourceDatabasePopulator populator = new ResourceDatabasePopulator(new ClassPathResource("sql/cache-data-remove.sql"));
  conn = cacheDataSource.getConnection();
  if (conn.getMetaData().getURL().contains("mysql")) {
    populator.addScript(new ClassPathResource("sql/cache-data-update-sequence.sql"));
  } else {
    populator.addScript(new ClassPathResource("sql/cache-data-alter-sequence.sql"));
  }
  populator.addScript(new ClassPathResource("sql/cache-data-insert.sql"));
  DatabasePopulatorUtils.execute(populator, cacheDataSource);
}
 
Example 27
@Override
public void afterPropertiesSet() throws Exception {
	boolean isInitializeEnabled = (this.taskProperties.isInitializeEnabled() != null)
			? this.taskProperties.isInitializeEnabled()
			: this.taskInitializationEnabled;
	if (this.dataSource != null && isInitializeEnabled && this.taskProperties
			.getTablePrefix().equals(TaskProperties.DEFAULT_TABLE_PREFIX)) {
		String platform = getDatabaseType(this.dataSource);
		if ("hsql".equals(platform)) {
			platform = "hsqldb";
		}
		if ("postgres".equals(platform)) {
			platform = "postgresql";
		}
		if ("oracle".equals(platform)) {
			platform = "oracle10g";
		}
		if ("mysql".equals(platform)) {
			platform = "mysql";
		}
		if ("sqlserver".equals(platform)) {
			platform = "sqlserver";
		}
		ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
		String schemaLocation = schema;
		schemaLocation = schemaLocation.replace("@@[email protected]@", platform);
		populator.addScript(this.resourceLoader.getResource(schemaLocation));
		populator.setContinueOnError(true);
		logger.debug(
				String.format("Initializing task schema for %s database", platform));
		DatabasePopulatorUtils.execute(populator, this.dataSource);
	}
}
 
Example 28
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 29
Source Project: batchers   Source File: AbstractBatchIntegrationTest.java    License: Apache License 2.0 5 votes vote down vote up
@After
public void clearJobTables() throws SQLException {
    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.setScripts(
            new ClassPathResource("org/springframework/batch/core/schema-truncate-hsqldb.sql")
    );
    DatabasePopulatorUtils.execute(databasePopulator, this.dataSource);
}
 
Example 30
Source Project: effectivejava   Source File: EmbeddedDatabaseFactoryBean.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void destroy() {
	if (this.databaseCleaner != null) {
		DatabasePopulatorUtils.execute(this.databaseCleaner, getDataSource());
	}
	shutdownDatabase();
}