Skip to content

Commit 8efb2cc

Browse files
authored
Merge pull request #1344 from kazuki43zoo/gh-1334_resultSetType
Change the default resultSetType to DEFAULT(same as unset) at annotation option
2 parents d0f8413 + af0016a commit 8efb2cc

File tree

25 files changed

+392
-31
lines changed

25 files changed

+392
-31
lines changed

src/main/java/org/apache/ibatis/annotations/Options.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public enum FlushCachePolicy {
4848

4949
FlushCachePolicy flushCache() default FlushCachePolicy.DEFAULT;
5050

51-
ResultSetType resultSetType() default ResultSetType.FORWARD_ONLY;
51+
ResultSetType resultSetType() default ResultSetType.DEFAULT;
5252

5353
StatementType statementType() default StatementType.PREPARED;
5454

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.FORWARD_ONLY;
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/builder/xml/mybatis-3-mapper.dtd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ parameterMap CDATA #IMPLIED
174174
parameterType CDATA #IMPLIED
175175
resultMap CDATA #IMPLIED
176176
resultType CDATA #IMPLIED
177-
resultSetType (FORWARD_ONLY | SCROLL_INSENSITIVE | SCROLL_SENSITIVE) #IMPLIED
177+
resultSetType (FORWARD_ONLY | SCROLL_INSENSITIVE | SCROLL_SENSITIVE | DEFAULT) #IMPLIED
178178
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
179179
fetchSize CDATA #IMPLIED
180180
timeout CDATA #IMPLIED

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -30,6 +30,7 @@
3030
import org.apache.ibatis.mapping.MappedStatement;
3131
import org.apache.ibatis.mapping.ParameterMapping;
3232
import org.apache.ibatis.mapping.ParameterMode;
33+
import org.apache.ibatis.mapping.ResultSetType;
3334
import org.apache.ibatis.session.ResultHandler;
3435
import org.apache.ibatis.session.RowBounds;
3536
import org.apache.ibatis.type.JdbcType;
@@ -82,10 +83,10 @@ public <E> Cursor<E> queryCursor(Statement statement) throws SQLException {
8283
@Override
8384
protected Statement instantiateStatement(Connection connection) throws SQLException {
8485
String sql = boundSql.getSql();
85-
if (mappedStatement.getResultSetType() != null) {
86-
return connection.prepareCall(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
87-
} else {
86+
if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
8887
return connection.prepareCall(sql);
88+
} else {
89+
return connection.prepareCall(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
8990
}
9091
}
9192

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
import org.apache.ibatis.executor.keygen.KeyGenerator;
2929
import org.apache.ibatis.mapping.BoundSql;
3030
import org.apache.ibatis.mapping.MappedStatement;
31+
import org.apache.ibatis.mapping.ResultSetType;
3132
import org.apache.ibatis.session.ResultHandler;
3233
import org.apache.ibatis.session.RowBounds;
3334

@@ -81,10 +82,10 @@ protected Statement instantiateStatement(Connection connection) throws SQLExcept
8182
} else {
8283
return connection.prepareStatement(sql, keyColumnNames);
8384
}
84-
} else if (mappedStatement.getResultSetType() != null) {
85-
return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
86-
} else {
85+
} else if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
8786
return connection.prepareStatement(sql);
87+
} else {
88+
return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
8889
}
8990
}
9091

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2015 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,6 +28,7 @@
2828
import org.apache.ibatis.executor.keygen.SelectKeyGenerator;
2929
import org.apache.ibatis.mapping.BoundSql;
3030
import org.apache.ibatis.mapping.MappedStatement;
31+
import org.apache.ibatis.mapping.ResultSetType;
3132
import org.apache.ibatis.session.ResultHandler;
3233
import org.apache.ibatis.session.RowBounds;
3334

@@ -83,10 +84,10 @@ public <E> Cursor<E> queryCursor(Statement statement) throws SQLException {
8384

8485
@Override
8586
protected Statement instantiateStatement(Connection connection) throws SQLException {
86-
if (mappedStatement.getResultSetType() != null) {
87-
return connection.createStatement(mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
88-
} else {
87+
if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
8988
return connection.createStatement();
89+
} else {
90+
return connection.createStatement(mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
9091
}
9192
}
9293

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

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,6 +21,12 @@
2121
* @author Clinton Begin
2222
*/
2323
public enum ResultSetType {
24+
/**
25+
* behavior with same as unset (driver dependent).
26+
*
27+
* @since 3.5.0
28+
*/
29+
DEFAULT(-1),
2430
FORWARD_ONLY(ResultSet.TYPE_FORWARD_ONLY),
2531
SCROLL_INSENSITIVE(ResultSet.TYPE_SCROLL_INSENSITIVE),
2632
SCROLL_SENSITIVE(ResultSet.TYPE_SCROLL_SENSITIVE);

src/main/java/org/apache/ibatis/reflection/MetaObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2009-2017 the original author or authors.
2+
* Copyright 2009-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

src/site/es/xdoc/java-api.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
422422
<td><code>@Options</code></td>
423423
<td><code>Method</code></td>
424424
<td>Attributes of mapped statements.</td>
425-
<td>Esta anotación proporciona acceso a un gran conjunto de opciones de configuración que normalmente aparecen como atributos en los mapped statements. En lugar de complicar cada anotación existente la anotación Options proporciona una forma sencilla y concisa de acceder a estas opciones. Atributos: useCache=true, flushCache=FlushCachePolicy.DEFAULT, resultSetType=FORWARD_ONLY, statementType=PREPARED, fetchSize=-1, timeout=-1, useGeneratedKeys=false, keyProperty=“”, keyColumn=“”, resultSets=“”. Es importante comprender que las anotaciones en Java no permiten indicar un valor nulo. Por lo tanto, cuando usas la anotación Options el statement usará todos los valores por defecto. Presta atención a estos valores pro defecto para evitar comportamientos inesperados. La keyColumn solo se requiere para algunas bases de datos (como PostgreSQL) cuando la columna no es la primera columna de la tabla.</td>
425+
<td>Esta anotación proporciona acceso a un gran conjunto de opciones de configuración que normalmente aparecen como atributos en los mapped statements. En lugar de complicar cada anotación existente la anotación Options proporciona una forma sencilla y concisa de acceder a estas opciones. Atributos: useCache=true, flushCache=FlushCachePolicy.DEFAULT, resultSetType=DEFAULT, statementType=PREPARED, fetchSize=-1, timeout=-1, useGeneratedKeys=false, keyProperty=“”, keyColumn=“”, resultSets=“”. Es importante comprender que las anotaciones en Java no permiten indicar un valor nulo. Por lo tanto, cuando usas la anotación Options el statement usará todos los valores por defecto. Presta atención a estos valores pro defecto para evitar comportamientos inesperados. La keyColumn solo se requiere para algunas bases de datos (como PostgreSQL) cuando la columna no es la primera columna de la tabla.</td>
426426
</tr>
427427
<tr>
428428
<td>

0 commit comments

Comments
 (0)