|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectwt.dataservice.SQLScriptExecutor
Used to execute general SQL strings or to SQL Script files, but the result is a long string equal to "as seen on a console".
This class is thread-safe but can only execute scripts on one thread at a time. However, it can be used multiple times in succession.
Nested Class Summary | |
static class |
SQLScriptExecutor.ExecutionException
|
Field Summary | |
private boolean |
configureFromPropertyFiles_
|
private String |
connectString_
|
private static String |
DB_DIR
|
private long |
inactivityTimeout_
|
private long |
overallTimeout_
|
private String |
password_
|
private static String |
SQL_DIR
|
private static File |
sqlPathFile_
|
private String |
userName_
|
private static WTProperties |
wtProperties_
|
Constructor Summary | |
SQLScriptExecutor()
|
Method Summary | |
private File |
createScriptToCall(String sql_to_execute)
|
private String |
execute(String sql_to_execute)
Buffers the constructor's argument in a wt.temp file and executes the file using SQLPlus. |
protected String |
execute(String sql_to_execute,
PrintStream print_stream)
Buffers the constructor's argument in a wt.temp file and executes the file using SQLPlus. |
String |
executeScript(File script_file)
Execute the script in the specified file. |
void |
executeScript(File script_file,
PrintStream print_stream)
Execute the script in the specified file. |
String |
executeScript(String sql_script_path)
Specify the full path to a script file or a relative path to the script based on $(wt.home)/db/sql ,
and it will be executed it in a SQLPlus session. |
String |
executeSQL(String sql_string)
Execute the supplied SQL String in a SQLPlus session. |
long |
getInactivityTimeOut()
|
private String |
getLoginStringFromFields()
|
private String |
getLoginStringFromProperties()
Parse the DSProperties for the USER/PASSWORD/SERVICE information, and maybe a connectString. |
long |
getOverallTimeOut()
|
private File |
getSQLPathFile()
The path to the SQL script file is held in a File object. |
private static WTProperties |
getWTProperties()
The constructor performed a one-time call to obtain these wt.properties |
static void |
main(String[] args)
When invoked will execute args[0] as a sql command in SQL*Plus using db.properties for connect credentials. |
void |
setConfigureConnectionFromPropertyFiles(boolean config_from_props)
If true, tells the executor that when it executes, it should obtain connection information from db.properties (in particular it should use the properties wt.pom.dbUser , wt.pom.dbPassword , wt.pom.serviceName ,
and optionally wt.pom.connectString
Otherwise, the methods setUserName(java.lang.String) , setPassword(java.lang.String) , and setConnectString(java.lang.String) must be used. |
void |
setConnectString(String connect_string)
Sets the SQL*Plus connect string (i.e. |
void |
setInactivityTimeout(long inactivity_time_out)
Sets the maximum amount of inactivity (time in milliseconds) that will be allowed before the SQL*Plus script is considered hung. |
void |
setOverallTimeout(long overall_time_out)
Sets the maximum time (in milliseconds) that will be allowed for each script to run in its entirety. |
void |
setPassword(String password)
Sets the SQL*Plus connect password. |
void |
setUserName(String user_name)
Sets the SQL*Plus connect user name. |
private String |
systemIndependentPath(String relative_path_file_name)
Corrects relative paths for the UNIX versus Windows standard for the separatorChar. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
private static final String DB_DIR
private static final String SQL_DIR
private static WTProperties wtProperties_
private static File sqlPathFile_
private long inactivityTimeout_
private long overallTimeout_
private boolean configureFromPropertyFiles_
private String userName_
private String password_
private String connectString_
Constructor Detail |
public SQLScriptExecutor()
Method Detail |
public void setConfigureConnectionFromPropertyFiles(boolean config_from_props)
wt.pom.dbUser
, wt.pom.dbPassword
, wt.pom.serviceName
,
and optionally wt.pom.connectString
Otherwise, the methods setUserName(java.lang.String)
, setPassword(java.lang.String)
, and setConnectString(java.lang.String)
must be used.
The default value for this is "false"
public void setUserName(String user_name)
(false)
is called.
public void setPassword(String password)
(false)
is called.
public void setConnectString(String connect_string)
(false)
is called.
public long getInactivityTimeOut()
public long getOverallTimeOut()
public void setOverallTimeout(long overall_time_out)
setInactivityTimeout(long)
public void setInactivityTimeout(long inactivity_time_out)
setOverallTimeout(long)
public String executeSQL(String sql_string) throws SQLScriptExecutor.ExecutionException
sql_string
- Approximately used for: " sqlplus user/password&064;system sql_string; ".
SQLScriptExecutor.ExecutionException
- If the SQL could not be executed. If there's a timeout, then getNestedThrowable() will be an instanceof wt.util.ProcessLauncher.TimeoutExceptionpublic String executeScript(String sql_script_path) throws SQLScriptExecutor.ExecutionException
$(wt.home)/db/sql
,
and it will be executed it in a SQLPlus session.
If you provide a relative path, then the wt.properties and db.properties files will be consulted
to identify the system's db/sql
path. For this to work, you must be able to load the
proper version of wt.properties off of the classpath.
sql_script_path
- the script to be executed as an absolute path to a file or a path relative to $(wt.home)/db/sql
SQLScriptExecutor.ExecutionException
- If the file cannot be found relative to the $(wt.home)/db/sql directory or if there is an error invoking SQLPlus or executing the SQL contained in the script file. If there's a timeout, then getNestedThrowable() will be an instanceof wt.util.ProcessLauncher.TimeoutExceptionpublic String executeScript(File script_file) throws SQLScriptExecutor.ExecutionException
script_file
- sql script that will be executed
SQLScriptExecutor.ExecutionException
- If the file cannot be found if there is an error invoking SQLPlus or executing the SQL contained in the script file. If there's a timeout, then getNestedThrowable() will be an instanceof wt.util.ProcessLauncher.TimeoutExceptionpublic void executeScript(File script_file, PrintStream print_stream) throws SQLScriptExecutor.ExecutionException
script_file
- Approximately used for:
" sqlplus user/password&064;system &064;script_file ".print_stream
- a stream to write the script's output to
SQLScriptExecutor.ExecutionException
- If the file cannot be found if there is an error invoking SQLPlus or executing the SQL contained in the script file. If there's a timeout, then getNestedThrowable() will be an instanceof wt.util.ProcessLauncher.TimeoutExceptionprivate String systemIndependentPath(String relative_path_file_name)
relative_path_file_name
- This may have back-slash characters.
private File getSQLPathFile() throws SQLScriptExecutor.ExecutionException
SQLScriptExecutor.ExecutionException
- If processing is unable to reade or use the properties.private static WTProperties getWTProperties() throws SQLScriptExecutor.ExecutionException
SQLScriptExecutor.ExecutionException
- A converted IOException.private String getLoginStringFromProperties() throws IOException, SQLScriptExecutor.ExecutionException
IOException
- If processing can not interpret or parse the strings in the db.properties file.
SQLScriptExecutor.ExecutionException
private String getLoginStringFromFields() throws SQLScriptExecutor.ExecutionException
SQLScriptExecutor.ExecutionException
private File createScriptToCall(String sql_to_execute) throws SQLScriptExecutor.ExecutionException
SQLScriptExecutor.ExecutionException
private String execute(String sql_to_execute) throws SQLScriptExecutor.ExecutionException
sql_to_execute
- Typical of the SQL command(s) one would type, where some previous lines performed the login.
SQLScriptExecutor.ExecutionException
- If the SQL could not be executed. If there's a timeout, then getNestedThrowable() will be an instanceof wt.util.ProcessLauncher.TimeoutExceptionprotected String execute(String sql_to_execute, PrintStream print_stream) throws SQLScriptExecutor.ExecutionException
This is the single point where all script execution is performed. Subtypes may override this to extend execution behavior.
sql_to_execute
- This is the SQL that is buffered into a file.print_stream
- Used to start reading large outputs, even before execution has completed.
SQLScriptExecutor.ExecutionException
- If the SQL could not be executed. If there's a timeout, then getNestedThrowable() will be an instanceof wt.util.ProcessLauncher.TimeoutExceptionpublic static void main(String[] args)
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |