ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Tony Qian" <daqiqi...@aol.com>
Subject Atomic transaction in iBATIS
Date Mon, 06 Mar 2006 15:03:19 GMT
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <title></title>
</head>
<body>
<font size="2"><font face="Arial,sans-serif">All,<br>
<br>
I need an atomic transaction for inserting data to several tables.
iBATIS supports that. I looked at the jpetstore code. I found that
atomic transaction could be made at both service and DAO level. Here
are some jpetstore codes.<br>
<br>
<br>
in OrderService.java<br>
&nbsp; public void insertOrder(Order order) {<br>
&nbsp;&nbsp;&nbsp; try {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; // Get the next id within a separate transaction<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; order.setOrderId(getNextId("ordernum"));<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; daoManager.startTransaction();<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; itemDao.updateAllQuantitiesFromOrder(order);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; orderDao.insertOrder(order);<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; daoManager.commitTransaction();<br>
&nbsp;&nbsp;&nbsp; } finally {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; daoManager.endTransaction();<br>
&nbsp;&nbsp;&nbsp; }<br>
&nbsp; }<br>
<br>
in AccountSqlMapDao.java<br>
&nbsp; public void insertAccount(Account account) {<br>
&nbsp;&nbsp;&nbsp; update("insertAccount", account);&nbsp;&nbsp;&nbsp;&nbsp;
//&nbsp; <font color="#0000ff">btw,
why is update? should it be insert? it seems to me that actual action
is controlled by action id not by key word (update)</font><br>
&nbsp;&nbsp;&nbsp; update("insertProfile", account);<br>
&nbsp;&nbsp;&nbsp; update("insertSignon", account);<br>
&nbsp; }<br>
<br>
in AccountService.java<br>
&nbsp;public void insertAccount(Account account) {<br>
&nbsp;&nbsp;&nbsp; accountDao.insertAccount(account);<br>
&nbsp; }<br>
<br>
<br>
insertOrder is apparently an atomic transaction, which is enforced at
service level. My question is whether insertAccount is an atomic
transaction, i.e. what if </font></font><font size="2"  face="Arial,sans-serif"><font
face="Arial,sans-serif">"update("insertSignon",
account);" fails? Should we enforce it at DAO level (put three updates
between startTransaction and endTransaction)? or we can do same thing
as inserOrder, i.e. put "</font></font><font size="2"  face="Arial,sans-serif"><font
face="Arial,sans-serif">accountDao.insertAccount(account);"</font></font><font
 size="2" face="Arial,sans-serif"><font face="Arial,sans-serif">
between daoManager.startTransaction and daoManager.endTransaction.<br>
<br>
If we use Abator to generate the DAO code, it makes sense that atomic
transaction is enforced at service level. But from software
architecture point of view, atomic transaction should be pushed down to
DAO level. any suggestions?<br>
<br>
thanks,<br>
Tony<br>
</font></font>
</body>
</html>


Mime
View raw message