Created
April 8, 2010 15:50
-
-
Save thesurlydev/360203 to your computer and use it in GitHub Desktop.
Using enums with iBatis iterator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can pass an enum (TrustType here) to the iBatis iterator.