/** * Execute the given SQL script. * <p>Use with caution outside of a transaction! * <p>The script will normally be loaded by classpath. * <p><b>Do not use this method to execute DDL if you expect rollback.</b> * @param sqlResourcePath the Spring resource path for the SQL script * @param continueOnError whether or not to continue without throwing an * exception in the event of an error * @throws DataAccessException if there is an error executing a statement * @see ResourceDatabasePopulator * @see #setSqlScriptEncoding */ protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException { DataSource ds = this.jdbcTemplate.getDataSource(); Assert.state(ds != null, "No DataSource set"); Assert.state(this.applicationContext != null, "No ApplicationContext available"); Resource resource = this.applicationContext.getResource(sqlResourcePath); new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(ds); }
/** * Execute the given SQL script. * <p>Use with caution outside of a transaction! * <p>The script will normally be loaded by classpath. * <p><b>Do not use this method to execute DDL if you expect rollback.</b> * @param sqlResourcePath the Spring resource path for the SQL script * @param continueOnError whether or not to continue without throwing an * exception in the event of an error * @throws DataAccessException if there is an error executing a statement * @see ResourceDatabasePopulator * @see #setSqlScriptEncoding */ protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException { DataSource ds = this.jdbcTemplate.getDataSource(); Assert.state(ds != null, "No DataSource set"); Assert.state(this.applicationContext != null, "No ApplicationContext set"); Resource resource = this.applicationContext.getResource(sqlResourcePath); new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(ds); }
@Test @Transactional public void transactionalTest() { TransactionTestUtils.assertInTransaction(true); ClassPathResource resource = new ClassPathResource("/org/springframework/test/context/jdbc/data.sql"); new ResourceDatabasePopulator(resource).execute(jdbcTemplate.getDataSource()); assertNumUsers(1); }
protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException { Resource resource = this.applicationContext.getResource(sqlResourcePath); new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(jdbcTemplate.getDataSource()); }
protected void executeSqlScript(String sqlResourcePath) throws DataAccessException { Resource resource = applicationContext.getResource(sqlResourcePath); new ResourceDatabasePopulator(resource).execute(this.jdbcTemplate.getDataSource()); }
@Before public void setUp() { ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(); databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-drop-hsqldb.sql")); databasePopulator.addScript(new ClassPathResource("/org/springframework/batch/core/schema-hsqldb.sql")); databasePopulator.addScript(new ClassPathResource("/business-schema-hsqldb.sql")); databasePopulator.execute(this.dataSource); }
@Override public void doInTransactionWithoutResult(TransactionStatus status) { populator.execute(finalDataSource); } });
public void createDefaultDB(DataSource dataSource) { Resource resource = new ClassPathResource("CreateDefaultDB.sql"); ResourceDatabasePopulator databasePopulator = new ResourceDatabasePopulator(resource); databasePopulator.execute(dataSource); }
private void initialize(DataSource dataSource) { ClassPathResource schemaResource = new ClassPathResource("schema.sql"); ClassPathResource dataResource = new ClassPathResource("data.sql"); ResourceDatabasePopulator populator = new ResourceDatabasePopulator(schemaResource, dataResource); populator.execute(dataSource); }
/** * Execute the given SQL script. * <p>Use with caution outside of a transaction! * <p>The script will normally be loaded by classpath. * <p><b>Do not use this method to execute DDL if you expect rollback.</b> * @param sqlResourcePath the Spring resource path for the SQL script * @param continueOnError whether or not to continue without throwing an * exception in the event of an error * @throws DataAccessException if there is an error executing a statement * @see ResourceDatabasePopulator * @see #setSqlScriptEncoding */ protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException { DataSource ds = this.jdbcTemplate.getDataSource(); Assert.state(ds != null, "No DataSource set"); Assert.state(this.applicationContext != null, "No ApplicationContext available"); Resource resource = this.applicationContext.getResource(sqlResourcePath); new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(ds); }
/** * Execute the given SQL script. * <p>Use with caution outside of a transaction! * <p>The script will normally be loaded by classpath. * <p><b>Do not use this method to execute DDL if you expect rollback.</b> * @param sqlResourcePath the Spring resource path for the SQL script * @param continueOnError whether or not to continue without throwing an * exception in the event of an error * @throws DataAccessException if there is an error executing a statement * @see ResourceDatabasePopulator * @see #setSqlScriptEncoding */ protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException { DataSource ds = this.jdbcTemplate.getDataSource(); Assert.state(ds != null, "No DataSource set"); Assert.state(this.applicationContext != null, "No ApplicationContext set"); Resource resource = this.applicationContext.getResource(sqlResourcePath); new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(ds); }
private void applyScripts(String url) throws SQLException, IOException { log.info("Apply Scripts ..."); Connection connection = getConnection(url); DataSource ds = new SingleConnectionDataSource(connection, false); FileSystemScanner scanner = new FileSystemScanner(); for (String location : builder.locations) { File directory = new File(location); if (directory.exists() && directory.isDirectory()) { Resource[] resources = scanner.scanForResources(location, "", ".sql"); ResourceDatabasePopulator populator = new ResourceDatabasePopulator(resources); populator.setSeparator(builder.separator); populator.execute(ds); } else { // log not existing directory } } log.info("Scripts applied!"); }
/** * Execute the given SQL script. * <p>Use with caution outside of a transaction! * <p>The script will normally be loaded by classpath. * <p><b>Do not use this method to execute DDL if you expect rollback.</b> * @param sqlResourcePath the Spring resource path for the SQL script * @param continueOnError whether or not to continue without throwing an * exception in the event of an error * @throws DataAccessException if there is an error executing a statement * @see ResourceDatabasePopulator * @see #setSqlScriptEncoding */ protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException { Resource resource = this.applicationContext.getResource(sqlResourcePath); new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(jdbcTemplate.getDataSource()); }
/** * @param sqlFile the sql file to execute * @param shouldContinueOnError * @throws IOException */ protected void executeSQLResource(final String sqlFile, boolean shouldContinueOnError) throws IOException, SQLException { final Resource sqlResource = getSQLResource(sqlFolder, sqlFile); ResourceDatabasePopulator populate = new ResourceDatabasePopulator(); populate.setContinueOnError(shouldContinueOnError); populate.setIgnoreFailedDrops(true); populate.addScript(sqlResource); populate.setSeparator(getSeparator()); populate.execute(datasource); logger.info("Executed SQL script " + sqlResource.getURL().getFile()); }
/** * Execute the given SQL script. * <p>Use with caution outside of a transaction! * <p>The script will normally be loaded by classpath. * <p><b>Do not use this method to execute DDL if you expect rollback.</b> * @param sqlResourcePath the Spring resource path for the SQL script * @param continueOnError whether or not to continue without throwing an * exception in the event of an error * @throws DataAccessException if there is an error executing a statement * @see ResourceDatabasePopulator * @see #setSqlScriptEncoding */ protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException { Resource resource = this.applicationContext.getResource(sqlResourcePath); new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(jdbcTemplate.getDataSource()); }
/** * @param sqlFile the sql file to execute * @param shouldContinueOnError * @throws IOException */ protected void executeSQLResource(final String sqlFile, boolean shouldContinueOnError) throws IOException, SQLException { final Resource sqlResource = getSQLResource(sqlFolder, sqlFile); ResourceDatabasePopulator populate = new ResourceDatabasePopulator(); populate.setContinueOnError(shouldContinueOnError); populate.setIgnoreFailedDrops(true); populate.addScript(sqlResource); populate.setSeparator(getSeparator()); populate.execute(datasource); logger.info("Executed SQL script " + sqlResource.getURL().getFile()); }
/** * Execute the given SQL script. * <p>The script will typically be loaded from the classpath. There should * be one statement per line. Any semicolons and line comments will be removed. * <p><b>Do not use this method to execute DDL if you expect rollback.</b> * @param jdbcTemplate the JdbcTemplate with which to perform JDBC operations * @param resource the resource (potentially associated with a specific encoding) * to load the SQL script from * @param continueOnError whether or not to continue without throwing an * exception in the event of an error * @throws DataAccessException if there is an error executing a statement * and {@code continueOnError} is {@code false} * @see ResourceDatabasePopulator * @deprecated as of Spring 4.0.3, in favor of using * {@link org.springframework.jdbc.datasource.init.ScriptUtils#executeSqlScript} * or {@link org.springframework.jdbc.datasource.init.ResourceDatabasePopulator}. */ @Deprecated public static void executeSqlScript(JdbcTemplate jdbcTemplate, EncodedResource resource, boolean continueOnError) throws DataAccessException { new ResourceDatabasePopulator(continueOnError, false, resource.getEncoding(), resource.getResource()).execute(jdbcTemplate.getDataSource()); }
populator.execute(dataSource);