提交 d33545bd 编写于 作者: S Sam Brannen

Avoid duplicate comment processing in ScriptUtils in spring-r2dbc

See gh-26947
上级 e8e157eb
...@@ -242,7 +242,7 @@ public abstract class ScriptUtils { ...@@ -242,7 +242,7 @@ public abstract class ScriptUtils {
InputStreamReader in = (resource.getCharset() != null ? InputStreamReader in = (resource.getCharset() != null ?
new InputStreamReader(is, resource.getCharset()) : new InputStreamReader(is)); new InputStreamReader(is, resource.getCharset()) : new InputStreamReader(is));
LineNumberReader lnr = new LineNumberReader(in); LineNumberReader lnr = new LineNumberReader(in);
String script = readScript(lnr, commentPrefixes, separator, blockCommentEndDelimiter); String script = readScript(lnr, separator);
sink.next(script); sink.next(script);
sink.complete(); sink.complete();
} }
...@@ -256,34 +256,22 @@ public abstract class ScriptUtils { ...@@ -256,34 +256,22 @@ public abstract class ScriptUtils {
} }
/** /**
* Read a script from the provided {@code LineNumberReader}, using the supplied * Read a script from the provided {@code LineNumberReader} and build a
* comment prefixes and statement separator, and build a {@code String} containing * {@code String} containing the lines.
* the lines.
* <p>Lines <em>beginning</em> with one of the comment prefixes are excluded
* from the results; however, line comments anywhere else &mdash; for example,
* within a statement &mdash; will be included in the results.
* @param lineNumberReader the {@code LineNumberReader} containing the script * @param lineNumberReader the {@code LineNumberReader} containing the script
* to be processed * to be processed
* @param commentPrefixes the prefixes that identify comments in the SQL script
* (typically "--")
* @param separator the statement separator in the SQL script (typically ";") * @param separator the statement separator in the SQL script (typically ";")
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
* @return a {@code String} containing the script lines * @return a {@code String} containing the script lines
* @throws IOException in case of I/O errors * @throws IOException in case of I/O errors
*/ */
private static String readScript(LineNumberReader lineNumberReader, @Nullable String[] commentPrefixes, private static String readScript(LineNumberReader lineNumberReader, @Nullable String separator) throws IOException {
@Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException {
String currentLine = lineNumberReader.readLine();
StringBuilder scriptBuilder = new StringBuilder(); StringBuilder scriptBuilder = new StringBuilder();
String currentLine = lineNumberReader.readLine();
while (currentLine != null) { while (currentLine != null) {
if ((blockCommentEndDelimiter != null && currentLine.contains(blockCommentEndDelimiter)) || if (scriptBuilder.length() > 0) {
(commentPrefixes != null && !startsWithAny(currentLine, commentPrefixes, 0))) { scriptBuilder.append('\n');
if (scriptBuilder.length() > 0) {
scriptBuilder.append('\n');
}
scriptBuilder.append(currentLine);
} }
scriptBuilder.append(currentLine);
currentLine = lineNumberReader.readLine(); currentLine = lineNumberReader.readLine();
} }
appendSeparatorToScriptIfNecessary(scriptBuilder, separator); appendSeparatorToScriptIfNecessary(scriptBuilder, separator);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册