; if (configurationElement == null) { throw new Exception("It ); database.DefaultCommandType = configurationElement.DedaultCommandType; Type dbParameterNameMappingType = Type.GetType(configurationElement.DbParameterNameMapping); ); database.DefaultCommandType = configurationElement.DedaultCommandType; Type dbParameterNameMappingType = Type.GetType(configurationElement.DbParameterNameMapping);
ElementInformation 获取包含 ConfigurationElement 对象的不可自定义的信息和功能的 ElementInformation 对象。 (从 ConfigurationElement 继承。) Errors 获取 CustomError 对象的集合,也就是其下面的<error>配置节。 (从 ConfigurationElement 继承。) LockAllElementsExcept 获取被锁定的元素的集合。 (从 ConfigurationElement 继承。) (从 ConfigurationElement 继承。) LockElements 获取被锁定的元素的集合。 (从 ConfigurationElement 继承。) (从 ConfigurationElement 继承。) Mode 获取或设置错误显示模式。
Properties.Settings访问 configsections xml节点:ConfigurationSection、ConfigurationElementCollection xml属性:ConfigurationElement ArcingMonitor.Config.ArcingConfigSection,ArcingMonitor" /> </sectionGroup> section定义节点和代码添加的节点没有关系 public class ArcingConfig : ConfigurationElement
System.Configuration; namespace SampleWebConfigSection.Configuration { public class baseSection : ConfigurationElement public string url { get { return (string)base["url"]; } set { url = value; } } } } 派生自ConfigurationElement public class fileUploadSection : ConfigurationElementCollection { protected override ConfigurationElement )] public int size { get { return (int)this["size"]; } set { size = value; } } } } 派生自ConfigurationElement ------------------------------ ps.补充一点Configuration自定义节点结构: ConfigurationSection:对应整个自定义节点Xml的最外层节点 ConfigurationElement
configuration.isResourceLoaded(resource)) { configurationElement(parser.evalNode("/mapper")); configuration.addLoadedResource(resource); //注册 Mapper 接 口 bindMapperForNamespace(); } //处理 configurationElement ()方法中解析失败的<resultMap>节点 parsePendingResultMaps(); //处理 configurationElement ()方法中 解析失败的< cache-ref >节点 parsePendingCacheRefs(); //处理 configurationElement ()方法中 解析失败的 SQL 语句节点 parsePendingStatements
configuration.isResourceLoaded(resource)) { configurationElement(parser.evalNode("/mapper")); configuration.addLoadedResource(resource); //注册 Mapper 接 口 bindMapperForNamespace(); } //处理 configurationElement ()方法中解析失败的<resultMap>节点 parsePendingResultMaps(); //处理 configurationElement ()方法中 解析失败的< cache-ref >节点 parsePendingCacheRefs(); //处理 configurationElement ()方法中 解析失败的 SQL 语句节点 parsePendingStatements
{ this["Password"] = value; } } } } } 第二种情况比第一种情况的区别就是,数据类型也是自己定义的,具体的配置属性写在ConfigurationElement value="Leo"></add> <add key="3" value="Lynn"></add> </Test4> </configuration> 为每个集合中的参数项创建一个从ConfigurationElement protected override ConfigurationElement CreateNewElement() { return new MyKeyValueSetting (); } protected override object GetElementKey(ConfigurationElement element) { { base.BaseRemove(name); } } public class MyKeyValueSetting : ConfigurationElement
{ this["Password"] = value; } } } } } 第二种情况比第一种情况的区别就是,数据类型也是自己定义的,具体的配置属性写在ConfigurationElement value="Leo"></add> <add key="3" value="Lynn"></add> </Test4> </configuration> 为每个集合中的参数项创建一个从ConfigurationElement protected override ConfigurationElement CreateNewElement() { return new MyKeyValueSetting (); } protected override object GetElementKey(ConfigurationElement element) { { base.BaseRemove(name); } } public class MyKeyValueSetting : ConfigurationElement
class AssemblyElementCollection : ConfigurationElementCollection 17: { 18: protected override ConfigurationElement return new AssemblyElement(); 21: } 22: protected override object GetElementKey(ConfigurationElement serviceTypeElement.AssemblyName; 26: } 27: } 28: 29: public class AssemblyElement : ConfigurationElement
比如ConfigurationSection、ConfigurationElement、ConfigurationElementCollection等。 顾名思义,NameTypeConfigurationElement就是具有两个基本配置属性Name和Type的配置元素(ConfigurationElement),其定义如下。 1: public class NameTypeConfigurationElement : ConfigurationElement 2: { 3: [ConfigurationProperty ConfigurationElementCollection where T : NameTypeConfigurationElement 2: { 3: protected override ConfigurationElement return Activator.CreateInstance<T>(); 6: } 7: protected override object GetElementKey(ConfigurationElement
configuration.isResourceLoaded(resource)) { //解析所有的mapper子标签 configurationElement(parser.evalNode 详细代码如下: //org.apache.ibatis.builder.xml.XMLMapperBuilder#configurationElement //configurationElement( ):解析的是Mapper.xml的标签 private void configurationElement(XNode context) { try { //获取到namespace命名空间 四、Mapper接口与MapperProxyFactory的绑定过程 前面我们分析了XMLMapperBuilder的parse()方法对mapper接口的解析过程,在执行完configurationElement 小总结: XMLMapperBuilder.parse()方法,是对 Mapper接口的解析,里面有两个方法: (1)configurationElement():解析所有的子标签,最终解析Mapper.xml
NamConfigurationElement则是我自定义的一个包含“name”配置属性的ConfigurationElement。 name) 4: { 5: return (T)this.BaseGet(name); 6: } 7: protected override ConfigurationElement return Activator.CreateInstance<T>(); 10: } 11: protected override object GetElementKey(ConfigurationElement 而RoomConfigurationElement则代表一个具体的Room的配置,除了具有一个名称(继承自ConfigurationElement)之外,它余下的配置就是XxxBuilder的集合了。
xyx.dsw.dao.mapper.admin.quotationwish.TempTestTableMapper.TempTestTableResult at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement xyx.dsw.dao.mapper.admin.quotationwish.TempTestTableMapper.TempTestTableResult at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement xyx.dsw.dao.mapper.admin.quotationwish.TempTestTableMapper.TempTestTableResult at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement xyx.dsw.dao.mapper.admin.quotationwish.TempTestTableMapper.TempTestTableResult at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement xyx.dsw.dao.mapper.admin.quotationwish.TempTestTableMapper.TempTestTableResult at org.apache.ibatis.builder.xml.XMLMapperBuilder.configurationElement
其追踪过程: XMLMapperBuilder#parse->XMLMapperBuilder#configurationElement#buildStatementFromContext#parseStatementNode configuration.isResourceLoaded(resource)) { //配置元素 重要 configurationElement(parser.evalNode(" parsePendingCacheRefs(); parsePendingStatements(); } 可以看到xpath的解析的结果是XNode对象: //配置元素 private void configurationElement
ServiceTypeElementCollection : ConfigurationElementCollection 16: { 17: protected override ConfigurationElement return new ServiceTypeElement(); 20: } 21: protected override object GetElementKey(ConfigurationElement serviceTypeElement.ServiceType.MetadataToken; 25: } 26: } 27: public class ServiceTypeElement : ConfigurationElement
buildSqlSessionFactory() 会遍历所有 mapperLocations(xml文件) 调用 xmlMapperBuilder.parse()解析,源码如下 图片 在 parse() 方法中, Mybatis 通过 configurationElement configuration.isResourceLoaded(resource)) { // xml文件解析逻辑 configurationElement(parser.evalNode parsePendingResultMaps(); parsePendingCacheRefs(); parsePendingStatements(); } private void configurationElement
configuration.isResourceLoaded(resource)) { /** * 1.解析xml中的节点信息,并生成 MappedStatement */ configurationElement XMLMapperBuilder.configurationElement(XNode context) private void configurationElement(XNode context)
configurationElement函数几乎解析了mapper节点下所有子节点,至此mybaits解析了mapper中的所有节点,并将其加入到了Configuration对象中提供给sqlSessionFactory
>> configurationElement(parser.evalNode("/mapper")); configuration.addLoadedResource(resource 一个namespace 一个 MapperProxyFactory >> bindMapperForNamespace(); // 注册 Mapper 接口 } // 处理 configurationElement 方法中解析失败的 <resultMap> 节点 parsePendingResultMaps(); // 处理 configurationElement 方法中解析失败的 <cache-ref > 节点 parsePendingCacheRefs(); // 处理 configurationElement 方法中解析失败的 SQL 语句节点 parsePendingStatements (); } 进入configurationElement方法中。
方法2: 继承ConfigurationSection类,配合ConfigurationProperty特性来实现 public class ObjectContainerElement : ConfigurationElement