use of org.apache.commons.dbutils.handlers.BeanListHandler in project tutorials by eugenp.
the class EmployeeHandler method handle.
@Override
public List<Employee> handle(ResultSet rs) throws SQLException {
List<Employee> employees = super.handle(rs);
QueryRunner runner = new QueryRunner();
BeanListHandler<Email> handler = new BeanListHandler<>(Email.class);
String query = "SELECT * FROM email WHERE employeeid = ?";
for (Employee employee : employees) {
List<Email> emails = runner.query(connection, query, handler, employee.getId());
employee.setEmails(emails);
}
return employees;
}
use of org.apache.commons.dbutils.handlers.BeanListHandler in project tutorials by eugenp.
the class DbUtilsUnitTest method givenResultHandler_whenExecutingQuery_thenEmployeeList.
@Test
public void givenResultHandler_whenExecutingQuery_thenEmployeeList() throws SQLException {
BeanListHandler<Employee> beanListHandler = new BeanListHandler<>(Employee.class);
QueryRunner runner = new QueryRunner();
List<Employee> employeeList = runner.query(connection, "SELECT * FROM employee", beanListHandler);
assertEquals(employeeList.size(), 5);
assertEquals(employeeList.get(0).getFirstName(), "John");
assertEquals(employeeList.get(4).getFirstName(), "Christian");
}
Aggregations