Java Reference
In-Depth Information
reader = Resources.getResourceAsReader(daoXml);
localDaoManager =
DaoManagerBuilder.buildDaoManager(reader, props);
} catch (IOException e) {
throw new RuntimeException(
"Unable to create DAO manager.", e);
}
return localDaoManager;
}
The code in listing 10.5 would create a dynamically configured DAO manager
whose properties were passed in at runtime, instead of the shared one that would
normally be returned. While this would provide much more flexibility, it would
also require the user of this DAO manager to keep a copy of it around, instead of
creating it every time it was needed.
Next we'll look at how to use the i BATIS DAO framework, and create some DAO
classes that it will manage for us.
10.4 A SQL Map DAO implementation example
The DAO pattern is all about hiding the data access implementations behind
interfaces, but you still have to build the underlying implementations. In this sec-
tion, we build a SQL Map implementation of our DAO interface. You'll learn more
about how to use the DAO pattern in chapter 11, where we will implement this
same interface again using different data access technologies: one with Hiber-
nate, and one with straight JDBC .
Before we build the implementations, let's build our DAO interface (listing 10.6).
Listing 10.6
The interface for our DAO
package org.apache.mapper2.examples.chapter10.dao;
import org.apache.mapper2.examples.bean.Account;
import org.apache.mapper2.examples.bean.IdDescription;
import java.util.List;
import java.util.Map;
public interface AccountDao {
public void insert(Account account);
public void update(Account account);
public int delete(Account account);
Search WWH ::




Custom Search