Java Reference
In-Depth Information
and a POJO façade would be wrapped with a Spring TransactionInterceptor .
However, since this design does not have a façade, it must use another approach
to transaction management, which turns out to be a tricky problem.
There are two ways to manage transactions. One option is to manage transac-
tions in the presentation tier using a servlet filter. The other option is to manage
transactions using a Spring AOP interceptor around the domain model services.
Both approaches have their drawbacks, but as you will discover, using an AOP
interceptor is the less problematic of the two. In this section you will learn some of
the ugly details of how the transactions interact with the presentation tier and the
persistence framework.
8.3.1
Managing transactions in the presentation tier
When using this approach, a servlet filter begins the transaction, invokes the serv-
lets and JSP pages, and commits the transaction. Because Spring does not provide
such a filter, you must write your own. You could, for example, write a single cus-
tom filter that manages both transactions and connections. Alternatively, you
could implement a transaction management filter that works with Spring's
OpenSessionInViewFilter or OpenPersistenceManagerInViewFilter . Figure 8.5
shows how the various classes collaborate in a design that uses the latter approach.
Persistence
Tier
Presentation Tier
Business Tier
:Web
Container
doFilter ()
: Connection
Filter
:Transaction
Filter
: PlaceOrder
Service
: Persistence
Framework
:Servle t
:JSP
:PendingOrder
open()
doFilter ()
beginTxn ()
service ()
updateDeliveryInfo ()
<<forward>>
getDeliveryAddress ()
commitTxn()
close()
Figure 8.5
Managing transactions with a servlet filter
 
 
Search WWH ::




Custom Search