Batch 処理
ibatis
public void executeUpdate(final List<bookinfobean> list) throws DataAccessException {
getSqlMapClientTemplate().execute(new SqlMapClientCallback() {
public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {
executor.startBatch();
Iterator<BookInfoBean> it = list.iterator();
while (it.hasNext()) {
BookInfoBean bean = it.next();
executor.update("kr.lancerme.insertBookInfo", bean);
}
executor.executeBatch();
return null;
}
});
}
mybatis
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="cacheEnabled" value="true" />
<setting name="lazyLoadingEnabled" value="false" />
<setting name="multipleResultSetsEnabled" value="true" />
<setting name="useColumnLabel" value="true" />
<setting name="useGeneratedKeys" value="false" />
<setting name="defaultExecutorType" value="BATCH" />
<setting name="defaultStatementTimeout" value="25000" />
</settings>
<typeHandlers>
<typeHandler javaType="java.sql.Timestamp" handler="org.apache.ibatis.type.DateTypeHandler"/>
<typeHandler javaType="java.sql.Time" handler="org.apache.ibatis.type.DateTypeHandler"/>
<typeHandler javaType="java.sql.Date" handler="org.apache.ibatis.type.DateTypeHandler"/>
</typeHandlers>
</configuration>
public Object insertBookInfo (BookInfoBean bean) {
return bookInfoDao.insertBookInfo (bean);
}
public void insertBookInfos(List<BookInfoBean> list) {
Iterator<BookInfoBean> it = list.iterator();
while (it.hasNext()) {
bookInfoDao.insertBookInfo(it.next());
}
}
public void insertBookInfo(BookInfoBean[] beans) {
for (int i = 0; i < beans.length; i++) {
bookInfoDao.insertBookInfo(beans[i]);
}
}
ifでjavaのclass methodを使う方法
<if test="@org.springframework.util.StringUtils@isEmpty(id)">
AND id = #{id}
</if>
<if test="@org.springframework.util.StringUtils@isEmpty(id) == false">
AND id = #{id}
</if>
<if test="@org.apache.commons.lang3.StringUtils@isNotEmpty(id)">
AND id = #{id}
</if>
migration from ibatis
isPropertyAvailable -> if
<isPropertyAvailable property="displayPriceType" >
<![CDATA[
desc
]]>
</isPropertyAvailable>
<if test="displayPriceType!=null">
<![CDATA[
desc
]]>
</if>
iterate -> foreach
<dynamic prepend="IN">
<iterate property="appAdminIDs" open="(" close=")" conjunction=",">
#appAdminIDs[]#
</iterate>
</dynamic>
IN
<foreach item="item" index="index" collection="appAdminIDs" open="(" separator="," close=")">
#{item}
</foreach>
References