ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject RE: Batch inserts and transactions with Spring
Date Fri, 26 May 2006 13:15:02 GMT
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<META http-equiv=Content-Type content="text/html; charset=us-ascii" 
format="flowed" plain; text Content-Type: 7bit Content-Transfer-Encoding:>
<META content="MSHTML 6.00.2900.2873" name=GENERATOR></HEAD>
<DIV dir=ltr align=left><FONT color=#0000ff size=2><SPAN 
class=704441013-26052006>If you are using Spring then you should be leverage the 
power of letting Spring manage the transactions for you with an interceptor. 
This is relatively painless to configure and you do not have to do anything in 
your code pertaining to transactions. Look&nbsp;in the examples directory of 
Spring and pay attention to the petstore sample app for configuring your 
transitions. This app is using iBatis for the persistence layer&nbsp;and has 
good examples for both local transactions as well as distributed 
<DIV class=OutlookMessageHeader lang=en-us dir=ltr align=left>
<HR tabIndex=-1>
<FONT face=Tahoma size=2><B>From:</B> John Moore &lt;john@jmsd.co.uk&gt;

[mailto:John Moore &lt;john@jmsd.co.uk&gt;] <BR><B>Sent:</B> Friday,
May 26, 
2006 3:07 AM<BR><B>To:</B> user-java@ibatis.apache.org<BR><B>Subject:</B>
inserts and transactions with Spring<BR></FONT><BR></DIV>
<DIV></DIV>I'm using Ibatis with Spring. I have batch inserts working after a

<BR>fashion with the following method from my dao class which extends 
<BR>SqlMapClientDaoSupport: <BR><BR><BR>public void insertWidgets(final

List<WIDGET> list) { <BR><BR>getSqlMapClientTemplate().execute(new 
SqlMapClientCallback() { <BR>public Object doInSqlMapClient(SqlMapExecutor 
executor) <BR>throws SQLException { <BR>executor.startBatch(); <BR>for (Widget

widget:list) { <BR>executor.insert("insertWidget", widget); <BR>} 
<BR>executor.executeBatch(); <BR>return null; <BR>} <BR>}); <BR><BR>}

<BR><BR><BR>What I want to do is to wrap that in a transaction now. I.e.,
the <BR>transaction with the batch, commit it after the batch has executed. 
<BR>SqlMapExecutor doesn't have a startTransaction method, though. 
<BR><BR>Actually, I could do with understanding a little more just what Ibatis

<BR>is doing here in terms of JDBC equivalent. Perhaps it's setting 
<BR>autocommit to false for the connection at the beginning of the batch 
<BR>anyway? Any pointers would be useful, thanks! <BR><BR>JM <BR><BR><BR>--

<BR>============================================== <BR>John Moore - Norwich, UK

- john@jmsd.co.uk <BR>============================================== 

View raw message