Git Product home page Git Product logo

mybatis's Introduction

mybatis源码中文注释版

1.兵马未动,日志先行
org.apache.ibatis.logging
org.apache.ibatis.logging.commons
org.apache.ibatis.logging.jdbc
org.apache.ibatis.logging.jdk14
org.apache.ibatis.logging.log4j
org.apache.ibatis.logging.log4j2
org.apache.ibatis.logging.nologging
org.apache.ibatis.logging.slf4j
org.apache.ibatis.logging.stdout
对象适配器设计模式
设计模式可参考http://www.cnblogs.com/liuling/archive/2013/04/12/adapter.html

2.异常
org.apache.ibatis.exceptions

3.缓存
org.apache.ibatis.cache
org.apache.ibatis.cache.decorators
org.apache.ibatis.cache.impl

4.解析
org.apache.ibatis.parsing
xml解析,${} 格式的字符串解析
源码分析可以参考http://www.cnblogs.com/sunzhenchao/p/3161093.html

5.类型处理器
org.apache.ibatis.type
实现java和jdbc中的类型之间转换
源码分析可以参考http://www.cnblogs.com/sunzhenchao/archive/2013/04/09/3009431.html

6.IO
org.apache.ibatis.io
通过类加载器在jar包中寻找一个package下满足条件(比如某个接口的子类)的所有类

7.反射
org.apache.ibatis.reflection
org.apache.ibatis.reflection.factory
org.apache.ibatis.reflection.invoker
org.apache.ibatis.reflection.property
org.apache.ibatis.reflection.wrapper
可以参考MetaObjectTest来跟踪调试,基本上用到了reflection包下所有的类
// 反射工厂的使用, 注意对象工厂以及对象包装工厂对于增强逻辑的埋点

8.数据源
org.apache.ibatis.datasource
org.apache.ibatis.datasource.jndi
org.apache.ibatis.datasource.pooled
org.apache.ibatis.datasource.unpooled

9.事务 封装connection,并提供了事务支持的基础方法的接口与工厂类
org.apache.ibatis.transaction
org.apache.ibatis.transaction.jdbc
org.apache.ibatis.transaction.managed

10.会话
org.apache.ibatis.session
org.apache.ibatis.session.defaults

11.jdbc单元测试工具
org.apache.ibatis.jdbc  很简单的通过建造者模式构建sql语句的实现。主要是用于测试方法执行脚本初始化db 使用。

12.构建
org.apache.ibatis.builder
org.apache.ibatis.builder.annotation
org.apache.ibatis.builder.xml

13.映射
org.apache.ibatis.mapping

14.脚本
org.apache.ibatis.scripting
org.apache.ibatis.scripting.defaults
org.apache.ibatis.scripting.xmltags

15.注解
org.apache.ibatis.annotations

16.绑定
org.apache.ibatis.binding   主要是使用动态代理生成对应的mapper的代理类,依赖sqlSession去执行对应的sql语句并返回结果。
    其中在MapperMethod中也有对于被代理方法签名中含有的@Param、RowBounds ResultHandler的解读,并提取作为sqlSession执行sql的参数传入。

17.执行器
org.apache.ibatis.executor
org.apache.ibatis.executor.keygen
org.apache.ibatis.executor.loader  实质是记录要延迟加载的的属性,然后在被调用的时候去数据库获取数据并缓存。 对于Tester进行调试的时候要特别注意关闭debugger的toString方法的调用,否者将会影响到测试结果。
这里需要注意的是还没有被延迟加载的属性持久化存储在缓存里面应该如何反序列化回来。

直接加载
:执行完主加载对象的select语句,马上就会执行关联对象的select语句。
侵入式延迟加载
:执行对主加载对象的查询时,不会执行关联对象的查询,但是当访问主加载对象的详情时,就会马上执行关联对象的select查询,也就是说关联对象的查询执行,侵入到了猪价在对象的详情访问中,可以理解为,将关联对象的详情侵入到主加载对象的详情中,作为它的一部分出现了。
深度延迟加载
:执行对主加载对象的查询的时候,不会执行对关联对象的查询,访问主加载对象的详情的时候,也不会执行关联对象的select查询,只有当真正的访问关联对象的详情的时候,才会执行对关联对象的select查询。

| 加载方式      | lazyLoadingEnabled        |  aggressiveLazyLoading      |
| :--------:   | :-----:                   | :----:                      |
| 直接加载      | 必须是false,默认是false    |   \                         |
| 侵入式延迟加载 | 必须是true                 |   必须是true                 |
| 深度延迟加载   | 必须是true                 |   必须是false,默认是false    |


org.apache.ibatis.executor.loader.cglib
org.apache.ibatis.executor.loader.javassist
org.apache.ibatis.executor.parameter
org.apache.ibatis.executor.result
org.apache.ibatis.executor.resultset
org.apache.ibatis.executor.statement

18.插件
org.apache.ibatis.plugin


Question 1: 如何做到属性在被调用的时候才去查询数据库的策略?





参考资料
csdn源码解析 - https://zhuanlan.zhihu.com/p/66543158   // 较为粗糙
MyBatis官方文档 - http://www.mybatis.org/mybatis-3/zh/index.html
MyBatis-Spring官方文档 - http://www.mybatis.org/spring/zh/index.html
MyBatis源码 - https://github.com/mybatis/mybatis-3
MyBatis-Spring源码 - https://github.com/mybatis/spring

mybatis's People

Contributors

emacarron avatar simonetripodi avatar harawata avatar jeffgbutler avatar nmaves avatar cbegin avatar hazendaz avatar darkidiot avatar wangdx avatar christianpoitras avatar mnesarco avatar frantam avatar jcsantosbr avatar agustafson avatar tuguangquan avatar xpenxpen avatar fengxx avatar apidevsm avatar htynkn avatar dave-r12 avatar ajablonski avatar xylsh avatar naixwf avatar mallim avatar hengyunabc avatar fromm0 avatar dengqiao avatar cr2121 avatar lguerrin avatar lmeadors avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.