BAEL-3961 Make the program more robust by only create the table when necessary and clean all data in the temp table.

This commit is contained in:
Gang Wu 2020-04-14 19:23:11 -06:00
parent 63027fd269
commit 78e180f35d
2 changed files with 7 additions and 1 deletions

View File

@ -45,7 +45,8 @@ public class EmployeeDAO {
}
public List<Employee> getEmployeesFromLargeIdList(List<Integer> ids) {
jdbcTemplate.execute("CREATE TEMPORARY TABLE employee_tmp (id INT NOT NULL)");
jdbcTemplate.execute("CREATE TEMPORARY TABLE IF NOT EXISTS employee_tmp (id INT NOT NULL)");
jdbcTemplate.update("DELETE FROM employee_tmp");
List<Object[]> employeeIds = new ArrayList<>();
for (Integer id : ids) {

View File

@ -98,5 +98,10 @@ public class EmployeeDAOUnitTest {
assertEquals(1, employees.get(0).getId());
assertEquals(3, employees.get(1).getId());
assertEquals(4, employees.get(2).getId());
ids.clear();
ids.add(2);
employees = employeeDAO.getEmployeesFromLargeIdList(ids);
assertEquals(1, employees.size());
}
}