public class DerbyScriptRunner extends Object
The script uses a single character set for reading the scripts as well as writing the logs. The class has a
Default Log Stream
which it uses when no log stream or file is
specified along with the script for execution (executeScript(String)
). A log stream may be specified with
the script resource using the executeScript(String, File)
or
executeScript(String, OutputStream, boolean)
methods.
The script resources provided to this class should be in the format supported by UrlResourceUtil
.
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_CHARSET
Default system character set to use if none is specified by the user.
|
Constructor and Description |
---|
DerbyScriptRunner(Connection dbConnection)
Initializes a new script runner for the connection.
|
DerbyScriptRunner(Connection dbConnection,
String charset)
Initializes a new script runner.
|
Modifier and Type | Method and Description |
---|---|
int |
executeScript(String scriptResource)
Executes the given script.
|
int |
executeScript(String scriptResource,
File scriptLogFile)
Executes the given script.
|
int |
executeScript(String script,
OutputStream scriptLogStream,
boolean closeScriptLogStream)
Executes the given script.
|
void |
setDefaultScriptLogStream(OutputStream defaultScriptLogStream)
Sets the log stream to log results to.
|
public static final String DEFAULT_CHARSET
public DerbyScriptRunner(Connection dbConnection, String charset)
dbConnection
- The database connection to run the scripts on.charset
- Character set to use for reading the script and writing the logpublic DerbyScriptRunner(Connection dbConnection)
DEFAULT_CHARSET
as the character set.dbConnection
- The database connection to run the scripts on.public void setDefaultScriptLogStream(OutputStream defaultScriptLogStream)
DerbyUtils.DEV_NULL
stream, which simply ignores all output.
Data will be written to this stream using the character set set in the constructor.
defaultScriptLogStream
- The default script log streampublic int executeScript(String scriptResource) throws IOException
setDefaultScriptLogStream(OutputStream)
.scriptResource
- The script source; should be in a format compatible with UrlResourceUtil0
if the execution succeeds without any errors; non zero
value otherwise.IOException
- Error reading script file, or writing to the log file.public int executeScript(String scriptResource, File scriptLogFile) throws IOException
scriptLogFile
.scriptResource
- The script source; should be in a format compatible with UrlResourceUtilscriptLogFile
- The file to which the output logs are written. If the file already exists, it is appended to0
if the execution succeeds without any errors; non zero
value otherwise.IOException
- Error reading script file, or writing to the log file.public int executeScript(String script, OutputStream scriptLogStream, boolean closeScriptLogStream) throws IOException
scriptLogStream
.script
- The script source; should be in a format compatible with UrlResourceUtilscriptLogStream
- The stream to which the output logs are written.closeScriptLogStream
- If set to true
, the log stream is closed at the end of the execution.0
if the execution succeeds without any errors; non zero
value otherwise.IOException
- Error reading script file, or writing to the log file.Copyright © 2015-2016 Development Entropy (deventropy.org) Contributors