Skip to content

Commit 9018356

Browse files
committed
Deprecate internal APIs in ScriptUtils
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 commit formally deprecates the following methods in ScriptUtils in spring-jdbc. - readScript(...) - containsSqlScriptDelimiters(...) - splitSqlScript(...) Closes gh-26947
1 parent b5ce514 commit 9018356

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
@@ -344,7 +344,10 @@ static String readScript(EncodedResource resource, @Nullable String separator,
344344
* @param blockCommentEndDelimiter the <em>end</em> block comment delimiter
345345
* @return a {@code String} containing the script lines
346346
* @throws IOException in case of I/O errors
347+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
348+
* This is an internal API and will likely be removed in Spring Framework 6.0.
347349
*/
350+
@Deprecated
348351
public static String readScript(LineNumberReader lineNumberReader, @Nullable String commentPrefix,
349352
@Nullable String separator, @Nullable String blockCommentEndDelimiter) throws IOException {
350353

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

@@ -416,7 +422,10 @@ private static void appendSeparatorToScriptIfNecessary(StringBuilder scriptBuild
416422
* @see #DEFAULT_COMMENT_PREFIXES
417423
* @see #DEFAULT_BLOCK_COMMENT_START_DELIMITER
418424
* @see #DEFAULT_BLOCK_COMMENT_END_DELIMITER
425+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
426+
* This is an internal API and will likely be removed in Spring Framework 6.0.
419427
*/
428+
@Deprecated
420429
public static boolean containsSqlScriptDelimiters(String script, String delimiter) {
421430
return containsStatementSeparator(null, script, delimiter, DEFAULT_COMMENT_PREFIXES,
422431
DEFAULT_BLOCK_COMMENT_START_DELIMITER, DEFAULT_BLOCK_COMMENT_END_DELIMITER);
@@ -519,7 +528,10 @@ else if (script.startsWith(blockCommentStartDelimiter, i)) {
519528
* @throws ScriptException if an error occurred while splitting the SQL script
520529
* @see #splitSqlScript(String, String, List)
521530
* @see #splitSqlScript(EncodedResource, String, String, String, String, String, List)
531+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
532+
* This is an internal API and will likely be removed in Spring Framework 6.0.
522533
*/
534+
@Deprecated
523535
public static void splitSqlScript(String script, char separator, List<String> statements) throws ScriptException {
524536
splitSqlScript(script, String.valueOf(separator), statements);
525537
}
@@ -543,7 +555,10 @@ public static void splitSqlScript(String script, char separator, List<String> st
543555
* @throws ScriptException if an error occurred while splitting the SQL script
544556
* @see #splitSqlScript(String, char, List)
545557
* @see #splitSqlScript(EncodedResource, String, String, String, String, String, List)
558+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
559+
* This is an internal API and will likely be removed in Spring Framework 6.0.
546560
*/
561+
@Deprecated
547562
public static void splitSqlScript(String script, String separator, List<String> statements) throws ScriptException {
548563
splitSqlScript(null, script, separator, DEFAULT_COMMENT_PREFIX, DEFAULT_BLOCK_COMMENT_START_DELIMITER,
549564
DEFAULT_BLOCK_COMMENT_END_DELIMITER, statements);
@@ -572,7 +587,10 @@ public static void splitSqlScript(String script, String separator, List<String>
572587
* never {@code null} or empty
573588
* @param statements the list that will contain the individual statements
574589
* @throws ScriptException if an error occurred while splitting the SQL script
590+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
591+
* This is an internal API and will likely be removed in Spring Framework 6.0.
575592
*/
593+
@Deprecated
576594
public static void splitSqlScript(@Nullable EncodedResource resource, String script,
577595
String separator, String commentPrefix, String blockCommentStartDelimiter,
578596
String blockCommentEndDelimiter, List<String> statements) throws ScriptException {
@@ -606,7 +624,10 @@ public static void splitSqlScript(@Nullable EncodedResource resource, String scr
606624
* @param statements the list that will contain the individual statements
607625
* @throws ScriptException if an error occurred while splitting the SQL script
608626
* @since 5.2
627+
* @deprecated as of Spring Framework 5.2.16 with no plans for replacement.
628+
* This is an internal API and will likely be removed in Spring Framework 6.0.
609629
*/
630+
@Deprecated
610631
public static void splitSqlScript(@Nullable EncodedResource resource, String script,
611632
String separator, String[] commentPrefixes, String blockCommentStartDelimiter,
612633
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
@@ -48,6 +48,7 @@
4848
public class ScriptUtilsUnitTests {
4949

5050
@Test
51+
@SuppressWarnings("deprecation")
5152
public void splitSqlScriptDelimitedWithSemicolon() {
5253
String rawStatement1 = "insert into customer (id, name)\nvalues (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
5354
String cleanedStatement1 = "insert into customer (id, name) values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
@@ -63,6 +64,7 @@ public void splitSqlScriptDelimitedWithSemicolon() {
6364
}
6465

6566
@Test
67+
@SuppressWarnings("deprecation")
6668
public void splitSqlScriptDelimitedWithNewLine() {
6769
String statement1 = "insert into customer (id, name) values (1, 'Rod ; Johnson'), (2, 'Adrian \n Collier')";
6870
String statement2 = "insert into orders(id, order_date, customer_id) values (1, '2008-01-02', 2)";
@@ -75,6 +77,7 @@ public void splitSqlScriptDelimitedWithNewLine() {
7577
}
7678

7779
@Test
80+
@SuppressWarnings("deprecation")
7881
public void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() {
7982
String statement1 = "do something";
8083
String statement2 = "do something else";
@@ -86,6 +89,7 @@ public void splitSqlScriptDelimitedWithNewLineButDefaultDelimiterSpecified() {
8689
}
8790

8891
@Test // SPR-13218
92+
@SuppressWarnings("deprecation")
8993
public void splitScriptWithSingleQuotesNestedInsideDoubleQuotes() throws Exception {
9094
String statement1 = "select '1' as \"Dogbert's owner's\" from dual";
9195
String statement2 = "select '2' as \"Dilbert's\" from dual";
@@ -97,6 +101,7 @@ public void splitScriptWithSingleQuotesNestedInsideDoubleQuotes() throws Excepti
97101
}
98102

99103
@Test // SPR-11560
104+
@SuppressWarnings("deprecation")
100105
public void readAndSplitScriptWithMultipleNewlinesAsSeparator() throws Exception {
101106
String script = readScript("db-test-data-multi-newline.sql");
102107
List<String> statements = new ArrayList<>();
@@ -124,6 +129,7 @@ public void readAndSplitScriptContainingCommentsWithMultiplePrefixes() throws Ex
124129
splitScriptContainingComments(script, "--", "#", "^");
125130
}
126131

132+
@SuppressWarnings("deprecation")
127133
private void splitScriptContainingComments(String script, String... commentPrefixes) throws Exception {
128134
List<String> statements = new ArrayList<>();
129135
splitSqlScript(null, script, ";", commentPrefixes, DEFAULT_BLOCK_COMMENT_START_DELIMITER,
@@ -137,6 +143,7 @@ private void splitScriptContainingComments(String script, String... commentPrefi
137143
}
138144

139145
@Test // SPR-10330
146+
@SuppressWarnings("deprecation")
140147
public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Exception {
141148
String script = readScript("test-data-with-comments-and-leading-tabs.sql");
142149
List<String> statements = new ArrayList<>();
@@ -148,6 +155,7 @@ public void readAndSplitScriptContainingCommentsWithLeadingTabs() throws Excepti
148155
}
149156

150157
@Test // SPR-9531
158+
@SuppressWarnings("deprecation")
151159
public void readAndSplitScriptContainingMultiLineComments() throws Exception {
152160
String script = readScript("test-data-with-multi-line-comments.sql");
153161
List<String> statements = new ArrayList<>();
@@ -158,6 +166,7 @@ public void readAndSplitScriptContainingMultiLineComments() throws Exception {
158166
}
159167

160168
@Test
169+
@SuppressWarnings("deprecation")
161170
public void readAndSplitScriptContainingMultiLineNestedComments() throws Exception {
162171
String script = readScript("test-data-with-multi-line-nested-comments.sql");
163172
List<String> statements = new ArrayList<>();
@@ -199,6 +208,7 @@ public void readAndSplitScriptContainingMultiLineNestedComments() throws Excepti
199208
"'/* double \" quotes */\ninsert into colors(color_num) values(42);' # ; # true",
200209
"'/* double \\\" quotes */\ninsert into colors(color_num) values(42);' # ; # true"
201210
})
211+
@SuppressWarnings("deprecation")
202212
public void containsStatementSeparator(String script, String delimiter, boolean expected) {
203213
// Indirectly tests ScriptUtils.containsStatementSeparator(EncodedResource, String, String, String[], String, String).
204214
assertThat(containsSqlScriptDelimiters(script, delimiter)).isEqualTo(expected);

0 commit comments

Comments
 (0)