阅读源码笔记一

一、build 

  public SqlSessionFactory build(InputStream inputStream) {
    return build(inputStream, null, null);
  }

build作用:建立一个SqlSessionFactory

返回值:inputstream输入流

二、build

 public SqlSessionFactory build(InputStream inputStream, String environment, Properties properties) {
    try {
      XMLConfigBuilder parser = new XMLConfigBuilder(inputStream, environment, properties);
      return build(parser.parse());
    } catch (Exception e) {
      throw ExceptionFactory.wrapException("Error building SqlSession.", e);
    } finally {
      ErrorContext.instance().reset();
      try {
        inputStream.close();
      } catch (IOException e) {
        // Intentionally ignore. Prefer previous error.
      }
    }
  }

build作用:建立一个SqlSessionFactory

返回值:

InputStream inputStream:输入流

String environment:环境

Properties properties:属性

XMLConfigBuilder parser = new XMLConfigBuilder(inputStream, environment, properties);

XMLConfigBuilder:读取.xml文件

parser:解析

return build(parser.parse());

返回配置文件

public SqlSessionFactory build(Configuration config) {
    return new DefaultSqlSessionFactory(config);
  }

 

三、XMLConfigBuilder

public XMLConfigBuilder(InputStream inputStream, String environment, Properties props) {
    this(new XPathParser(inputStream, true, props, new XMLMapperEntityResolver()), environment, props);
  }

XMLConfigBuilder作用:读取.xml文件

参数:

InputStream inputStream:输入流

String environment:环境

Properties props:属性

XPathParser作用:.xml路径解析

public XPathParser(InputStream inputStream, boolean validation, Properties variables, EntityResolver entityResolver) {
    commonConstructor(validation, variables, entityResolver);
    this.document = createDocument(new InputSource(inputStream));
  }

参数:

InputStream inputStream:输入流

 boolean validation:布尔类型

Properties variables:属性

 EntityResolver entityResolver:实体处理类

commonConstructor:公共构造函数

private void commonConstructor(boolean validation, Properties variables, EntityResolver entityResolver) {
    this.validation = validation;
    this.entityResolver = entityResolver;
    this.variables = variables;
    XPathFactory factory = XPathFactory.newInstance();
    this.xpath = factory.newXPath();
  }

this.document = createDocument(new InputSource(inputStream));

把输入流传进来的资源创建为一个文档

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值