Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Mybatis source code analysis [02.XMLConfigBuilder]

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/03 Report--

/ / BaseBuilder attribute public abstract class BaseBuilder {/ / requires configuration, type alias registration, type handler registration 3 things protected final Configuration configuration; protected final TypeAliasRegistry typeAliasRegistry; protected final TypeHandlerRegistry typeHandlerRegistry;}

Public class XMLConfigBuilder extends BaseBuilder {}, it can be seen that XMLConfigBuilder inherits from BaseBuilder

/ / XMLConfigBuilder attribute public class XMLConfigBuilder extends BaseBuilder {/ / whether the private boolean parsed; / / XPath parser private XPathParser parser; / / current environment private String environment;} has been parsed

SqlSessionFactoryBuilder calls the parse () function of XMLConfigBuilder

/ parsing configuration public Configuration parse () {/ / if you have already parsed, error if (parsed) {throw new BuilderException ("Each XMLConfigBuilder can only be used once.") } parsed = true; / / Root node is configuration parseConfiguration (parser.evalNode ("/ configuration")); return configuration;}

You can see from the source code that the parse () function is actually a called parseConfiguration () function, and the internal implementation is as follows:

Private void parseConfiguration (XNode root) {try {/ / step by step parsing / / issue # 117 read properties first / / 1.properties propertiesElement (root.evalNode ("properties")); / / 2. Type alias typeAliasesElement (root.evalNode ("typeAliases")); / / 3. Plug-in pluginElement (root.evalNode ("plugins")); / / 4. Object factory objectFactoryElement (root.evalNode ("objectFactory")); / / 5. Object packaging factory objectWrapperFactoryElement (root.evalNode ("objectWrapperFactory")); / / 6. Set settingsElement (root.evalNode ("settings")); / / read it after objectFactory and objectWrapperFactory issue # 631 / / 7. Environment environmentsElement (root.evalNode ("environments")); / / 8.databaseIdProvider databaseIdProviderElement (root.evalNode ("databaseIdProvider")); / / 9. Type processor typeHandlerElement (root.evalNode ("typeHandlers")); / / 10. Mapper mapperElement (root.evalNode ("mappers"));} catch (Exception e) {throw new BuilderException ("Error parsing SQL Mapper Configuration. Cause:" + e, e);}}

The above function is for mybatis to parse the key nodes of the configuration file.

PropertiesElement (XNode context) / typeAliasesElement (XNode context) / pluginElement (XNode context) / / MyBatis allows you to intercept calls executed by mapped statements at some point. By default MyBatis allows the use of plug-ins to intercept method calls / objectFactoryElement (XNode context) / objectWrapperFactoryElement (XNode context) settingsElement (XNode context) / environmentsElement (XNode context) / / databaseIdProviderElement (XNode context) / typeHandlerElement (XNode context) / mapperElement (XNode context) / / 1. Use the classpath / 2. Use absolute url path / 3. Use java class name / 4. Automatically scan all mappers under the package / /

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report