zoukankan      html  css  js  c++  java
  • 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);

  • 相关阅读:
    random模块学习笔记
    python3 控制结构知识及范例
    eclipse运行python 安装pydev 版本匹配问题
    接口自动化CSV文件生成超长随机字符串--java接口方法
    lucene 3.0 + 盘古分词 + 关键字高亮 + 分页的实现与demo
    Loading a Different jQuery Version for IE6-8
    选择排序和冒泡排序
    Bootstrap Tabs with AJAX snippet
    jquery.qrcode.js
    validator.w3.org for html5
  • 原文地址:https://www.cnblogs.com/kltsee/p/15168465.html
Copyright © 2011-2022 走看看