Java Reference
In-Depth Information
pattern is the best choice. Let's investigate when it makes sense to use the Transac-
tion Script pattern and how to implement it using POJO s, iBATIS , and Spring.
9.1.1
Applying the Transaction Script pattern
The Transaction Script pattern organizes the business logic into a set of transac-
tion scripts, each of which is a method that accesses the database and performs
computations. Each transaction script handles one request from the presentation
tier. They are usually grouped together to form a transaction script class that
implements the business logic for one or more use cases. Using the Transaction
Script pattern is very straightforward because you do not have to worry about
identifying classes and assigning responsibilities as you do when developing a
Domain Model pattern-based design. For each request, you simply write one
transaction script.
The simplicity of this pattern is also a major limitation. Unlike the Domain
Model pattern, which creates a design in which classes typically have both data
and behavior, the Transaction Script pattern creates a design in which classes have
either data or behavior. The transaction script classes have behavior but no data
and manipulate dumb data objects that have data but no behavior. As a result, the
business logic is concentrated in a relatively small number of transaction scripts,
which can make it difficult to understand and maintain, especially if it is complex.
A transaction script-based design consists of the transaction scripts; the DTO s,
which are the dumb data objects; and the DAO s, which are used by the transaction
scripts to access the database. Let's look briefly at each part of the design and then
explore an example.
Implementing transaction script classes
A transaction script class consists of a set of transaction script methods. It is almost
always a stateless class, which means that it does not store any state that relates to
its caller. In a traditional J2EE architecture, the transaction script class is imple-
mented as a stateless session bean. When using lightweight technologies such as
Spring, the transaction script class is a POJO that uses a Spring AOP interceptor to
manage transactions.
Using DTOs
A transaction script manipulates dumb data objects, also known as DTO s, that con-
tain data from the database and that are returned by the transaction script to the
presentation tier. A typical transaction script queries the database and creates one
or more DTO s that contain the results of the query. The transaction script might
then perform computations, change the DTO s, and update the database. It would
 
 
 
Search WWH ::




Custom Search