Spring SqlMapClientTemplate does not expose directly the batch
capabilities from Ibatis. Looks like trying to use to it directly from
the underlying SqlMapClient (and outside of Spring control) is not
working.  Anyway, Spring still let you access the underlying Ibatis
executor which can be used to batch queries. Syntax is a little more
complex, but it worked for me:
 
import com.ibatis.sqlmap.client.SqlMapExecutor;
import org.springframework.orm.ibatis.SqlMapClientCallback;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
 
    public void batchQueries(final Map propertyMap) {
 
        /**
         * Use an inner class to execute the different insert in a
batch mode.
         */
        Integer count = (Integer) getSqlMapClientTemplate().execute(new
SqlMapClientCallback() {
                public Object doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
                    executor.startBatch();
                    ....
                    //Run insert and return the next sequence value
                    Long key= (Long) executor.insert("myFirstInsert",
parameter);

                    executor.insert("mySecondInsert", otherParameter);
                   .....
 
                    return new Integer(executor.executeBatch());
                }
            });
}


Hope that helps,

Aymeric.

>>> [EMAIL PROTECTED] 2/11/2005 10:06:27 AM >>>

YAY!!!!!Yes!! SqlMapClient I am using is actually from
org.springframework.orm.ibatis.SqlMapClientFactoryBean. Thanks Aymeric.
Q   -----Original Message-----
From: Aymeric Alibert [mailto:[EMAIL PROTECTED] 
Sent: Friday, February 11, 2005 9:59 AM
To: ibatis-user-java@incubator.apache.org 
Subject: Re: batch problem - skips the first insert? Are you using
Ibatis from Spring? I had something similar when trying to manually
start and stop transaction from a SqlMapClient. If that's the case, let
me know,  I have a workaround somewhere.
 
Aymeric.

>>> [EMAIL PROTECTED] 2/8/2005 5:13:02 PM >>>
Hi, 1.     startBatch() 2.     do 10 inserts using for-loop. 3.    
endBatch.  When I do the above, it always skips the first one and
inserts the rest nine of them.When I only do one insert, it does not
insert.When I do two inserts, it only inserts the last one. Does this
ring anyone's mind? Thank you all! Kyunam


Reply via email to