Java Reference
In-Depth Information
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 API s to pro-
vide a simple and common API for application developers. This pattern is very
powerful, and is not unique to i BATIS , as other projects have created DAO imple-
mentations that you can use with i BATIS .
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 pat-
tern can make it easier to use different database access technologies with i BATIS
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
Listing 11.1 shows the XML fragment that we need in the Dao.xml file to describe
the DAO context that will use Hibernate.
Listing 11.1
XML fragment defining a DAO context using Hibernate
<context id="hibernate">
<transactionManager type="HIBERNATE">
<property name="hibernate.connection.driver_class"
value="org.postgresql.Driver" />
<property name="hibernate.connection.url"
value="jdbc:postgresql:ibatisdemo" />
<property name="hibernate.connection.username"
value="ibatis" />
<property name="hibernate.connection.password"
value="ibatis" />
<property name="hibernate.connection.pool_size"
value="5" />
Search WWH ::




Custom Search