Mybatis中的Executor(策略模式)
抽象统一接口:Excutor
适配器:BaseExecutor
不同的实现策略:SimpleExecutor | BatchExecutor | CachingExecutor | ClosedExecutor | ReuseExecutor
- SimpleExecutor 普通的执行器
- ReuseExecutor 重用预处理语句(PreparedStatement)
- BatchExecutor 重用预处理语句(PreparedStatement)且 执行批量更新
package org.apache.ibatis.executor;
import java.sql.SQLException;
import java.util.List;
import org.apache.ibatis.cache.CacheKey;
import org.apache.ibatis.cursor.Cursor;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.reflection.MetaObject;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.transaction.Transaction;
public interface Executor {
ResultHandler NO_RESULT_HANDLER = null;
int update(MappedStatement var1,Object var2) throws SQLException;
<E> List<E> query(MappedStatement var1,Object var2,RowBounds var3,ResultHandler var4,CacheKey var5,BoundSql var6) throws SQLException;
<E> List<E> query(MappedStatement var1,Object var2,RowBounds var3,ResultHandler var4) throws SQLException;
<E> Cursor<E> queryCursor();
}
Executor是Mybatis的核心执行器接口,包括SimpleExecutor、BatchExecutor、CachingExecutor和ReuseExecutor等不同策略实现。SimpleExecutor用于普通执行,ReuseExecutor和BatchExecutor都重用PreparedStatement,但BatchExecutor支持批量更新。CachingExecutor则结合了缓存功能。

2357

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



