Java Reference
In-Depth Information
Beyond the simple database operations we have looked at in the last two chapters,
i BATIS can be used to perform much more advanced tasks. In this chapter, we will
examine techniques that you can use to reduce the amount of code you need to
write, and you will learn ways to improve performance and minimize the footprint
of your application.
6.1 Using XML with iBATIS
Sometimes, you may need to work with XML -based data. The i BATIS framework
will allow you to use XML when passing parameters into a query, and also for
returning results from them. In both cases, it probably does not add much value
to use XML where you do not need to—using a plain old Java object ( POJO )
instead is much more efficient in most cases.
In addition, it is possible that this feature will be dropped in the next major
release for a couple of reasons. One of those reasons will become apparent as we
look at the functionality. The other reason is that it just doesn't fit with the philos-
ophy of the i BATIS framework, which is to make mapping queries to objects easier.
We will take a look at this feature, in case you have a system where you have to
use it; but we will also show you some ways to transition away from it so that if it
does disappear, you won't be left hanging high and dry looking for a way to make
your application work.
6.1.1
XML parameters
Using XML to pass parameters into a mapped statement can be accomplished with
either a String value or a DOM object, both of which use the exact same structure.
The structure of parameters is not exactly XML , but it is a well-formed XML
fragment. In this structure, a parameter element wraps the values to be passed in
and the values themselves are wrapped in elements, which provide the names.
For example:
<parameter><accountId>3</accountId></parameter>
Here, the mapped statement would get a single parameter named accountId , with
a value of 3. The following example uses an XML string to pass a parameter into a
mapped statement:
<select id="getByXmlId" resultClass="Account" parameterClass="xml">
select
accountId,
username,
password,
Search WWH ::




Custom Search