Java Reference
In-Depth Information
which often requires code that is messy and difficult to maintain. In addition, you
often need to optimize SQL statements to achieve acceptable performance.
One good solution to this problem is to use the i BATIS framework, which pro-
vides a mechanism for generating queries dynamically that requires only a few
lines of Java code. The i BATIS framework also keeps the intact SQL statement in
an XML file, which makes it easier to test and change. In addition, the framework
gives you control over how the result set is processed. You can either execute a
query that uses ROWNUM or you can choose rows from the result set. Overall, imple-
menting a DAO for a search screen using i BATIS is very straightforward except for,
of course, all the usual issues of maintaining handwritten SQL .
Using JDO or Hibernate avoids the problems associated with using SQL
directly, but implementing some search screen queries efficiently can be difficult.
Although JDO and Hibernate provide optimizations such as eager loading, you
are not always able to get good performance because you cannot use database-spe-
cific SQL features such as optimizer hints. Another issue is that while Hibernate
and some JDO implementations such as Kodo JDO let you pick the most efficient
way to select a page from the result set, others might not. Furthermore, unless you
use Hibernate criteria queries you have to write messy query-generation code.
JDO and Hibernate also support native SQL queries, which can use database-
specific features such as optimizer hints to improve performance. But, even when
using SQL queries, you still need to have control over the processing of the result
set. Moreover, both persistence frameworks lack support for generating SQL que-
ries, and so you have to write some potentially messy code. Sometimes, a better
approach is to use i BATIS to generate and execute the SQL queries.
In the next chapter, you will learn how to handle database concurrency issues.
Search WWH ::




Custom Search