-
Notifications
You must be signed in to change notification settings - Fork 13k
Add defaultResultSetType as global configuration #1056
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kazuki43zoo
merged 8 commits into
mybatis:master
from
kazuki43zoo:default-resultset-type
Jul 7, 2019
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
31a6a81
Add defaultResultSetType as global configuration
kazuki43zoo b968e78
Merge branch 'master' into default-resultset-type
kazuki43zoo 4c20603
Change assertion for #1344
kazuki43zoo 2694337
Change @since
kazuki43zoo cac7fd7
Update doc
kazuki43zoo e541e9f
Merge branch 'master' into default-resultset-type
kazuki43zoo 66c943a
Apply JUnit 5
kazuki43zoo 7765a86
Update introductory version
kazuki43zoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/test/java/org/apache/ibatis/builder/AnnotationMapperBuilderTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| /** | ||
| * Copyright 2009-2019 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. | ||
| */ | ||
| package org.apache.ibatis.builder; | ||
|
|
||
| import org.apache.ibatis.annotations.Insert; | ||
| import org.apache.ibatis.annotations.Options; | ||
| import org.apache.ibatis.annotations.Select; | ||
| import org.apache.ibatis.builder.annotation.MapperAnnotationBuilder; | ||
| import org.apache.ibatis.executor.keygen.Jdbc3KeyGenerator; | ||
| import org.apache.ibatis.mapping.MappedStatement; | ||
| import org.apache.ibatis.mapping.ResultSetType; | ||
| import org.apache.ibatis.mapping.StatementType; | ||
| import org.apache.ibatis.session.Configuration; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| class AnnotationMapperBuilderTest { | ||
|
|
||
| @Test | ||
| void withOptions() { | ||
| Configuration configuration = new Configuration(); | ||
| MapperAnnotationBuilder builder = new MapperAnnotationBuilder(configuration, Mapper.class); | ||
| builder.parse(); | ||
|
|
||
| MappedStatement mappedStatement = configuration.getMappedStatement("selectWithOptions"); | ||
| assertThat(mappedStatement.getFetchSize()).isEqualTo(200); | ||
| assertThat(mappedStatement.getTimeout()).isEqualTo(10); | ||
| assertThat(mappedStatement.getStatementType()).isEqualTo(StatementType.STATEMENT); | ||
| assertThat(mappedStatement.getResultSetType()).isEqualTo(ResultSetType.SCROLL_INSENSITIVE); | ||
| assertThat(mappedStatement.isFlushCacheRequired()).isTrue(); | ||
| assertThat(mappedStatement.isUseCache()).isFalse(); | ||
| assertThat(mappedStatement.getResultSets()).containsExactly("resultSets"); | ||
|
|
||
| mappedStatement = configuration.getMappedStatement("insertWithOptions"); | ||
| assertThat(mappedStatement.getKeyGenerator()).isInstanceOf(Jdbc3KeyGenerator.class); | ||
| assertThat(mappedStatement.getKeyColumns()).containsExactly("key_column"); | ||
| assertThat(mappedStatement.getKeyProperties()).containsExactly("keyProperty"); | ||
| } | ||
|
|
||
| @Test | ||
| void withOptionsAndWithoutOptionsAttributesWhenSpecifyDefaultValue() { | ||
| Configuration configuration = new Configuration(); | ||
| configuration.setDefaultResultSetType(ResultSetType.SCROLL_INSENSITIVE); | ||
| MapperAnnotationBuilder builder = new MapperAnnotationBuilder(configuration, Mapper.class); | ||
| builder.parse(); | ||
|
|
||
| MappedStatement mappedStatement = configuration.getMappedStatement("selectWithOptionsAndWithoutOptionsAttributes"); | ||
| assertThat(mappedStatement.getResultSetType()).isEqualTo(ResultSetType.SCROLL_INSENSITIVE); | ||
| } | ||
|
|
||
|
|
||
| @Test | ||
| void withOptionsAndWithoutOptionsAttributesWhenNotSpecifyDefaultValue() { | ||
| Configuration configuration = new Configuration(); | ||
| MapperAnnotationBuilder builder = new MapperAnnotationBuilder(configuration, Mapper.class); | ||
| builder.parse(); | ||
|
|
||
| MappedStatement mappedStatement = configuration.getMappedStatement("selectWithOptionsAndWithoutOptionsAttributes"); | ||
| assertThat(mappedStatement.getResultSetType()).isEqualTo(ResultSetType.DEFAULT); | ||
| } | ||
|
|
||
| @Test | ||
| void withoutOptionsWhenSpecifyDefaultValue() { | ||
| Configuration configuration = new Configuration(); | ||
| configuration.setDefaultResultSetType(ResultSetType.SCROLL_INSENSITIVE); | ||
| MapperAnnotationBuilder builder = new MapperAnnotationBuilder(configuration, Mapper.class); | ||
| builder.parse(); | ||
|
|
||
| MappedStatement mappedStatement = configuration.getMappedStatement("selectWithoutOptions"); | ||
| assertThat(mappedStatement.getResultSetType()).isEqualTo(ResultSetType.SCROLL_INSENSITIVE); | ||
| } | ||
|
|
||
| @Test | ||
| void withoutOptionsWhenNotSpecifyDefaultValue() { | ||
| Configuration configuration = new Configuration(); | ||
| MapperAnnotationBuilder builder = new MapperAnnotationBuilder(configuration, Mapper.class); | ||
| builder.parse(); | ||
|
|
||
| MappedStatement mappedStatement = configuration.getMappedStatement("selectWithoutOptions"); | ||
| assertThat(mappedStatement.getResultSetType()).isEqualTo(ResultSetType.DEFAULT); | ||
| } | ||
|
|
||
| interface Mapper { | ||
|
|
||
| @Insert("insert into test (name) values(#{name})") | ||
| @Options(useGeneratedKeys = true, keyColumn = "key_column", keyProperty = "keyProperty") | ||
| void insertWithOptions(String name); | ||
|
|
||
| @Select("select * from test") | ||
| @Options(fetchSize = 200, timeout = 10, statementType = StatementType.STATEMENT, resultSetType = ResultSetType.SCROLL_INSENSITIVE, flushCache = Options.FlushCachePolicy.TRUE, useCache = false, resultSets = "resultSets") | ||
| String selectWithOptions(Integer id); | ||
|
|
||
| @Select("select * from test") | ||
| @Options | ||
| String selectWithOptionsAndWithoutOptionsAttributes(Integer id); | ||
|
|
||
| @Select("select * from test") | ||
| String selectWithoutOptions(Integer id); | ||
|
|
||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.