polish
This commit is contained in:
parent
0320445316
commit
4bfcd16130
|
|
@ -21,6 +21,7 @@ import java.sql.Connection;
|
|||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
|
|
@ -52,6 +53,14 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
|||
scripts.add(script);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the scripts to execute to populate the database.
|
||||
* @param scripts the scripts to execute
|
||||
*/
|
||||
public void setScripts(Resource[] scripts) {
|
||||
this.scripts = Arrays.asList(scripts);
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify the encoding for SQL scripts, if different from the platform encoding.
|
||||
* Note setting this property has no effect on added scripts that are already {@link EncodedResource encoded resources}.
|
||||
|
|
@ -60,7 +69,7 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
|||
public void setSqlScriptEncoding(String sqlScriptEncoding) {
|
||||
this.sqlScriptEncoding = sqlScriptEncoding;
|
||||
}
|
||||
|
||||
|
||||
public void populate(Connection connection) throws SQLException {
|
||||
for (Resource script : scripts) {
|
||||
executeSqlScript(connection, applyEncodingIfNecessary(script), false);
|
||||
|
|
|
|||
|
|
@ -6,16 +6,19 @@ import javax.sql.DataSource;
|
|||
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
|
||||
public class EmbeddedDatabaseFactoryBeanTests {
|
||||
|
||||
|
||||
@Test
|
||||
public void testFactoryBeanLifecycle() throws Exception {
|
||||
EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean();
|
||||
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
|
||||
populator.addScript(new ClassPathResource("db-schema.sql", getClass()));
|
||||
populator.addScript(new ClassPathResource("db-test-data.sql", getClass()));
|
||||
populator.setScripts(new Resource[] {
|
||||
new ClassPathResource("db-schema.sql", getClass()),
|
||||
new ClassPathResource("db-test-data.sql", getClass())
|
||||
});
|
||||
bean.setDatabasePopulator(populator);
|
||||
bean.afterPropertiesSet();
|
||||
DataSource ds = bean.getObject();
|
||||
|
|
|
|||
Loading…
Reference in New Issue