Reusing Conditions in iBatis

One of the major outcome when the software industry got matured is the concept of reusage. Anything can be reused, components, methods, anything. Similarly I just came across the feature in iBatis where we can reuse the conditions in the where clause. Its very simple and reduce the size of the sqlmap file.

<select id=”selectValue”
resultMap=”ValueEntityResultGM” cacheModel=”data-cache”>
select * from VALUE_NUM
<include refid=”idset” />

The include tag with attribute refid points to a condition saved with the name idset. This will be stored as below

<sql id=”idset-params-gm”>

<isNotNull prepend=”AND” property=”scaleid”>
scaleid = #scaleid#
<isNotEmpty prepend=”AND” property=”scaleid_list” open=”(” close=”)”>
<iterate conjunction=”OR” property=”scaleid_list”>
scaleid = #scaleid_list[]#
<isNotNull prepend=”AND” property=”ownerid”>
ownerid = #ownerid#


The similar way this condition can be used in any number of queries.

When I keep on exploring iBatis, this is becoming more and more fun. Enjoy Coding. 🙂


Tags: , , ,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: