|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.agimatec.sql.script.SQLScriptParser
public class SQLScriptParser
Title: Agimatec GmbH
Description: This class is capable to parse Oracle-SQL scripts. It is not a fully SQL and PL/SQL parser and
somehow heuristic.
Able to parse:
- SQL-statements (insert, update, select, delete, merge, synonyms, grants, create table, alter table, ...).
Statements terminated by ; are correctly handled.
Statements terminated by / are correctly handled in most situations.
- SQL-comments (single- and multi-line comments)
- commit/rollback statements are detected
- Triggers
- PL/SQL blocks
Known limitations/bugs:
- parsing PL/SQL package files is currently not supported!
- parsing PL/SQL (triggers, blocks) is not always correct, when statement termination is not detected by this parser
correctly. (Just try it.)
Copyright: Copyright (c) 2007
Company: Agimatec GmbH
| Constructor Summary | |
|---|---|
SQLScriptParser(org.apache.commons.logging.Log aLog)
|
|
SQLScriptParser(java.lang.String aScriptRoot,
org.apache.commons.logging.Log aLog)
|
|
| Method Summary | |
|---|---|
void |
execSQLScript(ScriptVisitor visitor,
java.lang.String scriptName)
execute the content of a file as a single SQL statement. |
protected java.lang.String |
fixLF(java.lang.String aStatement)
Tested with: Oracle10.2 fix \r\n --> \n (always, otherwise the package will be invalid) remove last / but keep last ; (optional, only if a / was found after a ;) |
protected org.apache.commons.logging.Log |
getLog()
|
protected java.lang.String |
getScriptDir()
|
static java.io.Reader |
getURLReader(java.net.URL url)
|
protected void |
handleAffectedRow(int affectedRows,
java.lang.String command)
|
protected void |
handleError(JdbcException ex,
java.lang.String command)
|
protected void |
handleError(java.sql.SQLException ex,
java.lang.String command)
|
void |
iterateSQL(ScriptVisitor visitor,
java.io.Reader input)
parse and visit the statements in the given sql string. |
void |
iterateSQL(ScriptVisitor visitor,
java.lang.String aSqls)
parse and visit the statements in the given sql string. |
void |
iterateSQLScript(ScriptVisitor visitor,
java.lang.String scriptName)
parse an visit the statements in the given sql-script file. |
void |
iterateSQLScript(ScriptVisitor visitor,
java.net.URL url)
parse an visit the statements in the given sql-script file. |
protected java.lang.Object[] |
openReaderPath(java.lang.String scriptName)
when scriptName starts with cp:// read the scriptName as a resource from the classpath, otherwise access the script as a file or cp:// resource by scriptdir + scriptname. |
void |
setEnvironment(java.util.Map aEnv)
set a Map of environment entries that are replaced during parse inside the SQL Statements/comments |
void |
setFailOnError(boolean aFailOnError)
default = false true: stop executing the SQLScript when the first error occurs and throw an exception. |
void |
useLogger(org.apache.commons.logging.Log aLogger)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public SQLScriptParser(java.lang.String aScriptRoot,
org.apache.commons.logging.Log aLog)
public SQLScriptParser(org.apache.commons.logging.Log aLog)
| Method Detail |
|---|
public void useLogger(org.apache.commons.logging.Log aLogger)
public void setFailOnError(boolean aFailOnError)
aFailOnError - - true/false
protected void handleAffectedRow(int affectedRows,
java.lang.String command)
protected void handleError(java.sql.SQLException ex,
java.lang.String command)
throws java.sql.SQLException
java.sql.SQLException
protected void handleError(JdbcException ex,
java.lang.String command)
throws JdbcException
JdbcExceptionprotected org.apache.commons.logging.Log getLog()
public void setEnvironment(java.util.Map aEnv)
protected java.lang.String getScriptDir()
protected java.lang.String fixLF(java.lang.String aStatement)
aStatement - - file content as String
public void iterateSQLScript(ScriptVisitor visitor,
java.lang.String scriptName)
throws java.sql.SQLException,
java.io.IOException
java.sql.SQLException - - errors during execution of the SQL statements in the script
java.io.IOException - - error accessing the script file (e.g. FileNotFound)
public void execSQLScript(ScriptVisitor visitor,
java.lang.String scriptName)
throws java.io.IOException,
java.sql.SQLException
java.io.IOException
java.sql.SQLException
protected java.lang.Object[] openReaderPath(java.lang.String scriptName)
throws java.io.IOException
scriptName -
java.io.IOException - - file not found
public void iterateSQLScript(ScriptVisitor visitor,
java.net.URL url)
throws java.sql.SQLException,
java.io.IOException
url - - a complete URL (absolute URL) where the script is
java.sql.SQLException - - errors during execution of the SQL statements in the script
java.io.IOException - - error accessing the script file (e.g. FileNotFound)
public static java.io.Reader getURLReader(java.net.URL url)
throws java.io.IOException
java.io.IOException
public void iterateSQL(ScriptVisitor visitor,
java.lang.String aSqls)
throws java.sql.SQLException,
java.io.IOException
aSqls - - a SQLScript as a Stringvisitor - - the visitor to do something with the parsed statements
java.sql.SQLException
java.io.IOException
public void iterateSQL(ScriptVisitor visitor,
java.io.Reader input)
throws java.sql.SQLException,
java.io.IOException
input - - a Reader on sql statementsvisitor - - the visitor to do something with the parsed statements
java.sql.SQLException
java.io.IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||