Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/main/java/org/apache/ibatis/annotations/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public enum FlushCachePolicy {

FlushCachePolicy flushCache() default FlushCachePolicy.DEFAULT;

ResultSetType resultSetType() default ResultSetType.FORWARD_ONLY;
ResultSetType resultSetType() default ResultSetType.DEFAULT;

StatementType statementType() default StatementType.PREPARED;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void parseStatement(Method method) {
Integer fetchSize = null;
Integer timeout = null;
StatementType statementType = StatementType.PREPARED;
ResultSetType resultSetType = ResultSetType.FORWARD_ONLY;
ResultSetType resultSetType = null;
SqlCommandType sqlCommandType = getSqlCommandType(method);
boolean isSelect = sqlCommandType == SqlCommandType.SELECT;
boolean flushCache = !isSelect;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ parameterMap CDATA #IMPLIED
parameterType CDATA #IMPLIED
resultMap CDATA #IMPLIED
resultType CDATA #IMPLIED
resultSetType (FORWARD_ONLY | SCROLL_INSENSITIVE | SCROLL_SENSITIVE) #IMPLIED
resultSetType (FORWARD_ONLY | SCROLL_INSENSITIVE | SCROLL_SENSITIVE | DEFAULT) #IMPLIED
statementType (STATEMENT|PREPARED|CALLABLE) #IMPLIED
fetchSize CDATA #IMPLIED
timeout CDATA #IMPLIED
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -30,6 +30,7 @@
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ParameterMapping;
import org.apache.ibatis.mapping.ParameterMode;
import org.apache.ibatis.mapping.ResultSetType;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;
import org.apache.ibatis.type.JdbcType;
Expand Down Expand Up @@ -82,10 +83,10 @@ public <E> Cursor<E> queryCursor(Statement statement) throws SQLException {
@Override
protected Statement instantiateStatement(Connection connection) throws SQLException {
String sql = boundSql.getSql();
if (mappedStatement.getResultSetType() != null) {
return connection.prepareCall(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
} else {
if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
return connection.prepareCall(sql);
} else {
return connection.prepareCall(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.apache.ibatis.executor.keygen.KeyGenerator;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ResultSetType;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

Expand Down Expand Up @@ -81,10 +82,10 @@ protected Statement instantiateStatement(Connection connection) throws SQLExcept
} else {
return connection.prepareStatement(sql, keyColumnNames);
}
} else if (mappedStatement.getResultSetType() != null) {
return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
} else {
} else if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
return connection.prepareStatement(sql);
} else {
return connection.prepareStatement(sql, mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -28,6 +28,7 @@
import org.apache.ibatis.executor.keygen.SelectKeyGenerator;
import org.apache.ibatis.mapping.BoundSql;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.ResultSetType;
import org.apache.ibatis.session.ResultHandler;
import org.apache.ibatis.session.RowBounds;

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

@Override
protected Statement instantiateStatement(Connection connection) throws SQLException {
if (mappedStatement.getResultSetType() != null) {
return connection.createStatement(mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
} else {
if (mappedStatement.getResultSetType() == ResultSetType.DEFAULT) {
return connection.createStatement();
} else {
return connection.createStatement(mappedStatement.getResultSetType().getValue(), ResultSet.CONCUR_READ_ONLY);
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/apache/ibatis/mapping/MappedStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public Builder(Configuration configuration, String id, SqlSource sqlSource, SqlC
mappedStatement.id = id;
mappedStatement.sqlSource = sqlSource;
mappedStatement.statementType = StatementType.PREPARED;
mappedStatement.resultSetType = ResultSetType.DEFAULT;
mappedStatement.parameterMap = new ParameterMap.Builder(configuration, "defaultParameterMap", null, new ArrayList<>()).build();
mappedStatement.resultMaps = new ArrayList<>();
mappedStatement.sqlCommandType = sqlCommandType;
Expand Down Expand Up @@ -119,7 +120,7 @@ public Builder statementType(StatementType statementType) {
}

public Builder resultSetType(ResultSetType resultSetType) {
mappedStatement.resultSetType = resultSetType;
mappedStatement.resultSetType = resultSetType == null ? ResultSetType.DEFAULT : resultSetType;
return this;
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/apache/ibatis/mapping/ResultSetType.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,6 +21,12 @@
* @author Clinton Begin
*/
public enum ResultSetType {
/**
* behavior with same as unset (driver dependent).
*
* @since 3.5.0
*/
DEFAULT(-1),
FORWARD_ONLY(ResultSet.TYPE_FORWARD_ONLY),
SCROLL_INSENSITIVE(ResultSet.TYPE_SCROLL_INSENSITIVE),
SCROLL_SENSITIVE(ResultSet.TYPE_SCROLL_SENSITIVE);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/ibatis/reflection/MetaObject.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2017 the original author or authors.
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/site/es/xdoc/java-api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
<td><code>@Options</code></td>
<td><code>Method</code></td>
<td>Attributes of mapped statements.</td>
<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>
<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>
</tr>
<tr>
<td>
Expand Down
4 changes: 2 additions & 2 deletions src/site/es/xdoc/sqlmap-xml.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2009-2017 the original author or authors.
Copyright 2009-2018 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -182,7 +182,7 @@ ps.setInt(1,id);]]></source>
</tr>
<tr>
<td><code>resultSetType</code></td>
<td>Puede valer FORWARD_ONLY|SCROLL_SENSITIVE|SCROLL_INSENSITIVE. Por defecto: no informado (depende del driver de base de datos).
<td>Puede valer FORWARD_ONLY|SCROLL_SENSITIVE|SCROLL_INSENSITIVE|DEFAULT(same as unset). Por defecto: no informado (depende del driver de base de datos).
</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion src/site/ja/xdoc/java-api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
<td><code>Method</code></td>
<td>マップドステートメントの属性</td>
<td>このアノテーションを使うと、通常マップドステートメントの属性として指定される多様なスイッチや設定オプションにアクセスすることができます。<code>Options</code> アノテーションによって、各ステートメントのアノテーションを複雑化することなく、一貫したクリーンな方法で設定にアクセスできるよう工夫されています。キー: Attributes:
<code>useCache=true</code>, <code>flushCache=FlushCachePolicy.DEFAULT</code>, <code>resultSetType=FORWARD_ONLY</code>,
<code>useCache=true</code>, <code>flushCache=FlushCachePolicy.DEFAULT</code>, <code>resultSetType=DEFAULT</code>,
<code>statementType=PREPARED</code>, <code>fetchSize=-1</code>, <code>timeout=-1</code>,
<code>useGeneratedKeys=false</code>, <code>keyProperty=""</code>, <code>keyColumn=""</code>, <code>resultSets=""</code>.
Java アノテーションを使う場合、値として <code>null</code> を指定することはできないという制限があります。これはどういうことかというと、<code>Options</code> アノテーションを付加したステートメントにはデフォルトのオプションが適用されるということです。予期しない動作を防ぐため、各オプションのデフォルト値を把握しておくようにしてください。<br/><br/>
Expand Down
4 changes: 2 additions & 2 deletions src/site/ja/xdoc/sqlmap-xml.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2009-2017 the original author or authors.
Copyright 2009-2018 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -213,7 +213,7 @@ ps.setInt(1,id);]]></source>
<tr>
<td><code>resultSetType</code></td>
<td>
<code>FORWARD_ONLY</code>, <code>SCROLL_SENSITIVE</code>, <code>SCROLL_INSENSITIVE</code> のいずれかを指定します。デフォルトは未指定(ドライバー依存)です。
<code>FORWARD_ONLY</code>, <code>SCROLL_SENSITIVE</code>, <code>SCROLL_INSENSITIVE</code>, <code>DEFAULT</code>(未指定と同じ) のいずれかを指定します。デフォルトは未指定(ドライバー依存)です。
</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion src/site/ko/xdoc/java-api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
각 구문을 복잡하게 만들기 보다 Options 애노테이션으로 일관되고 깔끔한 방법으로 설정 할수 있게 한다.
사용가능한 속성들 : useCache=true,
flushCache=FlushCachePolicy.DEFAULT,
resultSetType=FORWARD_ONLY,
resultSetType=DEFAULT,
statementType=PREPARED,
fetchSize=-1,
timeout=-1,
Expand Down
2 changes: 1 addition & 1 deletion src/site/ko/xdoc/sqlmap-xml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ps.setInt(1,id);]]></source>
</tr>
<tr>
<td><code>resultSetType</code></td>
<td>FORWARD_ONLY|SCROLL_SENSITIVE|SCROLL_INSENSITIVE중 하나를 선택할 수 있다.
<td>FORWARD_ONLY|SCROLL_SENSITIVE|SCROLL_INSENSITIVE|DEFAULT(same as unset)중 하나를 선택할 수 있다.
디폴트는 셋팅하지 않는 것이고 드라이버에 다라 다소 지원되지 않을 수 있다.</td>
</tr>
<tr>
Expand Down
2 changes: 1 addition & 1 deletion src/site/xdoc/java-api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
<td>This annotation provides access to the wide range of switches and configuration options that are normally
present on the mapped statement as attributes. Rather than complicate each statement annotation, the
<code>Options</code> annotation provides a consistent and clear way to access these. Attributes:
<code>useCache=true</code>, <code>flushCache=FlushCachePolicy.DEFAULT</code>, <code>resultSetType=FORWARD_ONLY</code>,
<code>useCache=true</code>, <code>flushCache=FlushCachePolicy.DEFAULT</code>, <code>resultSetType=DEFAULT</code>,
<code>statementType=PREPARED</code>, <code>fetchSize=-1</code>, <code>timeout=-1</code>,
<code>useGeneratedKeys=false</code>, <code>keyProperty=""</code>, <code>keyColumn=""</code>, <code>resultSets=""</code>.
It's important to understand that with Java Annotations, there is no way to specify <code>null</code> as a value.
Expand Down
2 changes: 1 addition & 1 deletion src/site/xdoc/sqlmap-xml.xml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ ps.setInt(1,id);]]></source>
</tr>
<tr>
<td><code>resultSetType</code></td>
<td>Any one of <code>FORWARD_ONLY</code>|<code>SCROLL_SENSITIVE</code>|<code>SCROLL_INSENSITIVE</code>.
<td>Any one of <code>FORWARD_ONLY</code>|<code>SCROLL_SENSITIVE</code>|<code>SCROLL_INSENSITIVE</code>|<code>DEFAULT</code>(same as unset).
Default is <code>unset</code> (driver dependent).
</td>
</tr>
Expand Down
2 changes: 1 addition & 1 deletion src/site/zh/xdoc/java-api.xml
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ try (SqlSession session = sqlSessionFactory.openSession()) {
<td><code>@Options</code></td>
<td><code>方法</code></td>
<td>映射语句的属性</td>
       <td>这个注解提供访问大范围的交换和配置选项的入口,它们通常在映射语句上作为属性出现。<code>Options</code> 注解提供了通俗易懂的方式来访问它们,而不是让每条语句注解变复杂。属性有:<code>useCache=true</code>, <code>flushCache=FlushCachePolicy.DEFAULT</code>, <code>resultSetType=FORWARD_ONLY</code>, <code>statementType=PREPARED</code>, <code>fetchSize=-1</code>, <code>timeout=-1</code>, <code>useGeneratedKeys=false</code>, <code>keyProperty=""</code>, <code>keyColumn=""</code>, <code>resultSets=""</code>。值得一提的是, Java 注解无法指定 <code>null</code> 值。因此,一旦你使用了 <code>Options</code> 注解,你的语句就会被上述属性的默认值所影响。要注意避免默认值带来的预期以外的行为。<br/><br/>
       <td>这个注解提供访问大范围的交换和配置选项的入口,它们通常在映射语句上作为属性出现。<code>Options</code> 注解提供了通俗易懂的方式来访问它们,而不是让每条语句注解变复杂。属性有:<code>useCache=true</code>, <code>flushCache=FlushCachePolicy.DEFAULT</code>, <code>resultSetType=DEFAULT</code>, <code>statementType=PREPARED</code>, <code>fetchSize=-1</code>, <code>timeout=-1</code>, <code>useGeneratedKeys=false</code>, <code>keyProperty=""</code>, <code>keyColumn=""</code>, <code>resultSets=""</code>。值得一提的是, Java 注解无法指定 <code>null</code> 值。因此,一旦你使用了 <code>Options</code> 注解,你的语句就会被上述属性的默认值所影响。要注意避免默认值带来的预期以外的行为。<br/><br/>
       注意: <code>keyColumn</code> 属性只在某些数据库中有效(如 Oracle、PostgreSQL等)。请在插入语句一节查看更多关于 <code>keyColumn</code> 和 <code>keyProperty</code> 两者的有效值详情。</td>
</tr>
<tr>
Expand Down
4 changes: 2 additions & 2 deletions src/site/zh/xdoc/sqlmap-xml.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2009-2017 the original author or authors.
Copyright 2009-2018 the original author or authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -181,7 +181,7 @@ ps.setInt(1,id);]]></source>
</tr>
<tr>
<td><code>resultSetType</code></td>
<td>FORWARD_ONLY,SCROLL_SENSITIVE 或 SCROLL_INSENSITIVE 中的一个,默认值为 unset (依赖驱动)。
<td>FORWARD_ONLY,SCROLL_SENSITIVE, SCROLL_INSENSITIVE 或 DEFAULT(same as unset) 中的一个,默认值为 unset (依赖驱动)。
</td>
</tr>
<tr>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
--
-- Copyright 2009-2018 the original author or authors.
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
--

drop table users if exists
go

drop procedure getusers if exists
go

create table users (
id int,
name varchar(20)
)
go

create procedure getusers()
modifies sql data
dynamic result sets 1
BEGIN ATOMIC
declare cur cursor for select * from users order by id;
open cur;
END
go

insert into users (id, name) values(1, 'User1')
go

insert into users (id, name) values(2, 'User1')
go

insert into users (id, name) values(3, 'User1')
go

insert into users (id, name) values(4, 'User1')
go

insert into users (id, name) values(5, 'User1')
go



Loading