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;
        }
    

      

  • 相关阅读:
    WINDOWS黑客基础(5):利用内存来进行获取计算结果
    WINDOWS黑客基础(4):查找进程运行的基址
    WINDOWS黑客基础(3):注入代码
    shell中[[]]和[]的主要区别
    sed的实际用法举例
    linux oracle profile配置
    转 -Linux 自检和 SystemTap (强大的内核调试工具)---包含下载地址
    【转】DBMS_STATS.GATHER_TABLE_STATS详解 2012-04-22 09:20:10
    Linux中的15个‘echo’ 命令实例
    BEA-WEBLOGIC ---http://www.beansoft.biz/weblogic/docs92/index.html
  • 原文地址:https://www.cnblogs.com/lvjygogo/p/9531507.html
Copyright © 2011-2022 走看看