zoukankan      html  css  js  c++  java
  • 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;
        }
    

      

  • 相关阅读:
    华为移动HG8546M光猫路由器通过lan口再连接路由器
    Windows下使用Dev C++ 编写dll与使用dll(二)C++项目下的dll
    Windows下使用Dev C++ 编写dll与使用dll(一)C项目下的dll
    易语言之dll文件的编写与引入
    易语言之编写模块与引入模块
    Element ui 分页记录选中框
    MUI poppicker.js 增加搜索框
    element el-date-picker 去除自带的T格式
    element el-input小数保留两位小数,整数字符串去空格
    nginx vue三级目录配置
  • 原文地址:https://www.cnblogs.com/lvjygogo/p/9531507.html
Copyright © 2011-2022 走看看