Mybatis源码分析[05.Configuration]
发表于:2025-02-02 作者:千家信息网编辑
千家信息网最后更新 2025年02月02日,Mybatis的配置类public class Configuration { //环境 protected Environment environment; //---------节点----
千家信息网最后更新 2025年02月02日Mybatis源码分析[05.Configuration]
Mybatis的配置类
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; //默认启用缓存 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 lazyLoadTriggerMethods = new HashSet(Arrays.asList(new String[] { "equals", "clone", "hashCode", "toString" })); protected Integer defaultStatementTimeout; //默认为简单执行器 protected ExecutorType defaultExecutorType = ExecutorType.SIMPLE; protected AutoMappingBehavior autoMappingBehavior = AutoMappingBehavior.PARTIAL; //---------节点------- protected Properties variables = new Properties(); //对象工厂和对象包装器工厂 protected ObjectFactory objectFactory = new DefaultObjectFactory(); protected ObjectWrapperFactory objectWrapperFactory = new DefaultObjectWrapperFactory(); //映射注册机 protected MapperRegistry mapperRegistry = new MapperRegistry(this); //默认禁用延迟加载 protected boolean lazyLoadingEnabled = false; protected ProxyFactory proxyFactory = new JavassistProxyFactory(); // #224 Using internal Javassist instead of OGNL protected String databaseId; /** * Configuration factory class. * Used to create Configuration for loading deserialized unread properties. * * @see Issue 300 (google code) */ protected Class> configurationFactory; protected final InterceptorChain interceptorChain = new InterceptorChain(); //类型处理器注册机 protected final TypeHandlerRegistry typeHandlerRegistry = new TypeHandlerRegistry(); //类型别名注册机 protected final TypeAliasRegistry typeAliasRegistry = new TypeAliasRegistry(); protected final LanguageDriverRegistry languageRegistry = new LanguageDriverRegistry(); //映射的语句,存在Map里 protected final Map mappedStatements = new StrictMap("Mapped Statements collection"); //缓存,存在Map里 protected final Map caches = new StrictMap("Caches collection"); //结果映射,存在Map里 protected final Map resultMaps = new StrictMap("Result Maps collection"); protected final Map parameterMaps = new StrictMap("Parameter Maps collection"); protected final Map keyGenerators = new StrictMap("Key Generators collection"); protected final Set loadedResources = new HashSet(); protected final Map sqlFragments = new StrictMap("XML fragments parsed from previous mappers"); //不完整的SQL语句 protected final Collection incompleteStatements = new LinkedList(); protected final Collection incompleteCacheRefs = new LinkedList(); protected final Collection incompleteResultMaps = new LinkedList(); protected final Collection incompleteMethods = new LinkedList(); /* * 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 cacheRefMap = new HashMap(); public Configuration(Environment environment) { this(); this.environment = environment; } public Configuration() { //注册更多的类型别名 typeAliasRegistry.registerAlias("JDBC", JdbcTransactionFactory.class); typeAliasRegistry.registerAlias("MANAGED", ManagedTransactionFactory.class); typeAliasRegistry.registerAlias("JNDI", JndiDataSourceFactory.class); typeAliasRegistry.registerAlias("POOLED", PooledDataSourceFactory.class); typeAliasRegistry.registerAlias("UNPOOLED", UnpooledDataSourceFactory.class); typeAliasRegistry.registerAlias("PERPETUAL", PerpetualCache.class); typeAliasRegistry.registerAlias("FIFO", FifoCache.class); typeAliasRegistry.registerAlias("LRU", LruCache.class); typeAliasRegistry.registerAlias("SOFT", SoftCache.class); typeAliasRegistry.registerAlias("WEAK", WeakCache.class); typeAliasRegistry.registerAlias("DB_VENDOR", VendorDatabaseIdProvider.class); typeAliasRegistry.registerAlias("XML", XMLLanguageDriver.class); typeAliasRegistry.registerAlias("RAW", RawLanguageDriver.class); typeAliasRegistry.registerAlias("SLF4J", Slf4jImpl.class); typeAliasRegistry.registerAlias("COMMONS_LOGGING", JakartaCommonsLoggingImpl.class); typeAliasRegistry.registerAlias("LOG4J", Log4jImpl.class); typeAliasRegistry.registerAlias("LOG4J2", Log4j2Impl.class); typeAliasRegistry.registerAlias("JDK_LOGGING", Jdk14LoggingImpl.class); typeAliasRegistry.registerAlias("STDOUT_LOGGING", StdOutImpl.class); typeAliasRegistry.registerAlias("NO_LOGGING", NoLoggingImpl.class); typeAliasRegistry.registerAlias("CGLIB", CglibProxyFactory.class); typeAliasRegistry.registerAlias("JAVASSIST", JavassistProxyFactory.class); languageRegistry.setDefaultDriverClass(XMLLanguageDriver.class); languageRegistry.register(RawLanguageDriver.class); }}
Configuration类具有产生执行器的功能
//产生执行器 public Executor newExecutor(Transaction transaction, ExecutorType executorType) { executorType = executorType == null ? defaultExecutorType : executorType; executorType = executorType == null ? ExecutorType.SIMPLE : executorType; Executor executor; //然后就是简单的3个分支,产生3种执行器BatchExecutor/ReuseExecutor/SimpleExecutor 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); } //如果要求缓存,生成另一种CachingExecutor(默认就是有缓存),装饰者模式,所以默认都是返回CachingExecutor if (cacheEnabled) { executor = new CachingExecutor(executor); } //此处调用插件,通过插件可以改变Executor行为 executor = (Executor) interceptorChain.pluginAll(executor); return executor; }
缓存
执行器
注册机
类型
别名
对象
就是
工厂
插件
节点
语句
分支
功能
处理器
更多
模式
环境
结果
行为
包装
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
网络安全监测预警信息发布
乡镇政府网络安全应急方案
数据库利用触发器同步数据例子
服务器上的安全数据没有
软件开发培训学校北师大于丹
金铲铲之战语音服务器连接不上
传感器网络技术在医疗上的应用
分布式数据库选择题
合肥mysql数据库入门培训
服务器ip怎么查电话号
有关网络安全的演讲稿400字
动态ip怎么做代理服务器
英语词汇分级软件开发
软件开发产品集成意思
整站模板软件开发
网络安全通报联络机制
计算机网络技术自学考试能考哪些
腾讯云服务器安全么
安卓软件开发 过程
鹿泉区网络安全和信息化委员会
软件开发专业需要多少钱
网络安全管理内设机构
什么语言操作数据库性能好
网络安全法律颁布的顺序
甘肃天水软件开发培训学校
达梦数据库数据文件还原
网络安全工程怎么考
达梦数据库怎么看数据库字段信息
数据库日志备份
泉州网络安全平台作业