Created
June 28, 2012 08:46
-
-
Save luisartola/3009974 to your computer and use it in GitHub Desktop.
iBatis Snippets
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<select id=”selectProductCount” resultClass=”java.lang.Integer”> | |
select count(1) | |
from PRODUCT | |
</select> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<statement id="selectPersonsByAge" parameterClass=”int” resultClass="person"> | |
<![CDATA[ SELECT * FROM PERSON WHERE AGE > #value# ]]> | |
</statement> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- 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