org.springframework.r2dbc.connection.init

## Class ScriptUtils

- java.lang.Object
- - org.springframework.r2dbc.connection.init.ScriptUtils

-     public abstract class ScriptUtils
      extends Object

  Generic utility methods for working with SQL scripts in conjunction with R2DBC.

  Mainly for internal use within the framework.

  Since:
    5.3
  Author:
    Thomas Risberg, Sam Brannen, Juergen Hoeller, Keith Donald, Dave Syer, Chris Beams, Oliver Gierke, Chris Baldwin, Nicolas Debeissat, Phillip Webb, Mark Paluch
  See Also:
    `ScriptUtils`

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static String` | `DEFAULT_BLOCK_COMMENT_END_DELIMITER` Default end delimiter for block comments within SQL scripts: `"*/"`.
    `static String` | `DEFAULT_BLOCK_COMMENT_START_DELIMITER` Default start delimiter for block comments within SQL scripts: `"/*"`.
    `static String[]` | `DEFAULT_COMMENT_PREFIXES` Default prefixes for single-line comments within SQL scripts: `["--"]`.
    `static String` | `DEFAULT_STATEMENT_SEPARATOR` Default statement separator within SQL scripts: `";"`.
    `static String` | `EOF_STATEMENT_SEPARATOR` End of file (EOF) SQL statement separator: `"^^^ END OF SCRIPT ^^^"`.
    `static String` | `FALLBACK_STATEMENT_SEPARATOR` Fallback statement separator within SQL scripts: `"\n"`.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ScriptUtils()`

  - ### Method Summary

    All Methods Static Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `static reactor.core.publisher.Mono<Void>` | `executeSqlScript(io.r2dbc.spi.Connection connection, EncodedResource resource)` Execute the given SQL script using default settings for statement separators, comment delimiters, and exception handling flags.
    `static reactor.core.publisher.Mono<Void>` | `executeSqlScript(io.r2dbc.spi.Connection connection, EncodedResource resource, DataBufferFactory dataBufferFactory, boolean continueOnError, boolean ignoreFailedDrops, String[] commentPrefixes, String separator, String blockCommentStartDelimiter, String blockCommentEndDelimiter)` Execute the given SQL script.
    `static reactor.core.publisher.Mono<Void>` | `executeSqlScript(io.r2dbc.spi.Connection connection, EncodedResource resource, DataBufferFactory dataBufferFactory, boolean continueOnError, boolean ignoreFailedDrops, String commentPrefix, String separator, String blockCommentStartDelimiter, String blockCommentEndDelimiter)` Execute the given SQL script.
    `static reactor.core.publisher.Mono<Void>` | `executeSqlScript(io.r2dbc.spi.Connection connection, Resource resource)` Execute the given SQL script using default settings for statement separators, comment delimiters, and exception handling flags.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### DEFAULT_STATEMENT_SEPARATOR

          public static final String DEFAULT_STATEMENT_SEPARATOR

      Default statement separator within SQL scripts: `";"`.
      See Also:
        Constant Field Values

    - #### FALLBACK_STATEMENT_SEPARATOR

          public static final String FALLBACK_STATEMENT_SEPARATOR

      Fallback statement separator within SQL scripts: `"\n"`.

      Used if neither a custom separator nor the `DEFAULT_STATEMENT_SEPARATOR` is present in a given script.

      See Also:
        Constant Field Values

    - #### EOF_STATEMENT_SEPARATOR

          public static final String EOF_STATEMENT_SEPARATOR

      End of file (EOF) SQL statement separator: `"^^^ END OF SCRIPT ^^^"`.

      This value may be supplied as the `separator` to `executeSqlScript(Connection, EncodedResource, DataBufferFactory, boolean, boolean, String[], String, String, String)` to denote that an SQL script contains a single statement (potentially spanning multiple lines) with no explicit statement separator. Note that such a script should not actually contain this value; it is merely a virtual statement separator.

      See Also:
        Constant Field Values

    - #### DEFAULT_COMMENT_PREFIXES

          public static final String[] DEFAULT_COMMENT_PREFIXES

      Default prefixes for single-line comments within SQL scripts: `["--"]`.

    - #### DEFAULT_BLOCK_COMMENT_START_DELIMITER

          public static final String DEFAULT_BLOCK_COMMENT_START_DELIMITER

      Default start delimiter for block comments within SQL scripts: `"/*"`.
      See Also:
        Constant Field Values

    - #### DEFAULT_BLOCK_COMMENT_END_DELIMITER

          public static final String DEFAULT_BLOCK_COMMENT_END_DELIMITER

      Default end delimiter for block comments within SQL scripts: `"*/"`.
      See Also:
        Constant Field Values

  - ### Constructor Detail

    - #### ScriptUtils

          public ScriptUtils()

  - ### Method Detail

    - #### executeSqlScript

          public static reactor.core.publisher.Mono<Void> executeSqlScript(io.r2dbc.spi.Connection connection,
                                                                           Resource resource)

      Execute the given SQL script using default settings for statement separators, comment delimiters, and exception handling flags.

      Statement separators and comments will be removed before executing individual statements within the supplied script.

      Warning: this method does not release the provided `Connection`.

      Parameters:
        `connection` - the R2DBC connection to use to execute the script; already configured and ready to use
        `resource` - the resource to load the SQL script from; encoded with the current platform's default encoding
      Throws:
        `ScriptException` - if an error occurred while executing the SQL script
      See Also:
        `executeSqlScript(Connection, EncodedResource, DataBufferFactory, boolean, boolean, String[], String, String, String)`, `DEFAULT_STATEMENT_SEPARATOR`, `DEFAULT_COMMENT_PREFIXES`, `DEFAULT_BLOCK_COMMENT_START_DELIMITER`, `DEFAULT_BLOCK_COMMENT_END_DELIMITER`, `ConnectionFactoryUtils.getConnection(io.r2dbc.spi.ConnectionFactory)`, `ConnectionFactoryUtils.releaseConnection(io.r2dbc.spi.Connection, io.r2dbc.spi.ConnectionFactory)`

    - #### executeSqlScript

          public static reactor.core.publisher.Mono<Void> executeSqlScript(io.r2dbc.spi.Connection connection,
                                                                           EncodedResource resource)

      Execute the given SQL script using default settings for statement separators, comment delimiters, and exception handling flags.

      Statement separators and comments will be removed before executing individual statements within the supplied script.

      Warning: this method does not release the provided `Connection`.

      Parameters:
        `connection` - the R2DBC connection to use to execute the script; already configured and ready to use
        `resource` - the resource (potentially associated with a specific encoding) to load the SQL script from
      Throws:
        `ScriptException` - if an error occurred while executing the SQL script
      See Also:
        `executeSqlScript(Connection, EncodedResource, DataBufferFactory, boolean, boolean, String[], String, String, String)`, `DEFAULT_STATEMENT_SEPARATOR`, `DEFAULT_COMMENT_PREFIXES`, `DEFAULT_BLOCK_COMMENT_START_DELIMITER`, `DEFAULT_BLOCK_COMMENT_END_DELIMITER`, `ConnectionFactoryUtils.getConnection(io.r2dbc.spi.ConnectionFactory)`, `ConnectionFactoryUtils.releaseConnection(io.r2dbc.spi.Connection, io.r2dbc.spi.ConnectionFactory)`

    - #### executeSqlScript

          public static reactor.core.publisher.Mono<Void> executeSqlScript(io.r2dbc.spi.Connection connection,
                                                                           EncodedResource resource,
                                                                           DataBufferFactory dataBufferFactory,
                                                                           boolean continueOnError,
                                                                           boolean ignoreFailedDrops,
                                                                           String commentPrefix,
                                                                           @Nullable
                                                                           String separator,
                                                                           String blockCommentStartDelimiter,
                                                                           String blockCommentEndDelimiter)

      Execute the given SQL script.

      Statement separators and comments will be removed before executing individual statements within the supplied script.

      Warning: this method does not release the provided `Connection`.

      Parameters:
        `connection` - the R2DBC connection to use to execute the script; already configured and ready to use
        `resource` - the resource (potentially associated with a specific encoding) to load the SQL script from
        `dataBufferFactory` - the factory to create data buffers with
        `continueOnError` - whether to continue without throwing an exception in the event of an error
        `ignoreFailedDrops` - whether to continue in the event of specifically an error on a `DROP` statement
        `commentPrefix` - the prefix that identifies single-line comments in the SQL script (typically "--")
        `separator` - the script statement separator; defaults to ";" if not specified and falls back to "\n" as a last resort; may be set to "^^^ END OF SCRIPT ^^^" to signal that the script contains a single statement without a separator
        `blockCommentStartDelimiter` - the start block comment delimiter
        `blockCommentEndDelimiter` - the end block comment delimiter
      Throws:
        `ScriptException` - if an error occurred while executing the SQL script
      See Also:
        `DEFAULT_STATEMENT_SEPARATOR`, `FALLBACK_STATEMENT_SEPARATOR`, `EOF_STATEMENT_SEPARATOR`, `ConnectionFactoryUtils.getConnection(io.r2dbc.spi.ConnectionFactory)`, `ConnectionFactoryUtils.releaseConnection(io.r2dbc.spi.Connection, io.r2dbc.spi.ConnectionFactory)`

    - #### executeSqlScript

          public static reactor.core.publisher.Mono<Void> executeSqlScript(io.r2dbc.spi.Connection connection,
                                                                           EncodedResource resource,
                                                                           DataBufferFactory dataBufferFactory,
                                                                           boolean continueOnError,
                                                                           boolean ignoreFailedDrops,
                                                                           String[] commentPrefixes,
                                                                           @Nullable
                                                                           String separator,
                                                                           String blockCommentStartDelimiter,
                                                                           String blockCommentEndDelimiter)

      Execute the given SQL script.

      Statement separators and comments will be removed before executing individual statements within the supplied script.

      Warning: this method does not release the provided `Connection`.

      Parameters:
        `connection` - the R2DBC connection to use to execute the script; already configured and ready to use
        `resource` - the resource (potentially associated with a specific encoding) to load the SQL script from
        `dataBufferFactory` - the factory to create data buffers with
        `continueOnError` - whether to continue without throwing an exception in the event of an error
        `ignoreFailedDrops` - whether to continue in the event of specifically an error on a `DROP` statement
        `commentPrefixes` - the prefixes that identify single-line comments in the SQL script (typically "--")
        `separator` - the script statement separator; defaults to ";" if not specified and falls back to "\n" as a last resort; may be set to "^^^ END OF SCRIPT ^^^" to signal that the script contains a single statement without a separator
        `blockCommentStartDelimiter` - the start block comment delimiter
        `blockCommentEndDelimiter` - the end block comment delimiter
      Throws:
        `ScriptException` - if an error occurred while executing the SQL script
      See Also:
        `DEFAULT_STATEMENT_SEPARATOR`, `FALLBACK_STATEMENT_SEPARATOR`, `EOF_STATEMENT_SEPARATOR`, `ConnectionFactoryUtils.getConnection(io.r2dbc.spi.ConnectionFactory)`, `ConnectionFactoryUtils.releaseConnection(io.r2dbc.spi.Connection, io.r2dbc.spi.ConnectionFactory)`