ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pradheep" <pradheep.ayya...@appliedevelopment.com>
Subject Reuse SQL
Date Wed, 02 Aug 2006 07:12:50 GMT
wats the benefit of using the both?

<select id="selectItemCount" resultClass="int">

SELECT COUNT(*) AS total

FROM items

WHERE parentid = 6

</select>

<select id="selectItems" resultClass="Item">

SELECT id, name

FROM items

WHERE parentid = 6

</select>

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------

To eliminate this duplication, we use the tags <sql> and <include>. The <sql>-tag
contains the fragment to reuse, the <include>-tag to include such a fragment:

<sql id="selectItem_fragment">

FROM items

WHERE parentid = 6

</sql>

<select id="selectItemCount" resultClass="int">

SELECT COUNT(*) AS total

<include refid="selectItem_fragment"/>

</select>

<select id="selectItems" resultClass="Item">

SELECT id, name

<include refid="selectItem_fragment"/>

</select>

       P R A D H E E P A P P L I E D    D E V E L O P M E N T  

      Team Leader
      Chennai, India
      e: pradheep.ayyanar@appliedevelopment.com
       l: 00 91 44 39125333
      m: 00 91 94862 08089  

Mime
View raw message