Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save luisartola/3009974 to your computer and use it in GitHub Desktop.
Save luisartola/3009974 to your computer and use it in GitHub Desktop.
iBatis Snippets
<typeAlias alias=”product” type=”com.ibatis.example.Product” />
//Mappeo de subclases
<resultMap id=”select-product-result” class=”product”>
<result property=”id” column=”PRD_ID”/>
<result property=”description” column=”PRD_DESCRIPTION”/>
<result property=”category.id” column=”CAT_ID” />
<result property=”category.description” column=”CAT_DESCRIPTION” />
</resultMap>
<statement id=”selectProduct” parameterClass=”int” resultMap=”select-product-result”>
select *
from PRODUCT, CATEGORY
where PRD_CAT_ID=CAT_ID
and PRD_ID = #value#
</statement>
//Query types:
this.insert("", object);
this.update(arg0, arg1)
this.delete(arg0, arg1);
this.queryForInt(arg0);
this.queryForList(arg0);
this.queryForObject(arg0);
this.queryForPaginatedList(statementName, pageSize);
this.queryForMap(statementName, parameterObject, keyProperty)
http://ibatisnet.sourceforge.net/DevGuide.html#d0e366
<!—Oracle SEQUENCE Example -->
<insert id="insertProduct-ORACLE"
parameterClass="product"> <selectKey resultClass="int"
keyProperty="id" > SELECT STOCKIDSEQUENCE.NEXTVAL AS ID FROM DUAL
</selectKey> insert into PRODUCT (PRD_ID,PRD_DESCRIPTION) values
(#id#,#description#) </insert>
<parameterMap id=”insert-product-param” class=”product”>
<parameter property=”id”/>
<parameter property=”description”/>
</parameterMap>
<statement id=”insertProduct” parameterMap=”insert-product-param”>
insert into PRODUCT (PRD_ID, PRD_DESCRIPTION) values (?,?);
</statement>
<resultMap id=”select-product-result” class=”product”>
<result property=”id” column=”PRD_ID”/>
<result property=”description” column=”PRD_DESCRIPTION”/>
<result property=”category” column=”PRD_CAT_ID” select=”selectCategory”/>
</resultMap>
<resultMap id=”select-category-result” class=”category”>
<result property=”id” column=”CAT_ID”/>
<result property=”description” column=”CAT_DESCRIPTION”/>
</resultMap>
<select id=”selectProduct” parameterClass=”int” resultMap=”select-product-result”>
select * from PRODUCT where PRD_ID = #value#
</select>
<resultMap id=”select-product-result” class=”java.lang.String”>
<result property=”value” column=”PRD_DESCRIPTION”/>
</resultMap>
<!-- Java -->
<statement id=”selectProductCount” resultClass=”java.util.HashMap”>
select * from PRODUCT
</statement>
<select id=”selectProductCount” resultClass=”java.lang.Integer”>
select count(1)
from PRODUCT
</select>
<resultMap id=”select-category-result” class=”category”>
<result property=”id” column=”CAT_ID”/>
<result property=”description” column=”CAT_DESCRIPTION”/>
<result property=”payments” column=”{itemId=ORD_ID, custId=ORD_CST_ID}” select=”selectOrderPayments”/>
</resultMap>
<parameterMap id=”insert-product-param” class=”product”>
<parameter property=”description” />
<parameter property=”id”/>
</parameterMap>
<statement id=”insertProduct” parameterMap=”insert-product-param”>
insert into PRODUCT (PRD_DESCRIPTION, PRD_ID) values (?,?);
</statement>
<statement id="selectPersonsByAge" parameterClass=”int” resultClass="person">
<![CDATA[ SELECT * FROM PERSON WHERE AGE > #value# ]]>
</statement>
<statement id=”statementName”
[parameterMap=”nameOfParameterMap”]
[parameterClass=”some.class.Name”]
[resultMap=”nameOfResultMap”]
[resultClass=”some.class.Name”]
[cacheModel=”nameOfCache”]
[xmlResultName="nameOfResult”] (Java only)
>
<statement>, <insert>, <update>, <delete>, <select>, <procedure>
<statement id=”statementName”
[parameterMap=”nameOfParameterMap”]
[parameterClass=”some.class.Name”]
[resultMap=”nameOfResultMap”]
[resultClass=”some.class.Name”]
[cacheModel=”nameOfCache”]
[xmlResultName="nameOfResult”] (Java only)
>
<statement>, <insert>, <update>, <delete>, <select>, <procedure>
<!-- Java -->
<resultMap id=”resultMapName” class=”someClassName” [extends=”parent-resultMap”]>
<result property=”propertyName” column=”COLUMN_NAME”
[columnIndex=”1”] [javaType=”int”] [jdbcType=”NUMERIC”]
[nullValue=”-9999”] [select=”someOtherStatement”]
/>
<result ……/>
<result ……/>
<result ……/>
</resultMap>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment