zoukankan      html  css  js  c++  java
  • Mybaits中的简单的学习,以及他们之中的源码的简单的刨析

    SqlSession是Mybatis最重要的的构建之一,可以简单的惹味Mybatis一些列配置的目的是历史与JDBC的connecton对象的SqSession对象,这样才能于数据库开始沟通,mybaits其实就是sqlsession的增删查改的增强,纳闷他是如何执行实现的,

      SqlSession简单介绍

      SqlSession提供了select/insert/updte/delete方法,在旧版本中使用的是SqlSession接口中使用的这些方法,但是新版本中Mybatis中建议使用的是Mapper的方法。映射器其实就是一个动态代理队形,然后进入MapperMethod的

    excuutor  其实就是好到SqlSession ,执行SQL查询,从底层俩说他的本事是通过动态代理让接口跑起来,之后采用命令模式,最后还是采用SqlSession的接口方法,执行sql查询的。

      SqlSession的重要的四个对象

        1. Execute: 调度执行StatementHandler,ParmmeterHandlerResultHandler执行相应的sql

        2. StatementHandler:使用数据苦苦Statement(PrepareStatement) 下hi行操作,基底层是凤凰装好的的prepareStatement

        3. ParameterHandler:处理Sql参数

        3. ResultHandler:j结果集ResultSet封装处理

      SqlSession四大对象

        1. Execute 执行器,主要有三种执行器,SIMPLE默认的执行器、REISE是一些红预处理语句,BATCH批量更新批量专用处理器,

    package org.apache.ibatis.session;
    
    /**
     * @author Clinton Begin
     */
    public enum ExecutorType {
      SIMPLE, REUSE, BATCH
    }

        2. 执行处理器,Executor会先掉哦那个StatementHandler的prapare()方法预编译SQL语句,同事设置一些基本的运行餐宿,然后,StatementHandler 的parameterize()方法实际上启用了ParameteHandler设置参数,resultHandler在组装查询结果返回调用者完成一次预编译。

        第一:Executor通过Configuraton对象中的newExecutor()方法中选择相应的执行器生成

        

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

      

    MyBaits 的拦截器的介绍以及初步的认识。

  • 相关阅读:
    Java实现 LeetCode 101 对称二叉树
    编写在浏览器中不弹出警告的ActiveX控件
    ocx控件避免弹出警告的类--2
    修改注册表添加IE信任站点及启用Activex控件
    让动态创建的ActiveX控件响应Windows消息
    source code analyzer 功能强大的C/C++源代码分析软件 Celerity CRACK 破解版
    分析函数调用关系图(call graph)的几种方法
    用CodeViz绘制函数调用关系图(call graph)
    C++的辅助工具介绍
    局域网入侵的方法
  • 原文地址:https://www.cnblogs.com/dousil/p/13173247.html
Copyright © 2011-2022 走看看