用源码流程图来描述mybatis的执行原理

一、根据配置文件创建SQLSessionFactory

  1. 创建SqlSessionFactoryBuild对象
  2. build(input Stream)
  3. 创建解析器
  4. 解析每一个标签将详细信息保存到config中
  5. 解析mapper
  6. 返回config
  7. build(config)
  8. new  defaultSqlSession()
  9. 返回创建的DefaultSqlSession,包含了保存全局的配置信息的config

用源码流程图来描述mybatis的执行原理

总结:把配置文件的信息解析并保存在config对象中返回包含了 config的default对象

二、Executor创建

  1. 返回SqlSession的实现类DefaultSqlSession对象,它里面包含了Exector和Config;executor会在这一步被创建。
  2. openSession()
  3. openSessionFromDataSource()
  4. 获取信息 ,创建tx
  5. newExecutor()
  6. 根据Exector在全局配置中的类型,创建出SimpleExector/ReuseExrcutor/BatchRxcutor
  7. 如果有二级缓存配置开启,创建CachingExecutor(executor)
  8. exector =(Exector)interceptorChain.pLuginAll(exector);使用每一个拦截器重新包装exector并返回
  9. 创建DefaultSqlSession,包含config和Executor
  10. 返回DefaultSqlSession

用源码流程图来描述mybatis的执行原理

三、GetMapper返回接口的代理对象包含了SqlSession对象

用源码流程图来描述mybatis的执行原理

四、查询流程

用源码流程图来描述mybatis的执行原理