Topic 13
■■■
Transaction Management
Transactions are one of the most critical parts of building a reliable enterprise application. The most
common type of transaction is a database operation. In a typical database update operation, a database
transaction begins, data is updated, and then the transaction is committed or rolled back, depending
on the result of the database operation. However, in many cases, depending on the application
requirements and the backend resources that the application needs to interact with (such as an
RDBMS, message-oriented middleware, an ERP system, and so on), transaction management can be
much more complicated.
In the early days of Java application development (after JDBC was created but before the JEE
standard or an application framework like Spring was available), developers programmatically controlled
and managed transactions within application code. When JEE and, more specifically, the EJB standard
became available, developers were able to use container-managed transactions (CMTs) to manage
transactions in a declarative way. But the complicated transaction declaration in the EJB deployment
descriptor was difficult to maintain and introduced unnecessary complexity for transaction processing.
Some developers favored having more control over the transaction and chose bean-managed
transactions (BMT) to manage transactions in a programmatic way. However, the complexity of
programming with the Java Transaction API (JTA) also hindered developers' productivity.
As discussed in Chapters 6 and 7 on AOP, transaction management is a cross-cutting concern and
should not be coded within the business logic. The most appropriate way to implement transaction
management is to allow developers to define transaction requirements in a declarative way and have
frameworks such as Spring, JEE, or AOP weave in the transaction processing logic on our behalf. In this
chapter, we will discuss how Spring helps simplify the implementation of transaction-processing logic.
Spring provides support for both declarative and programmatic transaction management.
Spring offers excellent support for declarative transactions, which means you do not need to clutter
your business logic with transaction management code. All you have to do is declare those methods
(within classes or which layers) that must participate in a transaction, together with the details of
transaction configuration details, and Spring will take care of handling the transaction management. To
be more specific, in this chapter we look at the following:
Spring transaction abstraction layer: We discuss the base components of Spring
·
transaction abstraction classes and explain how to use these classes to control the
properties of the transactions.
Declarative transaction management: We show you how to use Spring to
·
implement declarative transactional management using just plain Java objects.
We offer examples for declarative transaction management using the XML
configuration files as well as Java annotations.
Programmatic transaction management: Even though programmatic transaction
·
management is not used very often, we explain how to use the Spring-provided
TransactionTemplate class, which gives you full control over the transaction
management code.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home