48
48
* @author Oliver Gierke
49
49
* @author Chris Baldwin
50
50
* @author Nicolas Debeissat
51
+ * @author Phillip Webb
51
52
* @since 4.0.3
52
53
*/
53
54
public abstract class ScriptUtils {
@@ -185,9 +186,9 @@ public static void splitSqlScript(@Nullable EncodedResource resource, String scr
185
186
* Split an SQL script into separate statements delimited by the provided
186
187
* separator string. Each individual statement will be added to the provided
187
188
* {@code List}.
188
- * <p>Within the script, the provided {@code commentPrefix } will be honored:
189
- * any text beginning with the comment prefix and extending to the end of the
190
- * line will be omitted from the output. Similarly, the provided
189
+ * <p>Within the script, the provided {@code commentPrefixes } will be honored:
190
+ * any text beginning with one of the comment prefixes and extending to the
191
+ * end of the line will be omitted from the output. Similarly, the provided
191
192
* {@code blockCommentStartDelimiter} and {@code blockCommentEndDelimiter}
192
193
* delimiters will be honored: any text enclosed in a block comment will be
193
194
* omitted from the output. In addition, multiple adjacent whitespace characters
@@ -212,7 +213,7 @@ public static void splitSqlScript(@Nullable EncodedResource resource, String scr
212
213
213
214
Assert .hasText (script , "'script' must not be null or empty" );
214
215
Assert .notNull (separator , "'separator' must not be null" );
215
- Assert .notNull (commentPrefixes , "'commentPrefixes' must not be null" );
216
+ Assert .notEmpty (commentPrefixes , "'commentPrefixes' must not be null or empty " );
216
217
for (int i = 0 ; i < commentPrefixes .length ; i ++) {
217
218
Assert .hasText (commentPrefixes [i ], "'commentPrefixes' must not contain null or empty elements" );
218
219
}
@@ -307,14 +308,14 @@ static String readScript(EncodedResource resource) throws IOException {
307
308
}
308
309
309
310
/**
310
- * Read a script from the provided resource, using the supplied comment prefix
311
+ * Read a script from the provided resource, using the supplied comment prefixes
311
312
* and statement separator, and build a {@code String} containing the lines.
312
- * <p>Lines <em>beginning</em> with the comment prefix are excluded from the
313
- * results; however, line comments anywhere else — for example, within
314
- * a statement — will be included in the results.
313
+ * <p>Lines <em>beginning</em> with one of the comment prefixes are excluded
314
+ * from the results; however, line comments anywhere else — for example,
315
+ * within a statement — will be included in the results.
315
316
* @param resource the {@code EncodedResource} containing the script
316
317
* to be processed
317
- * @param commentPrefixes the prefix that identifies comments in the SQL script
318
+ * @param commentPrefixes the prefixes that identify comments in the SQL script
318
319
* (typically "--")
319
320
* @param separator the statement separator in the SQL script (typically ";")
320
321
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
@@ -358,11 +359,11 @@ public static String readScript(LineNumberReader lineNumberReader, @Nullable Str
358
359
359
360
/**
360
361
* Read a script from the provided {@code LineNumberReader}, using the supplied
361
- * comment prefix and statement separator, and build a {@code String} containing
362
+ * comment prefixes and statement separator, and build a {@code String} containing
362
363
* the lines.
363
- * <p>Lines <em>beginning</em> with the comment prefix are excluded from the
364
- * results; however, line comments anywhere else — for example, within
365
- * a statement — will be included in the results.
364
+ * <p>Lines <em>beginning</em> with one of the comment prefixes are excluded
365
+ * from the results; however, line comments anywhere else — for example,
366
+ * within a statement — will be included in the results.
366
367
* @param lineNumberReader the {@code LineNumberReader} containing the script
367
368
* to be processed
368
369
* @param lineCommentPrefixes the prefixes that identify comments in the SQL script
@@ -407,9 +408,9 @@ private static void appendSeparatorToScriptIfNecessary(StringBuilder scriptBuild
407
408
}
408
409
}
409
410
410
- private static boolean startsWithAny (String script , String [] prefixes , int toffset ) {
411
+ private static boolean startsWithAny (String script , String [] prefixes , int offset ) {
411
412
for (String prefix : prefixes ) {
412
- if (script .startsWith (prefix , toffset )) {
413
+ if (script .startsWith (prefix , offset )) {
413
414
return true ;
414
415
}
415
416
}
0 commit comments