我在 mybatis 中的批处理语句超时。我想通过定期刷新语句来限制我发送到数据库的负载。在 iBATIS 中,我使用了回调,如下所示:
sqlMapClientTemplate.execute(new SqlMapClientCallback<Integer>() {
@Override
public Integer doInSqlMapClient(SqlMapExecutor executor)
throws SQLException {
executor.startBatch();
int tally = 0;
for (Foo foo: foos) {
executor.insert("FooSql.insertFoo",foo.getData());
/* executes batch when > MAX_TALLY */
tally = BatchHelper.updateTallyOnMod(executor, tally);
}
return executor.executeBatch();
}
});
在mybatis中有没有更好的方法来做到这一点?还是我需要用 SqlSessionCallback 做同样的事情?这感觉很麻烦。我真正想做的是配置项目以刷新每 N 个批处理语句。