Skip to content
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

Compacted-SQL #1153

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/java/org/apache/ibatis/parsing/XNode.java
Expand Up @@ -136,6 +136,18 @@ public String getStringBody(String def) {
}
}

public String getStringBody(String def, boolean removeBlankLines){
if(body == null){
return def;
} else {
if (removeBlankLines) {
return body.replaceAll("(\\n|\\r\\n)", " ").replaceAll("\\t"," ");
} else {
return body;
}
}
}

public Boolean getBooleanBody() {
return getBooleanBody(null);
}
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2017 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 @@ -61,12 +61,13 @@ public SqlSource parseScriptNode() {
}

List<SqlNode> parseDynamicTags(XNode node) {
final boolean compactedSQL = configuration.isCompactedSQL();
List<SqlNode> contents = new ArrayList<SqlNode>();
NodeList children = node.getNode().getChildNodes();
for (int i = 0; i < children.getLength(); i++) {
XNode child = node.newXNode(children.item(i));
if (child.getNode().getNodeType() == Node.CDATA_SECTION_NODE || child.getNode().getNodeType() == Node.TEXT_NODE) {
String data = child.getStringBody("");
String data = child.getStringBody("", compactedSQL);
TextSqlNode textSqlNode = new TextSqlNode(data);
if (textSqlNode.isDynamic()) {
contents.add(textSqlNode);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/apache/ibatis/session/Configuration.java
Expand Up @@ -109,6 +109,7 @@ public class Configuration {
protected boolean callSettersOnNulls;
protected boolean useActualParamName = true;
protected boolean returnInstanceForEmptyRow;
protected boolean compactedSQL = false;

protected String logPrefix;
protected Class <? extends Log> logImpl;
Expand Down Expand Up @@ -259,6 +260,14 @@ public void setReturnInstanceForEmptyRow(boolean returnEmptyInstance) {
this.returnInstanceForEmptyRow = returnEmptyInstance;
}

public boolean isCompactedSQL() {
return compactedSQL;
}

public void setCompactedSQL(boolean compactedSQL) {
this.compactedSQL = compactedSQL;
}

public String getDatabaseId() {
return databaseId;
}
Expand Down
@@ -1,5 +1,5 @@
/**
* Copyright 2009-2015 the original author or authors.
* Copyright 2009-2017 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