org.apache.ibatis.mapping.ResultSetType Java Examples

The following examples show how to use org.apache.ibatis.mapping.ResultSetType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MybatisMapperBuildAssistant.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
protected void 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) {

	assistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,
			fetchSize, timeout, parameterMap, parameterType, resultMap, resultType,
			resultSetType, flushCache, useCache, resultOrdered, keyGenerator,
			keyProperty, keyColumn, databaseId, lang, resultSets);

}
 
Example #2
Source File: MapperAnnotationBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private KeyGenerator handleSelectKeyAnnotation(SelectKey selectKeyAnnotation, String baseStatementId, Class<?> parameterTypeClass, LanguageDriver languageDriver) {
  String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
  Class<?> resultTypeClass = selectKeyAnnotation.resultType();
  StatementType statementType = selectKeyAnnotation.statementType();
  String keyProperty = selectKeyAnnotation.keyProperty();
  String keyColumn = selectKeyAnnotation.keyColumn();
  boolean executeBefore = selectKeyAnnotation.before();

  // defaults
  boolean useCache = false;
  KeyGenerator keyGenerator = new NoKeyGenerator();
  Integer fetchSize = null;
  Integer timeout = null;
  boolean flushCache = false;
  String parameterMap = null;
  String resultMap = null;
  ResultSetType resultSetTypeEnum = null;

  SqlSource sqlSource = buildSqlSourceFromStrings(selectKeyAnnotation.statement(), parameterTypeClass, languageDriver);
  SqlCommandType sqlCommandType = SqlCommandType.SELECT;

  assistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum,
      flushCache, useCache, false,
      keyGenerator, keyProperty, keyColumn, null, languageDriver, null);

  id = assistant.applyCurrentNamespace(id, false);

  MappedStatement keyStatement = configuration.getMappedStatement(id, false);
  SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore);
  configuration.addKeyGenerator(id, answer);
  return answer;
}
 
Example #3
Source File: MapperBuilderAssistant.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void setStatementResultMap(
    String resultMap,
    Class<?> resultType,
    ResultSetType resultSetType,
    MappedStatement.Builder statementBuilder) {
  resultMap = applyCurrentNamespace(resultMap, true);

  List<ResultMap> resultMaps = new ArrayList<ResultMap>();
  if (resultMap != null) {
    //2.1 resultMap是高级功能
    String[] resultMapNames = resultMap.split(",");
    for (String resultMapName : resultMapNames) {
      try {
        resultMaps.add(configuration.getResultMap(resultMapName.trim()));
      } catch (IllegalArgumentException e) {
        throw new IncompleteElementException("Could not find result map " + resultMapName, e);
      }
    }
  } else if (resultType != null) {
    //2.2 resultType,一般用这个足矣了
    //<select id="selectUsers" resultType="User">
    //这种情况下,MyBatis 会在幕后自动创建一个 ResultMap,基于属性名来映射列到 JavaBean 的属性上。
    //如果列名没有精确匹配,你可以在列名上使用 select 字句的别名来匹配标签。
    //创建一个inline result map, 把resultType设上就OK了,
    //然后后面被DefaultResultSetHandler.createResultObject()使用
    //DefaultResultSetHandler.getRowValue()使用
    ResultMap.Builder inlineResultMapBuilder = new ResultMap.Builder(
        configuration,
        statementBuilder.id() + "-Inline",
        resultType,
        new ArrayList<ResultMapping>(),
        null);
    resultMaps.add(inlineResultMapBuilder.build());
  }
  statementBuilder.resultMaps(resultMaps);

  statementBuilder.resultSetType(resultSetType);
}
 
Example #4
Source File: MapperBuilderAssistant.java    From mybaties with Apache License 2.0 5 votes vote down vote up
/** Backward compatibility signature */
//向后兼容方法
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) {
  return addMappedStatement(
    id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, 
    parameterMap, parameterType, resultMap, resultType, resultSetType, 
    flushCache, useCache, resultOrdered, keyGenerator, keyProperty, 
    keyColumn, databaseId, lang, null);
}
 
Example #5
Source File: XMLStatementBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
private void parseSelectKeyNode(String id, XNode nodeToHandle, Class<?> parameterTypeClass, LanguageDriver langDriver, String databaseId) {
  String resultType = nodeToHandle.getStringAttribute("resultType");
  Class<?> resultTypeClass = resolveClass(resultType);
  StatementType statementType = StatementType.valueOf(nodeToHandle.getStringAttribute("statementType", StatementType.PREPARED.toString()));
  String keyProperty = nodeToHandle.getStringAttribute("keyProperty");
  String keyColumn = nodeToHandle.getStringAttribute("keyColumn");
  boolean executeBefore = "BEFORE".equals(nodeToHandle.getStringAttribute("order", "AFTER"));

  //defaults
  boolean useCache = false;
  boolean resultOrdered = false;
  KeyGenerator keyGenerator = new NoKeyGenerator();
  Integer fetchSize = null;
  Integer timeout = null;
  boolean flushCache = false;
  String parameterMap = null;
  String resultMap = null;
  ResultSetType resultSetTypeEnum = null;

  SqlSource sqlSource = langDriver.createSqlSource(configuration, nodeToHandle, parameterTypeClass);
  SqlCommandType sqlCommandType = SqlCommandType.SELECT;

  builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,
      fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass,
      resultSetTypeEnum, flushCache, useCache, resultOrdered,
      keyGenerator, keyProperty, keyColumn, databaseId, langDriver, null);

  id = builderAssistant.applyCurrentNamespace(id, false);

  MappedStatement keyStatement = configuration.getMappedStatement(id, false);
  configuration.addKeyGenerator(id, new SelectKeyGenerator(keyStatement, executeBefore));
}
 
Example #6
Source File: BaseBuilder.java    From mybaties with Apache License 2.0 5 votes vote down vote up
protected ResultSetType resolveResultSetType(String alias) {
  if (alias == null) {
    return null;
  }
  try {
    return ResultSetType.valueOf(alias);
  } catch (IllegalArgumentException e) {
    throw new BuilderException("Error resolving ResultSetType. Cause: " + e, e);
  }
}
 
Example #7
Source File: MapperAnnotationBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private KeyGenerator handleSelectKeyAnnotation(SelectKey selectKeyAnnotation, String baseStatementId, Class<?> parameterTypeClass, LanguageDriver languageDriver) {
  String id = baseStatementId + SelectKeyGenerator.SELECT_KEY_SUFFIX;
  Class<?> resultTypeClass = selectKeyAnnotation.resultType();
  StatementType statementType = selectKeyAnnotation.statementType();
  String keyProperty = selectKeyAnnotation.keyProperty();
  String keyColumn = selectKeyAnnotation.keyColumn();
  boolean executeBefore = selectKeyAnnotation.before();

  // defaults
  boolean useCache = false;
  KeyGenerator keyGenerator = new NoKeyGenerator();
  Integer fetchSize = null;
  Integer timeout = null;
  boolean flushCache = false;
  String parameterMap = null;
  String resultMap = null;
  ResultSetType resultSetTypeEnum = null;

  SqlSource sqlSource = buildSqlSourceFromStrings(selectKeyAnnotation.statement(), parameterTypeClass, languageDriver);
  SqlCommandType sqlCommandType = SqlCommandType.SELECT;

  assistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass, resultSetTypeEnum,
      flushCache, useCache, false,
      keyGenerator, keyProperty, keyColumn, null, languageDriver, null);

  id = assistant.applyCurrentNamespace(id, false);

  MappedStatement keyStatement = configuration.getMappedStatement(id, false);
  SelectKeyGenerator answer = new SelectKeyGenerator(keyStatement, executeBefore);
  configuration.addKeyGenerator(id, answer);
  return answer;
}
 
Example #8
Source File: MapperBuilderAssistant.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void setStatementResultMap(
    String resultMap,
    Class<?> resultType,
    ResultSetType resultSetType,
    MappedStatement.Builder statementBuilder) {
  resultMap = applyCurrentNamespace(resultMap, true);

  List<ResultMap> resultMaps = new ArrayList<ResultMap>();
  if (resultMap != null) {
    //2.1 resultMap是高级功能
    String[] resultMapNames = resultMap.split(",");
    for (String resultMapName : resultMapNames) {
      try {
        resultMaps.add(configuration.getResultMap(resultMapName.trim()));
      } catch (IllegalArgumentException e) {
        throw new IncompleteElementException("Could not find result map " + resultMapName, e);
      }
    }
  } else if (resultType != null) {
    //2.2 resultType,一般用这个足矣了
    //<select id="selectUsers" resultType="User">
    //这种情况下,MyBatis 会在幕后自动创建一个 ResultMap,基于属性名来映射列到 JavaBean 的属性上。
    //如果列名没有精确匹配,你可以在列名上使用 select 字句的别名来匹配标签。
    //创建一个inline result map, 把resultType设上就OK了,
    //然后后面被DefaultResultSetHandler.createResultObject()使用
    //DefaultResultSetHandler.getRowValue()使用
    ResultMap.Builder inlineResultMapBuilder = new ResultMap.Builder(
        configuration,
        statementBuilder.id() + "-Inline",
        resultType,
        new ArrayList<ResultMapping>(),
        null);
    resultMaps.add(inlineResultMapBuilder.build());
  }
  statementBuilder.resultMaps(resultMaps);

  statementBuilder.resultSetType(resultSetType);
}
 
Example #9
Source File: MapperBuilderAssistant.java    From mybatis with Apache License 2.0 5 votes vote down vote up
/** Backward compatibility signature */
//向后兼容方法
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) {
  return addMappedStatement(
    id, sqlSource, statementType, sqlCommandType, fetchSize, timeout, 
    parameterMap, parameterType, resultMap, resultType, resultSetType, 
    flushCache, useCache, resultOrdered, keyGenerator, keyProperty, 
    keyColumn, databaseId, lang, null);
}
 
Example #10
Source File: XMLStatementBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
private void parseSelectKeyNode(String id, XNode nodeToHandle, Class<?> parameterTypeClass, LanguageDriver langDriver, String databaseId) {
  String resultType = nodeToHandle.getStringAttribute("resultType");
  Class<?> resultTypeClass = resolveClass(resultType);
  StatementType statementType = StatementType.valueOf(nodeToHandle.getStringAttribute("statementType", StatementType.PREPARED.toString()));
  String keyProperty = nodeToHandle.getStringAttribute("keyProperty");
  String keyColumn = nodeToHandle.getStringAttribute("keyColumn");
  boolean executeBefore = "BEFORE".equals(nodeToHandle.getStringAttribute("order", "AFTER"));

  //defaults
  boolean useCache = false;
  boolean resultOrdered = false;
  KeyGenerator keyGenerator = new NoKeyGenerator();
  Integer fetchSize = null;
  Integer timeout = null;
  boolean flushCache = false;
  String parameterMap = null;
  String resultMap = null;
  ResultSetType resultSetTypeEnum = null;

  SqlSource sqlSource = langDriver.createSqlSource(configuration, nodeToHandle, parameterTypeClass);
  SqlCommandType sqlCommandType = SqlCommandType.SELECT;

  builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,
      fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass,
      resultSetTypeEnum, flushCache, useCache, resultOrdered,
      keyGenerator, keyProperty, keyColumn, databaseId, langDriver, null);

  id = builderAssistant.applyCurrentNamespace(id, false);

  MappedStatement keyStatement = configuration.getMappedStatement(id, false);
  configuration.addKeyGenerator(id, new SelectKeyGenerator(keyStatement, executeBefore));
}
 
Example #11
Source File: BaseBuilder.java    From mybatis with Apache License 2.0 5 votes vote down vote up
protected ResultSetType resolveResultSetType(String alias) {
  if (alias == null) {
    return null;
  }
  try {
    return ResultSetType.valueOf(alias);
  } catch (IllegalArgumentException e) {
    throw new BuilderException("Error resolving ResultSetType. Cause: " + e, e);
  }
}
 
Example #12
Source File: MapperBuilderAssistant.java    From mybaties with Apache License 2.0 4 votes vote down vote up
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) {
  
  if (unresolvedCacheRef) {
    throw new IncompleteElementException("Cache-ref not yet resolved");
  }
  
  //为id加上namespace前缀
  id = applyCurrentNamespace(id, false);
  //是否是select语句
  boolean isSelect = sqlCommandType == SqlCommandType.SELECT;

  //又是建造者模式
  MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType);
  statementBuilder.resource(resource);
  statementBuilder.fetchSize(fetchSize);
  statementBuilder.statementType(statementType);
  statementBuilder.keyGenerator(keyGenerator);
  statementBuilder.keyProperty(keyProperty);
  statementBuilder.keyColumn(keyColumn);
  statementBuilder.databaseId(databaseId);
  statementBuilder.lang(lang);
  statementBuilder.resultOrdered(resultOrdered);
  statementBuilder.resulSets(resultSets);
  setStatementTimeout(timeout, statementBuilder);

  //1.参数映射
  setStatementParameterMap(parameterMap, parameterType, statementBuilder);
  //2.结果映射
  setStatementResultMap(resultMap, resultType, resultSetType, statementBuilder);
  setStatementCache(isSelect, flushCache, useCache, currentCache, statementBuilder);

  MappedStatement statement = statementBuilder.build();
  //建造好调用configuration.addMappedStatement
  configuration.addMappedStatement(statement);
  return statement;
}
 
Example #13
Source File: XMLStatementBuilder.java    From mybaties with Apache License 2.0 4 votes vote down vote up
public void parseStatementNode() {
   String id = context.getStringAttribute("id");
   String databaseId = context.getStringAttribute("databaseId");

   //如果databaseId不匹配,退出
   if (!databaseIdMatchesCurrent(id, databaseId, this.requiredDatabaseId)) {
     return;
   }

   //暗示驱动程序每次批量返回的结果行数
   Integer fetchSize = context.getIntAttribute("fetchSize");
   //超时时间
   Integer timeout = context.getIntAttribute("timeout");
   //引用外部 parameterMap,已废弃
   String parameterMap = context.getStringAttribute("parameterMap");
   //参数类型
   String parameterType = context.getStringAttribute("parameterType");
   Class<?> parameterTypeClass = resolveClass(parameterType);
   //引用外部的 resultMap(高级功能)
   String resultMap = context.getStringAttribute("resultMap");
   //结果类型
   String resultType = context.getStringAttribute("resultType");
   //脚本语言,mybatis3.2的新功能
   String lang = context.getStringAttribute("lang");
   //得到语言驱动
   LanguageDriver langDriver = getLanguageDriver(lang);

   Class<?> resultTypeClass = resolveClass(resultType);
   //结果集类型,FORWARD_ONLY|SCROLL_SENSITIVE|SCROLL_INSENSITIVE 中的一种
   String resultSetType = context.getStringAttribute("resultSetType");
   //语句类型, STATEMENT|PREPARED|CALLABLE 的一种
   StatementType statementType = StatementType.valueOf(context.getStringAttribute("statementType", StatementType.PREPARED.toString()));
   ResultSetType resultSetTypeEnum = resolveResultSetType(resultSetType);

   //获取命令类型(select|insert|update|delete)
   String nodeName = context.getNode().getNodeName();
   SqlCommandType sqlCommandType = SqlCommandType.valueOf(nodeName.toUpperCase(Locale.ENGLISH));
   boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
   boolean flushCache = context.getBooleanAttribute("flushCache", !isSelect);
   //是否要缓存select结果
   boolean useCache = context.getBooleanAttribute("useCache", isSelect);
   //仅针对嵌套结果 select 语句适用:如果为 true,就是假设包含了嵌套结果集或是分组了,这样的话当返回一个主结果行的时候,就不会发生有对前面结果集的引用的情况。
   //这就使得在获取嵌套的结果集的时候不至于导致内存不够用。默认值:false。 
   boolean resultOrdered = context.getBooleanAttribute("resultOrdered", false);

   // Include Fragments before parsing
   //解析之前先解析<include>SQL片段
   XMLIncludeTransformer includeParser = new XMLIncludeTransformer(configuration, builderAssistant);
   includeParser.applyIncludes(context.getNode());

   // Parse selectKey after includes and remove them.
   //解析之前先解析<selectKey>
   processSelectKeyNodes(id, parameterTypeClass, langDriver);
   
   // Parse the SQL (pre: <selectKey> and <include> were parsed and removed)
   //解析成SqlSource,一般是DynamicSqlSource
   SqlSource sqlSource = langDriver.createSqlSource(configuration, context, parameterTypeClass);
   String resultSets = context.getStringAttribute("resultSets");
   //(仅对 insert 有用) 标记一个属性, MyBatis 会通过 getGeneratedKeys 或者通过 insert 语句的 selectKey 子元素设置它的值
   String keyProperty = context.getStringAttribute("keyProperty");
   //(仅对 insert 有用) 标记一个属性, MyBatis 会通过 getGeneratedKeys 或者通过 insert 语句的 selectKey 子元素设置它的值
   String keyColumn = context.getStringAttribute("keyColumn");
   KeyGenerator keyGenerator;
   String keyStatementId = id + SelectKeyGenerator.SELECT_KEY_SUFFIX;
   keyStatementId = builderAssistant.applyCurrentNamespace(keyStatementId, true);
   if (configuration.hasKeyGenerator(keyStatementId)) {
     keyGenerator = configuration.getKeyGenerator(keyStatementId);
   } else {
     keyGenerator = context.getBooleanAttribute("useGeneratedKeys",
         configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType))
         ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
   }

//又去调助手类
   builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,
       fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass,
       resultSetTypeEnum, flushCache, useCache, resultOrdered, 
       keyGenerator, keyProperty, keyColumn, databaseId, langDriver, resultSets);
 }
 
Example #14
Source File: MapperBuilderAssistant.java    From mybatis with Apache License 2.0 4 votes vote down vote up
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) {
  
  if (unresolvedCacheRef) {
    throw new IncompleteElementException("Cache-ref not yet resolved");
  }
  
  //为id加上namespace前缀
  id = applyCurrentNamespace(id, false);
  //是否是select语句
  boolean isSelect = sqlCommandType == SqlCommandType.SELECT;

  //又是建造者模式
  MappedStatement.Builder statementBuilder = new MappedStatement.Builder(configuration, id, sqlSource, sqlCommandType);
  statementBuilder.resource(resource);
  statementBuilder.fetchSize(fetchSize);
  statementBuilder.statementType(statementType);
  statementBuilder.keyGenerator(keyGenerator);
  statementBuilder.keyProperty(keyProperty);
  statementBuilder.keyColumn(keyColumn);
  statementBuilder.databaseId(databaseId);
  statementBuilder.lang(lang);
  statementBuilder.resultOrdered(resultOrdered);
  statementBuilder.resulSets(resultSets);
  setStatementTimeout(timeout, statementBuilder);

  //1.参数映射
  setStatementParameterMap(parameterMap, parameterType, statementBuilder);
  //2.结果映射
  setStatementResultMap(resultMap, resultType, resultSetType, statementBuilder);
  setStatementCache(isSelect, flushCache, useCache, currentCache, statementBuilder);

  MappedStatement statement = statementBuilder.build();
  //建造好调用configuration.addMappedStatement
  configuration.addMappedStatement(statement);
  return statement;
}
 
Example #15
Source File: XMLStatementBuilder.java    From mybatis with Apache License 2.0 4 votes vote down vote up
public void parseStatementNode() {
   String id = context.getStringAttribute("id");
   String databaseId = context.getStringAttribute("databaseId");

   //如果databaseId不匹配,退出
   if (!databaseIdMatchesCurrent(id, databaseId, this.requiredDatabaseId)) {
     return;
   }

   //暗示驱动程序每次批量返回的结果行数
   Integer fetchSize = context.getIntAttribute("fetchSize");
   //超时时间
   Integer timeout = context.getIntAttribute("timeout");
   //引用外部 parameterMap,已废弃
   String parameterMap = context.getStringAttribute("parameterMap");
   //参数类型
   String parameterType = context.getStringAttribute("parameterType");
   Class<?> parameterTypeClass = resolveClass(parameterType);
   //引用外部的 resultMap(高级功能)
   String resultMap = context.getStringAttribute("resultMap");
   //结果类型
   String resultType = context.getStringAttribute("resultType");
   //脚本语言,mybatis3.2的新功能
   String lang = context.getStringAttribute("lang");
   //得到语言驱动
   LanguageDriver langDriver = getLanguageDriver(lang);

   Class<?> resultTypeClass = resolveClass(resultType);
   //结果集类型,FORWARD_ONLY|SCROLL_SENSITIVE|SCROLL_INSENSITIVE 中的一种
   String resultSetType = context.getStringAttribute("resultSetType");
   //语句类型, STATEMENT|PREPARED|CALLABLE 的一种
   StatementType statementType = StatementType.valueOf(context.getStringAttribute("statementType", StatementType.PREPARED.toString()));
   ResultSetType resultSetTypeEnum = resolveResultSetType(resultSetType);

   //获取命令类型(select|insert|update|delete)
   String nodeName = context.getNode().getNodeName();
   SqlCommandType sqlCommandType = SqlCommandType.valueOf(nodeName.toUpperCase(Locale.ENGLISH));
   boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
   boolean flushCache = context.getBooleanAttribute("flushCache", !isSelect);
   //是否要缓存select结果
   boolean useCache = context.getBooleanAttribute("useCache", isSelect);
   //仅针对嵌套结果 select 语句适用:如果为 true,就是假设包含了嵌套结果集或是分组了,这样的话当返回一个主结果行的时候,就不会发生有对前面结果集的引用的情况。
   //这就使得在获取嵌套的结果集的时候不至于导致内存不够用。默认值:false。 
   boolean resultOrdered = context.getBooleanAttribute("resultOrdered", false);

   // Include Fragments before parsing
   //解析之前先解析<include>SQL片段
   XMLIncludeTransformer includeParser = new XMLIncludeTransformer(configuration, builderAssistant);
   includeParser.applyIncludes(context.getNode());

   // Parse selectKey after includes and remove them.
   //解析之前先解析<selectKey>
   processSelectKeyNodes(id, parameterTypeClass, langDriver);
   
   // Parse the SQL (pre: <selectKey> and <include> were parsed and removed)
   //解析成SqlSource,一般是DynamicSqlSource
   SqlSource sqlSource = langDriver.createSqlSource(configuration, context, parameterTypeClass);
   String resultSets = context.getStringAttribute("resultSets");
   //(仅对 insert 有用) 标记一个属性, MyBatis 会通过 getGeneratedKeys 或者通过 insert 语句的 selectKey 子元素设置它的值
   String keyProperty = context.getStringAttribute("keyProperty");
   //(仅对 insert 有用) 标记一个属性, MyBatis 会通过 getGeneratedKeys 或者通过 insert 语句的 selectKey 子元素设置它的值
   String keyColumn = context.getStringAttribute("keyColumn");
   KeyGenerator keyGenerator;
   String keyStatementId = id + SelectKeyGenerator.SELECT_KEY_SUFFIX;
   keyStatementId = builderAssistant.applyCurrentNamespace(keyStatementId, true);
   if (configuration.hasKeyGenerator(keyStatementId)) {
     keyGenerator = configuration.getKeyGenerator(keyStatementId);
   } else {
     keyGenerator = context.getBooleanAttribute("useGeneratedKeys",
         configuration.isUseGeneratedKeys() && SqlCommandType.INSERT.equals(sqlCommandType))
         ? new Jdbc3KeyGenerator() : new NoKeyGenerator();
   }

//又去调助手类
   builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,
       fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass,
       resultSetTypeEnum, flushCache, useCache, resultOrdered, 
       keyGenerator, keyProperty, keyColumn, databaseId, langDriver, resultSets);
 }