Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完善MappedStatement构建的参数映射流程注释 #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,7 @@ private void setStatementParameterMap(
String parameterMap,
Class<?> parameterTypeClass,
MappedStatement.Builder statementBuilder) {
// 给parameterMap加上namespace 但是因为parameterMap被弃用 所以一般返回null
parameterMap = applyCurrentNamespace(parameterMap, true);

if (parameterMap != null) {
Expand All @@ -350,12 +351,16 @@ private void setStatementParameterMap(
throw new IncompleteElementException("Could not find parameter map " + parameterMap, e);
}
} else if (parameterTypeClass != null) {
// 解析 parameterType生成的类对象
List<ParameterMapping> parameterMappings = new ArrayList<ParameterMapping>();
// 构造ParameterMap类内部的构建类
// 这里主要是 parameterTypeClass 的赋值 而parameterMapping仅作为一个空列表传入
ParameterMap.Builder inlineParameterMapBuilder = new ParameterMap.Builder(
configuration,
statementBuilder.id() + "-Inline",
parameterTypeClass,
parameterMappings);
// 通过内部构建类构建ParameterMap并传入配置对象中
statementBuilder.parameterMap(inlineParameterMapBuilder.build());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void parseStatementNode() {
includeParser.applyIncludes(context.getNode());

// Parse selectKey after includes and remove them.
//解析之前先解析<selectKey>
//解析之前先解析<selectKey> selectKey主要涉及需要某些特殊关系来设置主键的值
processSelectKeyNodes(id, parameterTypeClass, langDriver);

// Parse the SQL (pre: <selectKey> and <include> were parsed and removed)
Expand All @@ -145,7 +145,7 @@ public void parseStatementNode() {
? new Jdbc3KeyGenerator() : new NoKeyGenerator();
}

//又去调助手类
//调用助手类去真正创建MappedStatement然后加入配置Configuration中
builderAssistant.addMappedStatement(id, sqlSource, statementType, sqlCommandType,
fetchSize, timeout, parameterMap, parameterTypeClass, resultMap, resultTypeClass,
resultSetTypeEnum, flushCache, useCache, resultOrdered,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/apache/ibatis/mapping/ParameterMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ private ParameterMap() {
public static class Builder {
private ParameterMap parameterMap = new ParameterMap();

// 在构建者内部再持有ParameterMap对象并执行一系列赋值构建操作
public Builder(Configuration configuration, String id, Class<?> type, List<ParameterMapping> parameterMappings) {
parameterMap.id = id;
parameterMap.type = type;
Expand Down