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
"-// DAO Configuration 2.0//EN"
<context id="example">
<transactionManager type="SQLMAP">
The DAO context
The transaction
The one and only DAO defined
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 .
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).
Search WWH ::

Custom Search