您的位置:首页 > 其它

[转]Ibatis 批量添加修改删除-batch-insert-update-delete

2011-08-01 19:56 519 查看
public void batchUpdate(final String statementName, final List list) {

try {

if (list != null) {

this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {

public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {

executor.startBatch();

for (int i = 0, n = list.size(); i < n; i++) {

executor.update(statementName, list.get(i));

}

executor.executeBatch();

return null;

}

});

}

} catch (Exception e) {

if (log.isDebugEnabled()) {

e.printStackTrace();

log.debug("batchUpdate error: id [" + statementName + "], parameterObject ["+ list + "]. Cause: "+ e.getMessage());

}

}

}

public void batchInsert(final String statementName, final List list) {

try {

if (list != null) {

this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {

public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {

executor.startBatch();

for (int i = 0, n = list.size(); i < n; i++) {

executor.insert(statementName, list.get(i));

}

executor.executeBatch();

return null;

}

});

}

} catch (Exception e) {

if (log.isDebugEnabled()) {

e.printStackTrace();

log.debug("batchInsert error: id [" + statementName + "], parameterObject ["+ list + "]. Cause: "+ e.getMessage());

}

}

}

public void batchDelete(final String statementName, final List list) {

try {

if (list != null) {

this.getSqlMapClientTemplate().execute(new SqlMapClientCallback() {

public Object doInSqlMapClient(SqlMapExecutor executor) throws SQLException {

executor.startBatch();

for (int i = 0, n = list.size(); i < n; i++) {

executor.delete(statementName, list.get(i));

}

executor.executeBatch();

return null;

}

});

}

} catch (Exception e) {

if (log.isDebugEnabled()) {

e.printStackTrace();

log.debug("batchDelete error: id [" + statementName + "], parameterObject ["+ list + "]. Cause: "+ e.getMessage());

}

}

}转自:
http://blog.sina.com.cn/s/blog_60a393100100qqgt.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐