最近没什么事,花了一周的时间把mybatis源码看完了,现自我总结一下,尽可能的用一句话总结,方便自己理解和回顾。
出名的框架几乎都是从初始化配置文件开始的,mybatis也一样。
mybatis的配置文件是通过工具类XMLConfigBuilder,XMLMapperBuilder,XMLStatementBuilder解析后都存在Configuration中
private void parseConfiguration(XNode root) {
try {
propertiesElement(root.evalNode("properties")); //issue #117 read properties first
typeAliasesElement(root.evalNode("typeAliases"));
pluginElement(root.evalNode("plugins"));
objectFactoryElement(root.evalNode("objectFactory"));
objectWrapperFactoryElement(root.evalNode("objectWrapperFactory"));
settingsElement(root.evalNode("settings"));
environmentsElement(root.evalNode("environments")); // read it after objectFactory and objectWrapperFactory issue #631
databaseIdProviderElement(root.evalNode("databaseIdProvider"));
typeHandlerElement(root.evalNode("typeHandlers"));
mapperElement(root.evalNode("mappers"));
} catch (Exception e) {
throw new BuilderException("Error parsing SQL Mapper Configuration. Cause: " + e, e);
}
}
public class Configuration {
protected Environment environment;
protected boolean safeRowBoundsEnabled = false;
protected boolean safeResultHandlerEnabled = true;
protected boolean mapUnderscoreToCamelCase = false;
protected boolean aggressiveLazyLoading = true;
protected boolean multipleResultSetsEnabled = true;
protected boolean useGeneratedKeys = false;
protected boolean useColumnLabel = true;
//二级缓存开关,直接决定sqlSession是否启用CachingExecutor
protected boolean cacheEnabled = true;
protected boolean callSettersOnNulls = false;
protected String logPrefix;
protected Class <? extends Log> logImpl;
//一级缓存的默认作用域
protected LocalCacheScope localCacheScope = LocalCacheScope.SESSION;
protected JdbcType jdbcTypeForNull = JdbcType.OTHER;
protected Set<String> lazyLoadTriggerMethods = new HashSet<String>(Arrays.asList(new String[] { "equals", "clone", "hashCode", "toString" }));
protected Integer defaultStatementTimeout;
protected Integer defaultFetchSize;
protected ExecutorType defaultExecutorType = ExecutorType.SIMPLE;
protected AutoMappingBehavior autoMappingBehavior = AutoMappingBehavior.PARTIAL;
//config配置文件Properties标签的数据存储 -----全局属性配置对象
protected Properties variables = new Properties();
protected ReflectorFactory reflectorFactory = new DefaultReflectorFactory();
//config配置文件objectFactory标签的数据存储
protected ObjectFactory objectFactory = new DefaultObjectFactory();
protected ObjectWrapperFactory objectWrapperFactory = new DefaultObjectWrapperFactory();
//maper接口的存储容器, mybatis访问数据库的动态代理接口,MapperProxyFactory 是经典的C/S架构客户端同步访问实现
protected MapperRegistry mapperRegistry = new MapperRegistry(this);
protected boolean lazyLoadingEnabled = false;
protected ProxyFactory proxyFactory = new JavassistProxyFactory(); // #224 Using internal Javassist instead of OGNL
//数据源 id
protected String databaseId;
/**
* Configuration factory class.
* Used to create Configuration for loading deserialized unread properties.
*
* @see <a href='https://code.google.com/p/mybatis/issues/detail?id=300'>Issue 300</a> (google code)
*/
protected Class<?> configurationFactory;
//插件,可以在核心业务逻辑处理类“statementHandler”中增加sql解析,sql路由等等功能
protected final InterceptorChain interceptorChain = new InterceptorChain();
//config配置文件typeHandler标签的数据容器
protected final TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry();
//config配置文件typeAlias标签的数据容器 ---别名对应容器
protected final TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry();
//language容器
protected final LanguageDriverRegistry languageRegistry = new LanguageDriverRegistry();
//mapper配置文件的数据容器
protected final Map<String, MappedStatement> mappedStatements = new StrictMap<MappedStatement>("Mapped Statements collection");
//缓存容器
protected final Map<String, Cache> caches = new StrictMap<Cache>("Caches collection");
//resultMap容器,思考:抛弃ORM设计思想, 还可以通过JDBC的ResultSet相关方法组装成map对象返回,不需要resultSetHandler.<E>handleResultSets(statement)。
protected final Map<String, ResultMap> resultMaps = new StrictMap<ResultMap>("Result Maps collection");
//输入参数类型容器
protected final Map<String, ParameterMap> parameterMaps = new StrictMap<ParameterMap>("Parameter Maps collection");
//主键生成器容器
protected final Map<String, KeyGenerator> keyGenerators = new StrictMap<KeyGenerator>("Key Generators collection");
protected final Set<String> loadedResources = new HashSet<String>();
protected final Map<String, XNode> sqlFragments = new StrictMap<XNode>("XML fragments parsed from previous mappers");
//异常数据容器
protected final Collection<XMLStatementBuilder> incompleteStatements = new LinkedList<XMLStatementBuilder>();
//异常数据容器
protected final Collection<CacheRefResolver> incompleteCacheRefs = new LinkedList<CacheRefResolver>();
//异常数据容器
protected final Collection<ResultMapResolver> incompleteResultMaps = new LinkedList<ResultMapResolver>();
//异常数据容器
protected final Collection<MethodResolver> incompleteMethods = new LinkedList<MethodResolver>();
/*
* A map holds cache-ref relationship. The key is the namespace that
* references a cache bound to another namespace and the value is the
* namespace which the actual cache is bound to.
*/
protected final Map<String, String> cacheRefMap = new HashMap<String, String>();
分享到:
相关推荐
mybatis-3.5.9 源码(mybatis-3-mybatis-3.5.9.tar.gz)
mybatis-3.5.9 源码(mybatis-3-mybatis-3.5.9.zip)
mybatis-plus源码(mybatis-plus-3.5.1.zip)
mybatis源码是mybatis-3.2.6的源码,用户使用mybatis时可以进行参考
3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3.4.2开发工具 mybatis-3
源码下载!绝对的mybatis源码,在Myeclipes或Eclipse中直接引入即可看源码!
mybatis-plus-sample-reduce-springmvc: 简化掉默认mapper类示例(Spring MVC版本) mybatis-plus-sample-generator: 代码生成器示例 mybatis-plus-sample-crud: 完整 CRUD 示例 mybatis-plus-sample-wrapper: 条件...
赠送jar包:mybatis-generator-core-1.3.7.jar; 赠送原API文档:mybatis-generator-core-1.3.7-javadoc.jar; 赠送源代码:mybatis-generator-core-1.3.7-sources.jar; 赠送Maven依赖信息文件:mybatis-generator-...
mybatis-plus源码(mybatis-plus-3.5.1.tar.gz)
mybatis-3-mybatis-3.5.7.zip源码
赠送jar包:mybatis-plus-annotation-3.1.0.jar; 赠送原API文档:mybatis-plus-annotation-3.1.0-javadoc.jar; 赠送源代码:mybatis-plus-annotation-3.1.0-sources.jar; 赠送Maven依赖信息文件:mybatis-plus-...
mybatis-3.2.7.jar mybatis-3.2.2.jar mybatis-3.1.1.jar
mybatis在持久层框架中还是比较火的,一般项目都是基于ssm。虽然mybatis可以直接在xml中...《MyBatis-Plus入门文档》主要介绍了MyBatis-Plus入门使用,以及关于mybatis-plus的更多介绍及特性,感兴趣的可以下载学习一下
mybatis mybatis-spring-boot-starter-2.0.0.jar下载
MyBatis3_用户指南--MyBatis-3-User-Guide-zh_CN.pdf 非常实用
赠送jar包:mybatis-plus-annotation-3.5.1.jar; 赠送原API文档:mybatis-plus-annotation-3.5.1-javadoc.jar; 赠送源代码:mybatis-plus-annotation-3.5.1-sources.jar; 赠送Maven依赖信息文件:mybatis-plus-...
baomidou-mybatis-plus-3.0 mybatis-plus源码 。
赠送jar包:mybatis-spring-boot-autoconfigure-2.1.1.jar; 赠送原API文档:mybatis-spring-boot-autoconfigure-2.1.1-javadoc.jar; 赠送源代码:mybatis-spring-boot-autoconfigure-2.1.1-sources.jar; 赠送...
赠送jar包:mybatis-spring-boot-autoconfigure-2.1.1.jar; 赠送原API文档:mybatis-spring-boot-autoconfigure-2.1.1-javadoc.jar; 赠送源代码:mybatis-spring-boot-autoconfigure-2.1.1-sources.jar; 赠送...
mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip mybatis-plus最新代码生成器项目源码 :mybatis-plus-generator.zip ...