Skip to content

Commit fdf7a9e

Browse files
committed
Change the default resultSetType to DEFAULT(same as unset) at annotation option
Fixes #1334
1 parent d0f8413 commit fdf7a9e

File tree

24 files changed

+387
-28
lines changed

24 files changed

+387
-28
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 = ResultSetType.DEFAULT;
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: 3 additions & 6 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.
@@ -26,10 +26,7 @@
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.BoundSql;
30-
import org.apache.ibatis.mapping.MappedStatement;
31-
import org.apache.ibatis.mapping.ParameterMapping;
32-
import org.apache.ibatis.mapping.ParameterMode;
29+
import org.apache.ibatis.mapping.*;
3330
import org.apache.ibatis.session.ResultHandler;
3431
import org.apache.ibatis.session.RowBounds;
3532
import org.apache.ibatis.type.JdbcType;
@@ -82,7 +79,7 @@ public <E> Cursor<E> queryCursor(Statement statement) throws SQLException {
8279
@Override
8380
protected Statement instantiateStatement(Connection connection) throws SQLException {
8481
String sql = boundSql.getSql();
85-
if (mappedStatement.getResultSetType() != null) {
82+
if (mappedStatement.getResultSetType() != null && mappedStatement.getResultSetType() != ResultSetType.DEFAULT) {
8683
return connection.prepareCall(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
8784
} else {
8885
return connection.prepareCall(sql);

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

Lines changed: 3 additions & 2 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,7 +82,7 @@ protected Statement instantiateStatement(Connection connection) throws SQLExcept
8182
} else {
8283
return connection.prepareStatement(sql, keyColumnNames);
8384
}
84-
} else if (mappedStatement.getResultSetType() != null) {
85+
} else if (mappedStatement.getResultSetType() != null && mappedStatement.getResultSetType() != ResultSetType.DEFAULT) {
8586
return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
8687
} else {
8788
return connection.prepareStatement(sql);

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

Lines changed: 3 additions & 2 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,7 +84,7 @@ 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+
if (mappedStatement.getResultSetType() != null && mappedStatement.getResultSetType() != ResultSetType.DEFAULT) {
8788
return connection.createStatement(mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
8889
} else {
8990
return connection.createStatement();

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>

src/site/es/xdoc/sqlmap-xml.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2009-2017 the original author or authors.
4+
Copyright 2009-2018 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.
@@ -182,7 +182,7 @@ ps.setInt(1,id);]]></source>
182182
</tr>
183183
<tr>
184184
<td><code>resultSetType</code></td>
185-
<td>Puede valer FORWARD_ONLY|SCROLL_SENSITIVE|SCROLL_INSENSITIVE. Por defecto: no informado (depende del driver de base de datos).
185+
<td>Puede valer FORWARD_ONLY|SCROLL_SENSITIVE|SCROLL_INSENSITIVE|DEFAULT(same as unset). Por defecto: no informado (depende del driver de base de datos).
186186
</td>
187187
</tr>
188188
<tr>

0 commit comments

Comments
 (0)