• mybatis语句的存储


    sqlSession --|》configuration --|》 MappedStatement --|》 SqlSource --|》BoundSql

    XMLStatementBuilder 解析xml,解析qlSource等属性,生成MappedStatement

    SqlSource sqlSource = langDriver.createSqlSource(configuration, context, parameterTypeClass);
    根据xml解析,生成SqlSource

    String resultSets = context.getStringAttribute("resultSets"); // context 是一个XNode ,就是一个类似这种
    String keyProperty = context.getStringAttribute("keyProperty");
    String keyColumn = context.getStringAttribute("keyColumn");
    获取解析的resultSets、keyProperty、eyColumn

    builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,
    fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass,
    resultSetTypeEnum, flushCache, useCache, resultOrdered,
    keyGenerator, keyProperty, keyColumn, databaseId, langDriver, resultSets);
    把解析的这些属性,通过MapperBuilderAssistant添加一个MappedStatement到configuration中。

    MapperBuilderAssistant

    public MappedStatement addMappedStatement(
    String id,
    SqlSource sqlSource,
    StatementType statementType,
    SqlCommandType sqlCommandType,
    Integer fetchSize,
    Integer timeout,
    String parameterMap,
    Class<?> parameterType,
    String resultMap,
    Class<?> resultType,
    ResultSetType resultSetType,
    boolean flushCache,
    boolean useCache,
    boolean resultOrdered,
    KeyGenerator keyGenerator,
    String keyProperty,
    String keyColumn,
    String databaseId,
    LanguageDriver lang,
    String resultSets) {...}
    把MappedStatement添加到configuration中。在XMLScriptBuilder的parseScriptNode()中调用了addMappedStatement这个方法

    MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType);
    生成MappedStatement.Builder,传入了sqlSource。

    MappedStatement statement = statementBuilder.build();
    构造MappedStatement

    configuration.addMappedStatement(statement);
    添加到configuration

    XMLLanguageDriver 创建SqlSource的工厂。

    public SqlSource createSqlSource(Configuration configuration, XNode script, Class<?> parameterType) {...}
    XMLScriptBuilder builder = new XMLScriptBuilder(configuration, script, parameterType);
    return builder.parseScriptNode();

    XMLScriptBuilder

    public XMLScriptBuilder(Configuration configuration, XNode context, Class<?> parameterType) {...}
    构造函数,传入XNode进去给它们解析

    public SqlSource parseScriptNode() {...}
    解析XNode生成SqlSource
    List contents = parseDynamicTags(context);
    解析XNode,获取当前XNode的所有SqlNode
    MixedSqlNode rootSqlNode = new MixedSqlNode(contents);
    sqlSource = new DynamicSqlSource(configuration, rootSqlNode);
    return sqlSource;

    private List parseDynamicTags(XNode node){...}

    NodeHandler handler = nodeHandlers.get(nodeName);
    handler.handleNode(child, contents);
    根据nodeName获取相应类型的NodeHandler,去解析生成SQLNode // SQLNode是 trim、if、where 这些

    StaticSqlSource SqlSource是一个工厂,用于生产BoundSql

    public BoundSql getBoundSql(Object parameterObject) {...}
    return new BoundSql(configuration, sql, parameterMappings, parameterObject);

  • 相关阅读:
    P1246 编码
    P2638 安全系统
    P3913 车的攻击
    P2789 直线交点数
    What?100%基于深度强化学习的对冲基金
    AI | 重磅推荐!哥大开源“FinRL”:一个用于量化金融自动交易的深度强化学习库
    神经霍克斯过程:一个基于神经网络的自调节多变量点过程
    量化都玩IPU了?Man Group-Oxford研究所给你答案
    为什么数字资产生态系统能够增长到2万亿美元以上?
    ICML 获奖者陆昱成:去中心化机器学习的理论极限在哪里?
  • 原文地址:https://www.cnblogs.com/kltsee/p/15168465.html
Copyright © 2020-2023  润新知