|
||||||||||
| 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(String aScriptRoot,
org.apache.commons.logging.Log aLog)
|
|
| Method Summary | |
|---|---|
void |
execSQLScript(ScriptVisitor visitor,
String scriptName)
execute the content of a file as a single SQL statement. |
protected String |
fixLF(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 String |
getScriptDir()
|
static Reader |
getURLReader(URL url)
|
protected void |
handleAffectedRow(int affectedRows,
String command)
|
protected void |
handleError(JdbcException ex,
String command)
|
protected void |
handleError(SQLException ex,
String command)
|
void |
iterateSQL(ScriptVisitor visitor,
Reader input)
parse and visit the statements in the given sql string. |
void |
iterateSQL(ScriptVisitor visitor,
String aSqls)
parse and visit the statements in the given sql string. |
void |
iterateSQLScript(ScriptVisitor visitor,
String scriptName)
parse an visit the statements in the given sql-script file. |
void |
iterateSQLScript(ScriptVisitor visitor,
URL url)
parse an visit the statements in the given sql-script file. |
protected Object[] |
openReaderPath(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(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(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,
String command)
protected void handleError(SQLException ex,
String command)
throws SQLException
SQLException
protected void handleError(JdbcException ex,
String command)
throws JdbcException
JdbcExceptionprotected org.apache.commons.logging.Log getLog()
public void setEnvironment(Map aEnv)
protected String getScriptDir()
protected String fixLF(String aStatement)
aStatement - - file content as String
public void iterateSQLScript(ScriptVisitor visitor,
String scriptName)
throws SQLException,
IOException
SQLException - - errors during execution of the SQL statements in the script
IOException - - error accessing the script file (e.g. FileNotFound)
public void execSQLScript(ScriptVisitor visitor,
String scriptName)
throws IOException,
SQLException
IOException
SQLException
protected Object[] openReaderPath(String scriptName)
throws IOException
scriptName -
IOException - - file not found
public void iterateSQLScript(ScriptVisitor visitor,
URL url)
throws SQLException,
IOException
url - - a complete URL (absolute URL) where the script is
SQLException - - errors during execution of the SQL statements in the script
IOException - - error accessing the script file (e.g. FileNotFound)
public static Reader getURLReader(URL url)
throws IOException
IOException
public void iterateSQL(ScriptVisitor visitor,
String aSqls)
throws SQLException,
IOException
aSqls - - a SQLScript as a Stringvisitor - - the visitor to do something with the parsed statements
SQLException
IOException
public void iterateSQL(ScriptVisitor visitor,
Reader input)
throws SQLException,
IOException
input - - a Reader on sql statementsvisitor - - the visitor to do something with the parsed statements
SQLException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||