Example usage for org.springframework.jdbc.datasource.init ResourceDatabasePopulator setContinueOnError

List of usage examples for org.springframework.jdbc.datasource.init ResourceDatabasePopulator setContinueOnError

Introduction

In this page you can find the example usage for org.springframework.jdbc.datasource.init ResourceDatabasePopulator setContinueOnError.

Prototype

public void setContinueOnError(boolean continueOnError) 

Source Link

Document

Flag to indicate that all failures in SQL should be logged but not cause a failure.

Usage

From source file:org.dawnsci.marketplace.config.DatabaseConfiguration.java

private DatabasePopulator createDatabasePopulator() {
    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.setContinueOnError(true);
    // populate the database with required tables
    databasePopulator.addScript(new ClassPathResource("schema.sql"));
    return databasePopulator;
}

From source file:com.searchbox.framework.config.DataConfiguration.java

@Bean
@DependsOn("entityManagerFactory")
public ResourceDatabasePopulator initDatabase(DataSource dataSource) throws Exception {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.setContinueOnError(true);
    populator.addScript(new ClassPathResource("data/oppfinUsers.sql"));
    populator.addScript(new ClassPathResource("org/springframework/batch/core/schema-mysql.sql"));
    //populator.addScript(new ClassPathResource("data/spring-batch-h2-schema.sql"));
    populator.populate(dataSource.getConnection());
    return populator;
}

From source file:com.musala.configuration.RssAplicationConfiguration.java

private DatabasePopulator createDatabasePopulator() {
    ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator();
    databasePopulator.setContinueOnError(false);
    databasePopulator.addScript(new ClassPathResource("sql/rss-schema.ddl"));
    databasePopulator.addScript(new ClassPathResource("sql/test-data.sql"));
    return databasePopulator;
}

From source file:org.cloudfoundry.identity.uaa.db.InitialPreDatabaseVersioningSchemaCreator.java

@Override
public void migrate(Connection connection) throws Exception {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(//from   ww  w . j a  v  a2s  .c  om
            new ClassPathResource("org/cloudfoundry/identity/uaa/db/" + type + "/V1_5_2__initial_db.sql"));
    populator.setContinueOnError(true);
    populator.setIgnoreFailedDrops(true);
    populator.populate(connection);
}

From source file:com.example.DBConfig.java

@PostConstruct
protected void initialize() throws Exception {
    String platform = DatabaseType.fromMetaData(this.dataSource()).toString().toLowerCase();
    String schemaCreateLocation = this.env.getProperty("schema", DEFAULT_SCHEMA_LOCATION);
    schemaCreateLocation = schemaCreateLocation.replace("@@platform@@", platform);
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(this.resourceLoader.getResource(schemaCreateLocation));
    populator.setContinueOnError(true);
    DatabasePopulatorUtils.execute(populator, dataSource());
}

From source file:com.vladmihalcea.util.DatabaseScriptLifecycleHandler.java

protected ResourceDatabasePopulator createResourceDatabasePopulator() {
    ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
    resourceDatabasePopulator.setCommentPrefix(getCommentPrefix());
    resourceDatabasePopulator.setContinueOnError(isContinueOnError());
    resourceDatabasePopulator.setIgnoreFailedDrops(isIgnoreFailedDrops());
    resourceDatabasePopulator.setSqlScriptEncoding(getSqlScriptEncoding());
    return resourceDatabasePopulator;
}

From source file:org.jblogcms.core.config.PersistenceContext.java

@Bean
public DataSourceInitializer databasePopulator() {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(/*from   w w  w  .j a  v  a 2  s  .  c  o  m*/
            new ClassPathResource("org/springframework/social/connect/jdbc/JdbcUsersConnectionRepository.sql"));
    populator.setContinueOnError(true);

    DataSourceInitializer initializer = new DataSourceInitializer();
    initializer.setDatabasePopulator(populator);
    initializer.setDataSource(dataSource());

    return initializer;
}

From source file:org.cloudfoundry.identity.uaa.db.FixFailedBackportMigrations_4_0_4.java

@Override
public void migrate(Connection connection) throws Exception {
    if ("sqlserver".equals(type) || "hsqldb".equals(type)) {
        //we don't have this problem with sqlserver or in memory DB
        logger.info("Skipping 4.0.4 migration for " + type + ", not affected by 3.9.9 back ports.");
        return;/*from  w  ww  .ja v a2 s .c  om*/
    }
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    SingleConnectionDataSource dataSource = new SingleConnectionDataSource(connection, true);
    JdbcTemplate template = new JdbcTemplate(dataSource);
    boolean run = false;
    for (Map.Entry<String, String> script : getScripts()) {
        int count = template.queryForObject(checkExistsSql, Integer.class, script.getKey());
        if (count == 0) {
            String path = "org/cloudfoundry/identity/uaa/db/" + type + "/" + script.getValue();
            logger.info(
                    String.format("[4.0.4] Adding script for version %s with path %s", script.getKey(), path));
            populator.addScript(new ClassPathResource(path));
            run = true;
        }
    }
    if (run) {
        logger.info("Running missing migrations.");
        populator.setContinueOnError(false);
        populator.setIgnoreFailedDrops(true);
        populator.populate(connection);
        logger.info("Completed missing migrations.");
    } else {
        logger.info("Skipping 4.0.4 migrations, no migrations missing.");
    }
}

From source file:org.springframework.batch.sample.config.DataSourceConfiguration.java

@PostConstruct
protected void initialize() {
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    populator.addScript(resourceLoader.getResource(environment.getProperty("batch.schema.script")));
    populator.setContinueOnError(true);
    DatabasePopulatorUtils.execute(populator, dataSource());
}

From source file:org.springframework.boot.autoconfigure.jdbc.DataSourceInitialization.java

private boolean runScripts(String scripts) {

    if (this.dataSource == null) {
        logger.debug("No DataSource found so not initializing");
        return false;
    }/*from  www.  j  a va 2  s .  co  m*/

    List<Resource> resources = getSchemaResources(scripts);

    boolean continueOnError = this.properties.isContinueOnError();
    boolean exists = false;
    ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
    for (Resource resource : resources) {
        if (resource.exists()) {
            exists = true;
            populator.addScript(resource);
            populator.setContinueOnError(continueOnError);
        }
    }
    populator.setSeparator(this.properties.getSeparator());

    if (exists) {
        DatabasePopulatorUtils.execute(populator, this.dataSource);
    }

    return exists;

}