Java Reference
In-Depth Information
9.3 Implementing a POJO transaction script
Once you have identified the transaction scripts and determined their parameters
and return types, the next step in the process is to implement them using a test-
driven approach. The PlaceOrderTransactionScripts interface is implemented
by PlaceOrderTransactionScriptsImpl , which is shown in figure 9.4. PlaceOrder-
TransactionScriptsImpl is a POJO and uses Spring AOP for JDBC connection and
transaction management. Its constructors take the DAO s that it calls to access the
database as parameters. This enables Spring to supply the DAO s to the PlaceOr-
derTransactionScriptsImpl by using constructor injection.
To understand how to implement a transaction script, let's take an in-depth
look at one of them: the updateDeliveryInfo() transaction script. From analyz-
ing the use case, we determined it has the following responsibilities. It must cre-
ate the pending order if required, validate the delivery information, and store it
in the pending order. In addition, updateDeliveryInfo() must return an Update-
DeliveryInfoResult containing a successful status code, PendingOrderDTO , and
the list of available restaurants. As before, we will start by writing a test and using
it to drive the design.
9.3.1
Writing a test for the transaction script
The updateDeliveryInfo() transaction script can be invoked with many different
combinations of arguments. For example, the pending order ID can be null ,
which indicates a new pending order, or it can identify an existing pending order.
Spring TransactionInterceptor
<<interface>>
PlaceOrderTransactionScripts
PlaceOrderTransactionScriptsImpl
<<transaction scripts>>
updateDeliveryInfo()
updateRestaurant()
updateQuantities()
...
Figure 9.4
Transaction Script-based
business tier design
<<interface>>
RestaurantDAO
<<interface>>
PendingOrderDAO
 
 
 
 
Search WWH ::




Custom Search