declareParameter(new SqlParameter("ids", Types.NUMERIC));
compile();
}
protected Object 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 findCustomers(List ids) {
Map params = new HashMap();
params.put("ids", ids);
return (List) executeByNamedParam(params);
}
}
CustomerQuery query = new CustomerQuery(mockDataSource);
List ids = new ArrayList();
ids.add(new Integer(1));
ids.add(new Integer(2));
List cust = query.findCustomers(ids);
assertEquals("We got two customers back", cust.size(), 2);
assertEquals("First customer id was assigned correctly", ((Customer)cust.get(0)).getId(), 1);
assertEquals("First customer forename was assigned correctly", ((Customer)cust.get(0)).getForename(), "rod");
assertEquals("Second customer id was assigned correctly", ((Customer)cust.get(1)).getId(), 2);
assertEquals("Second customer forename was assigned correctly", ((Customer)cust.get(1)).getForename(), "juergen");
}