Java Reference
In-Depth Information
Listing 10.4 A dao.xml using a <properties /> element to insert implementation
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE daoConfig
"-// DAO Configuration 2.0//EN"
<properties resource=""/>
<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}" />
<dao interface=""
In listing 10.4, all of the server settings and the data access implementation are
external to the main configuration file.
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