Interface ScriptRunner
- All Known Implementing Classes:
DefaultScriptRunner, PostgresScriptRunner
public interface ScriptRunner
SQL script runner.
-
Method Summary
Modifier and TypeMethodDescriptionvoidaddExecutionListener(Consumer<String> listener) Adds a listener to be notified when each statement is submitted to the backend.voidaddResultListener(Consumer<ScriptRunnerResult> listener) Adds a listener to be notified when each statement is successfully executed.voidaddResultSetListener(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 invokeResultSet.beforeFirst()to process it again.voidcancel()Cancels the script execution.Gets the backend for this script runner.Gets the connection for this script runner.intGets the execution timeout in seconds.intGets the maximum number of rows to be returned by each statement within the script.booleanReturns whether the script execution was canceled.booleanReturns whether JDBC escape processing is enabled.booleanReturns whether the connection is used in read-only mode.booleanReturns whether the script is executed within a transaction.Runs the SQL script.voidsetEscapeProcessingEnabled(boolean enabled) Enables or disables JDBC escape processing.voidsetExecutionTimeout(int seconds) Sets the execution timeout for each statement in seconds.
The timeout must be set before executing the script!voidsetMaxRows(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!voidsetReadOnly(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 ifreadOnlyis false.voidsetTransactional(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 iftransactionalis false.
-
Method Details
-
getBackend
-
getConnection
-
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 ifreadOnlyis 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 iftransactionalis 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
ScriptRunnerExceptionif the execution of some SQL statement within the script failed.
ThrowsBackendExceptionif 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
-
addResultListener
Adds a listener to be notified when each statement is successfully executed.- Parameters:
listener- the listener receives the runner result
-
addResultSetListener
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 invokeResultSet.beforeFirst()to process it again.The backend must support
ResultSet.TYPE_SCROLL_INSENSITIVEto 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
-