@@ -259,7 +259,7 @@ else if (c == ' ' || c == '\n' || c == '\t') {
259
259
* @throws IOException in case of I/O errors
260
260
*/
261
261
static String readScript (EncodedResource resource ) throws IOException {
262
- return readScript (resource , DEFAULT_COMMENT_PREFIX , DEFAULT_STATEMENT_SEPARATOR );
262
+ return readScript (resource , DEFAULT_COMMENT_PREFIX , DEFAULT_STATEMENT_SEPARATOR , DEFAULT_BLOCK_COMMENT_END_DELIMITER );
263
263
}
264
264
265
265
/**
@@ -273,15 +273,16 @@ static String readScript(EncodedResource resource) throws IOException {
273
273
* @param commentPrefix the prefix that identifies comments in the SQL script —
274
274
* typically "--"
275
275
* @param separator the statement separator in the SQL script — typically ";"
276
+ * @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
276
277
* @return a {@code String} containing the script lines
277
278
* @throws IOException in case of I/O errors
278
279
*/
279
280
private static String readScript (EncodedResource resource , @ Nullable String commentPrefix ,
280
- @ Nullable String separator ) throws IOException {
281
+ @ Nullable String separator , @ Nullable String blockCommentEndDelimiter ) throws IOException {
281
282
282
283
LineNumberReader lnr = new LineNumberReader (resource .getReader ());
283
284
try {
284
- return readScript (lnr , commentPrefix , separator );
285
+ return readScript (lnr , commentPrefix , separator , blockCommentEndDelimiter );
285
286
}
286
287
finally {
287
288
lnr .close ();
@@ -297,19 +298,21 @@ private static String readScript(EncodedResource resource, @Nullable String comm
297
298
* a statement — will be included in the results.
298
299
* @param lineNumberReader the {@code LineNumberReader} containing the script
299
300
* to be processed
300
- * @param commentPrefix the prefix that identifies comments in the SQL script —
301
+ * @param lineCommentPrefix the prefix that identifies comments in the SQL script —
301
302
* typically "--"
302
303
* @param separator the statement separator in the SQL script — typically ";"
304
+ * @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
303
305
* @return a {@code String} containing the script lines
304
306
* @throws IOException in case of I/O errors
305
307
*/
306
- public static String readScript (LineNumberReader lineNumberReader , @ Nullable String commentPrefix ,
307
- @ Nullable String separator ) throws IOException {
308
+ public static String readScript (LineNumberReader lineNumberReader , @ Nullable String lineCommentPrefix ,
309
+ @ Nullable String separator , @ Nullable String blockCommentEndDelimiter ) throws IOException {
308
310
309
311
String currentStatement = lineNumberReader .readLine ();
310
312
StringBuilder scriptBuilder = new StringBuilder ();
311
313
while (currentStatement != null ) {
312
- if (commentPrefix != null && !currentStatement .startsWith (commentPrefix )) {
314
+ if ((blockCommentEndDelimiter != null && currentStatement .contains (blockCommentEndDelimiter )) ||
315
+ (lineCommentPrefix != null && !currentStatement .startsWith (lineCommentPrefix ))) {
313
316
if (scriptBuilder .length () > 0 ) {
314
317
scriptBuilder .append ('\n' );
315
318
}
@@ -460,7 +463,7 @@ public static void executeSqlScript(Connection connection, EncodedResource resou
460
463
461
464
String script ;
462
465
try {
463
- script = readScript (resource , commentPrefix , separator );
466
+ script = readScript (resource , commentPrefix , separator , blockCommentEndDelimiter );
464
467
}
465
468
catch (IOException ex ) {
466
469
throw new CannotReadScriptException (resource , ex );
0 commit comments