Skip to content

Commit

Permalink
回滚动态脚本换行处理(增加缓存空节点).
Browse files Browse the repository at this point in the history
  • Loading branch information
nieqiurong committed Feb 21, 2025
1 parent c0a8afd commit 02750cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.ConcurrentHashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -130,6 +131,8 @@ private synchronized static String cacheStr(String str) {

private static final Pattern PATTERN = Pattern.compile("^\\s+|\\s+$");

private static final Map<String, StaticTextSqlNode> CACHE_EMPTY_SQL_NODE = new ConcurrentHashMap<>();

/**
* 将前后空白符替换成空格
*
Expand All @@ -149,12 +152,11 @@ protected MixedSqlNode parseDynamicTags(XNode node) {
XNode child = node.newXNode(children.item(i));
if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) {
String text = cacheStr(child.getStringBody(""));
String trimText = text.trim();
if (trimText.isEmpty()) {
contents.add(SPACE_SQL_NODE);
if (text.trim().isEmpty()) {
StaticTextSqlNode staticTextSqlNode = CACHE_EMPTY_SQL_NODE.computeIfAbsent(text, StaticTextSqlNode::new);
contents.add(staticTextSqlNode);
continue;
}
text = replaceLeadingAndTrailingWhitespace(text);
TextSqlNode textSqlNode = new TextSqlNode(text);
if (textSqlNode.isDynamic()) {
contents.add(textSqlNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ protected MappedStatement addMappedStatement(Class<?> mapperClass, SqlSource sql
* @since 3.5.3.2
*/
public SqlSource createSqlSource(Configuration configuration, String script, Class<?> parameterType) {
return languageDriver.createSqlSource(configuration, script, parameterType);
return languageDriver.createSqlSource(configuration, SqlSourceBuilder.removeExtraWhitespaces(script), parameterType);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

import org.apache.ibatis.scripting.xmltags.XMLLanguageDriver;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Disabled
public class MybatisXMLLanguageDriverTest {

private static final Logger LOGGER = LoggerFactory.getLogger(MybatisXMLLanguageDriver.class);
Expand Down

0 comments on commit 02750cd

Please sign in to comment.