org.eclipse.datatools.sqltools.parsers.sql
Class SQLParserManager

java.lang.Object
  extended by org.eclipse.datatools.sqltools.parsers.sql.SQLParserManager
Direct Known Subclasses:
SQLQueryParserManager

public abstract class SQLParserManager
extends java.lang.Object

Author:
ckadner DOCME

Field Summary
 int astElementCount
           
 int byteCount
           
 boolean debugPerformance
           
static int ERROR_DIAGNOSING_NONE
          Constant to supress error diagnosing.
static int ERROR_DIAGNOSING_NUMBER_MAX_DEFAULT
          Default limit for number of errors diagnosed, value: 5
static int ERROR_DIAGNOSING_TIME_MAX_DEFAULT
          Default time limit for error diagnosing in ms, value: 1500
static int ERROR_DIAGNOSING_UNLIMITED
          Constant for unlimited error diagnosing.
 EObjectPrinter PRINTER
           
 int statementCount
           
 int timeCount
           
 
Constructor Summary
SQLParserManager()
           
SQLParserManager(SQLQuerySourceFormat sourceFormat, java.util.List postParseProcessors)
           
 
Method Summary
 QueryStatement checkSyntax(java.lang.String stmt)
          Parses the given String representation of a SQL statement and returns an instance of the @link SQLQueryObject model (QueryStatement) which will have no references and contain no structural information about the given SQL statement.
 java.util.List checkSyntaxScript(java.lang.String script)
          Parses the given SQL script and returns a List of QueryStatements, which will have no references and contain no structural information about the given SQL statement.
 void configParser(SQLQuerySourceFormat sourceFormat, java.util.List postParseProcessors)
          Configures this SQLParserManager for the following parses.
 void configPostParseProcessors(PostParseProcessorConfiguration config)
          Configures this SQLParserManager's PostParseProcessors with the arguments given in the PostParseProcessorConfiguration config.
abstract  java.util.List copyDefaultPostParseProcessorList()
          Returns a value-copy of the static list of default PostParseProcessor s returned by getDefaultPostParseProcessorList().
abstract  java.util.List getDefaultPostParseProcessorList()
          Returns the static list of default PostParseProcessors that can be used with parse(String) or parseScript(String).
 int getErrorDiagnosingNumberMax()
           
 int getErrorDiagnosingTimeMax()
           
 java.util.List getPostParseProcessors()
           
 SQLQuerySourceFormat getSourceFormat()
           
 SQLParseResult parse(java.lang.String stmt)
          Parses the given String representation of a SQL statement into an instance of the SQLQueryObject model.
 java.util.List parseScript(java.lang.String script)
          Parses the given String representation of a SQL statement or a list of SQL statements separated by the statement terminator provided by the given format (SQLQuerySourceFormat.getStatementTerminator()).
 void printAST(java.util.List sqlStmts)
          Prints the SQL source and the abstract syntax tree elements (SQLObject) in the given List of SQLStatements.
 void printAST(SQLStatement p_Stmt)
          Prints the SQL source and the abstract syntax tree elements (SQLQueryObject) in the given List of SQLQueryStatements.
 void printErrorList(SQLParseResult parseResult)
           
 void printParseRuntimeException(SQLParserException e1)
           
 void printSQL(java.util.List sqlQueryStmts)
          Prints the SQL source of the SQLQueryStatements in the given List by calling SQLQueryObject.getSQL().
 void setErrorDiagnosingNumberMax(int errorDiagnosingNumberMax)
           
 void setErrorDiagnosingTimeMax(int errorDiagnosingTimeMax)
           
 void setPostParseProcessors(java.util.List postParseProcessors)
          Sets the post parse processors used for semantical checks and resolvings after successful syntactical parsing.
 void setSourceFormat(SQLQuerySourceFormat sourceFormat)
          Sets the SQL source format options for the following parses.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

statementCount

public int statementCount

astElementCount

public int astElementCount

byteCount

public int byteCount

timeCount

public int timeCount

debugPerformance

public boolean debugPerformance

ERROR_DIAGNOSING_NONE

public static final int ERROR_DIAGNOSING_NONE
Constant to supress error diagnosing.

See Also:
Constant Field Values

ERROR_DIAGNOSING_UNLIMITED

public static final int ERROR_DIAGNOSING_UNLIMITED
Constant for unlimited error diagnosing.

See Also:
Constant Field Values

ERROR_DIAGNOSING_TIME_MAX_DEFAULT

public static final int ERROR_DIAGNOSING_TIME_MAX_DEFAULT
Default time limit for error diagnosing in ms, value: 1500

See Also:
Constant Field Values

ERROR_DIAGNOSING_NUMBER_MAX_DEFAULT

public static final int ERROR_DIAGNOSING_NUMBER_MAX_DEFAULT
Default limit for number of errors diagnosed, value: 5

See Also:
Constant Field Values

PRINTER

public EObjectPrinter PRINTER
Constructor Detail

SQLParserManager

public SQLParserManager()

SQLParserManager

public SQLParserManager(SQLQuerySourceFormat sourceFormat,
                        java.util.List postParseProcessors)
Method Detail

getDefaultPostParseProcessorList

public abstract java.util.List getDefaultPostParseProcessorList()
Returns the static list of default PostParseProcessors that can be used with parse(String) or parseScript(String). Returned List at least consists of:
  1. TableReferenceResolver
  2. DataTypeResolver

Note: Modifications to the properties of the PostParseProcessor s contained in the returned list, will affect post-parse-process behaviour of parse(String) or parseScript(String) on a different instance of SQLParserManager using the List of PostParseProcessors returned by invoking this method on that instance, as the List of default PostParseProcessors is hold by a static reference in the specific SQLParserManager.

Returns:
List of PostParseProcessor s
See Also:
copyDefaultPostParseProcessorList()

copyDefaultPostParseProcessorList

public abstract java.util.List copyDefaultPostParseProcessorList()
Returns a value-copy of the static list of default PostParseProcessor s returned by getDefaultPostParseProcessorList(). That list can be used or be extended for use with parse(String) or parseScript(String). Returned List consists at least of:
  1. TableReferenceResolver
  2. DataTypeResolver

Modifications to the properties of the PostParseProcessor s contained in this list, will not affect post-parse-process behaviour of parse(String) or parseScript(String) on a different instance of SQLParserManager using the List of PostParseProcessors returned by invoking this method on that instance.

Returns:
List of PostParseProcessors

getPostParseProcessors

public final java.util.List getPostParseProcessors()

setPostParseProcessors

public final void setPostParseProcessors(java.util.List postParseProcessors)
Sets the post parse processors used for semantical checks and resolvings after successful syntactical parsing.

Parameters:
postParseProcessors -

getSourceFormat

public SQLQuerySourceFormat getSourceFormat()

setSourceFormat

public void setSourceFormat(SQLQuerySourceFormat sourceFormat)
Sets the SQL source format options for the following parses.

Note: referential modifications on the given sourceFormat will not be reflected in the parse results, unless this method is called after modifying the SQLQuerySourceFormat and before the parse.

Parameters:
sourceFormat -

configParser

public void configParser(SQLQuerySourceFormat sourceFormat,
                         java.util.List postParseProcessors)
Configures this SQLParserManager for the following parses. The result of a call to this method is equal to the result of calls to the methods setSourceFormat(SQLQuerySourceFormat) and setPostParseProcessors(List).

Parameters:
sourceFormat -
postParseProcessors -

configPostParseProcessors

public void configPostParseProcessors(PostParseProcessorConfiguration config)
Configures this SQLParserManager's PostParseProcessors with the arguments given in the PostParseProcessorConfiguration config. If this SQLParserManager was not yet setup for post-parse-processing, it herewith will be setup with the list of default PostParseProcessor s returned by copyDefaultPostParseProcessorList() and configured according to the given PostParseProcessorConfiguration config. That method is especially useful when the runtime type of PostParseProcessors is unknown and specific setter methods therefore can not be invoked.

Parameters:
config - the PostParseProcessorConfiguration providing the configuration arguments for this SQLParserManager's PostParseProcessors

parse

public SQLParseResult parse(java.lang.String stmt)
                     throws SQLParserException,
                            SQLParserInternalException
Parses the given String representation of a SQL statement into an instance of the SQLQueryObject model. Returns the instance of the SQLQueryObject model and a List of SQLParseErrorInfo objects wraped in a SQLQueryParseResult. For the parameter format you can use a copy of the default SQLQuerySourceFormat returned by SQLQuerySourceFormat.copyDefaultFormat(). For the parameter postParseProcessors you can use the default List of PostParseProcessors of the SQLParserManager getDefaultPostParseProcessorList().

Note: During the post parse processing, no Exceptions other than SQLParserException will be thrown, as post parse processing is not considered to be crucial for the success of a parse. Any other type of Exception that shall be trown during post parse processing has to be wrapped within a SQLParserException. For that purpose you might subclass an existing PostParseProcessor and overwrite its process(SQLQueryObject) method, catching the desired Exception and throwing it wrapped into a new SQLParserException.

TODO: doc behaviour If this SQLParserManager a very basic standard post parse processing will be done, using the getDefaultPostParseProcessorList() . Note: SQLParserException will be thrown, if the given stmt contains more than one SQL statement.

Parameters:
stmt - the SQL text input to parse
format - optional the source format options, you can explicitly use the default SQLQuerySourceFormat.copyDefaultFormat(), that will be used if format is not specified
postParseProcessors - list of PostParseProcessors to be invoked in the post parse phase, ordering is important as the first PostParseProcessor in the list will get invoked first, you can use getDefaultPostParseProcessorList()
Returns:
a SQLQueryParseResults containing the parsed input as QueryStatement and a List of SQLParseErrorInfo objects containing sementical errors found during the post parse process
Throws:
SQLParserException - if the input is not accepted by the parser
SQLParserException - if the given stmt contains more than one SQL statement
SQLParserInternalException - if an internal error occurs

parseScript

public java.util.List parseScript(java.lang.String script)
                           throws SQLParserException,
                                  SQLParserInternalException
Parses the given String representation of a SQL statement or a list of SQL statements separated by the statement terminator provided by the given format (SQLQuerySourceFormat.getStatementTerminator()). Returns an instance of the SQLQueryObject model and a List of SQLParseErrorInfo objects wraped in a SQLQueryParseResult for each SQL statement contained in the given SQL script. For the parameter format you can use a copy of the default SQLQuerySourceFormat returned by SQLQuerySourceFormat.copyDefaultFormat(). For the parameter postParseProcessors you can use the default List of PostParseProcessors of the SQLParserManager getDefaultPostParseProcessorList().

Note: During the post parse processing, no Exceptions other than SQLParserException will be thrown, as post parse processing is not considered to be crucial for the success of a parse. Any other type of Exception that shall be trown during post parse processing has to be wrapped within a SQLParserException. For that purpose you might subclass an existing PostParseProcessor and overwrite its process(SQLQueryObject) method, catching the desired Exception and throwing it wrapped into a new SQLParserException.

Parameters:
script - the SQL script (separated list of statements) to be parsed
format - optional the source format options, you can explicitly use the default SQLQuerySourceFormat.copyDefaultFormat(), that will be used if format is not specified
postParseProcessors - List of org.eclipse.datatools.sqltools.parsers.sql.query.postparse.PostParseProcessors to be invoked in the post parse phase, ordering is important as the first PostParseProcessor in the list will get invoked first, you can use getDefaultPostParseProcessorList()
Returns:
a List of SQLQueryParseResults for each parsed SQL statement, containing the parsed input as QueryStatement and a List of SQLParseErrorInfo objects containing sementical errors found during the post parse process
Throws:
SQLParserException - if an SQL syntactical (or semantical) error occurs in the given stmt
SQLParserInternalException - if an internal error occurs
See Also:
SQLQuerySourceFormat, PostParseProcessor

checkSyntax

public QueryStatement checkSyntax(java.lang.String stmt)
                           throws SQLParserException,
                                  SQLParserInternalException
Parses the given String representation of a SQL statement and returns an instance of the @link SQLQueryObject model (QueryStatement) which will have no references and contain no structural information about the given SQL statement. Note: SQLParserException will be thrown, if the given stmt contains more than one SQL statement.

Parameters:
stmt - the SQL statement to be parsed
format - optional the source format options, you can explicitly use the default SQLQuerySourceFormat.copyDefaultFormat(), that will be used if format is not specified
Returns:
an empty QueryStatement object only to indicate the type of SQL statement given
Throws:
SQLParserException - if an SQL syntactical error occurs in the given stmt
SQLParserException - if the given stmt contains more than one SQL statement
SQLParserInternalException - if an internal error occurs

checkSyntaxScript

public java.util.List checkSyntaxScript(java.lang.String script)
                                 throws SQLParserException,
                                        SQLParserInternalException
Parses the given SQL script and returns a List of QueryStatements, which will have no references and contain no structural information about the given SQL statement. Only syntax checking is performed.

Parameters:
script - the SQL script (separated list of statements) to be parsed
format - optional the source format options, you can explicitly use the default SQLQuerySourceFormat.copyDefaultFormat(), that will be used if format is not specified
Returns:
a List of empty QueryStatements only to indicate the types of SQL statements given
Throws:
SQLParserException - if an SQL syntactical error occurs in the given stmt
SQLParserInternalException - if an internal error occurs

getErrorDiagnosingNumberMax

public int getErrorDiagnosingNumberMax()
Returns:
Returns the errorDiagnosingNumberMax.

setErrorDiagnosingNumberMax

public void setErrorDiagnosingNumberMax(int errorDiagnosingNumberMax)
Parameters:
errorDiagnosingNumberMax - The errorDiagnosingNumberMax to set.

getErrorDiagnosingTimeMax

public int getErrorDiagnosingTimeMax()
Returns:
Returns the errorDiagnosingTimeMax.

setErrorDiagnosingTimeMax

public void setErrorDiagnosingTimeMax(int errorDiagnosingTimeMax)
Parameters:
errorDiagnosingTimeMax - The errorDiagnosingTimeMax to set.

printParseRuntimeException

public void printParseRuntimeException(SQLParserException e1)

printErrorList

public void printErrorList(SQLParseResult parseResult)
Parameters:
errorList -
queryStmt - TODO

printAST

public void printAST(java.util.List sqlStmts)
Prints the SQL source and the abstract syntax tree elements (SQLObject) in the given List of SQLStatements.


printAST

public void printAST(SQLStatement p_Stmt)
Prints the SQL source and the abstract syntax tree elements (SQLQueryObject) in the given List of SQLQueryStatements.


printSQL

public void printSQL(java.util.List sqlQueryStmts)
Prints the SQL source of the SQLQueryStatements in the given List by calling SQLQueryObject.getSQL().