Skip to content

Instantly share code, notes, and snippets.

@thesurlydev
Created April 8, 2010 15:50
Show Gist options
  • Save thesurlydev/360203 to your computer and use it in GitHub Desktop.
Save thesurlydev/360203 to your computer and use it in GitHub Desktop.
Using enums with iBatis iterator
<select id="getByCreatedAndModelType" resultMap="TrustResult" resultClass="Trust">
select * from trkr_trust
where trunc(created) = trunc(#created#)
and model_id = #modelId#
<iterate property="types" prepend="AND" open="(" close=")" conjunction="OR">
trust_type=#types[].id#
</iterate>
order by coupon, wala, intex_deal_name
</select>
public List<Trust> getByCreatedAndModelType(Date date, Long modelId, TrustType... types) {
Map<String, Object> params = getCreatedAndModelParams(date, modelId);
params.put("types", types);
return (List<Trust>) getSqlMapClientTemplate().queryForList("Trust.getByCreatedAndModelType", params);
}
@Test
public void getByCreatedAndModelTypeAll() throws Exception {
List<Trust> trusts = trustDaoSqlMap.getByCreatedAndModelType(new Date(), Model.DBMM);
Assert.assertEquals(134, trusts.size());
}
@Test
public void getByCreatedAndModelTypeIos() throws Exception {
List<Trust> trusts = trustDaoSqlMap.getByCreatedAndModelType(new Date(), Model.DBMM, TrustType.IOS);
Assert.assertEquals(3, trusts.size());
}
public enum TrustType implements IdAware {
DEFAULT(1, "default"),
IOS(2, "ios");
private int id;
private String name;
TrustType(int id_, String name_) {
this.id = id_;
this.name = name_;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
}
@thesurlydev
Copy link
Author

You can pass an enum (TrustType here) to the iBatis iterator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment