From 9ec145e76378b1098efd8ce9f9a39db7b6c1ff6c Mon Sep 17 00:00:00 2001 From: "heegu.lee" Date: Tue, 21 Apr 2020 23:39:07 +0900 Subject: [PATCH 01/12] minifySqlEnabled option added. It is remove white space character from query string in xml file. --- .../ibatis/builder/SqlSourceBuilder.java | 8 +++- .../ibatis/logging/jdbc/BaseJdbcLogger.java | 10 +--- .../apache/ibatis/parsing/StringParser.java | 16 +++++++ .../apache/ibatis/session/Configuration.java | 9 ++++ .../ibatis/builder/SqlSourceBuilderTest.java | 47 +++++++++++++++++++ 5 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 src/main/java/org/apache/ibatis/parsing/StringParser.java create mode 100644 src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java diff --git a/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java b/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java index a84c3cae930..5263ac8bc51 100644 --- a/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java +++ b/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java @@ -22,6 +22,7 @@ import org.apache.ibatis.mapping.ParameterMapping; import org.apache.ibatis.mapping.SqlSource; import org.apache.ibatis.parsing.GenericTokenParser; +import org.apache.ibatis.parsing.StringParser; import org.apache.ibatis.parsing.TokenHandler; import org.apache.ibatis.reflection.MetaClass; import org.apache.ibatis.reflection.MetaObject; @@ -42,7 +43,12 @@ public SqlSourceBuilder(Configuration configuration) { public SqlSource parse(String originalSql, Class parameterType, Map additionalParameters) { ParameterMappingTokenHandler handler = new ParameterMappingTokenHandler(configuration, parameterType, additionalParameters); GenericTokenParser parser = new GenericTokenParser("#{", "}", handler); - String sql = parser.parse(originalSql); + String sql; + if (configuration.isMinifySqlEnabled()) { + sql = parser.parse(StringParser.removeBreakingWhitespace(originalSql)); + } else { + sql = parser.parse(originalSql); + } return new StaticSqlSource(configuration, sql, handler.getParameterMappings()); } diff --git a/src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java b/src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java index e086d782540..f4c5c4b73c4 100644 --- a/src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java +++ b/src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java @@ -26,10 +26,10 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.StringTokenizer; import java.util.stream.Collectors; import org.apache.ibatis.logging.Log; +import org.apache.ibatis.parsing.StringParser; import org.apache.ibatis.reflection.ArrayUtil; /** @@ -121,13 +121,7 @@ protected void clearColumnInfo() { } protected String removeBreakingWhitespace(String original) { - StringTokenizer whitespaceStripper = new StringTokenizer(original); - StringBuilder builder = new StringBuilder(); - while (whitespaceStripper.hasMoreTokens()) { - builder.append(whitespaceStripper.nextToken()); - builder.append(" "); - } - return builder.toString(); + return StringParser.removeBreakingWhitespace(original); } protected boolean isDebugEnabled() { diff --git a/src/main/java/org/apache/ibatis/parsing/StringParser.java b/src/main/java/org/apache/ibatis/parsing/StringParser.java new file mode 100644 index 00000000000..c64f4db6a80 --- /dev/null +++ b/src/main/java/org/apache/ibatis/parsing/StringParser.java @@ -0,0 +1,16 @@ +package org.apache.ibatis.parsing; + +import java.util.StringTokenizer; + +public class StringParser { + + public static String removeBreakingWhitespace(String original) { + StringTokenizer whitespaceStripper = new StringTokenizer(original); + StringBuilder builder = new StringBuilder(); + while (whitespaceStripper.hasMoreTokens()) { + builder.append(whitespaceStripper.nextToken()); + builder.append(" "); + } + return builder.toString().trim(); + } +} diff --git a/src/main/java/org/apache/ibatis/session/Configuration.java b/src/main/java/org/apache/ibatis/session/Configuration.java index d427f97ed63..f3c0dc96865 100644 --- a/src/main/java/org/apache/ibatis/session/Configuration.java +++ b/src/main/java/org/apache/ibatis/session/Configuration.java @@ -113,6 +113,7 @@ public class Configuration { protected boolean callSettersOnNulls; protected boolean useActualParamName = true; protected boolean returnInstanceForEmptyRow; + protected boolean minifySqlEnabled; protected String logPrefix; protected Class logImpl; @@ -266,6 +267,14 @@ public void setReturnInstanceForEmptyRow(boolean returnEmptyInstance) { this.returnInstanceForEmptyRow = returnEmptyInstance; } + public boolean isMinifySqlEnabled() { + return minifySqlEnabled; + } + + public void setMinifySqlEnabled(boolean minifySqlEnabled) { + this.minifySqlEnabled = minifySqlEnabled; + } + public String getDatabaseId() { return databaseId; } diff --git a/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java new file mode 100644 index 00000000000..5f00ff709cd --- /dev/null +++ b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java @@ -0,0 +1,47 @@ +package org.apache.ibatis.builder; + +import java.io.Reader; +import org.apache.ibatis.builder.xml.XMLConfigBuilder; +import org.apache.ibatis.io.Resources; +import org.apache.ibatis.mapping.BoundSql; +import org.apache.ibatis.mapping.SqlSource; +import org.apache.ibatis.session.Configuration; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; + +public class SqlSourceBuilderTest { + + private static Configuration configuration; + private static SqlSourceBuilder sqlSourceBuilder; + String sqlFromXml = "SELECT * \n FROM user\n WHERE user_id = 1"; + + @BeforeAll + static void setUp() throws Exception { + // create an SqlSessionFactory + try (Reader reader = Resources + .getResourceAsReader("org/apache/ibatis/submitted/empty_row/mybatis-config.xml")) { + XMLConfigBuilder parser = new XMLConfigBuilder(reader, null, null); + configuration = parser.parse(); + } + + sqlSourceBuilder = new SqlSourceBuilder(configuration); + } + + @Test + void testMinifySqlEnabledIsFalse() { + SqlSource sqlSource = sqlSourceBuilder.parse(sqlFromXml, null, null); + BoundSql boundSql = sqlSource.getBoundSql(null); + String actual = boundSql.getSql(); + Assertions.assertEquals(sqlFromXml, actual); + } + + @Test + void testMinifySqlEnabledIsTrue() { + configuration.setMinifySqlEnabled(true); + SqlSource sqlSource = sqlSourceBuilder.parse(sqlFromXml, null, null); + BoundSql boundSql = sqlSource.getBoundSql(null); + String actual = boundSql.getSql(); + Assertions.assertNotEquals(sqlFromXml, actual); + } +} From dc8b67c32b7df06e593e9f84d65eb6be7c8798b2 Mon Sep 17 00:00:00 2001 From: "heegu.lee" Date: Tue, 21 Apr 2020 23:57:55 +0900 Subject: [PATCH 02/12] apache license comment added. --- .../org/apache/ibatis/parsing/StringParser.java | 15 +++++++++++++++ .../ibatis/builder/SqlSourceBuilderTest.java | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/src/main/java/org/apache/ibatis/parsing/StringParser.java b/src/main/java/org/apache/ibatis/parsing/StringParser.java index c64f4db6a80..b3e606f7413 100644 --- a/src/main/java/org/apache/ibatis/parsing/StringParser.java +++ b/src/main/java/org/apache/ibatis/parsing/StringParser.java @@ -1,3 +1,18 @@ +/* + * Copyright 2009-2020 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.parsing; import java.util.StringTokenizer; diff --git a/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java index 5f00ff709cd..e6d71bc2161 100644 --- a/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java +++ b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2009-2020 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 java.io.Reader; From 95b8ec93786df9ee895b4112d53ce10c8f9c6acd Mon Sep 17 00:00:00 2001 From: "heegu.lee" Date: Sun, 17 May 2020 15:06:14 +0900 Subject: [PATCH 03/12] variable name is modified from minifiySqlEnabled to shrinkWhitespacesInSql. (https://github.com/mybatis/mybatis-3/pull/1901#discussion_r426217525) --- .../org/apache/ibatis/builder/SqlSourceBuilder.java | 2 +- .../java/org/apache/ibatis/session/Configuration.java | 10 +++++----- .../apache/ibatis/builder/SqlSourceBuilderTest.java | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java b/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java index 5263ac8bc51..f7d7a065208 100644 --- a/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java +++ b/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java @@ -44,7 +44,7 @@ public SqlSource parse(String originalSql, Class parameterType, Map logImpl; @@ -267,12 +267,12 @@ public void setReturnInstanceForEmptyRow(boolean returnEmptyInstance) { this.returnInstanceForEmptyRow = returnEmptyInstance; } - public boolean isMinifySqlEnabled() { - return minifySqlEnabled; + public boolean isShrinkWhitespacesInSql() { + return shrinkWhitespacesInSql; } - public void setMinifySqlEnabled(boolean minifySqlEnabled) { - this.minifySqlEnabled = minifySqlEnabled; + public void setShrinkWhitespacesInSql(boolean shrinkWhitespacesInSql) { + this.shrinkWhitespacesInSql = shrinkWhitespacesInSql; } public String getDatabaseId() { diff --git a/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java index e6d71bc2161..d9787ce7e10 100644 --- a/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java +++ b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java @@ -53,7 +53,7 @@ void testMinifySqlEnabledIsFalse() { @Test void testMinifySqlEnabledIsTrue() { - configuration.setMinifySqlEnabled(true); + configuration.setShrinkWhitespacesInSql(true); SqlSource sqlSource = sqlSourceBuilder.parse(sqlFromXml, null, null); BoundSql boundSql = sqlSource.getBoundSql(null); String actual = boundSql.getSql(); From 08635fd46fc1b71e62811dd4951eff6480459107 Mon Sep 17 00:00:00 2001 From: "heegu.lee" Date: Sun, 17 May 2020 15:11:53 +0900 Subject: [PATCH 04/12] test case code refactoring (https://github.com/mybatis/mybatis-3/pull/1901) --- .../ibatis/builder/SqlSourceBuilderTest.java | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java index d9787ce7e10..d0f99167a28 100644 --- a/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java +++ b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java @@ -15,30 +15,22 @@ */ package org.apache.ibatis.builder; -import java.io.Reader; -import org.apache.ibatis.builder.xml.XMLConfigBuilder; -import org.apache.ibatis.io.Resources; import org.apache.ibatis.mapping.BoundSql; import org.apache.ibatis.mapping.SqlSource; import org.apache.ibatis.session.Configuration; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class SqlSourceBuilderTest { private static Configuration configuration; private static SqlSourceBuilder sqlSourceBuilder; - String sqlFromXml = "SELECT * \n FROM user\n WHERE user_id = 1"; + String sqlFromXml = "\\t\\n\\n SELECT * \\n FROM user\\n \\t WHERE user_id = 1\\n\\t "; - @BeforeAll - static void setUp() throws Exception { - // create an SqlSessionFactory - try (Reader reader = Resources - .getResourceAsReader("org/apache/ibatis/submitted/empty_row/mybatis-config.xml")) { - XMLConfigBuilder parser = new XMLConfigBuilder(reader, null, null); - configuration = parser.parse(); - } + @BeforeEach + void setUp() { + configuration = new Configuration(); sqlSourceBuilder = new SqlSourceBuilder(configuration); } @@ -53,10 +45,13 @@ void testMinifySqlEnabledIsFalse() { @Test void testMinifySqlEnabledIsTrue() { + String expected = "\\t\\n\\n SELECT * \\n FROM user\\n \\t WHERE user_id = 1\\n\\t"; + configuration.setShrinkWhitespacesInSql(true); SqlSource sqlSource = sqlSourceBuilder.parse(sqlFromXml, null, null); BoundSql boundSql = sqlSource.getBoundSql(null); String actual = boundSql.getSql(); - Assertions.assertNotEquals(sqlFromXml, actual); + + Assertions.assertEquals(expected, actual); } } From 7c3ff9719fdf994334a53fa8faebf2166499a044 Mon Sep 17 00:00:00 2001 From: "heegu.lee" Date: Sun, 17 May 2020 18:29:43 +0900 Subject: [PATCH 05/12] backslash is duplicated and remove / test case method name is changed --- .../apache/ibatis/builder/SqlSourceBuilderTest.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java index d0f99167a28..d5b108844ec 100644 --- a/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java +++ b/src/test/java/org/apache/ibatis/builder/SqlSourceBuilderTest.java @@ -26,7 +26,7 @@ public class SqlSourceBuilderTest { private static Configuration configuration; private static SqlSourceBuilder sqlSourceBuilder; - String sqlFromXml = "\\t\\n\\n SELECT * \\n FROM user\\n \\t WHERE user_id = 1\\n\\t "; + private final String sqlFromXml = "\t\n\n SELECT * \n FROM user\n \t WHERE user_id = 1\n\t "; @BeforeEach void setUp() { @@ -36,7 +36,7 @@ void setUp() { } @Test - void testMinifySqlEnabledIsFalse() { + void testShrinkWhitespacesInSqlIsFalse() { SqlSource sqlSource = sqlSourceBuilder.parse(sqlFromXml, null, null); BoundSql boundSql = sqlSource.getBoundSql(null); String actual = boundSql.getSql(); @@ -44,14 +44,13 @@ void testMinifySqlEnabledIsFalse() { } @Test - void testMinifySqlEnabledIsTrue() { - String expected = "\\t\\n\\n SELECT * \\n FROM user\\n \\t WHERE user_id = 1\\n\\t"; - + void testShrinkWhitespacesInSqlIsTrue() { configuration.setShrinkWhitespacesInSql(true); SqlSource sqlSource = sqlSourceBuilder.parse(sqlFromXml, null, null); BoundSql boundSql = sqlSource.getBoundSql(null); String actual = boundSql.getSql(); - Assertions.assertEquals(expected, actual); + String shrankWhitespacesInSql = "SELECT * FROM user WHERE user_id = 1"; + Assertions.assertEquals(shrankWhitespacesInSql, actual); } } From 660cef1437ef52c223ceb7d062021a9d3f6296df Mon Sep 17 00:00:00 2001 From: "heegu.lee" Date: Sun, 17 May 2020 21:14:52 +0900 Subject: [PATCH 06/12] Update XmlConfigBuilderTest --- .../java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java | 1 + .../apache/ibatis/builder/CustomizedSettingsMapperConfig.xml | 1 + .../java/org/apache/ibatis/builder/XmlConfigBuilderTest.java | 2 ++ .../ibatis/builder/xsd/CustomizedSettingsMapperConfig.xml | 1 + .../org/apache/ibatis/builder/xsd/XmlConfigBuilderTest.java | 2 ++ 5 files changed, 7 insertions(+) diff --git a/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java b/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java index c55ea66298e..a9ca156c647 100644 --- a/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java +++ b/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java @@ -268,6 +268,7 @@ private void settingsElement(Properties props) { configuration.setReturnInstanceForEmptyRow(booleanValueOf(props.getProperty("returnInstanceForEmptyRow"), false)); configuration.setLogPrefix(props.getProperty("logPrefix")); configuration.setConfigurationFactory(resolveClass(props.getProperty("configurationFactory"))); + configuration.setShrinkWhitespacesInSql(booleanValueOf(props.getProperty("shrinkWhitespacesInSql"), false)); } private void environmentsElement(XNode context) throws Exception { diff --git a/src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml b/src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml index d816fe95fa4..80da190a796 100644 --- a/src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml +++ b/src/test/java/org/apache/ibatis/builder/CustomizedSettingsMapperConfig.xml @@ -54,6 +54,7 @@ + diff --git a/src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java b/src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java index a1453ac5273..ef1851130dd 100644 --- a/src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java +++ b/src/test/java/org/apache/ibatis/builder/XmlConfigBuilderTest.java @@ -100,6 +100,7 @@ void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception { assertNull(config.getLogImpl()); assertNull(config.getConfigurationFactory()); assertThat(config.getTypeHandlerRegistry().getTypeHandler(RoundingMode.class)).isInstanceOf(EnumTypeHandler.class); + assertThat(config.isShrinkWhitespacesInSql()).isFalse(); } } @@ -194,6 +195,7 @@ void shouldSuccessfullyLoadXMLConfigFile() throws Exception { assertThat(config.getLogImpl().getName()).isEqualTo(Slf4jImpl.class.getName()); assertThat(config.getVfsImpl().getName()).isEqualTo(JBoss6VFS.class.getName()); assertThat(config.getConfigurationFactory().getName()).isEqualTo(String.class.getName()); + assertThat(config.isShrinkWhitespacesInSql()).isTrue(); assertThat(config.getTypeAliasRegistry().getTypeAliases().get("blogauthor")).isEqualTo(Author.class); assertThat(config.getTypeAliasRegistry().getTypeAliases().get("blog")).isEqualTo(Blog.class); diff --git a/src/test/java/org/apache/ibatis/builder/xsd/CustomizedSettingsMapperConfig.xml b/src/test/java/org/apache/ibatis/builder/xsd/CustomizedSettingsMapperConfig.xml index 4114fff0dea..b77b7521ca8 100644 --- a/src/test/java/org/apache/ibatis/builder/xsd/CustomizedSettingsMapperConfig.xml +++ b/src/test/java/org/apache/ibatis/builder/xsd/CustomizedSettingsMapperConfig.xml @@ -50,6 +50,7 @@ + diff --git a/src/test/java/org/apache/ibatis/builder/xsd/XmlConfigBuilderTest.java b/src/test/java/org/apache/ibatis/builder/xsd/XmlConfigBuilderTest.java index 60bce8aa492..c4a8a35f642 100644 --- a/src/test/java/org/apache/ibatis/builder/xsd/XmlConfigBuilderTest.java +++ b/src/test/java/org/apache/ibatis/builder/xsd/XmlConfigBuilderTest.java @@ -84,6 +84,7 @@ void shouldSuccessfullyLoadMinimalXMLConfigFile() throws Exception { assertNull(config.getLogPrefix()); assertNull(config.getLogImpl()); assertNull(config.getConfigurationFactory()); + assertFalse(config.isShrinkWhitespacesInSql()); } finally { // System.clearProperty(XPathParser.KEY_USE_XSD); } @@ -121,6 +122,7 @@ void shouldSuccessfullyLoadXMLConfigFile() throws Exception { assertEquals(Slf4jImpl.class.getName(), config.getLogImpl().getName()); assertEquals(JBoss6VFS.class.getName(), config.getVfsImpl().getName()); assertEquals(String.class.getName(), config.getConfigurationFactory().getName()); + assertTrue(config.isShrinkWhitespacesInSql()); assertEquals(Author.class, config.getTypeAliasRegistry().getTypeAliases().get("blogauthor")); assertEquals(Blog.class, config.getTypeAliasRegistry().getTypeAliases().get("blog")); From 18d1464f9b7ac40bcb3a673b66f6562a86c61da3 Mon Sep 17 00:00:00 2001 From: "heegu.lee" Date: Sun, 17 May 2020 21:17:22 +0900 Subject: [PATCH 07/12] Add new option description in document. (en, ko). other languages is added to en language. --- src/site/es/xdoc/configuration.xml | 14 ++++++++++++++ src/site/ja/xdoc/configuration.xml | 14 ++++++++++++++ src/site/ko/xdoc/configuration.xml | 14 ++++++++++++++ src/site/xdoc/configuration.xml | 14 ++++++++++++++ src/site/zh/xdoc/configuration.xml | 14 ++++++++++++++ 5 files changed, 70 insertions(+) diff --git a/src/site/es/xdoc/configuration.xml b/src/site/es/xdoc/configuration.xml index 44f66a02673..5ca1583208c 100644 --- a/src/site/es/xdoc/configuration.xml +++ b/src/site/es/xdoc/configuration.xml @@ -547,6 +547,20 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ Not set + + + shrinkWhitespacesInSql + + + When reading a query from the mapper xml file, the whitespace characters are reduced as much as possible to reduce the packets transmitted over the network. + + + true | false + + + false + +

diff --git a/src/site/ja/xdoc/configuration.xml b/src/site/ja/xdoc/configuration.xml index 12b55e2bd30..c468af82de6 100644 --- a/src/site/ja/xdoc/configuration.xml +++ b/src/site/ja/xdoc/configuration.xml @@ -572,6 +572,20 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ 未指定 + + + shrinkWhitespacesInSql + + + When reading a query from the mapper xml file, the whitespace characters are reduced as much as possible to reduce the packets transmitted over the network. + + + true | false + + + false + +

diff --git a/src/site/ko/xdoc/configuration.xml b/src/site/ko/xdoc/configuration.xml index bba6bc54cfb..000e5f663e8 100644 --- a/src/site/ko/xdoc/configuration.xml +++ b/src/site/ko/xdoc/configuration.xml @@ -555,6 +555,20 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ 설정하지 않음 + + + shrinkWhitespacesInSql + + + mapper xml 파일에서 쿼리를 읽을때 whitespace 문자를 최대한 줄여 네트워크로 전송하는 패킷을 줄여준다. + + + true | false + + + false + +

위 설정을 모두 사용한 setting 엘리먼트의 예제이다:

diff --git a/src/site/xdoc/configuration.xml b/src/site/xdoc/configuration.xml index 117dc4bef57..4f5da048dd7 100644 --- a/src/site/xdoc/configuration.xml +++ b/src/site/xdoc/configuration.xml @@ -634,6 +634,20 @@ SqlSessionFactory factory = Not set + + + shrinkWhitespacesInSql + + + When reading a query from the mapper xml file, the whitespace characters are reduced as much as possible to reduce the packets transmitted over the network. + + + true | false + + + false + +

diff --git a/src/site/zh/xdoc/configuration.xml b/src/site/zh/xdoc/configuration.xml index c449db26aee..fdc1bb0053f 100644 --- a/src/site/zh/xdoc/configuration.xml +++ b/src/site/zh/xdoc/configuration.xml @@ -565,6 +565,20 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ 未设置 + + + shrinkWhitespacesInSql + + + When reading a query from the mapper xml file, the whitespace characters are reduced as much as possible to reduce the packets transmitted over the network. + + + true | false + + + false + +

From 2c5a986c791996b49f1796801e43e328cb4dd8b9 Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Mon, 18 May 2020 00:07:59 +0900 Subject: [PATCH 08/12] This feature also affects SQLs in annotations; added a note and version --- src/site/es/xdoc/configuration.xml | 2 +- src/site/ja/xdoc/configuration.xml | 2 +- src/site/ko/xdoc/configuration.xml | 2 +- src/site/xdoc/configuration.xml | 2 +- src/site/zh/xdoc/configuration.xml | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/site/es/xdoc/configuration.xml b/src/site/es/xdoc/configuration.xml index 5ca1583208c..aa50d64c08a 100644 --- a/src/site/es/xdoc/configuration.xml +++ b/src/site/es/xdoc/configuration.xml @@ -552,7 +552,7 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ shrinkWhitespacesInSql - When reading a query from the mapper xml file, the whitespace characters are reduced as much as possible to reduce the packets transmitted over the network. + Removes extra whitespace characters from the SQL. Note that this also affects literal strings in SQL. (Since 3.5.5) true | false diff --git a/src/site/ja/xdoc/configuration.xml b/src/site/ja/xdoc/configuration.xml index c468af82de6..bdfbf56cb3e 100644 --- a/src/site/ja/xdoc/configuration.xml +++ b/src/site/ja/xdoc/configuration.xml @@ -577,7 +577,7 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ shrinkWhitespacesInSql - When reading a query from the mapper xml file, the whitespace characters are reduced as much as possible to reduce the packets transmitted over the network. + SQL 内の余分な空白文字を削除します。リテラル文字列も対象となる点に注意してください。(導入されたバージョン: 3.5.5) true | false diff --git a/src/site/ko/xdoc/configuration.xml b/src/site/ko/xdoc/configuration.xml index 000e5f663e8..5b99eb26087 100644 --- a/src/site/ko/xdoc/configuration.xml +++ b/src/site/ko/xdoc/configuration.xml @@ -560,7 +560,7 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ shrinkWhitespacesInSql - mapper xml 파일에서 쿼리를 읽을때 whitespace 문자를 최대한 줄여 네트워크로 전송하는 패킷을 줄여준다. + mapper xml 파일에서 쿼리를 읽을때 whitespace 문자를 최대한 줄여 네트워크로 전송하는 패킷을 줄여준다. Removes extra whitespace characters from the SQL. Note that this also affects literal strings in SQL. (Since 3.5.5) true | false diff --git a/src/site/xdoc/configuration.xml b/src/site/xdoc/configuration.xml index 4f5da048dd7..ebdff1a11ad 100644 --- a/src/site/xdoc/configuration.xml +++ b/src/site/xdoc/configuration.xml @@ -639,7 +639,7 @@ SqlSessionFactory factory = shrinkWhitespacesInSql - When reading a query from the mapper xml file, the whitespace characters are reduced as much as possible to reduce the packets transmitted over the network. + Removes extra whitespace characters from the SQL. Note that this also affects literal strings in SQL. (Since 3.5.5) true | false diff --git a/src/site/zh/xdoc/configuration.xml b/src/site/zh/xdoc/configuration.xml index fdc1bb0053f..48344b3b3de 100644 --- a/src/site/zh/xdoc/configuration.xml +++ b/src/site/zh/xdoc/configuration.xml @@ -570,7 +570,7 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ shrinkWhitespacesInSql - When reading a query from the mapper xml file, the whitespace characters are reduced as much as possible to reduce the packets transmitted over the network. + Removes extra whitespace characters from the SQL. Note that this also affects literal strings in SQL. (Since 3.5.5) true | false From 45fbebcb61606a1dbc922960be2a95bd98b2c026 Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Mon, 18 May 2020 01:07:10 +0900 Subject: [PATCH 09/12] Moved the method to SqlSourceBuilder and removed trim() call --- .../ibatis/builder/SqlSourceBuilder.java | 18 +++++++++-- .../ibatis/logging/jdbc/BaseJdbcLogger.java | 6 ++-- .../ibatis/logging/jdbc/ConnectionLogger.java | 2 +- .../ibatis/logging/jdbc/StatementLogger.java | 2 +- .../apache/ibatis/parsing/StringParser.java | 31 ------------------- 5 files changed, 21 insertions(+), 38 deletions(-) delete mode 100644 src/main/java/org/apache/ibatis/parsing/StringParser.java diff --git a/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java b/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java index f7d7a065208..262590f6140 100644 --- a/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java +++ b/src/main/java/org/apache/ibatis/builder/SqlSourceBuilder.java @@ -18,11 +18,11 @@ import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.StringTokenizer; import org.apache.ibatis.mapping.ParameterMapping; import org.apache.ibatis.mapping.SqlSource; import org.apache.ibatis.parsing.GenericTokenParser; -import org.apache.ibatis.parsing.StringParser; import org.apache.ibatis.parsing.TokenHandler; import org.apache.ibatis.reflection.MetaClass; import org.apache.ibatis.reflection.MetaObject; @@ -45,13 +45,27 @@ public SqlSource parse(String originalSql, Class parameterType, Map parameterMappings = new ArrayList<>(); diff --git a/src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java b/src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java index f4c5c4b73c4..0e2f0f5f001 100644 --- a/src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java +++ b/src/main/java/org/apache/ibatis/logging/jdbc/BaseJdbcLogger.java @@ -28,8 +28,8 @@ import java.util.Set; import java.util.stream.Collectors; +import org.apache.ibatis.builder.SqlSourceBuilder; import org.apache.ibatis.logging.Log; -import org.apache.ibatis.parsing.StringParser; import org.apache.ibatis.reflection.ArrayUtil; /** @@ -120,8 +120,8 @@ protected void clearColumnInfo() { columnValues.clear(); } - protected String removeBreakingWhitespace(String original) { - return StringParser.removeBreakingWhitespace(original); + protected String removeExtraWhitespace(String original) { + return SqlSourceBuilder.removeExtraWhitespaces(original); } protected boolean isDebugEnabled() { diff --git a/src/main/java/org/apache/ibatis/logging/jdbc/ConnectionLogger.java b/src/main/java/org/apache/ibatis/logging/jdbc/ConnectionLogger.java index dfbfd098b74..160811d21cb 100644 --- a/src/main/java/org/apache/ibatis/logging/jdbc/ConnectionLogger.java +++ b/src/main/java/org/apache/ibatis/logging/jdbc/ConnectionLogger.java @@ -50,7 +50,7 @@ public Object invoke(Object proxy, Method method, Object[] params) } if ("prepareStatement".equals(method.getName()) || "prepareCall".equals(method.getName())) { if (isDebugEnabled()) { - debug(" Preparing: " + removeBreakingWhitespace((String) params[0]), true); + debug(" Preparing: " + removeExtraWhitespace((String) params[0]), true); } PreparedStatement stmt = (PreparedStatement) method.invoke(connection, params); stmt = PreparedStatementLogger.newInstance(stmt, statementLog, queryStack); diff --git a/src/main/java/org/apache/ibatis/logging/jdbc/StatementLogger.java b/src/main/java/org/apache/ibatis/logging/jdbc/StatementLogger.java index 327fb610333..727b01460e3 100644 --- a/src/main/java/org/apache/ibatis/logging/jdbc/StatementLogger.java +++ b/src/main/java/org/apache/ibatis/logging/jdbc/StatementLogger.java @@ -48,7 +48,7 @@ public Object invoke(Object proxy, Method method, Object[] params) throws Throwa } if (EXECUTE_METHODS.contains(method.getName())) { if (isDebugEnabled()) { - debug(" Executing: " + removeBreakingWhitespace((String) params[0]), true); + debug(" Executing: " + removeExtraWhitespace((String) params[0]), true); } if ("executeQuery".equals(method.getName())) { ResultSet rs = (ResultSet) method.invoke(statement, params); diff --git a/src/main/java/org/apache/ibatis/parsing/StringParser.java b/src/main/java/org/apache/ibatis/parsing/StringParser.java deleted file mode 100644 index b3e606f7413..00000000000 --- a/src/main/java/org/apache/ibatis/parsing/StringParser.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2009-2020 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.parsing; - -import java.util.StringTokenizer; - -public class StringParser { - - public static String removeBreakingWhitespace(String original) { - StringTokenizer whitespaceStripper = new StringTokenizer(original); - StringBuilder builder = new StringBuilder(); - while (whitespaceStripper.hasMoreTokens()) { - builder.append(whitespaceStripper.nextToken()); - builder.append(" "); - } - return builder.toString().trim(); - } -} From a3bef5730e9c229769780036d56658822f2a3a99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=ED=9D=AC=EA=B5=AC?= Date: Mon, 18 May 2020 08:57:01 +0900 Subject: [PATCH 10/12] update korean description --- src/site/ko/xdoc/configuration.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/ko/xdoc/configuration.xml b/src/site/ko/xdoc/configuration.xml index 5b99eb26087..725a7916352 100644 --- a/src/site/ko/xdoc/configuration.xml +++ b/src/site/ko/xdoc/configuration.xml @@ -560,7 +560,7 @@ SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(reader, environ shrinkWhitespacesInSql - mapper xml 파일에서 쿼리를 읽을때 whitespace 문자를 최대한 줄여 네트워크로 전송하는 패킷을 줄여준다. Removes extra whitespace characters from the SQL. Note that this also affects literal strings in SQL. (Since 3.5.5) + SQL에서 여분의 whitespace 문자들을 삭제한다. 이는 SQL의 리터럴 문자열에도 영향을 미친다. (Since 3.5.5) true | false From 7e7e057d55d70ad0aee079bafe87519449ed6e21 Mon Sep 17 00:00:00 2001 From: Iwao AVE! Date: Mon, 18 May 2020 23:53:22 +0900 Subject: [PATCH 11/12] Removed byte order mark (BOM) --- src/site/xdoc/configuration.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/site/xdoc/configuration.xml b/src/site/xdoc/configuration.xml index ebdff1a11ad..d69ae0db65c 100644 --- a/src/site/xdoc/configuration.xml +++ b/src/site/xdoc/configuration.xml @@ -1,4 +1,4 @@ - +