Search in sources :

Example 11 with ResourceDatabasePopulator

use of org.springframework.jdbc.datasource.init.ResourceDatabasePopulator in project spring-framework by spring-projects.

the class AbstractEntityManagerFactoryIntegrationTests method executeSqlScript.

protected void executeSqlScript(String sqlResourcePath) throws DataAccessException {
    Resource resource = applicationContext.getResource(sqlResourcePath);
    new ResourceDatabasePopulator(resource).execute(this.jdbcTemplate.getDataSource());
}
Also used : ResourceDatabasePopulator(org.springframework.jdbc.datasource.init.ResourceDatabasePopulator) Resource(org.springframework.core.io.Resource)

Example 12 with ResourceDatabasePopulator

use of org.springframework.jdbc.datasource.init.ResourceDatabasePopulator in project spring-framework by spring-projects.

the class AbstractTransactionalTestNGSpringContextTests method executeSqlScript.

/**
	 * 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());
}
Also used : ResourceDatabasePopulator(org.springframework.jdbc.datasource.init.ResourceDatabasePopulator) Resource(org.springframework.core.io.Resource)

Example 13 with ResourceDatabasePopulator

use of org.springframework.jdbc.datasource.init.ResourceDatabasePopulator in project spring-framework by spring-projects.

the class AbstractTransactionalJUnit4SpringContextTests method executeSqlScript.

/**
	 * 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());
}
Also used : ResourceDatabasePopulator(org.springframework.jdbc.datasource.init.ResourceDatabasePopulator) Resource(org.springframework.core.io.Resource)

Example 14 with ResourceDatabasePopulator

use of org.springframework.jdbc.datasource.init.ResourceDatabasePopulator in project spring-framework by spring-projects.

the class PrimaryTransactionManagerTests method transactionalTest.

@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);
}
Also used : ResourceDatabasePopulator(org.springframework.jdbc.datasource.init.ResourceDatabasePopulator) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with ResourceDatabasePopulator

use of org.springframework.jdbc.datasource.init.ResourceDatabasePopulator in project vladmihalcea.wordpress.com by vladmihalcea.

the class DatabaseScriptLifecycleHandler method createResourceDatabasePopulator.

protected ResourceDatabasePopulator createResourceDatabasePopulator() {
    ResourceDatabasePopulator resourceDatabasePopulator = new ResourceDatabasePopulator();
    resourceDatabasePopulator.setCommentPrefix(getCommentPrefix());
    resourceDatabasePopulator.setContinueOnError(isContinueOnError());
    resourceDatabasePopulator.setIgnoreFailedDrops(isIgnoreFailedDrops());
    resourceDatabasePopulator.setSqlScriptEncoding(getSqlScriptEncoding());
    return resourceDatabasePopulator;
}
Also used : ResourceDatabasePopulator(org.springframework.jdbc.datasource.init.ResourceDatabasePopulator)

Aggregations

ResourceDatabasePopulator (org.springframework.jdbc.datasource.init.ResourceDatabasePopulator)17 Resource (org.springframework.core.io.Resource)7 ClassPathResource (org.springframework.core.io.ClassPathResource)6 DataSource (javax.sql.DataSource)3 Bean (org.springframework.context.annotation.Bean)3 DependsOn (org.springframework.context.annotation.DependsOn)3 LocalContainerEntityManagerFactoryBean (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean)3 Connection (java.sql.Connection)2 SQLException (java.sql.SQLException)2 Test (org.junit.Test)2 DataAccessException (org.springframework.dao.DataAccessException)2 PostConstruct (javax.annotation.PostConstruct)1 ByteArrayResource (org.springframework.core.io.ByteArrayResource)1 JdbcTemplate (org.springframework.jdbc.core.JdbcTemplate)1 PlatformTransactionManager (org.springframework.transaction.PlatformTransactionManager)1 Transactional (org.springframework.transaction.annotation.Transactional)1 DefaultTransactionAttribute (org.springframework.transaction.interceptor.DefaultTransactionAttribute)1 TransactionAttribute (org.springframework.transaction.interceptor.TransactionAttribute)1 TransactionTemplate (org.springframework.transaction.support.TransactionTemplate)1