compile();
}
@Override
protected Customer mapRow(ResultSet rs, int rownum) throws SQLException {
Customer cust = new Customer();
cust.setId(rs.getInt(COLUMN_NAMES[0]));
cust.setForename(rs.getString(COLUMN_NAMES[1]));
return cust;
}
public List<Customer> findCustomers(List<Integer> ids) {
Map<String, Object> params = new HashMap<String, Object>();
params.put("ids", ids);
return executeByNamedParam(params);
}
}
CustomerQuery query = new CustomerQuery(dataSource);
List<Integer> ids = new ArrayList<Integer>();
ids.add(1);
ids.add(2);
List<Customer> cust = query.findCustomers(ids);
assertEquals("We got two customers back", cust.size(), 2);
assertEquals("First customer id was assigned correctly", cust.get(0).getId(), 1);
assertEquals("First customer forename was assigned correctly", cust.get(0).getForename(), "rod");
assertEquals("Second customer id was assigned correctly", cust.get(1).getId(), 2);
assertEquals("Second customer forename was assigned correctly", cust.get(1).getForename(), "juergen");
verify(preparedStatement).setObject(1, 1, Types.NUMERIC);
verify(preparedStatement).setObject(2, 2, Types.NUMERIC);
verify(resultSet).close();
verify(preparedStatement).close();
verify(connection).close();