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 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 and has
good examples for both local transactions as well as distributed
transactions.
From: John Moore <[EMAIL PROTECTED]> [mailto:John Moore <[EMAIL PROTECTED]>]
Sent: Friday, May 26, 2006 3:07 AM
To: [email protected]
Subject: Batch inserts and transactions with Spring
fashion with the following method from my dao class which extends
SqlMapClientDaoSupport:
public void insertWidgets(final List
getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
executor.startBatch();
for (Widget widget:list) {
executor.insert("insertWidget", widget);
}
executor.executeBatch();
return null;
}
});
}
What I want to do is to wrap that in a transaction now. I.e., start the
transaction with the batch, commit it after the batch has executed.
SqlMapExecutor doesn't have a startTransaction method, though.
Actually, I could do with understanding a little more just what Ibatis
is doing here in terms of JDBC equivalent. Perhaps it's setting
autocommit to false for the connection at the beginning of the batch
anyway? Any pointers would be useful, thanks!
JM
--
==============================================
John Moore - Norwich, UK - [EMAIL PROTECTED]
==============================================
