当前位置: 首页 > news >正文

mybatis 源码分析二

1.SqlSession下的四大对象

Executor、StatementHandler、ParameterHandler、ResultSetHandler

StatementHandler的作用是使用数据库的Statement(PreparedStatement)执行操作

ParameterHandler是用来处理SQL参数的

ResultSetHandler是进行数据集的封装返回处理的

2.mybatis中有3中执行器:

SIMPLE——简易执行器,默认

REUSE——是一种能够执行重用预处理语句的执行器

BATCH ——执行器重用语句和批量更新,批量专用的执行器

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, autoCommit);
            var8 = new DefaultSqlSession(this.configuration, executor);
        } catch (Exception var12) {
            this.closeTransaction(tx);
            throw ExceptionFactory.wrapException("Error opening session.  Cause: " + var12, var12);
        } finally {
            ErrorContext.instance().reset();
        }

        return var8;
    }

  

public Executor newExecutor(Transaction transaction, ExecutorType executorType, boolean autoCommit) {
        executorType = executorType == null ? this.defaultExecutorType : executorType;
        executorType = executorType == null ? ExecutorType.SIMPLE : executorType;
        Object 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 (this.cacheEnabled) {
            executor = new CachingExecutor((Executor)executor, autoCommit);
        }

        Executor executor = (Executor)this.interceptorChain.pluginAll(executor);
        return executor;
    }

  

转载于:https://www.cnblogs.com/lvjygogo/p/9531507.html

相关文章:

  • 聊聊sentinel的DegradeSlot
  • 前端UI框架选择区别对比推荐
  • 解压缩软件居然还有多种工作模式!长见识了
  • 小白科普:分布式和集群
  • dubbo与springcloud初识
  • Android 5.1 预制输入法
  • Python游戏《外星人入侵》来了~
  • win10装双系统图文教程
  • 第10章神经网络基础
  • MpVue 致力打造H5与小程序的代码共用
  • 参加2018之江杯全球人工智能大赛 :视频识别问答(三)
  • 解决加载模型预测数据时报错的问题
  • java 颠倒整数
  • 【火炉炼AI】机器学习022-使用均值漂移聚类算法构建模型
  • Python从菜鸟到高手(5):数字
  • [ JavaScript ] 数据结构与算法 —— 链表
  • 【css3】浏览器内核及其兼容性
  • Android Studio:GIT提交项目到远程仓库
  • Angular 响应式表单之下拉框
  • k个最大的数及变种小结
  • MobX
  • nfs客户端进程变D,延伸linux的lock
  • Redis 中的布隆过滤器
  • SAP云平台运行环境Cloud Foundry和Neo的区别
  • 不用申请服务号就可以开发微信支付/支付宝/QQ钱包支付!附:直接可用的代码+demo...
  • 对象引论
  • 分享自己折腾多时的一套 vue 组件 --we-vue
  • 机器学习学习笔记一
  • 技术发展面试
  • 前端性能优化--懒加载和预加载
  • 浅析微信支付:申请退款、退款回调接口、查询退款
  • 巧用 TypeScript (一)
  • 我有几个粽子,和一个故事
  • elasticsearch-head插件安装
  • # include “ “ 和 # include < >两者的区别
  • # 计算机视觉入门
  • #Linux(帮助手册)
  • $.ajax中的eval及dataType
  • (附源码)ssm考生评分系统 毕业设计 071114
  • (四)Linux Shell编程——输入输出重定向
  • (算法)前K大的和
  • .form文件_一篇文章学会文件上传
  • .NET 5.0正式发布,有什么功能特性(翻译)
  • .NET C#版本和.NET版本以及VS版本的对应关系
  • .NET Conf 2023 回顾 – 庆祝社区、创新和 .NET 8 的发布
  • .NET Core 项目指定SDK版本
  • .NET Core跨平台微服务学习资源
  • .NET 发展历程
  • .Net程序帮助文档制作
  • .pop ----remove 删除
  • @31省区市高考时间表来了,祝考试成功
  • []新浪博客如何插入代码(其他博客应该也可以)
  • [ActionScript][AS3]小小笔记
  • [BUUCTF]-PWN:wustctf2020_number_game解析(补码,整数漏洞)
  • [BZOJ1010] [HNOI2008] 玩具装箱toy (斜率优化)