Merge pull request #26 from trisberg/improved-RDP
This commit is contained in:
commit
ff84419f4d
|
|
@ -181,9 +181,10 @@ public class ResourceDatabasePopulator implements DatabasePopulator {
|
||||||
for (String statement : statements) {
|
for (String statement : statements) {
|
||||||
lineNumber++;
|
lineNumber++;
|
||||||
try {
|
try {
|
||||||
int rowsAffected = stmt.executeUpdate(statement);
|
stmt.execute(statement);
|
||||||
|
int rowsAffected = stmt.getUpdateCount();
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(rowsAffected + " rows affected by SQL: " + statement);
|
logger.debug(rowsAffected + " returned as updateCount for SQL: " + statement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SQLException ex) {
|
catch (SQLException ex) {
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,6 @@ import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
|
||||||
|
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.springframework.core.io.ClassRelativeResourceLoader;
|
import org.springframework.core.io.ClassRelativeResourceLoader;
|
||||||
|
|
@ -49,7 +47,7 @@ public class DatabasePopulatorTests {
|
||||||
assertEquals(name, jdbcTemplate.queryForObject("select NAME from T_TEST", String.class));
|
assertEquals(name, jdbcTemplate.queryForObject("select NAME from T_TEST", String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void assertUsersDatabaseCreated(DataSource db) {
|
private void assertUsersDatabaseCreated() {
|
||||||
assertEquals("Sam", jdbcTemplate.queryForObject("select first_name from users where last_name = 'Brannen'",
|
assertEquals("Sam", jdbcTemplate.queryForObject("select first_name from users where last_name = 'Brannen'",
|
||||||
String.class));
|
String.class));
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +189,22 @@ public class DatabasePopulatorTests {
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
assertUsersDatabaseCreated(db);
|
assertUsersDatabaseCreated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testBuildWithSelectStatements() throws Exception {
|
||||||
|
databasePopulator.addScript(resourceLoader.getResource("db-schema.sql"));
|
||||||
|
databasePopulator.addScript(resourceLoader.getResource("db-test-data-select.sql"));
|
||||||
|
Connection connection = db.getConnection();
|
||||||
|
try {
|
||||||
|
databasePopulator.populate(connection);
|
||||||
|
} finally {
|
||||||
|
connection.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Keith'"));
|
||||||
|
assertEquals(1, jdbcTemplate.queryForInt("select COUNT(NAME) from T_TEST where NAME='Dave'"));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
insert into T_TEST (NAME) values ('Keith');
|
||||||
|
insert into T_TEST (NAME) values ('Dave');
|
||||||
|
select NAME from T_TEST where NAME = 'Keith';
|
||||||
Loading…
Reference in New Issue