一、SimpleExecutor
SimpleExecutor继承BaseExecutor
主要实现:doUpdate、doQuery、doFlushStatements
可以看代码主要是:
1、获取声明处理类:StatementHandler handler
2、获取声明类:stmt = prepareStatement(handler, ms.getStatementLog());
3、处理声明,执行SQL处理
二、ReuseExecutor
与SimpleExecutor不同的是:重用声明
private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException {
Statement stmt;
BoundSql boundSql = handler.getBoundSql();
String sql = boundSql.getSql();
if (hasStatementFor(sql)) {
stmt = getStatement(sql);
} else {
Connection connection = getConnection(statementLog);
stmt = handler.prepare(connection);
putStatement(sql, stmt);
}
handler.parameterize(stmt);
return stmt;
}
SQL语句一样的,就用同样的声明。不过这个好像也仅仅是同一个session内的有效。

本文详细解析了MyBatis的四大执行器:SimpleExecutor,用于简单执行SQL;ReuseExecutor,提高执行效率,重复使用PreparedStatement;BatchExecutor,批处理执行器,优化批量操作;CachingExecutor,缓存执行器,结合二级缓存,提高性能。
最低0.47元/天 解锁文章
3997

被折叠的 条评论
为什么被折叠?



