Skip to content

Commit 4bfcd16

Browse files
author
Keith Donald
committed
polish
1 parent 0320445 commit 4bfcd16

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

org.springframework.jdbc/src/main/java/org/springframework/jdbc/datasource/embedded/ResourceDatabasePopulator.java

+10-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.sql.SQLException;
2222
import java.sql.Statement;
2323
import java.util.ArrayList;
24+
import java.util.Arrays;
2425
import java.util.LinkedList;
2526
import java.util.List;
2627

@@ -52,6 +53,14 @@ public void addScript(Resource script) {
5253
scripts.add(script);
5354
}
5455

56+
/**
57+
* Set the scripts to execute to populate the database.
58+
* @param scripts the scripts to execute
59+
*/
60+
public void setScripts(Resource[] scripts) {
61+
this.scripts = Arrays.asList(scripts);
62+
}
63+
5564
/**
5665
* Specify the encoding for SQL scripts, if different from the platform encoding.
5766
* Note setting this property has no effect on added scripts that are already {@link EncodedResource encoded resources}.
@@ -60,7 +69,7 @@ public void addScript(Resource script) {
6069
public void setSqlScriptEncoding(String sqlScriptEncoding) {
6170
this.sqlScriptEncoding = sqlScriptEncoding;
6271
}
63-
72+
6473
public void populate(Connection connection) throws SQLException {
6574
for (Resource script : scripts) {
6675
executeSqlScript(connection, applyEncodingIfNecessary(script), false);

org.springframework.jdbc/src/test/java/org/springframework/jdbc/datasource/embedded/EmbeddedDatabaseFactoryBeanTests.java

+6-3
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,19 @@
66

77
import org.junit.Test;
88
import org.springframework.core.io.ClassPathResource;
9+
import org.springframework.core.io.Resource;
910
import org.springframework.jdbc.core.JdbcTemplate;
1011

1112
public class EmbeddedDatabaseFactoryBeanTests {
12-
13+
1314
@Test
1415
public void testFactoryBeanLifecycle() throws Exception {
1516
EmbeddedDatabaseFactoryBean bean = new EmbeddedDatabaseFactoryBean();
1617
ResourceDatabasePopulator populator = new ResourceDatabasePopulator();
17-
populator.addScript(new ClassPathResource("db-schema.sql", getClass()));
18-
populator.addScript(new ClassPathResource("db-test-data.sql", getClass()));
18+
populator.setScripts(new Resource[] {
19+
new ClassPathResource("db-schema.sql", getClass()),
20+
new ClassPathResource("db-test-data.sql", getClass())
21+
});
1922
bean.setDatabasePopulator(populator);
2023
bean.afterPropertiesSet();
2124
DataSource ds = bean.getObject();

0 commit comments

Comments
 (0)