Skip to content

Commit 788236f

Browse files
committed
Polishing #1344
1 parent fdf7a9e commit 788236f

File tree

5 files changed

+17
-12
lines changed

5 files changed

+17
-12
lines changed

src/main/java/org/apache/ibatis/builder/annotation/MapperAnnotationBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ void parseStatement(Method method) {
297297
Integer fetchSize = null;
298298
Integer timeout = null;
299299
StatementType statementType = StatementType.PREPARED;
300-
ResultSetType resultSetType = ResultSetType.DEFAULT;
300+
ResultSetType resultSetType = null;
301301
SqlCommandType sqlCommandType = getSqlCommandType(method);
302302
boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
303303
boolean flushCache = !isSelect;

src/main/java/org/apache/ibatis/executor/statement/CallableStatementHandler.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
import org.apache.ibatis.executor.Executor;
2727
import org.apache.ibatis.executor.ExecutorException;
2828
import org.apache.ibatis.executor.keygen.KeyGenerator;
29-
import org.apache.ibatis.mapping.*;
29+
import org.apache.ibatis.mapping.BoundSql;
30+
import org.apache.ibatis.mapping.MappedStatement;
31+
import org.apache.ibatis.mapping.ParameterMapping;
32+
import org.apache.ibatis.mapping.ParameterMode;
33+
import org.apache.ibatis.mapping.ResultSetType;
3034
import org.apache.ibatis.session.ResultHandler;
3135
import org.apache.ibatis.session.RowBounds;
3236
import org.apache.ibatis.type.JdbcType;
@@ -79,10 +83,10 @@ public <E> Cursor<E> queryCursor(Statement statement) throws SQLException {
7983
@Override
8084
protected Statement instantiateStatement(Connection connection) throws SQLException {
8185
String sql = boundSql.getSql();
82-
if (mappedStatement.getResultSetType() != null && mappedStatement.getResultSetType() != ResultSetType.DEFAULT) {
83-
return connection.prepareCall(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
84-
} else {
86+
if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
8587
return connection.prepareCall(sql);
88+
} else {
89+
return connection.prepareCall(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
8690
}
8791
}
8892

src/main/java/org/apache/ibatis/executor/statement/PreparedStatementHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ protected Statement instantiateStatement(Connection connection) throws SQLExcept
8282
} else {
8383
return connection.prepareStatement(sql, keyColumnNames);
8484
}
85-
} else if (mappedStatement.getResultSetType() != null && mappedStatement.getResultSetType() != ResultSetType.DEFAULT) {
86-
return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
87-
} else {
85+
} else if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
8886
return connection.prepareStatement(sql);
87+
} else {
88+
return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
8989
}
9090
}
9191

src/main/java/org/apache/ibatis/executor/statement/SimpleStatementHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,10 @@ public <E> Cursor<E> queryCursor(Statement statement) throws SQLException {
8484

8585
@Override
8686
protected Statement instantiateStatement(Connection connection) throws SQLException {
87-
if (mappedStatement.getResultSetType() != null && mappedStatement.getResultSetType() != ResultSetType.DEFAULT) {
88-
return connection.createStatement(mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
89-
} else {
87+
if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
9088
return connection.createStatement();
89+
} else {
90+
return connection.createStatement(mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
9191
}
9292
}
9393

src/main/java/org/apache/ibatis/mapping/MappedStatement.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public Builder(Configuration configuration, String id, SqlSource sqlSource, SqlC
6969
mappedStatement.id = id;
7070
mappedStatement.sqlSource = sqlSource;
7171
mappedStatement.statementType = StatementType.PREPARED;
72+
mappedStatement.resultSetType = ResultSetType.DEFAULT;
7273
mappedStatement.parameterMap = new ParameterMap.Builder(configuration, "defaultParameterMap", null, new ArrayList<>()).build();
7374
mappedStatement.resultMaps = new ArrayList<>();
7475
mappedStatement.sqlCommandType = sqlCommandType;
@@ -119,7 +120,7 @@ public Builder statementType(StatementType statementType) {
119120
}
120121

121122
public Builder resultSetType(ResultSetType resultSetType) {
122-
mappedStatement.resultSetType = resultSetType;
123+
mappedStatement.resultSetType = resultSetType == null ? ResultSetType.DEFAULT : resultSetType;
123124
return this;
124125
}
125126

0 commit comments

Comments
 (0)