org.eclipse.datatools.sqltools.parsers.sql.query.postparse
Class TableReferenceResolver

java.lang.Object
  extended by org.eclipse.datatools.sqltools.parsers.sql.query.postparse.TableReferenceResolver
All Implemented Interfaces:
PostParseProcessor

public class TableReferenceResolver
extends java.lang.Object
implements PostParseProcessor

The TableReferenceResolver resolves references between columns and tables as well as tables and schemas. It also populates tables with the columns they expose and their datatypes.

Author:
ckadner

Field Summary
static java.lang.String ERROR_CODE_COLUMN_AMBIGUOUS
          Error code constant - not a message, column exists in multiple tables
static java.lang.String ERROR_CODE_COLUMN_UNRESOLVED
          Error code constant - not a message, column reference unresolved
static java.lang.String ERROR_CODE_DATABASE_SCHEMAS_NOTLOADED
          Error code constant - not a message, database schemas not loaded
static java.lang.String ERROR_CODE_NONEXISTENT_COLUMN
          Error code constant - not a message, column not existent in table
static java.lang.String ERROR_CODE_TABLE_UNRESOLVED
          Error code constant - not a message, table reference unresolved
 
Constructor Summary
TableReferenceResolver()
          Note: use TableReferenceResolver(Database, String) if the Database is available and the default Schema is know in order to properly resolve table references!
TableReferenceResolver(boolean logError)
          Note: use TableReferenceResolver(Database, String) if the Database is available and the default Schema is know in order to properly resolve table references!
TableReferenceResolver(Database aDB, java.lang.String aDefaultSchemaName)
          Constructs a new TableReferenceResolver with the Database connected to which table references and column references in TableInDatabase will be resolved.
TableReferenceResolver(Database aDB, java.lang.String aDefaultSchemaName, boolean logError)
          Constructs a new TableReferenceResolver with the Database connected to which table references and column references in TableInDatabase will be resolved.
 
Method Summary
 void config(PostParseProcessorConfiguration config)
          Configures this TableReferenceResolver with the Database and default Schema name.
 Database getDatabase()
           
 java.lang.String getDefaultSchemaName()
           
 java.util.Map getParsedObjectsReplacementMap()
          Returns a Map containing parsed SQLQueryObjects mapped to either the SQLQueryObject that replaces it, or is mapped to null, if that parsed object simply is to be removed.
 java.lang.Class[] getProcessCandidateTypes()
          This TableReferenceResolver's candidate types are: QueryStatement TableExpression* QuerySelect TableJoined TableWithSpecification TableInDatabase ValueExpressionColumn
* even though TableExpression includes some of the other candidate types, more special processing steps will be executed for its subtypes, that are listed here separately
 java.util.List process(SQLQueryObject sqlQuery)
          The call back method invoked for each of the SQLQueryObjects in the SQLQueryObject model instance returned by the parser, if the SQLQueryObject complies with one of the types in the Class[] returned by this PostParseProcessor.getProcessCandidateTypes()
 void resetState()
          If this PostParseProcessor is stateful within the context of one QueryStatement, this method should reset the state, as it might be used for post parse processing of more than one QueryStatement.
 void setDatabase(Database database)
           
 void setDefaultSchemaName(java.lang.String defaultSchemaName)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_CODE_DATABASE_SCHEMAS_NOTLOADED

public static final java.lang.String ERROR_CODE_DATABASE_SCHEMAS_NOTLOADED
Error code constant - not a message, database schemas not loaded

See Also:
Constant Field Values

ERROR_CODE_COLUMN_UNRESOLVED

public static final java.lang.String ERROR_CODE_COLUMN_UNRESOLVED
Error code constant - not a message, column reference unresolved

See Also:
Constant Field Values

ERROR_CODE_TABLE_UNRESOLVED

public static final java.lang.String ERROR_CODE_TABLE_UNRESOLVED
Error code constant - not a message, table reference unresolved

See Also:
Constant Field Values

ERROR_CODE_NONEXISTENT_COLUMN

public static final java.lang.String ERROR_CODE_NONEXISTENT_COLUMN
Error code constant - not a message, column not existent in table

See Also:
Constant Field Values

ERROR_CODE_COLUMN_AMBIGUOUS

public static final java.lang.String ERROR_CODE_COLUMN_AMBIGUOUS
Error code constant - not a message, column exists in multiple tables

See Also:
Constant Field Values
Constructor Detail

TableReferenceResolver

public TableReferenceResolver()
Note: use TableReferenceResolver(Database, String) if the Database is available and the default Schema is know in order to properly resolve table references!

Constructs a new TableReferenceResolver without the Database connected to which table references and column references in TableInDatabase will be resolved. For resolving of table and column references with the database tables and columns use constructor TableReferenceResolver(Database,String).

See Also:
TableReferenceResolver(Database, String)

TableReferenceResolver

public TableReferenceResolver(boolean logError)
Note: use TableReferenceResolver(Database, String) if the Database is available and the default Schema is know in order to properly resolve table references!

Constructs a new TableReferenceResolver without the Database connected to which table references and column references in TableInDatabase will be resolved. For resolving of table and column references with the database tables and columns use constructor TableReferenceResolver(Database,String).

Parameters:
logError - if true errors will be logged to the console, default is true
See Also:
TableReferenceResolver(Database, String)

TableReferenceResolver

public TableReferenceResolver(Database aDB,
                              java.lang.String aDefaultSchemaName)
Constructs a new TableReferenceResolver with the Database connected to which table references and column references in TableInDatabase will be resolved. If the optional default Schema name is given the unqualified table references (((TableInDatabase) tableRef).getDatabaseTable().getSchema() == null) are resolved only within the context of the Schema with the given name aDefaultSchemaName in the Database.

Note: If the parser also is provided a current default Schema name ( org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parse(String, SQLQuerySourceFormat), SQLQuerySourceFormat.getOmitSchema() ), which will be associated with all unqualified table references in the SQL source parsed, the given default Schema name for this TableReferenceResolver will not have the expected effect if it the two names are different!

Parameters:
aDB - the Database connected to which table references and column references in TableInDatabasewill be resolved
aDefaultSchemaName - - optional - name of default org.eclipse.wst.rdb.internal.models.sql.schema.Schema, if specified the unqualified table references ( ((TableInDatabase) tableRef).getDatabaseTable().getSchema() == null) are resolved only within the context of the Schema with the given name aDefaultSchemaName in the Database,
See Also:
org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parse(String, SQLQuerySourceFormat), org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parse(String, SQLQuerySourceFormat, List), org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parseScript(String, SQLQuerySourceFormat), org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parseScript(String, SQLQuerySourceFormat, List), SQLQuerySourceFormat.getOmitSchema()

TableReferenceResolver

public TableReferenceResolver(Database aDB,
                              java.lang.String aDefaultSchemaName,
                              boolean logError)
Constructs a new TableReferenceResolver with the Database connected to which table references and column references in TableInDatabase will be resolved. If the optional default Schema name is given the unqualified table references (((TableInDatabase) tableRef).getDatabaseTable().getSchema() == null) are resolved only within the context of the Schema with the given name aDefaultSchemaName in the Database.

Note: If the parser also is provided a current default Schema name ( org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parse(String, SQLQuerySourceFormat), SQLQuerySourceFormat.getOmitSchema() ), which will be associated with all unqualified table references in the SQL source parsed, the given default Schema name for this TableReferenceResolver will not have the expected effect if it the two names are different!

Parameters:
aDB - the Database connected to which table references and column references in TableInDatabasewill be resolved
aDefaultSchemaName - - optional - name of default org.eclipse.wst.rdb.internal.models.sql.schema.Schema, if specified the unqualified table references ( ((TableInDatabase) tableRef).getDatabaseTable().getSchema() == null) are resolved only within the context of the Schema with the given name aDefaultSchemaName in the Database
logError - if true errors will be logged to the console, default is true
See Also:
org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parse(String, SQLQuerySourceFormat), org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parse(String, SQLQuerySourceFormat, List), org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parseScript(String, SQLQuerySourceFormat), org.eclipse.datatools.sqltools.parsers.sql.query.SQLQueryParserManager#parseScript(String, SQLQuerySourceFormat, List), SQLQuerySourceFormat.getOmitSchema()
Method Detail

getDatabase

public Database getDatabase()
Returns:
Returns the database.

setDatabase

public void setDatabase(Database database)
Parameters:
database - The database to set.

getDefaultSchemaName

public java.lang.String getDefaultSchemaName()
Returns:
Returns the defaultSchemaName.

setDefaultSchemaName

public void setDefaultSchemaName(java.lang.String defaultSchemaName)
Parameters:
defaultSchemaName - The defaultSchemaName to set.

getProcessCandidateTypes

public java.lang.Class[] getProcessCandidateTypes()
This TableReferenceResolver's candidate types are:
* even though TableExpression includes some of the other candidate types, more special processing steps will be executed for its subtypes, that are listed here separately

Specified by:
getProcessCandidateTypes in interface PostParseProcessor
Returns:
Class[] of SQLObject types
See Also:
org.eclipse.datatools.sqltools.parsers.sql.query.postparse.PostParseProcessor#getProcessCandidateTypes()

config

public void config(PostParseProcessorConfiguration config)
Configures this TableReferenceResolver with the Database and default Schema name.

Specified by:
config in interface PostParseProcessor
Parameters:
config - the PostParseProcessorConfiguration providing the Database and the default Schema name

process

public java.util.List process(SQLQueryObject sqlQuery)
                       throws SQLParserException
Description copied from interface: PostParseProcessor
The call back method invoked for each of the SQLQueryObjects in the SQLQueryObject model instance returned by the parser, if the SQLQueryObject complies with one of the types in the Class[] returned by this PostParseProcessor.getProcessCandidateTypes()

Specified by:
process in interface PostParseProcessor
Parameters:
sqlQuery - instance of one of the types in the Class[] returned by PostParseProcessor.getProcessCandidateTypes()
Returns:
List of SQLParseErrorInfo objects, with information about the error encountered, must not be null
Throws:
SQLParserException - if the error encountered is severe enough to discard the instance of the SQLQueryObject model returned by the parser

getParsedObjectsReplacementMap

public java.util.Map getParsedObjectsReplacementMap()
Description copied from interface: PostParseProcessor
Returns a Map containing parsed SQLQueryObjects mapped to either the SQLQueryObject that replaces it, or is mapped to null, if that parsed object simply is to be removed. This method will be invoked after this PostParseProcessor is done processing one QueryStatement before the PostParseProcessor.resetState() method is called. This method should return a mapping, if during the post parse processing SQLQueryObjects are found that are determined to have been created by the parser mistakenly, because the parser did not have the knowledge about context or semantics. This then PostParseProcessor might create a substitution for it or simply delete it by mapping the original SQLQueryObject to null. By providing this mapping, invalid SQLQueryObjects can be removed from the parser's parsed-element-list and therefore will not be subject to further post parse processing of other PostParseProcessors.

Specified by:
getParsedObjectsReplacementMap in interface PostParseProcessor
Returns:
Map containing parsed SQLQueryObjects mapped to either the SQLQueryObject that replaces it to null, if that parsed object simply is to be removed

resetState

public void resetState()
Description copied from interface: PostParseProcessor
If this PostParseProcessor is stateful within the context of one QueryStatement, this method should reset the state, as it might be used for post parse processing of more than one QueryStatement. This method is invoked after the SQLParserManager bottom-up processed the SQLQueryObject elements of a QueryStatement up to the top/root-element - the QueryStatement object itself.

Specified by:
resetState in interface PostParseProcessor
See Also:
org.eclipse.datatools.sqltools.parsers.sql.query.postparse.PostParseProcessor#resetState()