will make sure it doesn't hang around longer than the 24 hours indicated by the
<flushInterval> tag. This will help to keep things relatively fresh in our applica-
tion. Setting the size of our LRU will allow one hundred different results to be
stored in the productCache cache model. If we receive high traffic on our site, we
are sure to retain good performance with at least a daily mandatory flush.
Next comes our select statement. We provide the id of the select with some-
thing that represents what the SQL actually does. Don't be afraid of verbosity; ver-
bosity clarifies the purpose of the SQL that is contained in the body of the select.
In this case we provide an id of getProductListByCategory . There is no mistaking
that the SQL contained within will return a list based on the category provided.
Taking advantage of the typeAlias that we defined, we will specify the select
statement's resultClass as product. Note that even though we are retrieving a list
by running this select in our data access object, we do not specify a List as our
return result. The reason is that this same select could be used to return a single
Product object. This may seem absurd since we named it getProductListByCate-
gory , but there are situations where a select will be multipurpose and return a sin-
gle object or a list of objects.
The parameterClass for this select will use an alias of string (defined by
default). As you have probably guessed, this alias represents the String object. A
parameterClass attribute may also use a user-defined alias.
The final attribute that we take advantage of on our select is cacheModel ,
which references our previously defined productCache cache model. Specifying
cacheModel ensures that all category product lists that are queried will be
cached. This provides us with speedy performance and fewer unnecessary hits
on the database.
The next step is to fill the body of the select tag with our SQL . Our select state-
ment will retrieve a result set of records from the Product table and map them
into a list of product objects as specified by our select tag configuration. All of the
fields will map smoothly to properties in the Product object because the column
names correspond with the property names.
Once we have finished configuring our sql-map-config.xml , our alias, our
cacheModel , and our select, we are ready to use the i BATIS API in Java code. We
will take advantage of the SQLMap by writing an implementation to our Product-
Interface and implementation
It's a good practice to code against an interface when working between layers of an
application. In this case we are working between the service layer and the data access
Search WWH ::