Overview
The iBATIS Data Mapper provides a simple and flexible means of moving data between your Java and .NET objects and a relational database. The Data Mapper framework helps to significantly reduce the amount of Java and .NET code that is normally needed to access a relational database. This framework maps classes to SQL statements using a simple XML descriptor.
Caching improves performance by avoiding making unnecessary trips to the database. To support caching, iBATIS provides a pluggable caching system. Cacheonix offers a plugin for iBatis. Configuring Cacheonix for iBatis includes the following steps:
- Configuring iBatis cache model
- Setting iBatis mapped statement to use cache model
- Configuring Cacheonix cache
The following sections discuss configuring Cacheonix plugin for iBatis in detail.
Configuring Cache Model
iBatis cache model is defined by <cacheModel> element that you add to your DataMapper configuration file. The name of Cacheonix implementation for iBatis cache model is cacheonix.plugin.ibatis.v230.CacheonixCacheController .
In the example below product-cache defines a name the cache model that will be used in a mapped statement. cacheonix.plugin.ibatis.v230.CacheonixCacheController is Cacheonix implementation of iBatis cache. Property name cacheonix.cache.name is a name of the cache configuration in Cacheonix configuration file cacheonix-config.xml.
Example: Configuring iBatis Cache Model to Use Cacheonix Cache Controller
<cacheModel id="product-cache" implementation="cacheonix.plugin.ibatis.v230.CacheonixCacheController" readOnly="true" serialize="false"> <flushInterval hours="1"/> <flushOnExecute statement="insertProduct"/> <flushOnExecute statement="updateProduct"/> <flushOnExecute statement="deleteProduct"/> <property name="cacheonix.cache.name" value="com.example.Product"/> </cacheModel>
Setting Mapped Statement to Use Cache
Once the cache model is configured, you can specify the cache model to be used by a mapped statement:
<statement id="getProductList" cacheModel="product-cache">select * from PRODUCT where PRD_CAT_ID = #value#</statement>
Configuring Cacheonix Cache
Cacheonix delegates the rest of the cache configuration to Cacheonix configuration file cacheonix-config.xml.
Example: Configuring cacheonix-config.xml for iBatis
<cacheonix> <cluster address="192.168.123.172" port="8877" multicastAddress="224.0.1.2" multicastPort="9999"> <cache name="com.example.Product" maxSize="1000" policy="lru" expiration="1000" disk="no"/> <cache name="com.example.Invoice" maxSize="2000" policy="lru" expiration="1000" disk="no"/> </cluster> </cacheonix>
