Java Reference
In-Depth Information
i
BATIS
to create
DAO
s. The
DaoManager
class is configured using the
Dao.xml
con-
figuration file.
The Dao.xml configuration file
To configure the
DaoManager
, you start with an
XML
configuration file, commonly
named
dao.xml
, which contains the information required to tell i
BATIS
how to
put the
DAO
together. Listing 10.1 contains an example of an
XML
configuration
file for a
SQL
Map-based
DAO
layer.
Listing 10.1
A simple dao.xml example
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE daoConfig
PUBLIC
"-//ibatis.apache.org//DTD DAO Configuration 2.0//EN"
"http://ibatis.apache.org/dtd/dao-2.dtd">
<daoConfig>
<context id="example">
<transactionManager type="SQLMAP">
<property
name="SqlMapConfigResource"
value="examples/SqlMapConfig.xml"/>
</transactionManager>
<dao
interface="examples.dao.AccountDao"
implementation="examples.dao.impl.AccountDao"/>
</context>
</daoConfig>
B
The DAO context
The transaction
manager
C
D
The one and only DAO defined
b
C
Listing 10.1 defines a
DAO
context named
example
that will use
SQL
Maps for
managing transactions (which were covered in chapter 7) and contains a single
Account
DAO
. In the next section, we'll look more closely at this file's contents,
so if you are not totally clear on it, that is
OK
.
D
Creating the DaoManager
Next, you need to create a
DaoManager
instance (which is analogous to
JDBC
's
Data-
Source
as the starting point of our data access layer) from which you can get the
DAO. Because building the
DAO
manager takes time, you will want to create an
instance of it and store it in a known location for later use. In section 10.4, we look
at some other ways to accomplish this; but for now, let's create a simple
DaoService
class that will create and store our
DaoManager
instance for us (see listing 10.2).

















