Showing posts with label iBATIS. Show all posts
Showing posts with label iBATIS. Show all posts

Thursday, June 2, 2011

Parameterizing the table name in iBATIS (use of DYNAMIC tags in sql)


Notice the difference in syntax of parameters passed for schema or table name versus the parameters in sql condition like Where clause or And clause.

For table name use $paramName$ and for other conditions use #paramName#!

     
      <resultMap id="jokersMap" class="com.ragsetty.jokers.Kilaadi">
            <result property="name" column="PERSON_NAME" />
            <result property="height" column="PERSON_HEIGHT" />
            ......
            ......
      </resultMap>



      <statement id="findAllJokers" parameterClass="java.util.Map" resultMap="jokersMap">
            SELECT *
            <dynamic prepend="FROM">
                  <isNotNull property="tableName">
                        $tableName$
                  </isNotNull>
                  <isNull property="tableName">
                        MY_SCHEMA.DEFAULT_PERSON_TABLE
                  </isNull>
            </dynamic>
            WHERE PERSON_TYPE = #personType#
      </statement>