Java Reference
In-Depth Information
chooses based on the outcome of calling
PlaceOrderService
. A
JSP
page generates
the response using the domain objects passed to them by the servlets.
Persistence framework connections are managed by Spring's
OpenSessionIn-
ViewFilter
and
OpenPersistenceManagerInViewFilter
classes. Transactions are
managed by Spring's
TransactionInterceptor
, which uses a persistence frame-
work-specific
PlatformTransactionManager
that invokes the persistence frame-
work's transaction management
API
s. The Hibernate version uses the
HibernateTransactionManager
, which calls the Hibernate Transaction
API
, and the
JDO
version uses
JdoTransactionManager
, which calls the
JDO
Transaction
API
.
TransactionRetryInterceptor
is a custom interceptor that automatically retries a
transaction that was rolled back because of a database concurrency failure and is
described in chapter 12.
In the rest of this section, let's look at the servlets, the
JSP
pages, and the con-
figuration of the
PlaceOrderService
Spring bean, which are the same regardless
of which persistence framework is used. After that, in the following sections we
describe the persistence framework-specific parts of the design.
8.4.1
Servlet design
The servlets handle
HTTP
requests from the user's browser, invoke the business
logic, and forward requests to a
JSP
page, which generates the response. To see how
these servlets work, let's look at
UpdateDeliveryInfoServlet
, which handles the sub-
mission of the delivery information form. Listing 8.1 shows the source code for
UpdateDeliveryInfoServlet
. The servlet gets the
PlaceOrderService
from the
Spring
WebApplicationContext
, a Spring bean factory for the web application.
WebApplicationContext
instantiates
PlaceOrderService
, injects any dependencies,
and wraps it with the
AOP
interceptors that manage transactions. The servlet obtains
a
RestaurantRepository
from the
WebApplicationContext
. The servlet calls
Place-
OrderService
and
RestaurantRepository
and forwards the request to a JSP page.
Listing 8.1
UpdateDeliveryInfoServlet
public class UpdateDeliveryInfoServlet extends HttpServlet {
private ServletConfig servletConfig;
private PlaceOrderService service;
bb
private RestaurantRepository restaurantRepository;
public void init(ServletConfig servletConfig)
throws ServletException {
super.init(servletConfig);
this.servletConfig = servletConfig;
Search WWH ::
Custom Search