net.sf.farrago.util
Class SqlRunner

java.lang.Object
  extended by net.sf.farrago.util.SqlRunner

public class SqlRunner
extends Object

Wrapper around the sqlline code to enable running of a SQL script from within Java code.

Since:
Jun 30, 2006
Version:
$Id: //open/dev/farrago/src/net/sf/farrago/util/SqlRunner.java#7 $
Author:
chard

Field Summary
protected static Logger logger
           
private static InputStream quitStream
           
private static SqlRunner singleton
           
 
Constructor Summary
private SqlRunner()
          Private constructor for singleton use.
 
Method Summary
static SqlRunner instance()
          Get a singleton instance of the SqlRunner class to run one or more scripts with.
 void runScript(String pathName, String url, String userName, String password)
          Run the specified SQL script against the server at the specified URL using the supplied credentials.
 void runScript(String pathName, String url, String userName, String password, PrintStream out)
          Run the specified SQL script against the server at the specified URL using the supplied credentials.
 void runScript(String pathName, String url, String userName, String password, PrintStream out, PrintStream err)
          Run the specified SQL script against the server at the specified URL.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleton

private static SqlRunner singleton

logger

protected static Logger logger

quitStream

private static InputStream quitStream
Constructor Detail

SqlRunner

private SqlRunner()
Private constructor for singleton use. Call the instance() method to get an instance of the class to use.

Method Detail

runScript

public void runScript(String pathName,
                      String url,
                      String userName,
                      String password)
               throws SQLException
Run the specified SQL script against the server at the specified URL using the supplied credentials. All outputs to stdout and stderr are unchanged.

Parameters:
pathName - String containing a path name to a SQL script
url - String specifying the URL of a server
userName - String specifying the user to log into the server as
password - String containing the password for the specified user
Throws:
SQLException

runScript

public void runScript(String pathName,
                      String url,
                      String userName,
                      String password,
                      PrintStream out)
               throws SQLException
Run the specified SQL script against the server at the specified URL using the supplied credentials. All outputs to stdout and stderr are redirected to the soecified PrintStream.

Parameters:
pathName - String containing a path name to a SQL script
url - String specifying the URL of a server
userName - String specifying the user to log into the server as
password - String containing the password for the specified user
out - PrintStream to redirect stdout and stderr to
Throws:
SQLException

runScript

public void runScript(String pathName,
                      String url,
                      String userName,
                      String password,
                      PrintStream out,
                      PrintStream err)
               throws SQLException
Run the specified SQL script against the server at the specified URL. The caller can redirect stdout and/or stderr to alternate streams, if desired.

Parameters:
pathName - String containing a path name to a SQL script
url - String specifying the URL of a server
userName - String specifying the user to log into the server as
password - String containing the password for the specified user
out - PrintStream to redirect stdout to while executing the script, or null to leave stdout unchanged
err - PrintStream to redirect stderr to while executing the script, or null to leave stderr unchanged
Throws:
SQLException - All errors in execution are converted into SQLException and thrown. Null values for either pathName or url will assert.

instance

public static SqlRunner instance()
Get a singleton instance of the SqlRunner class to run one or more scripts with.

Returns:
Always returns the same instance of SqlRunner