Java Reference
In-Depth Information
<select id="getMapListByExample" resultClass="hashmap">
<include refid="getByExample" />
</select>
Mapped statement
for a map
F
<select id="getIdDescriptionListByExample"
resultClass="IdDescription">
select
accountId as id,
COALESCE(firstname, '(no first name)')
|| ' '
|| COALESCE(lastname, '(no last name)')
as description
from Account
<include refid="whereByExample" />
</select>
Mapped statement
for a name/value list
G
<select id="getById" resultClass="Account">
select
<include refid="allFields" />
from Account
where accountId = #value#
</select>
</sqlMap>
b
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
C
D
E
and another to get
F
G
a List of Maps
. In the
getIdDescriptionListByExample
mapped statement
, we
use the complex
WHERE
clause again to get a List of a different type of beans.
10.4.5
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).















