标签:
本章中分析delete元素的解析。
1 配置文件
<delete id="deleteByPrimaryKey" parameterType="java.lang.Integer"> <!-- WARNING - @mbggenerated This element is automatically generated by MyBatis Generator, do not modify. This element was generated on Fri Aug 14 16:08:36 CST 2015. --> delete from tb_menu where Id = #{id,jdbcType=INTEGER} </delete>
2 方法parseStatementNode
public void parseStatementNode() { // deleteByPrimaryKey String id = context.getStringAttribute("id"); // null String databaseId = context.getStringAttribute("databaseId"); // 第一次检查这里是不通过的,直接跳过 if (!databaseIdMatchesCurrent(id, databaseId, this.requiredDatabaseId)) return; // null Integer fetchSize = context.getIntAttribute("fetchSize"); // null Integer timeout = context.getIntAttribute("timeout"); // null String parameterMap = context.getStringAttribute("parameterMap"); // java.lang.Integer String parameterType = context.getStringAttribute("parameterType"); // class java.lang.Integer Class<?> parameterTypeClass = resolveClass(parameterType); // null String resultMap = context.getStringAttribute("resultMap"); // null String resultType = context.getStringAttribute("resultType"); // null String lang = context.getStringAttribute("lang"); // 获取默认的处理对象 // org.apache.ibatis.scripting.xmltags.XMLLanguageDriver LanguageDriver langDriver = getLanguageDriver(lang); // null Class<?> resultTypeClass = resolveClass(resultType); // null String resultSetType = context.getStringAttribute("resultSetType"); // PREPARED StatementType statementType = StatementType.valueOf(context.getStringAttribute("statementType", StatementType.PREPARED.toString())); ResultSetType resultSetTypeEnum = resolveResultSetType(resultSetType); // delete String nodeName = context.getNode().getNodeName(); // DELETE SqlCommandType sqlCommandType = SqlCommandType.valueOf(nodeName.toUpperCase(Locale.ENGLISH)); // false boolean isSelect = sqlCommandType == SqlCommandType.SELECT; // true boolean flushCache = context.getBooleanAttribute("flushCache", !isSelect); // false boolean useCache = context.getBooleanAttribute("useCache", isSelect); // false boolean resultOrdered = context.getBooleanAttribute("resultOrdered", false); // Include Fragments before parsing XMLIncludeTransformer includeParser = new XMLIncludeTransformer(configuration, builderAssistant); // 解析<include refid="Base_Column_List" /> includeParser.applyIncludes(context.getNode()); // Parse selectKey after includes and remove them. processSelectKeyNodes(id, parameterTypeClass, langDriver); // 这里很明显也是静态SQL // org.apache.ibatis.builder.StaticSqlSource SqlSource sqlSource = langDriver.createSqlSource(configuration, context, parameterTypeClass); // null String resultSets = context.getStringAttribute("resultSets"); // null String keyProperty = context.getStringAttribute("keyProperty"); // null String keyColumn = context.getStringAttribute("keyColumn"); // org.apache.ibatis.executor.keygen.NoKeyGenerator KeyGenerator keyGenerator; // deleteByPrimaryKey!selectKey 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); }
deleteByPrimaryKey最终的MappedStatement
标签:
原文地址:http://my.oschina.net/u/1269959/blog/523704