iBATIS.NET 学习笔记(十)
Data Map (.NET):
Example:
Mapped Statements
Mapped Statements can hold any SQL statement and can use Parameter Maps and Result Maps for input and output. (A stored procedure is a specialized form of a statement.)
下面是6种Statement-type 元素
Example:
<?xml version="1.0" encoding="UTF-8" ?>
<sqlMap namespace="Product"
xmlns="http://ibatis.apache.org/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<alias>
<typeAlias alias="Product" type="Example.Domain.Product, Example.Domain" />
</alias>
<!-- keeps the result of the last one thousand of these queries in active memory for up to 24 hours-->
<cacheModels>
<cacheModel id="productCache" type="LRU">
<flushInterval hours="24"/>
<property name="CacheSize" value="1000" />
</cacheModel>
</cacheModels>
<!--maps the columns to our object properties-->
<resultMaps>
<resultMap id="productResult" class="Product">
<result property="Id" column="Product_Id"/>
<result property="Description" column="Product_Description"/>
</resultMap>
</resultMaps>
<statements>
<select id="GetProduct" parameterMap="productParam" cacheModel="productCache">
select * from Products where Product_Id = ?
</select>
</statements>
<!--maps the SQL "?" to the product Id property-->
<parameterMaps>
<parameterMap id="productParam" class="Product">
<parameter property="Id"/>
</parameterMap>
<parameterMaps>
</sqlMap>
<sqlMap namespace="Product"
xmlns="http://ibatis.apache.org/mapping"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<alias>
<typeAlias alias="Product" type="Example.Domain.Product, Example.Domain" />
</alias>
<!-- keeps the result of the last one thousand of these queries in active memory for up to 24 hours-->
<cacheModels>
<cacheModel id="productCache" type="LRU">
<flushInterval hours="24"/>
<property name="CacheSize" value="1000" />
</cacheModel>
</cacheModels>
<!--maps the columns to our object properties-->
<resultMaps>
<resultMap id="productResult" class="Product">
<result property="Id" column="Product_Id"/>
<result property="Description" column="Product_Description"/>
</resultMap>
</resultMaps>
<statements>
<select id="GetProduct" parameterMap="productParam" cacheModel="productCache">
select * from Products where Product_Id = ?
</select>
</statements>
<!--maps the SQL "?" to the product Id property-->
<parameterMaps>
<parameterMap id="productParam" class="Product">
<parameter property="Id"/>
</parameterMap>
<parameterMaps>
</sqlMap>
Mapped Statements
Mapped Statements can hold any SQL statement and can use Parameter Maps and Result Maps for input and output. (A stored procedure is a specialized form of a statement.)
Statement element syntax
<statement id="statement.name"
[parameterMap="parameterMap.name"]
[parameterClass="alias"]
[resultMap="resultMap.name"]
[resultClass="class.name|alias"]
[listClass="class.name|alias"]
[cacheModel="cache.name"]
>
select * from Products where Product_Id = [?|#propertyName#]
order by [$simpleDynamic$]
</statement>
[]中的参数是可选项。<statement id="statement.name"
[parameterMap="parameterMap.name"]
[parameterClass="alias"]
[resultMap="resultMap.name"]
[resultClass="class.name|alias"]
[listClass="class.name|alias"]
[cacheModel="cache.name"]
>
select * from Products where Product_Id = [?|#propertyName#]
order by [$simpleDynamic$]
</statement>
下面是6种Statement-type 元素
Statement Element | Attributes | Child Elements | Methods |
---|---|---|---|
<statement> |
id parameterClass resultClass listClass parameterMap resultMap cacheModel |
All dynamic elements |
Insert Update Delete All query methods |
<insert> |
id parameterClass parameterMap |
All dynamic elements <selectKey> <generate> |
Insert Update Delete |
<update> |
id parameterClass parameterMap extends |
All dynamic elements <generate> |
Insert Update Delete |
<delete> |
id parameterClass parameterMap extends |
All dynamic elements <generate> |
Insert Update Delete |
<select> |
id parameterClass resultClass listClass parameterMap resultMap cacheModel extends |
All dynamic elements <generate> |
All query methods |
<procedure> |
id parameterMap resultClass resultMap cacheModel |
All dynamic elements |
Insert Update Delete All query methods |