Chapter 11. Doing more with DAO

 

This chapter covers

  • More sample DAOs
  • Using Spring instead of IBATIS
  • Creating a DAO layer from scratch

As we saw in the previous chapter, the Data Access Object (DAO) pattern can be used to hide the unique implementation peculiarities of data-related APIs to provide a simple and common API for application developers. This pattern is very powerful, and is not unique to iBATIS, as other projects have created DAO implementations that you can use with iBATIS.

In this chapter, we look at a couple more SQL-based DAO implementations, as well as a couple of DAO implementations for other data sources (LDAP and web services). Then we explore the other options for DAO layers, including the Spring framework’s excellent DAO implementation. We also consider the implications of creating your own custom DAO layer.

11.1. Non-SQLMap DAO implementations

In the last chapter, we defined an interface for a DAO, and then built a SQL Map–based implementation of it. In the next two sections, we implement that interface again with both Hibernate and JDBC to show you how the DAO pattern can make it easier to use different database access technologies with iBATIS in your application.

11.1.1. A Hibernate DAO implementation

The Hibernate DAO implementation is very different from the SQL Map version, but because of the DAO interface, it is used in exactly the same manner as far as the application code that uses it is concerned.

Defining the DAO context

11.2. Using the DAO pattern with other data sources

11.3. Using the Spring DAO

11.4. Creating your own DAO layer

11.5. Summary