Skip to content

Commit

Permalink
Merge pull request mybatis#377 from kazuki43zoo/issues/376_support-de…
Browse files Browse the repository at this point in the history
…faultFetchSize

mybatis#376: Support the defaultFetchSize in config.xml
  • Loading branch information
emacarron committed Mar 19, 2015
2 parents 1fbcf09 + 7ea3568 commit 7088e18
Show file tree
Hide file tree
Showing 7 changed files with 138 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ private void settingsElement(XNode context) throws Exception {
configuration.setUseGeneratedKeys(booleanValueOf(props.getProperty("useGeneratedKeys"), false));
configuration.setDefaultExecutorType(ExecutorType.valueOf(props.getProperty("defaultExecutorType", "SIMPLE")));
configuration.setDefaultStatementTimeout(integerValueOf(props.getProperty("defaultStatementTimeout"), null));
configuration.setDefaultFetchSize(integerValueOf(props.getProperty("defaultFetchSize"), null));
configuration.setMapUnderscoreToCamelCase(booleanValueOf(props.getProperty("mapUnderscoreToCamelCase"), false));
configuration.setSafeRowBoundsEnabled(booleanValueOf(props.getProperty("safeRowBoundsEnabled"), false));
configuration.setLocalCacheScope(LocalCacheScope.valueOf(props.getProperty("localCacheScope", "SESSION")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@ protected void setFetchSize(Statement stmt) throws SQLException {
Integer fetchSize = mappedStatement.getFetchSize();
if (fetchSize != null) {
stmt.setFetchSize(fetchSize);
return;
}
Integer defaultFetchSize = configuration.getDefaultFetchSize();
if (defaultFetchSize != null) {
stmt.setFetchSize(defaultFetchSize);
}
}

Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/apache/ibatis/session/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ public class Configuration {
protected JdbcType jdbcTypeForNull = JdbcType.OTHER;
protected Set<String> lazyLoadTriggerMethods = new HashSet<String>(Arrays.asList(new String[] { "equals", "clone", "hashCode", "toString" }));
protected Integer defaultStatementTimeout;
protected Integer defaultFetchSize;
protected ExecutorType defaultExecutorType = ExecutorType.SIMPLE;
protected AutoMappingBehavior autoMappingBehavior = AutoMappingBehavior.PARTIAL;

Expand Down Expand Up @@ -362,6 +363,14 @@ public void setDefaultStatementTimeout(Integer defaultStatementTimeout) {
this.defaultStatementTimeout = defaultStatementTimeout;
}

public Integer getDefaultFetchSize() {
return defaultFetchSize;
}

public void setDefaultFetchSize(Integer defaultFetchSize) {
this.defaultFetchSize = defaultFetchSize;
}

public boolean isUseColumnLabel() {
return useColumnLabel;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!--
Copyright 2009-2015 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.
-->

<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

<settings>
<setting name="autoMappingBehavior" value="NONE"/>
<setting name="cacheEnabled" value="false"/>
<setting name="proxyFactory" value="CGLIB"/>
<setting name="lazyLoadingEnabled" value="true"/>
<setting name="aggressiveLazyLoading" value="false"/>
<setting name="multipleResultSetsEnabled" value="false"/>
<setting name="useColumnLabel" value="false"/>
<setting name="useGeneratedKeys" value="true"/>
<setting name="defaultExecutorType" value="BATCH"/>
<setting name="defaultStatementTimeout" value="10"/>
<setting name="defaultFetchSize" value="100"/>
<setting name="mapUnderscoreToCamelCase" value="true"/>
<setting name="safeRowBoundsEnabled" value="true"/>
<setting name="localCacheScope" value="STATEMENT"/>
<setting name="jdbcTypeForNull" value="NULL"/>
<setting name="lazyLoadTriggerMethods" value="equals,clone,hashCode,toString,xxx"/>
<setting name="safeResultHandlerEnabled" value="false"/>
<setting name="defaultScriptingLanguage" value="org.apache.ibatis.scripting.defaults.RawLanguageDriver"/>
<setting name="callSettersOnNulls" value="true"/>
<setting name="logPrefix" value="mybatis_"/>
<setting name="logImpl" value="SLF4J"/>
<setting name="configurationFactory" value="java.lang.String"/>
</settings>

</configuration>
74 changes: 70 additions & 4 deletions src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,37 @@
*/
package org.apache.ibatis.builder;

import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import java.io.InputStream;
import java.io.StringReader;
import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.ibatis.builder.xml.XMLConfigBuilder;
import org.apache.ibatis.executor.loader.cglib.CglibProxyFactory;
import org.apache.ibatis.executor.loader.javassist.JavassistProxyFactory;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.logging.slf4j.Slf4jImpl;
import org.apache.ibatis.scripting.defaults.RawLanguageDriver;
import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
import org.apache.ibatis.session.AutoMappingBehavior;
import org.apache.ibatis.session.Configuration;
import org.apache.ibatis.session.ExecutorType;
import org.apache.ibatis.session.LocalCacheScope;
import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.apache.ibatis.type.TypeHandler;
import org.apache.ibatis.type.TypeHandlerRegistry;
import org.junit.Test;

import static org.hamcrest.core.Is.*;
import static org.hamcrest.core.IsInstanceOf.*;
import static org.junit.Assert.*;

public class XmlConfigBuilderTest {

@Test
Expand All @@ -44,6 +55,28 @@ public void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception {
XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
Configuration config = builder.parse();
assertNotNull(config);
assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.PARTIAL));
assertThat(config.isCacheEnabled(), is(true));
assertThat(config.getProxyFactory(), is(instanceOf(JavassistProxyFactory.class)));
assertThat(config.isLazyLoadingEnabled(), is(false));
assertThat(config.isAggressiveLazyLoading(), is(true));
assertThat(config.isMultipleResultSetsEnabled(), is(true));
assertThat(config.isUseColumnLabel(), is(true));
assertThat(config.isUseGeneratedKeys(), is(false));
assertThat(config.getDefaultExecutorType(), is(ExecutorType.SIMPLE));
assertNull(config.getDefaultStatementTimeout());
assertNull(config.getDefaultFetchSize());
assertThat(config.isMapUnderscoreToCamelCase(), is(false));
assertThat(config.isSafeRowBoundsEnabled(), is(false));
assertThat(config.getLocalCacheScope(), is(LocalCacheScope.SESSION));
assertThat(config.getJdbcTypeForNull(), is(JdbcType.OTHER));
assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString"))));
assertThat(config.isSafeResultHandlerEnabled(), is(true));
assertThat(config.getDefaultScriptingLanuageInstance(), is(instanceOf(XMLLanguageDriver.class)));
assertThat(config.isCallSettersOnNulls(), is(false));
assertNull(config.getLogPrefix());
assertNull(config.getLogImpl());
assertNull(config.getConfigurationFactory());
}

enum MyEnum {
Expand Down Expand Up @@ -102,4 +135,37 @@ public void registerJavaTypeInitializingTypeHandler() {
assertTrue(typeHandler instanceof EnumOrderTypeHandler);
assertArrayEquals(MyEnum.values(), ((EnumOrderTypeHandler) typeHandler).constants);
}

@Test
public void shouldSuccessfullyLoadXMLConfigFile() throws Exception {
String resource = "org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml";
InputStream inputStream = Resources.getResourceAsStream(resource);
XMLConfigBuilder builder = new XMLConfigBuilder(inputStream);
Configuration config = builder.parse();

assertThat(config.getAutoMappingBehavior(), is(AutoMappingBehavior.NONE));
assertThat(config.isCacheEnabled(), is(false));
assertThat(config.getProxyFactory(), is(instanceOf(CglibProxyFactory.class)));
assertThat(config.isLazyLoadingEnabled(), is(true));
assertThat(config.isAggressiveLazyLoading(), is(false));
assertThat(config.isMultipleResultSetsEnabled(), is(false));
assertThat(config.isUseColumnLabel(), is(false));
assertThat(config.isUseGeneratedKeys(), is(true));
assertThat(config.getDefaultExecutorType(), is(ExecutorType.BATCH));
assertThat(config.getDefaultStatementTimeout(), is(10));
assertThat(config.getDefaultFetchSize(), is(100));
assertThat(config.isMapUnderscoreToCamelCase(), is(true));
assertThat(config.isSafeRowBoundsEnabled(), is(true));
assertThat(config.getLocalCacheScope(), is(LocalCacheScope.STATEMENT));
assertThat(config.getJdbcTypeForNull(), is(JdbcType.NULL));
assertThat(config.getLazyLoadTriggerMethods(), is((Set<String>) new HashSet<String>(Arrays.asList("equals", "clone", "hashCode", "toString", "xxx"))));
assertThat(config.isSafeResultHandlerEnabled(), is(false));
assertThat(config.getDefaultScriptingLanuageInstance(), is(instanceOf(RawLanguageDriver.class)));
assertThat(config.isCallSettersOnNulls(), is(true));
assertThat(config.getLogPrefix(), is("mybatis_"));
assertThat(config.getLogImpl().getName(), is(Slf4jImpl.class.getName()));
assertThat(config.getConfigurationFactory().getName(), is(String.class.getName()));

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ public BaseExecutorTest() {
config.setMultipleResultSetsEnabled(true);
config.setUseColumnLabel(true);
config.setDefaultStatementTimeout(5000);
config.setDefaultFetchSize(100);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static MappedStatement prepareSelectAllAuthorsAutoMappedStatement(final C
}
}).build());
}
}).build();
}).fetchSize(1000).build();
}

public static MappedStatement prepareSelectOneAuthorMappedStatementWithConstructorResults(final Configuration config) {
Expand Down

0 comments on commit 7088e18

Please sign in to comment.