Java Reference
In-Depth Information
public Account getById(Integer accountId) {
return (Account)queryForObject("Account.getById",
public Account getById(Account account) {
return getById(account.getAccountId());
On the surface, it does not look like there is really much there. In the class decla-
ration, we see that the class implements the AccountDao interface and extends the
SqlMapDaoTemplate class.
The SqlMapDaoTemplate class does much of the heavy lifting for us by providing
all of the components of the SQL Map API in one tidy little package. In addition, it
provides local methods that delegate calls to the SqlMapExecutor for us, so instead
of getting an instance of a SqlMapClient or a SqlMapExecutor , we can just call their
methods as though they were part of our DAO class.
While this may seem like a lot of work just to separate our DAO class from its
implementation, subsequent DAO classes only require the creation of the inter-
face, the creation of the implementation, the creation of the SQL Map, and finally
a one-line addition to the Dao.xml file. In the next chapter, we implement the
same DAO interface with Hibernate and JDBC directly. All three implementations
use the same API (the AccountDao interface), in spite of using radically different
underlying technologies for accessing the database.
10.5 Summary
In this chapter, we explained the rationale for using a data access layer in an appli-
cation, and how to set up the i BATIS DAO framework. We also looked at some of
the more advanced ways to configure the i BATIS DAO framework, and you saw
how to create a SQL Map-based DAO .
In the next chapter, we will look at how to set up other DAO types, as well as a
more advanced use of the i BATIS DAO framework by building a non- SQL DAO
implementation. We will also explore other ways to implement a DAO layer in
your application using the Spring framework, and look at some things you need
to consider when creating your own DAO layer from scratch.
Search WWH ::

Custom Search