Interface ScriptRunner

All Known Implementing Classes:
DefaultScriptRunner, PostgresScriptRunner

public interface ScriptRunner
SQL script runner.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Adds a listener to be notified when each statement is submitted to the backend.
    void
    Adds a listener to be notified when each statement is successfully executed.
    void
    Adds a listener to be notified when each result set has been processed.
    Since the result set is positioned after the end of the last row, the listener must invoke ResultSet.beforeFirst() to process it again.
    void
    Cancels the script execution.
    Gets the backend for this script runner.
    Gets the connection for this script runner.
    int
    Gets the execution timeout in seconds.
    int
    Gets the maximum number of rows to be returned by each statement within the script.
    boolean
    Returns whether the script execution was canceled.
    boolean
    Returns whether JDBC escape processing is enabled.
    boolean
    Returns whether the connection is used in read-only mode.
    boolean
    Returns whether the script is executed within a transaction.
    run(String script)
    Runs the SQL script.
    void
    setEscapeProcessingEnabled(boolean enabled)
    Enables or disables JDBC escape processing.
    void
    setExecutionTimeout(int seconds)
    Sets the execution timeout for each statement in seconds.
    The timeout must be set before executing the script!
    void
    setMaxRows(int maxRows)
    Sets the maximum number of rows to be returned by each statement within the script.
    The limit must be set before executing the script!
    void
    setReadOnly(boolean readOnly)
    Sets the connection to read-only mode during execution.
    If the connection is already in read-only mode, this method has no effect, even if readOnly is false.
    void
    setTransactional(boolean transactional)
    Requests that the script should be executed within a transaction.
    If there is already a transaction running, this method has no effect, even if transactional is false.
  • Method Details

    • getBackend

      Backend getBackend()
      Gets the backend for this script runner.
      Returns:
      the backend
    • getConnection

      Connection getConnection()
      Gets the connection for this script runner.
      Returns:
      the connection
    • setEscapeProcessingEnabled

      void setEscapeProcessingEnabled(boolean enabled)
      Enables or disables JDBC escape processing.
      Parameters:
      enabled - true if escape processing is enabled
      See Also:
    • isEscapeProcessingEnabled

      boolean isEscapeProcessingEnabled()
      Returns whether JDBC escape processing is enabled.
      Returns:
      true if enabled (default)
    • setMaxRows

      void setMaxRows(int maxRows)
      Sets the maximum number of rows to be returned by each statement within the script.
      The limit must be set before executing the script!
      Parameters:
      maxRows - the maximum number of rows, 0 if no limit (default)
    • getMaxRows

      int getMaxRows()
      Gets the maximum number of rows to be returned by each statement within the script.
      Returns:
      the maximum number of rows, 0 if no limit (default)
    • setExecutionTimeout

      void setExecutionTimeout(int seconds)
      Sets the execution timeout for each statement in seconds.
      The timeout must be set before executing the script!
      Parameters:
      seconds - the timeout in seconds, 0 if no timeout (default)
    • getExecutionTimeout

      int getExecutionTimeout()
      Gets the execution timeout in seconds.
      Returns:
      the timeout in seconds, 0 if no timeout (default)
    • setReadOnly

      void setReadOnly(boolean readOnly)
      Sets the connection to read-only mode during execution.
      If the connection is already in read-only mode, this method has no effect, even if readOnly is false. The connection is switched back to read-write mode after the script execution if the connection was in read-write mode before.
      Parameters:
      readOnly - true if read-only
    • isReadOnly

      boolean isReadOnly()
      Returns whether the connection is used in read-only mode.
      Returns:
      true if read-only
    • setTransactional

      void setTransactional(boolean transactional)
      Requests that the script should be executed within a transaction.
      If there is already a transaction running, this method has no effect, even if transactional is false.
      Parameters:
      transactional - true if start a transaction if none is running
    • isTransactional

      boolean isTransactional()
      Returns whether the script is executed within a transaction.
      Returns:
      true if transactional
    • run

      Runs the SQL script.

      Throws ScriptRunnerException if the execution of some SQL statement within the script failed.
      Throws BackendException if some other error occurred.

      Parameters:
      script - the SQL script
      Returns:
      the results, never null
    • cancel

      void cancel()
      Cancels the script execution.
    • isCanceled

      boolean isCanceled()
      Returns whether the script execution was canceled.
      Returns:
      true if canceled
    • addExecutionListener

      void addExecutionListener(Consumer<String> listener)
      Adds a listener to be notified when each statement is submitted to the backend.
      Parameters:
      listener - the listener receives the SQL code
    • addResultListener

      void addResultListener(Consumer<ScriptRunnerResult> listener)
      Adds a listener to be notified when each statement is successfully executed.
      Parameters:
      listener - the listener receives the runner result
    • addResultSetListener

      void addResultSetListener(BiConsumer<String, ResultSet> listener)
      Adds a listener to be notified when each result set has been processed.
      Since the result set is positioned after the end of the last row, the listener must invoke ResultSet.beforeFirst() to process it again.

      The backend must support ResultSet.TYPE_SCROLL_INSENSITIVE to be able to use this feature.

      The result set is closed after all result set listeners have been notified.

      Parameters:
      listener - the listener receives the SQL code and the result set