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
WHERE VALUE IS NOT NULL
<include refid=”idset” />
</select>

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#
</isNotNull>
<isNotEmpty prepend=”AND” property=”scaleid_list” open=”(” close=”)”>
<iterate conjunction=”OR” property=”scaleid_list”>
scaleid = #scaleid_list[]#
</iterate>
</isNotEmpty>
<isNotNull prepend=”AND” property=”ownerid”>
ownerid = #ownerid#
</isNotNull>

</sql>

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. 🙂

Advertisements

Tags: , , ,

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: