Skip to content

Commit e1c17aa

Browse files
committed
Update MapperMethod.java
1 parent e2cdb39 commit e1c17aa

File tree

1 file changed

+31
-25
lines changed

1 file changed

+31
-25
lines changed

src/main/java/org/apache/ibatis/binding/MapperMethod.java

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,39 @@ public MapperMethod(Class<?> mapperInterface, Method method, Configuration confi
5151

5252
public Object execute(SqlSession sqlSession, Object[] args) {
5353
Object result;
54-
if (SqlCommandType.INSERT == command.getType()) {
55-
Object param = method.convertArgsToSqlCommandParam(args);
56-
result = rowCountResult(sqlSession.insert(command.getName(), param));
57-
} else if (SqlCommandType.UPDATE == command.getType()) {
58-
Object param = method.convertArgsToSqlCommandParam(args);
59-
result = rowCountResult(sqlSession.update(command.getName(), param));
60-
} else if (SqlCommandType.DELETE == command.getType()) {
61-
Object param = method.convertArgsToSqlCommandParam(args);
62-
result = rowCountResult(sqlSession.delete(command.getName(), param));
63-
} else if (SqlCommandType.SELECT == command.getType()) {
64-
if (method.returnsVoid() && method.hasResultHandler()) {
65-
executeWithResultHandler(sqlSession, args);
66-
result = null;
67-
} else if (method.returnsMany()) {
68-
result = executeForMany(sqlSession, args);
69-
} else if (method.returnsMap()) {
70-
result = executeForMap(sqlSession, args);
71-
} else if (method.returnsCursor()) {
72-
result = executeForCursor(sqlSession, args);
73-
} else {
54+
switch (command.getType()) {
55+
case INSERT:
7456
Object param = method.convertArgsToSqlCommandParam(args);
75-
result = sqlSession.selectOne(command.getName(), param);
76-
}
77-
} else if (SqlCommandType.FLUSH == command.getType()) {
57+
result = rowCountResult(sqlSession.insert(command.getName(), param));
58+
break;
59+
case UPDATE:
60+
Object param = method.convertArgsToSqlCommandParam(args);
61+
result = rowCountResult(sqlSession.update(command.getName(), param));
62+
break;
63+
case DELETE:
64+
Object param = method.convertArgsToSqlCommandParam(args);
65+
result = rowCountResult(sqlSession.delete(command.getName(), param));
66+
break;
67+
case SELECT:
68+
if (method.returnsVoid() && method.hasResultHandler()) {
69+
executeWithResultHandler(sqlSession, args);
70+
result = null;
71+
} else if (method.returnsMany()) {
72+
result = executeForMany(sqlSession, args);
73+
} else if (method.returnsMap()) {
74+
result = executeForMap(sqlSession, args);
75+
} else if (method.returnsCursor()) {
76+
result = executeForCursor(sqlSession, args);
77+
} else {
78+
Object param = method.convertArgsToSqlCommandParam(args);
79+
result = sqlSession.selectOne(command.getName(), param);
80+
}
81+
break;
82+
case FLUSH:
7883
result = sqlSession.flushStatements();
79-
} else {
80-
throw new BindingException("Unknown execution method for: " + command.getName());
84+
break;
85+
case default:
86+
throw new BindingException("Unknown execution method for: " + command.getName());
8187
}
8288
if (result == null && method.getReturnType().isPrimitive() && !method.returnsVoid()) {
8389
throw new BindingException("Mapper method '" + command.getName()

0 commit comments

Comments
 (0)