@@ -85,15 +85,10 @@ public abstract class ScriptUtils {
85
85
*/
86
86
public static final String EOF_STATEMENT_SEPARATOR = "^^^ END OF SCRIPT ^^^" ;
87
87
88
- /**
89
- * Default prefix for single-line comments within SQL scripts: {@code "--"}.
90
- */
91
- public static final String DEFAULT_COMMENT_PREFIX = "--" ;
92
-
93
88
/**
94
89
* Default prefixes for single-line comments within SQL scripts: {@code ["--"]}.
95
90
*/
96
- public static final String [] DEFAULT_COMMENT_PREFIXES = {DEFAULT_COMMENT_PREFIX };
91
+ public static final String [] DEFAULT_COMMENT_PREFIXES = {"--" };
97
92
98
93
/**
99
94
* Default start delimiter for block comments within SQL scripts: {@code "/*"}.
@@ -109,87 +104,6 @@ public abstract class ScriptUtils {
109
104
private static final Log logger = LogFactory .getLog (ScriptUtils .class );
110
105
111
106
112
- /**
113
- * Split an SQL script into separate statements delimited by the provided
114
- * separator character. Each individual statement will be added to the
115
- * provided {@code List}.
116
- * <p>Within the script, {@value #DEFAULT_COMMENT_PREFIX} will be used as the
117
- * comment prefix; any text beginning with the comment prefix and extending to
118
- * the end of the line will be omitted from the output. Similarly,
119
- * {@value #DEFAULT_BLOCK_COMMENT_START_DELIMITER} and
120
- * {@value #DEFAULT_BLOCK_COMMENT_END_DELIMITER} will be used as the
121
- * <em>start</em> and <em>end</em> block comment delimiters: any text enclosed
122
- * in a block comment will be omitted from the output. In addition, multiple
123
- * adjacent whitespace characters will be collapsed into a single space.
124
- * @param script the SQL script
125
- * @param separator character separating each statement (typically a ';')
126
- * @param statements the list that will contain the individual statements
127
- * @throws ScriptException if an error occurred while splitting the SQL script
128
- * @see #splitSqlScript(String, String, List)
129
- * @see #splitSqlScript(EncodedResource, String, String, String, String, String, List)
130
- */
131
- public static void splitSqlScript (String script , char separator , List <String > statements ) throws ScriptException {
132
- splitSqlScript (script , String .valueOf (separator ), statements );
133
- }
134
-
135
- /**
136
- * Split an SQL script into separate statements delimited by the provided
137
- * separator string. Each individual statement will be added to the
138
- * provided {@code List}.
139
- * <p>Within the script, {@value #DEFAULT_COMMENT_PREFIX} will be used as the
140
- * comment prefix; any text beginning with the comment prefix and extending to
141
- * the end of the line will be omitted from the output. Similarly,
142
- * {@value #DEFAULT_BLOCK_COMMENT_START_DELIMITER} and
143
- * {@value #DEFAULT_BLOCK_COMMENT_END_DELIMITER} will be used as the
144
- * <em>start</em> and <em>end</em> block comment delimiters: any text enclosed
145
- * in a block comment will be omitted from the output. In addition, multiple
146
- * adjacent whitespace characters will be collapsed into a single space.
147
- * @param script the SQL script
148
- * @param separator text separating each statement
149
- * (typically a ';' or newline character)
150
- * @param statements the list that will contain the individual statements
151
- * @throws ScriptException if an error occurred while splitting the SQL script
152
- * @see #splitSqlScript(String, char, List)
153
- * @see #splitSqlScript(EncodedResource, String, String, String, String, String, List)
154
- */
155
- public static void splitSqlScript (String script , String separator , List <String > statements ) throws ScriptException {
156
- splitSqlScript (null , script , separator , DEFAULT_COMMENT_PREFIX , DEFAULT_BLOCK_COMMENT_START_DELIMITER ,
157
- DEFAULT_BLOCK_COMMENT_END_DELIMITER , statements );
158
- }
159
-
160
- /**
161
- * Split an SQL script into separate statements delimited by the provided
162
- * separator string. Each individual statement will be added to the provided
163
- * {@code List}.
164
- * <p>Within the script, the provided {@code commentPrefix} will be honored:
165
- * any text beginning with the comment prefix and extending to the end of the
166
- * line will be omitted from the output. Similarly, the provided
167
- * {@code blockCommentStartDelimiter} and {@code blockCommentEndDelimiter}
168
- * delimiters will be honored: any text enclosed in a block comment will be
169
- * omitted from the output. In addition, multiple adjacent whitespace characters
170
- * will be collapsed into a single space.
171
- * @param resource the resource from which the script was read
172
- * @param script the SQL script
173
- * @param separator text separating each statement
174
- * (typically a ';' or newline character)
175
- * @param commentPrefix the prefix that identifies SQL line comments
176
- * (typically "--")
177
- * @param blockCommentStartDelimiter the <em>start</em> block comment delimiter;
178
- * never {@code null} or empty
179
- * @param blockCommentEndDelimiter the <em>end</em> block comment delimiter;
180
- * never {@code null} or empty
181
- * @param statements the list that will contain the individual statements
182
- * @throws ScriptException if an error occurred while splitting the SQL script
183
- */
184
- public static void splitSqlScript (@ Nullable EncodedResource resource , String script ,
185
- String separator , String commentPrefix , String blockCommentStartDelimiter ,
186
- String blockCommentEndDelimiter , List <String > statements ) throws ScriptException {
187
-
188
- Assert .hasText (commentPrefix , "'commentPrefix' must not be null or empty" );
189
- splitSqlScript (resource , script , separator , new String [] { commentPrefix },
190
- blockCommentStartDelimiter , blockCommentEndDelimiter , statements );
191
- }
192
-
193
107
/**
194
108
* Split an SQL script into separate statements delimited by the provided
195
109
* separator string. Each individual statement will be added to the provided
@@ -214,7 +128,7 @@ public static void splitSqlScript(@Nullable EncodedResource resource, String scr
214
128
* @param statements the list that will contain the individual statements
215
129
* @throws ScriptException if an error occurred while splitting the SQL script
216
130
*/
217
- public static void splitSqlScript (@ Nullable EncodedResource resource , String script ,
131
+ static void splitSqlScript (@ Nullable EncodedResource resource , String script ,
218
132
String separator , String [] commentPrefixes , String blockCommentStartDelimiter ,
219
133
String blockCommentEndDelimiter , List <String > statements ) throws ScriptException {
220
134
@@ -303,18 +217,6 @@ else if (c == ' ' || c == '\r' || c == '\n' || c == '\t') {
303
217
}
304
218
}
305
219
306
- /**
307
- * Read a script from the given resource, using "{@code --}" as the comment prefix
308
- * and "{@code ;}" as the statement separator, and build a String containing the lines.
309
- * @param resource the {@code EncodedResource} to be read
310
- * @param dataBufferFactory the factory to create data buffers with
311
- * @return {@code String} containing the script lines
312
- */
313
- public static Mono <String > readScript (EncodedResource resource , DataBufferFactory dataBufferFactory ) {
314
- return readScript (resource , dataBufferFactory , DEFAULT_STATEMENT_SEPARATOR , DEFAULT_COMMENT_PREFIXES ,
315
- DEFAULT_BLOCK_COMMENT_END_DELIMITER );
316
- }
317
-
318
220
/**
319
221
* Read a script from the provided resource, using the supplied comment prefixes
320
222
* and statement separator, and build a {@code String} containing the lines.
@@ -331,7 +233,7 @@ public static Mono<String> readScript(EncodedResource resource, DataBufferFactor
331
233
* @return a {@link Mono} of {@link String} containing the script lines that
332
234
* completes once the resource was loaded
333
235
*/
334
- private static Mono <String > readScript (EncodedResource resource , DataBufferFactory dataBufferFactory ,
236
+ static Mono <String > readScript (EncodedResource resource , DataBufferFactory dataBufferFactory ,
335
237
@ Nullable String separator , @ Nullable String [] commentPrefixes , @ Nullable String blockCommentEndDelimiter ) {
336
238
337
239
return DataBufferUtils .join (DataBufferUtils .read (resource .getResource (), dataBufferFactory , 8192 ))
@@ -353,29 +255,6 @@ private static Mono<String> readScript(EncodedResource resource, DataBufferFacto
353
255
});
354
256
}
355
257
356
- /**
357
- * Read a script from the provided {@code LineNumberReader}, using the supplied
358
- * comment prefix and statement separator, and build a {@code String} containing
359
- * the lines.
360
- * <p>Lines <em>beginning</em> with the comment prefix are excluded from the
361
- * results; however, line comments anywhere else — for example, within
362
- * a statement — will be included in the results.
363
- * @param lineNumberReader the {@code LineNumberReader} containing the script
364
- * to be processed
365
- * @param commentPrefix the prefix that identifies comments in the SQL script
366
- * (typically "--")
367
- * @param separator the statement separator in the SQL script (typically ";")
368
- * @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
369
- * @return a {@code String} containing the script lines
370
- * @throws IOException in case of I/O errors
371
- */
372
- public static String readScript (LineNumberReader lineNumberReader , @ Nullable String commentPrefix ,
373
- @ Nullable String separator , @ Nullable String blockCommentEndDelimiter ) throws IOException {
374
-
375
- String [] commentPrefixes = (commentPrefix != null ) ? new String [] { commentPrefix } : null ;
376
- return readScript (lineNumberReader , commentPrefixes , separator , blockCommentEndDelimiter );
377
- }
378
-
379
258
/**
380
259
* Read a script from the provided {@code LineNumberReader}, using the supplied
381
260
* comment prefixes and statement separator, and build a {@code String} containing
@@ -392,7 +271,7 @@ public static String readScript(LineNumberReader lineNumberReader, @Nullable Str
392
271
* @return a {@code String} containing the script lines
393
272
* @throws IOException in case of I/O errors
394
273
*/
395
- public static String readScript (LineNumberReader lineNumberReader , @ Nullable String [] commentPrefixes ,
274
+ private static String readScript (LineNumberReader lineNumberReader , @ Nullable String [] commentPrefixes ,
396
275
@ Nullable String separator , @ Nullable String blockCommentEndDelimiter ) throws IOException {
397
276
398
277
String currentStatement = lineNumberReader .readLine ();
@@ -435,25 +314,6 @@ private static boolean startsWithAny(String script, String[] prefixes, int offse
435
314
return false ;
436
315
}
437
316
438
- /**
439
- * Determine if the provided SQL script contains the specified delimiter.
440
- * <p>This method is intended to be used to find the string delimiting each
441
- * SQL statement — for example, a ';' character.
442
- * <p>Any occurrence of the delimiter within the script will be ignored if it
443
- * is within a <em>literal</em> block of text enclosed in single quotes
444
- * ({@code '}) or double quotes ({@code "}), if it is escaped with a backslash
445
- * ({@code \}), or if it is within a single-line comment or block comment.
446
- * @param script the SQL script to search within
447
- * @param delimiter the statement delimiter to search for
448
- * @see #DEFAULT_COMMENT_PREFIXES
449
- * @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER
450
- * @see #DEFAULT_BLOCK_COMMENT_END_DELIMITER
451
- */
452
- public static boolean containsSqlScriptDelimiters (String script , String delimiter ) {
453
- return containsStatementSeparator (null , script , delimiter , DEFAULT_COMMENT_PREFIXES ,
454
- DEFAULT_BLOCK_COMMENT_START_DELIMITER , DEFAULT_BLOCK_COMMENT_END_DELIMITER );
455
- }
456
-
457
317
/**
458
318
* Determine if the provided SQL script contains the specified statement separator.
459
319
* <p>This method is intended to be used to find the string separating each
@@ -474,7 +334,7 @@ public static boolean containsSqlScriptDelimiters(String script, String delimite
474
334
* (typically <code>"*/"</code>)
475
335
* @since 5.3.8
476
336
*/
477
- private static boolean containsStatementSeparator (@ Nullable EncodedResource resource , String script ,
337
+ static boolean containsStatementSeparator (@ Nullable EncodedResource resource , String script ,
478
338
String separator , String [] commentPrefixes , String blockCommentStartDelimiter ,
479
339
String blockCommentEndDelimiter ) throws ScriptException {
480
340
@@ -547,7 +407,7 @@ else if (script.startsWith(blockCommentStartDelimiter, i)) {
547
407
* @throws ScriptException if an error occurred while executing the SQL script
548
408
* @see #executeSqlScript(Connection, EncodedResource, DataBufferFactory, boolean, boolean, String[], String, String, String)
549
409
* @see #DEFAULT_STATEMENT_SEPARATOR
550
- * @see #DEFAULT_COMMENT_PREFIX
410
+ * @see #DEFAULT_COMMENT_PREFIXES
551
411
* @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER
552
412
* @see #DEFAULT_BLOCK_COMMENT_END_DELIMITER
553
413
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#getConnection
@@ -571,15 +431,15 @@ public static Mono<Void> executeSqlScript(Connection connection, Resource resour
571
431
* @throws ScriptException if an error occurred while executing the SQL script
572
432
* @see #executeSqlScript(Connection, EncodedResource, DataBufferFactory, boolean, boolean, String[], String, String, String)
573
433
* @see #DEFAULT_STATEMENT_SEPARATOR
574
- * @see #DEFAULT_COMMENT_PREFIX
434
+ * @see #DEFAULT_COMMENT_PREFIXES
575
435
* @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER
576
436
* @see #DEFAULT_BLOCK_COMMENT_END_DELIMITER
577
437
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#getConnection
578
438
* @see org.springframework.r2dbc.connection.ConnectionFactoryUtils#releaseConnection
579
439
*/
580
440
public static Mono <Void > executeSqlScript (Connection connection , EncodedResource resource ) throws ScriptException {
581
441
return executeSqlScript (connection , resource , DefaultDataBufferFactory .sharedInstance , false , false ,
582
- DEFAULT_COMMENT_PREFIX , DEFAULT_STATEMENT_SEPARATOR , DEFAULT_BLOCK_COMMENT_START_DELIMITER ,
442
+ DEFAULT_COMMENT_PREFIXES , DEFAULT_STATEMENT_SEPARATOR , DEFAULT_BLOCK_COMMENT_START_DELIMITER ,
583
443
DEFAULT_BLOCK_COMMENT_END_DELIMITER );
584
444
}
585
445
0 commit comments