Java Reference
In-Depth Information
<select id="getMapListByExample" resultClass="hashmap">
<include refid="getByExample" />
Mapped statement
for a map
<select id="getIdDescriptionListByExample"
accountId as id,
COALESCE(firstname, '(no first name)')
|| ' '
|| COALESCE(lastname, '(no last name)')
as description
from Account
<include refid="whereByExample" />
Mapped statement
for a name/value list
<select id="getById" resultClass="Account">
<include refid="allFields" />
from Account
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
, we
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).
Search WWH ::

Custom Search