Java Reference
In-Depth Information
These classes work together as follows. When the presentation tier calls the Place-
OrderFacade , the Spring TransactionInterceptor begins a transaction and opens
a persistence framework connection for use by the repositories. The PlaceOrder-
FacadeImpl invokes the domain model classes to validate the input and perform
computations. When the PlaceOrderFacade returns, the TransactionInterceptor
closes the persistence framework connection and commits the transaction.
In section 7.3 we will dive into details of this design. But first, let's review when
it is appropriate to use a POJO façade and its benefits and drawbacks.
7.1.2
Benefits of a POJO façade
A POJO façade has several benefits. Let's look at each one in turn.
Faster and easier development
It is a lot easier and faster to develop and test business logic that is encapsulated
with a POJO façade. Unlike an EJB façade, the POJO façade can be developed and
tested outside of the application server, and there is no need to develop and main-
tain DTO s for the domain objects.
Potentially eliminates need to use an EJB container
Another benefit of using POJO façades instead of EJB façades is that it can some-
times remove the requirement for the application to use EJB s. In many applica-
tions EJB s are only used to encapsulate the business logic. If the EJB session
façades are replaced with POJO façades, then the application often no longer
needs to use EJB s and can be deployed in a cheaper and simpler web container.
Simplified presentation tier
The Exposed Domain Model pattern, which is described in the next chapter, uses a
servlet filter to manage persistence framework connections. In comparison, when
using a POJO façade all transaction management and database access happens
within the façade and the Spring-supplied interceptors. The presentation tier is
completely unaware of those mechanisms.
Consistent view of the database
Because each call to the façade consists of a single database transaction, the appli-
cation can have a consistent view of the database by using the appropriate transac-
tion isolation level (see chapter 12). In comparison, the Exposed Domain Model
pattern potentially uses multiple database transactions per request and cannot
obtain a consistent view of the database.
 
 
 
 
 
 
Search WWH ::




Custom Search