<select id="getMapListByExample" resultClass="hashmap">
<include refid="getByExample" />
for a map
accountId as id,
COALESCE(firstname, '(no first name)')
|| ' '
|| COALESCE(lastname, '(no last name)')
<include refid="whereByExample" />
for a name/value list
<select id="getById" resultClass="Account">
<include refid="allFields" />
where accountId = #value#
In this SQL map, we define a SQL fragment that list all of our fields. In this case,
the driver we are using messes with the case of the columns, so we used explicit col-
umn aliases to make sure they were right for our implicit property mapping.
Another SQL fragment is used to define a complex WHERE clause that we will use.
A third SQL fragment is used to pull the other two into a single fragment that we
then use in two select statements—one to get a List of beans
and another to get
a List of Maps
. In the getIdDescriptionListByExample mapped statement
use the complex WHERE clause again to get a List of a different type of beans.
Coding the DAO implementation
Finally, we get to the actual DAO implementation. As we mentioned before, to cre-
ate a DAO , we provide both an interface and an implementation. In this case, the
interface is defined as com.mycompany.system.dao.AccountDao , and the imple-
mentation is defined as com.mycompany.system.dao.sqlmap.AccountDaoImpl .
We saw the interface in section 10.3, so we will not repeat it here, but we will
take a look at the DAO implementation class (see listing 10.11).