读mybatis源码之五:执行器Executor创建

         在sqlsession中主要是执行都是通过executor来处理的:

 executor.query(ms, wrapCollection(parameter), rowBounds, handler);

executor.update(ms, wrapCollection(parameter));
      执行器从哪里来呢?在 DefaultSqlSessionFactory里面openSessionFromDataSource:

 final Executor executor = configuration.newExecutor(tx, execType, autoCommit);

看configuration里面怎么构建执行器的:

public Executor newExecutor(Transaction transaction, ExecutorType executorType, boolean autoCommit) {
    executorType = executorType == null ? defaultExecutorType : executorType;
    executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
    Executor executor;
    if (ExecutorType.BATCH == executorType) {
      executor = new BatchExecutor(this, transaction);
    } else if (ExecutorType.REUSE == executorType) {
      executor = new ReuseExecutor(this, transaction);
    } else {
      executor = new SimpleExecutor(this, transaction);
    }
    if (cacheEnabled) {
      <span style="color:#ff0000;">executor = new CachingExecutor(executor, autoCommit);</span>
    }
    executor = (Executor) interceptorChain.pluginAll(executor);
    return executor;
  }
可以看到,默认是是简单执行器,还有批量、重用执行器,下面这段话解释不用的执行器使用方式:




executor = (Executor) interceptorChain.pluginAll(executor);  

是将执行器添加到拦截器中,这个很重要,为后续写插件提供时机。

具体为session指定执行器可以使用类似这种方式 sessionFactory.openSession(ExecutorType.BATCH, false);



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值