Java Reference
In-Depth Information
The final element to set up is the
<sqlMap>
tag. This tag specifies the location
of the
SQLMap
configuration files. Whenever i
BATIS
is accessed for the first time,
the configured
SQLMap
s and their contents will be loaded into memory so that the
SQL
contents can be executed when needed.
14.8.2
SQLMap
We'll need to create a
SQLMap
file to house our
SQL
call for the category product
list. Within this file, which we'll name
Product.xml
, we will need to define a
typeAlias
for the
Product
object, a cache model to cache results, and a select
statement to house our select
SQL
(see listing 14.17).
Listing 14.17
SQLMap Product.xml SQL file
<sqlMap namespace="Product">
<typeAlias
alias="product"
type="org.apache.ibatis.jgamestore.domain.Product"/>
<cacheModel id="productCache" type="LRU">
<flushInterval hours="24"/>
<property name="size" value="100"/>
</cacheModel>
…
<select
id="getProductListByCategory" resultClass="product"
parameterClass="string" cacheModel="productCache">
SELECT
PRODUCTID,
NAME,
DESCRIPTION,
IMAGE,
CATEGORYID
FROM PRODUCT
WHERE CATEGORYID = #value#
</select>
…
</sqlMap>
The
typeAlias
will define an alias to the fully qualified class name of the
Product
domain object. Here, we'll specify the alias
product
. This saves us time typing the
fully qualified class name every time we refer to the
Product
domain object.
Our cache model is going to be quite simple. We'll configure its type as
LRU
and name it
productCache
. Since the
LRU
has the potential to last a long time, we








