Java Reference
In-Depth Information
queries the RESTAURANT table to find the available restaurants for the specified
delivery information, and a result map, which constructs RestaurantDTO from
each row of the result set.
Listing 9.4
Example iBATIS description file
<sqlMap>
<select id="findAvailableRestaurants"
parameterClass="java.util.Map"
resultMap="RestaurantResultMap">
SELECT r.*
FROM RESTAURANT r,
RESTAURANT_ZIPCODE rz,
RESTAURANT_TIME_RANGE tr
WHERE rz.ZIPCODE = #zipCode#
AND rz.RESTAURANT_ID = r.RESTAURANT_ID
AND tr.RESTAURANT_ID = r.RESTAURANT_ID
AND tr.DAY_OF_WEEK = #dayOfWeek#
</select>
<resultMap id="RestaurantResultMap"
class="net.chrisrichardson.foodToGo…details.RestaurantDTO">
<result property="restaurantId" column="RESTAURANT_ID"/>
<result property="name" column="NAME"/>
</resultMap>
</sqlMap>
The findAvailableRestaurants statement takes a Map as a parameter and uses its
entries in the WHERE clause of the SELECT statement. The #propertyName# notation
specifies the property to pass as a parameter.
RestaurantResultMap is used by the statement to construct the RestaurantDTO s
from the ResultSet . It maps the columns of the ResultSet returned by executing
the query to the properties of the RestaurantDTO . It constructs a RestaurantDTO
for each row in the result set.
In addition to mapping columns to properties, a result map can also set a
property to the result of executing a nested SELECT statement. An application can
use this feature to automatically retrieve one or more related objects. Later on
you will see some example code that uses this feature.
The i BATIS XML files that define the mapped statements along with an i BATIS
configuration file, which lists the map XML files, are deployed in either a class
 
 
Search WWH ::




Custom Search