Java Reference
In-Depth Information
c.get(Calendar.DAY_OF_WEEK);
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
Map parameters = new HashMap();
parameters.put("zipCode",
deliveryAddress.getZip());
parameters.put("day",
new Integer(dayOfWeek));
parameters.put("hour",
new Integer(hour));
parameters.put("minute",
new Integer(minute));
C Creates
parameters
ExecuteNamedQueryWithMapCallback
callback =
new ExecuteNamedQueryWithMapCallback(
Restaurant.class,
"Restaurant.findAvailableRestaurants", parameters);
return (List)
getJdoTemplate().execute(callback);
}
D Creates
callback
E Executes
callback
JDORestaurantRepositoryImpl implements RestaurantRepository and
extends JdoDaoSupport , which is a Spring-provided support class that includes
convenience methods such as setJdoTemplate() and getJdoTemplate() . Let's
look at the details:
The constructor takes a JdoTemplate as a parameter and calls setJdoTem-
plate() .
The findRestaurants() method uses a Calendar to get the day of week, hour,
and minute from the delivery time and then creates a Map containing the query
parameters.
B
C
D
The findRestaurants() method instantiates an ExecuteNamedQueryWithMap-
Callback object, passing the name of the query, the restaurant class, and the
query parameters to its constructor.
It calls JdoTemplate.execute() to execute the ExecuteNamedQueryWithMap-
Callback object.
As you can see, implementing a repository using JDO is quite easy. The only com-
plication was the requirement to define a named JdoCallback class in order to
make the findAvailableRestaurants() method easier to test.
E
Search WWH ::




Custom Search