Java Reference
In-Depth Information
bbb
AND
bbbbb
r.restaurant_id = o.restaurant_id
bbb
AND l.order_id = o.order_id
ORDER BY o.order_id ASC
This statement retrieves the order information from the
PLACED_ORDER
,
RES-
TAURANT
, and
PLACED_ORDER_LINE_ITEM
tables. The
OrderDAO
stores the ver-
sion in the
OrderDTO
, which is returned to the
sendOrders()
transaction script.
The
OrderDAO
updates the
Order
using the following
SQL
statement:
UPDATE PLACED_ORDER
SET VERSION = VERSION + 1,
STATUS = 'SENT', MESSAGE_ID = ?, SENT_TIME = ?
WHERE ORDER_ID = ? AND VERSION = ?
This
UPDATE
statement changes the state of a specific order to
SENT
and updates
the
MESSAGE_ID
,
SENT_TIME
, and
VERSION
columns only if the
VERSION
column is
unchanged since it was read.
The
markOrderAsSent()
method, which executes the
UPDATE
statement, checks
the count of the rows updated and throws an exception if it is zero. It executes the
UPDATE
statement by calling
SqlMapClientTemplate.update()
:
public class OrderDAOIBatisImpl extends SqlMapClientDaoSupport
implements OrderDAO {
public OrderDAOIBatisImpl(
SqlMapClientTemplate sqlMapClientTemplate) {
setSqlMapClientTemplate(sqlMapClientTemplate);
}
void markOrdersAsSent(List orders, …) {
…
int rowCount = getSqlMapClientTemplate()
.update("markOrderAsSent", …);
if (rowCount == 0)
throw new OptimisticLockingFailureException();
…
}
…
If the
rowCount
is zero, this method throws an
OptimisticLockingFailureExcep-
tion
, which is a Spring framework data access exception that is described in more
detail in section 12.2.5. In section 12.4, we describe how the application can catch
this exception and retry the transaction.
Search WWH ::
Custom Search