Skip to content

Commit 7c75602

Browse files
committed
Deprecate internal APIs in ScriptUtils in spring-jdbc
Many of the utility methods in ScriptUtils are public only because they were once invoked from JdbdTestUtils in spring-test, which is no longer the case. Consequently, there should no longer be a need for any external clients to invoke such methods. To address this, this commit formally deprecates the following methods in ScriptUtils in spring-jdbc. - readScript(...) - containsSqlScriptDelimiters(...) - splitSqlScript(...) Closes gh-26947
1 parent 4c642cc commit 7c75602

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

spring-jdbc/src/main/java/org/springframework/jdbc/datasource/init/ScriptUtils.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,10 @@ static String readScript(EncodedResource resource, @Nullable String separator,
345345
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
346346
* @return a {@code String} containing the script lines
347347
* @throws IOException in case of I/O errors
348+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
349+
* This is an internal API and will likely be removed in Spring Framework 6.0.
348350
*/
351+
@Deprecated
349352
public static String readScript(LineNumberReader lineNumberReader, @Nullable String commentPrefix,
350353
@Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException {
351354

@@ -369,7 +372,10 @@ public static String readScript(LineNumberReader lineNumberReader, @Nullable Str
369372
* @return a {@code String} containing the script lines
370373
* @throws IOException in case of I/O errors
371374
* @since 5.2
375+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
376+
* This is an internal API and will likely be removed in Spring Framework 6.0.
372377
*/
378+
@Deprecated
373379
public static String readScript(LineNumberReader lineNumberReader, @Nullable String[] commentPrefixes,
374380
@Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException {
375381

@@ -417,7 +423,10 @@ private static void appendSeparatorToScriptIfNecessary(StringBuilder scriptBuild
417423
* @see #DEFAULT_COMMENT_PREFIXES
418424
* @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER
419425
* @see #DEFAULT_BLOCK_COMMENT_END_DELIMITER
426+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
427+
* This is an internal API and will likely be removed in Spring Framework 6.0.
420428
*/
429+
@Deprecated
421430
public static boolean containsSqlScriptDelimiters(String script, String delimiter) {
422431
return containsStatementSeparator(null, script, delimiter, DEFAULT_COMMENT_PREFIXES,
423432
DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER);
@@ -520,7 +529,10 @@ else if (script.startsWith(blockCommentStartDelimiter, i)) {
520529
* @throws ScriptException if an error occurred while splitting the SQL script
521530
* @see #splitSqlScript(String, String, List)
522531
* @see #splitSqlScript(EncodedResource, String, String, String, String, String, List)
532+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
533+
* This is an internal API and will likely be removed in Spring Framework 6.0.
523534
*/
535+
@Deprecated
524536
public static void splitSqlScript(String script, char separator, List<String> statements) throws ScriptException {
525537
splitSqlScript(script, String.valueOf(separator), statements);
526538
}
@@ -544,7 +556,10 @@ public static void splitSqlScript(String script, char separator, List<String> st
544556
* @throws ScriptException if an error occurred while splitting the SQL script
545557
* @see #splitSqlScript(String, char, List)
546558
* @see #splitSqlScript(EncodedResource, String, String, String, String, String, List)
559+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
560+
* This is an internal API and will likely be removed in Spring Framework 6.0.
547561
*/
562+
@Deprecated
548563
public static void splitSqlScript(String script, String separator, List<String> statements) throws ScriptException {
549564
splitSqlScript(null, script, separator, DEFAULT_COMMENT_PREFIX, DEFAULT_BLOCK_COMMENT_START_DELIMITER,
550565
DEFAULT_BLOCK_COMMENT_END_DELIMITER, statements);
@@ -573,7 +588,10 @@ public static void splitSqlScript(String script, String separator, List<String>
573588
* never {@code null} or empty
574589
* @param statements the list that will contain the individual statements
575590
* @throws ScriptException if an error occurred while splitting the SQL script
591+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
592+
* This is an internal API and will likely be removed in Spring Framework 6.0.
576593
*/
594+
@Deprecated
577595
public static void splitSqlScript(@Nullable EncodedResource resource, String script,
578596
String separator, String commentPrefix, String blockCommentStartDelimiter,
579597
String blockCommentEndDelimiter, List<String> statements) throws ScriptException {
@@ -607,7 +625,10 @@ public static void splitSqlScript(@Nullable EncodedResource resource, String scr
607625
* @param statements the list that will contain the individual statements
608626
* @throws ScriptException if an error occurred while splitting the SQL script
609627
* @since 5.2
628+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
629+
* This is an internal API and will likely be removed in Spring Framework 6.0.
610630
*/
631+
@Deprecated
611632
public static void splitSqlScript(@Nullable EncodedResource resource, String script,
612633
String separator, String[] commentPrefixes, String blockCommentStartDelimiter,
613634
String blockCommentEndDelimiter, List<String> statements) throws ScriptException {

spring-jdbc/src/test/java/org/springframework/jdbc/datasource/init/ScriptUtilsUnitTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
public class ScriptUtilsUnitTests {
5050

5151
@Test
52+
@SuppressWarnings("deprecation")
5253
public void splitSqlScriptDelimitedWithSemicolon() {
5354
String rawStatement1 = "insert into customer (id, name)\nvalues (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
5455
String cleanedStatement1 = "insert into customer (id, name) values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
@@ -67,6 +68,7 @@ public void splitSqlScriptDelimitedWithSemicolon() {
6768
}
6869

6970
@Test
71+
@SuppressWarnings("deprecation")
7072
public void splitSqlScriptDelimitedWithNewLine() {
7173
String statement1 = "insert into customer (id, name) values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
7274
String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)";
@@ -82,6 +84,7 @@ public void splitSqlScriptDelimitedWithNewLine() {
8284
}
8385

8486
@Test
87+
@SuppressWarnings("deprecation")
8588
public void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() {
8689
String statement1 = "do something";
8790
String statement2 = "do something else";
@@ -96,6 +99,7 @@ public void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() {
9699
}
97100

98101
@Test // SPR-13218
102+
@SuppressWarnings("deprecation")
99103
public void splitScriptWithSingleQuotesNestedInsideDoubleQuotes() {
100104
String statement1 = "select '1' as \"Dogbert's owner's\" from dual";
101105
String statement2 = "select '2' as \"Dilbert's\" from dual";
@@ -110,6 +114,7 @@ public void splitScriptWithSingleQuotesNestedInsideDoubleQuotes() {
110114
}
111115

112116
@Test // SPR-11560
117+
@SuppressWarnings("deprecation")
113118
public void readAndSplitScriptWithMultipleNewlinesAsSeparator() throws Exception {
114119
String script = readScript("db-test-data-multi-newline.sql");
115120
List<String> statements = new ArrayList<>();
@@ -139,6 +144,7 @@ public void readAndSplitScriptContainingCommentsWithMultiplePrefixes() throws Ex
139144
splitScriptContainingComments(script, "--", "#", "^");
140145
}
141146

147+
@SuppressWarnings("deprecation")
142148
private void splitScriptContainingComments(String script, String... commentPrefixes) {
143149
List<String> statements = new ArrayList<>();
144150
splitSqlScript(null, script, ";", commentPrefixes, DEFAULT_BLOCK_COMMENT_START_DELIMITER,
@@ -154,6 +160,7 @@ private void splitScriptContainingComments(String script, String... commentPrefi
154160
}
155161

156162
@Test // SPR-10330
163+
@SuppressWarnings("deprecation")
157164
public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Exception {
158165
String script = readScript("test-data-with-comments-and-leading-tabs.sql");
159166
List<String> statements = new ArrayList<>();
@@ -167,6 +174,7 @@ public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Excepti
167174
}
168175

169176
@Test // SPR-9531
177+
@SuppressWarnings("deprecation")
170178
public void readAndSplitScriptContainingMultiLineComments() throws Exception {
171179
String script = readScript("test-data-with-multi-line-comments.sql");
172180
List<String> statements = new ArrayList<>();
@@ -179,6 +187,7 @@ public void readAndSplitScriptContainingMultiLineComments() throws Exception {
179187
}
180188

181189
@Test
190+
@SuppressWarnings("deprecation")
182191
public void readAndSplitScriptContainingMultiLineNestedComments() throws Exception {
183192
String script = readScript("test-data-with-multi-line-nested-comments.sql");
184193
List<String> statements = new ArrayList<>();
@@ -222,6 +231,7 @@ public void readAndSplitScriptContainingMultiLineNestedComments() throws Excepti
222231
"'/* double \" quotes */\ninsert into colors(color_num) values(42);' # ; # true",
223232
"'/* double \\\" quotes */\ninsert into colors(color_num) values(42);' # ; # true"
224233
})
234+
@SuppressWarnings("deprecation")
225235
public void containsStatementSeparator(String script, String delimiter, boolean expected) {
226236
// Indirectly tests ScriptUtils.containsStatementSeparator(EncodedResource, String, String, String[], String, String).
227237
assertThat(containsSqlScriptDelimiters(script, delimiter)).isEqualTo(expected);

0 commit comments

Comments
 (0)