Java Reference
In-Depth Information
read consistency can use a serializable isolation level. To determine the right
approach, you need to examine the requirements of each use case.
Now that we have gotten an overview of fully isolated transactions, pessimistic
locking, and optimistic locking, let's look at how to use them to handle concur-
rent updates in an enterprise application.
12.2 Handling concurrent updates
in a JDBC/iBATIS application
The details of how an application uses each of the three concurrency mechanisms
described in the previous section depends on which database access mechanism it
uses. We will start by looking at how to use those concurrency options in an appli-
cation that executes
SQL
statements directly using either
JDBC
or i
BATIS
. This will
enable you to learn how the different concurrency mechanisms work at the
SQL
level, which later sections will build on as they describe how
JDO
and Hibernate
applications use them.
We'll use the business logic for the Send Orders to Restaurant use case as an
example. First we provide an overview of a design for the business logic that is
based on the Transaction Script
pattern
and uses an i
BATIS/JDBC
-based
DAO
to
access the database. After that, you'll learn the details of how each of the concur-
rency mechanisms is used.
12.2.1
Design overview
The Send Orders to Restaurant use case describes how orders are sent to a restau-
rant for preparation:
X
minutes before the scheduled delivery time, the system sends (emails or
faxes) a placed order to the restaurant.
This use case is driven by a scheduler and has no UI. Figure 12.3 shows the trans-
action script version of the business logic for this use case. It consists of a transaction
script that finds the orders to send, sends them, and then changes each order's sta-
tus to indicate that it was sent. It uses i
BATIS
to execute
SQL
statements that find and
update the orders and uses Spring to manage transactions and connections. The
transaction script is wrapped with a Spring
TransactionInterceptor
, which man-
ages transactions and a
JDBC
connection. This design works for serializable trans-
actions, optimistic locking, and pessimistic locking, with only minor changes to the
Search WWH ::
Custom Search