Introduce execute(DataSource) in ResrcDbPopulator

To simplify common use cases, this commit introduces a new
execute(DataSource) method in ResourceDatabasePopulator that complements
the existing populate(Connection) method.

Issue: SPR-11629
This commit is contained in:
Sam Brannen
2014-03-30 17:01:48 +02:00
parent b766686c40
commit 5d049e0de8
4 changed files with 30 additions and 28 deletions

View File

@@ -23,8 +23,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestExecutionListeners;
@@ -180,14 +178,11 @@ public abstract class AbstractTransactionalJUnit4SpringContextTests extends Abst
* exception in the event of an error
* @throws DataAccessException if there is an error executing a statement
* @see ResourceDatabasePopulator
* @see DatabasePopulatorUtils
* @see #setSqlScriptEncoding
*/
protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException {
Resource resource = this.applicationContext.getResource(sqlResourcePath);
DatabasePopulator databasePopulator = new ResourceDatabasePopulator(continueOnError, false,
this.sqlScriptEncoding, resource);
DatabasePopulatorUtils.execute(databasePopulator, jdbcTemplate.getDataSource());
new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(jdbcTemplate.getDataSource());
}
}

View File

@@ -23,8 +23,6 @@ import org.springframework.context.ApplicationContext;
import org.springframework.core.io.Resource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.transaction.TransactionalTestExecutionListener;
@@ -171,14 +169,11 @@ public abstract class AbstractTransactionalTestNGSpringContextTests extends Abst
* exception in the event of an error
* @throws DataAccessException if there is an error executing a statement
* @see ResourceDatabasePopulator
* @see DatabasePopulatorUtils
* @see #setSqlScriptEncoding
*/
protected void executeSqlScript(String sqlResourcePath, boolean continueOnError) throws DataAccessException {
Resource resource = this.applicationContext.getResource(sqlResourcePath);
DatabasePopulator databasePopulator = new ResourceDatabasePopulator(continueOnError, false,
this.sqlScriptEncoding, resource);
DatabasePopulatorUtils.execute(databasePopulator, jdbcTemplate.getDataSource());
new ResourceDatabasePopulator(continueOnError, false, this.sqlScriptEncoding, resource).execute(jdbcTemplate.getDataSource());
}
}

View File

@@ -29,8 +29,6 @@ import org.springframework.core.io.support.EncodedResource;
import org.springframework.dao.DataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.SqlParameterValue;
import org.springframework.jdbc.datasource.init.DatabasePopulator;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.jdbc.datasource.init.ScriptUtils;
import org.springframework.util.StringUtils;
@@ -164,7 +162,6 @@ public class JdbcTestUtils {
* @throws DataAccessException if there is an error executing a statement
* and {@code continueOnError} is {@code false}
* @see ResourceDatabasePopulator
* @see DatabasePopulatorUtils
* @see #executeSqlScript(JdbcTemplate, Resource, boolean)
* @deprecated as of Spring 4.0.3, in favor of using
* {@link org.springframework.jdbc.datasource.init.ScriptUtils#executeSqlScript}
@@ -192,7 +189,6 @@ public class JdbcTestUtils {
* @throws DataAccessException if there is an error executing a statement
* and {@code continueOnError} is {@code false}
* @see ResourceDatabasePopulator
* @see DatabasePopulatorUtils
* @see #executeSqlScript(JdbcTemplate, EncodedResource, boolean)
* @deprecated as of Spring 4.0.3, in favor of using
* {@link org.springframework.jdbc.datasource.init.ScriptUtils#executeSqlScript}
@@ -217,7 +213,6 @@ public class JdbcTestUtils {
* @throws DataAccessException if there is an error executing a statement
* and {@code continueOnError} is {@code false}
* @see ResourceDatabasePopulator
* @see DatabasePopulatorUtils
* @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}.
@@ -225,9 +220,7 @@ public class JdbcTestUtils {
@Deprecated
public static void executeSqlScript(JdbcTemplate jdbcTemplate, EncodedResource resource, boolean continueOnError)
throws DataAccessException {
DatabasePopulator databasePopulator = new ResourceDatabasePopulator(continueOnError, false,
resource.getEncoding(), resource.getResource());
DatabasePopulatorUtils.execute(databasePopulator, jdbcTemplate.getDataSource());
new ResourceDatabasePopulator(continueOnError, false, resource.getEncoding(), resource.getResource()).execute(jdbcTemplate.getDataSource());
}
/**