Mybatis原理分析之三:包和类

参考:http://blog.csdn.net/fansunion/article/details/8254979

Mybatis源代码地址:https://github.com/mybatis/mybatis-3

中文注释:https://github.com/tuguangquan/mybatis

1.annotation

org.apache.ibatis.builder
org.apache.ibatis.builder.annotation
org.apache.ibatis.builder.xml

  本包定义了Mybatis框架中的24个注解。
  本包对Mybatis的其它包没有任何依赖,也不依赖于第三方的库。
  本包只被builder.annotation包的MapperAnnotationBuilder类引用。

2.binding

org.apache.ibatis.binding

映射绑定,mapper.xml等映射文件相关实体的抽象。

3.builder

org.apache.ibatis.builder
org.apache.ibatis.builder.annotation
org.apache.ibatis.builder.xml
解析Mybatis的配置文件和映射文件,包括Xml格式和Annotation格式2种配置。

4.cache

org.apache.ibatis.cache
org.apache.ibatis.cache.decorators
org.apache.ibatis.cache.impl

  本包包含了Mybatis框架的缓存接口定义和实现。
  PerpetualCache直接实现了Cache接口,其它缓存类实现采用装饰模式实现。
  采用装饰模式,一个个包装起来,形成一个链,典型的就是SynchronizedCache->LoggingCache->SerializedCache->LruCache->PerpetualCache,通过链起来达到功能增加。
 
  缓存框架按照 Key-Value方式存储,Key的生成采取规则为:[hashcode:checksum:mappedStementId:offset:limit:executeSql:queryParams]。
 
  本包只引用了Mybatis的io包的Resources,不依赖于任何第三方库。
 
  Mybatis的其它包大量引用了本包中的类和接口,即严重依赖于本包。

5.datasource

org.apache.ibatis.datasource
org.apache.ibatis.datasource.jndi
org.apache.ibatis.datasource.pooled
org.apache.ibatis.datasource.unpooled
数据源相关接口和类。
 
  本包主要引用了Mybatis的reflection的ExceptionUtil类和loggin包的Log接口和LogFactory类。
  Mybatis的session包的Configuration类,builder.xml包的XMLConfigBuilder类引用了本包中的类和接口。

6.exceptions

org.apache.ibatis.exceptions
本包定义了Mybatis框架中的异常。
 只依赖于Mybatis的executor的ErrorContext。
 Mybatis的其它包大量引用了本包中的类和接口,即严重依赖于本包。

7.executor

org.apache.ibatis.executor
org.apache.ibatis.executor.keygen
org.apache.ibatis.executor.loader
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
执行器接口和实现类及周边类和接口

8.io

org.apache.ibatis.io
通过类加载器在jar包中寻找一个package下满足条件(比如某个接口的子类)的所有类
本包主要包含了资源加载和访问相关的类。
 本包只引用了Mybatis的logging包的Log接口和LogFactory类。
 Mybatis的其它包大量引用了本包中的类和接口,即严重依赖于本包。

9.jdbc

org.apache.ibatis.jdbc
  JDBC和SQL相关的类。

10.logging

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
 把日志抽象成Log接口,该接口有7种实现。
  1.Apache Commons Logging
  2.JDBC Logging
  3.Java Util Logging
  4.Log4j
  5.No Logging
  6.Slf4J
  7.Stdout

一个接口多种实现是框架的一贯作风.
  本包主要依赖了,Mybatis的reflection包的ExceptionUtil和io包的Resources。
  以及第三方的Log4j,Slf4j,CommonsLogging。
  Mybatis的其它包大量引用了本包中的类和接口,即严重依赖于本包。

11.mapping

org.apache.ibatis.mapping
Mybatis配置文件-映射文件相关的类。

12.parsing

org.apache.ibatis.parsing
xml解析,${} 格式的字符串解析
源码分析可以参考http://www.cnblogs.com/sunzhenchao/p/3161093.html
解析配置文件的核心类和接口

13.plugin

org.apache.ibatis.plugin
插件相关接口和类。

14.reflection

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包下所有的类
反射相关类。

15.scripting

org.apache.ibatis.scripting
org.apache.ibatis.scripting.defaults
org.apache.ibatis.scripting.xmltags
脚本解析相关类。

16.session

org.apache.ibatis.session
org.apache.ibatis.session.defaults
会话相关类,提供对外核心接口.

17.transaction

org.apache.ibatis.transaction
org.apache.ibatis.transaction.jdbc
org.apache.ibatis.transaction.managed
Transaction接口是对事务的抽象,有2种实现方式:
  1.JdbcTransaction,jdbc:手动管理
  2.ManagedTransaction,managed:container manage the full lifecycle of the transaction

18.type

org.apache.ibatis.type
实现java和jdbc中的类型之间转换
源码分析可以参考http://www.cnblogs.com/sunzhenchao/archive/2013/04/09/3009431.html
类型处理,包含了类型处理器接口TypeHandler,父类BaseTypeHandler,以及若干个子类


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值