Mybatis执行SimpleExecutor(三)
2016-09-23 21:49
295 查看
SimpleExecutor通过类名可以看出,它是一个简单的执行类,并不会做一些处理就执行sql,源码及分析如下:
/** * @author Clinton Begin */ public class SimpleExecutor extends BaseExecutor { public SimpleExecutor(Configuration configuration, Transaction transaction) { super(configuration, transaction); } @Override public int doUpdate(MappedStatement ms, Object parameter) throws SQLException { Statement stmt = null; try { //获得配置文件对象 Configuration configuration = ms.getConfiguration(); //获得statementHandler里面有statement,来处理 StatementHandler handler = configuration.newStatementHandler(this, ms, parameter, RowBounds.DEFAULT, null, null); stmt = prepareStatement(handler, ms.getStatementLog()); //最终是一个statement进行处理 return handler.update(stmt); } finally { closeStatement(stmt); } } @Override public <E> List<E> doQuery(MappedStatement ms, Object parameter, RowBounds rowBounds, ResultHandler resultHandler, BoundSql boundSql) throws SQLException { Statement stmt = null; try { //获得配置文件对象 Configuration configuration = ms.getConfiguration(); //获得statementHandler里面有statement,来处理 StatementHandler handler = configuration.newStatementHandler(wrapper, ms, parameter, rowBounds, resultHandler, boundSql); //获得statement stmt = prepareStatement(handler, ms.getStatementLog()); //最终是一个statement进行处理 return handler.<E>query(stmt, resultHandler); } finally { closeStatement(stmt); } } @Override public List<BatchResult> doFlushStatements(boolean isRollback) throws SQLException { return Collections.emptyList(); } private Statement prepareStatement(StatementHandler handler, Log statementLog) throws SQLException { Statement stmt; Connection connection = getConnection(statementLog); stmt = handler.prepare(connection); //将Statement转为PrepareStatement handler.parameterize(stmt); return stmt; } }
相关文章推荐
- Mybatis执行SimpleExecutor(三)
- Mybatis执行SimpleExecutor(三)
- Mybatis执行Executor(一)
- Mybatis执行Executor(一)
- Mybatis执行Executor(一)
- Mybatis执行BaseExecutor(二)
- Mybatis执行BaseExecutor(二)
- Mybatis执行BaseExecutor(二)
- myBatis源码之SimpleExecutor
- Mybatis源码之SimpleExecutor
- Mybatis执行ReuseExecutor(五)
- Mybatis源码之SimpleExecutor
- Mybatis执行ReuseExecutor(五)
- Mybatis源码之SimpleExecutor
- Mybatis执行ReuseExecutor(五)
- ScheduledExecutorService执行周期性或定时任务
- mybatis执行批量更新batch update 的方法(oracle,mysql)
- mybatis将执行的sql语句输出
- mybatis执行批量更新batch update 的方法(oracle,mysql)
- 使用mybatis的ScriptRunner执行sql文件