Java Reference
In-Depth Information
Listing 10.4 A dao.xml using a <properties /> element to insert implementation
information
<?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>
<properties resource="config.properties"/>
<context>
<transactionManager type="JDBC">
<property name="DataSource" value="SIMPLE"/>
<property name="JDBC.Driver" value="${jdbcDriver}" />
<property name="JDBC.ConnectionURL"
value="${jdbcUrl}" />
<property name="JDBC.Username" value="${jdbcUser}" />
<property name="JDBC.Password"
value="${jdbcPassword}" />
<property name="JDBC.DefaultAutoCommit"
value="${jdbcAutoCommit}" />
</transactionManager>
<dao interface="com.company.system.dao.AccountDao"
implementation="${impl}.AccountDaoImpl"/>
</context>
</daoConfig>
In listing 10.4, all of the server settings and the data access implementation are
external to the main configuration file.
10.3.3
Runtime configuration changes
As if this were not enough flexibility, the DAO manager can also be built with
properties that are determined at runtime and passed in when the DAO manager
is created.
A second form of the code we saw in section 10.1.1 to pass in runtime configu-
ration information might provide a method like listing 10.5.
Listing 10.5
Creating a DaoManager with runtime properties
public static DaoManager getDaoManager(Properties props)
{
String daoXml = "/org/apache/mapper2/examples/Dao.xml";
Reader reader;
DaoManager localDaoManager;
try {
Search WWH ::




Custom Search