从三个主要的对象SqlSessionFactoryBuilder->SqlSessionFactory->SqlSession说起

            inputStream = Resources.getResourceAsStream(resource);
sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
  1. 读取全局配置文件
inputStream = Resources.getResourceAsStream(resource);
  1. 创建了一个SqlSessionFactoryBuilder对象

  2. 调用.getResourceAsStream(resource)方法,完成相关配置并创建SqlSessionFactory对象

//点击进入可知对XML文件进行了解析,从而获得了XMLConfiguration,且该对象继承自Configuration对象.进入下一步的build查看
public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) {
SqlSessionFactory var5;
try {
XMLConfigBuilder parser = new XMLConfigBuilder(inputStream, environment, properties);
var5 = this.build(parser.parse());
} catch (Exception var14) {
throw ExceptionFactory.wrapException("Error building SqlSession.", var14);
} finally {
ErrorContext.instance().reset(); try {
inputStream.close();
} catch (IOException var13) {
} } return var5;
} //加Configuration对象加载给SqlSessionFactory对象,完成了SqlSessionFactory的创建
public SqlSessionFactory build(Configuration config) {
return new DefaultSqlSessionFactory(config);
}
  1. 调用SqlSessionFactory对象的openSession方法完SqlSession对象的实例化
//往下:可以看出是先继承了Configuration中的Environment,完成了transaction相关的操作,继而产生executor,最后才完成了SqlSession的实例化,能力有限,这里就不深究了
private SqlSession openSessionFromDataSource(ExecutorType execType, TransactionIsolationLevel level, boolean autoCommit) {
Transaction tx = null; DefaultSqlSession var8;
try {
Environment environment = this.configuration.getEnvironment();
TransactionFactory transactionFactory = this.getTransactionFactoryFromEnvironment(environment);
tx = transactionFactory.newTransaction(environment.getDataSource(), level, autoCommit);
Executor executor = this.configuration.newExecutor(tx, execType);
var8 = new DefaultSqlSession(this.configuration, executor, autoCommit);
} catch (Exception var12) {
this.closeTransaction(tx);
throw ExceptionFactory.wrapException("Error opening session. Cause: " + var12, var12);
} finally {
ErrorContext.instance().reset();
} return var8;
}
  1. CURD的执行(产生错误就回滚)
  2. 检测是否执行(产生错误就回滚)
  3. 提交

    8.关闭

最新文章

  1. c++中的lambda特性
  2. Lind.DDD.Manager里菜单权限的设计
  3. AjaxUpload跨域上传问题
  4. How to select Multiple images from UIImagePickerController [duplicate]
  5. 使用ajax异步提交表单数据(史上最完整的版本)
  6. Oracle错误:动态执行表不可访问,本会话自动统计被禁止,关闭自动统计之后的问题
  7. web版扫雷小游戏(三)
  8. cocos2d与cocos2d-X中的draw和update
  9. Android为应用在桌面添加一个快捷方式
  10. Swift - 闭包的介绍及用法(以数组排序为例)
  11. Angularjs 基于karma和jasmine的单元测试
  12. bash shell:重定向标准错误输出
  13. 遇到scan configurtation CDT builder等的错误
  14. 001 java简介
  15. css 底层知识点
  16. 实体lis<T>t转换datatable
  17. docker zabbix
  18. eclipse无法断点调试JDK源码的问题
  19. Beanstalkd 基本概念和使用
  20. Unity3D笔记 愤怒的小鸟<四> 实现Selelction界面

热门文章

  1. notepad++颜色属性解释
  2. 我们一起来学Shell - shell的函数
  3. Spring是什么? 核心总结
  4. 数据分析刚入门?这几个BI软件你一定得知道!
  5. C# 9.0元组 (ValueTuple)详细解说
  6. 《Java编程思想》学习笔记(详细)
  7. VIM对替换的数字进行计算
  8. Python:matplotlib.pyplot
  9. QT:Qt Creator使用CTRL+C后变成了光标覆盖,插入模式
  10. 进程&线程(三):外部子进程subprocess、异步IO、协程、分布式进程