Java Reference
In-Depth Information
Person
SELECT
ID as identifier,
FIRST_NAME as firstName,
LAST_NAME as lastName
MIDDLE_NAME as middleName,
HAIR_COLOR as hairColor,
HEIGHT as height,
WEIGHT as weight
FROM PERSON
WHERE ID = #identifier#
Person
identifier
firstName
lastName
middleName
hairColor
height
weight
ID
FIRST_NAME
LAST_NAME
MIDDLE_NAME
HAIR_COLOR
HEIGHT
WEIGHT
Figure 2.2
iBATIS SQL mapping
As you can see in figure 2.2, the mapping layer of i
BATIS
is actual
SQL
. i
BATIS
lets
you write your
SQL
. i
BATIS
takes care of mapping the parameters and results
between the class properties and the columns of the database table. For this rea-
son, and to eliminate any confusion around the various mapping approaches, the
i
BATIS
team often refers to the data mapper as a
SQL
mapper.
2.1 Mapping SQL
Any
SQL
statement can be viewed as a set of
inputs and outputs. The inputs are the param-
eters, typically found in the
WHERE
clause of the
SQL
statement. The outputs are the columns
found in the
SELECT
clause. Figure 2.3 depicts
this idea.
The advantage to this approach is that the
SQL
statement leaves a great deal of flexibility
in the hands of the developer. One can easily
manipulate the data to match the object
model without changing the underlying table
design. Furthermore, developers can actually introduce multiple tables or results
from built-in database functions or stored procedures. The full power of
SQL
is at
their fingertips.
i
BATIS
maps the inputs and outputs of the statement using a simple
XML
descriptor file. Listing 2.1 shows an example of this.
Output
Output
SELECT FIRST_NAME, LAST_NAME
FROM EMPLOYEE
WHERE EMPLOYEE_NUMBER=1234
Input
Figure 2.3 SQL can be viewed as inputs
and outputs.


















