org.eclipse.datatools.modelbase.sql.query.helper
Class TableHelper

java.lang.Object
  extended byorg.eclipse.datatools.modelbase.sql.query.helper.TableHelper

public class TableHelper
extends java.lang.Object

Author:
nbhatia, ckadner Provides utility functions related to tables

Field Summary
static java.lang.String copyright
           
static java.lang.String DELIMITED_IDENTIFIER_QUOTE
          TODO: make that DELIMITED_IDENTIFIER_QUOTE String flexible with Database info String constant for the quote that are used for delimited identifiers like "Col1" where this delimited identifier should not be modified to or be compared equal to COL1 or col1, value: "\"", the character "
 
Constructor Summary
TableHelper()
           
 
Method Summary
static java.lang.String createFromClauseForStatement(QueryStatement stmt)
          Creates the From Clause with the tables used in the given SQLStatement.
static java.lang.String createFromClauseForStatement(SQLQueryObject stmt)
          Creates the From Clause with the tables used in the given SQLStatement.
static TableInDatabase createTableExpressionForTable(Table table)
          Creates and Returns SQLRDBTable for the given Table and initializes its list of SQLValueExpressColumn corresponding to each column of the table.
static java.util.List exposeEffectiveResultColumns(QueryExpressionBody nestedQuery)
          Adds a ValueExpressionColumn to the given nestedQuery for each of its QuerySelect's ResultColumns that have either a name or reference a ValueExpressionColumn that has a name.
static java.util.List exposeEffectiveResultColumns(TableExpression tableExpr)
          Populates the given tableExpr's columnList with ValueExpressionColumns, with name, dataType and in ordering, so the given tableExpr can be handled like a TableInDatabase.
static java.util.List exposeEffectiveResultColumns(WithTableReference withTable)
          Populates the given withTable's columnList with ValueExpressionColumns, with name, dataType and in ordering, so the given tableExpr can be handled like a TableInDatabase.
static java.util.Set findColumnReferencesInGroupingExpression(GroupingExpression groupingExpr)
          Returns a Set containing all ValueExpressionColumn s found in the given GroupingExpression.
static java.util.Set findColumnReferencesInGroupingSpecification(GroupingSpecification groupingSpec)
          Returns a Set containing all ValueExpressionColumn s found in the given GroupingSpecification.
static java.util.Set findColumnReferencesInGroupingSpecificationList(java.util.List groupingSpecList)
          Returns a Set containing all ValueExpressionColumn s found in the given GroupingSpecification list.
static java.util.Set findColumnReferencesInOrderBySpecification(OrderBySpecification orderBySpec)
          Returns a Set containing all ValueExpressionColumn s found in the given OrderBySpecification.
static java.util.Set findColumnReferencesInOrderBySpecificationList(java.util.List orderBySpecList)
          Returns a Set containing all ValueExpressionColumn s found in the given List of OrderBySpecification.
static java.util.Set findColumnReferencesInPredicate(Predicate predicate)
          Returns a Set containing all ValueExpressionColumns found in the given Predicate.
static java.util.Set findColumnReferencesInQueryExpressionBody(QueryExpressionBody queryExprBody)
          TODO: Developer Note: not completely implemented.
static java.util.Set findColumnReferencesInQueryExpressionRoot(QueryExpressionRoot queryExprRoot)
          Returns a Set containing all ValueExpressionColumns found in the given QueryExpressionRoot.
static java.util.Set findColumnReferencesInQueryResultSpecification(QueryResultSpecification queryResult)
          Returns a Set containing all ValueExpressionColumn s found in the given QueryResultSpecification.
static java.util.Set findColumnReferencesInQueryResultSpecificationList(java.util.List queryResultSpecList)
          Returns a Set containing all ValueExpressionColumn s found in the given QueryResultSpecification list.
static java.util.Set findColumnReferencesInQuerySelectStatement(QuerySelectStatement querySelect)
          Returns a Set containing all ValueExpressionColumn s found in the given QuerySelectStatement.
static java.util.Set findColumnReferencesInQueryUpdateStatement(QueryUpdateStatement updateStmt)
          Returns a Set containing all ValueExpressionColumn s found in the given QueryUpdateStatement.
static java.util.Set findColumnReferencesInSearchCondition(QuerySearchCondition searchCond)
          Returns a Set of not neccessarily distinct ValueExpressionColumns found in the given SearchCondition, means you have to expect duplicates regarding column names.
static java.util.Set findColumnReferencesInUpdateAssignmentExpr(UpdateAssignmentExpression updateAssignmentExpr)
          Returns a Set containing all ValueExpressionColumn s found in the given List of UpdateAssignmentExpression.
static java.util.Set findColumnReferencesInUpdateAssignmentExprList(java.util.List updateAssignmentExprList)
          Returns a Set containing all ValueExpressionColumn s found in the given List of UpdateAssignmentExpressions.
static java.util.Set findColumnReferencesInUpdateSourceExprList(UpdateSourceExprList updateSourceExprList)
          Returns a Set containing all ValueExpressionColumn s found in the given UpdateSourceExprList.
static java.util.Set findColumnReferencesInValueExpression(QueryValueExpression valueExpr)
          Returns a Set containing all ValueExpressionColumn s found in the given QueryValueExpression.
static java.util.Set findColumnReferencesInValueExpressionList(java.util.List valueExprList)
          Returns a Set containing all ValueExpressionColumn s found in the given ValueExpression list.
static java.util.Set findColumnReferencesInValuesRow(ValuesRow valuesRow)
          Returns a Set containing all ValueExpressionColumns found in the given ValuesRow.
static TableExpression findTableExpressionInTableExpressionList(java.lang.String schemaName, java.lang.String tableName, java.util.List tableExprList)
          Finds in the given List of TableExpression s the one TableExpression with a name that matches the given tableName and, if a schemaName is given, with a Schema whose name matches the schemaName.
static TableExpression findTableExpressionsByNameOrAlias(java.lang.String tableNameOrAlias, java.util.List tableExprList, java.lang.String defaultSchemaName)
          Finds in the given List of TableExpression s the TableExpression with a name that matches the given tableNameOrAlias or a tableCorrelation with a name that matches tableNameOrAlias.
static ValueExpressionColumn getColumnExpressionForColumn(TableExpression tableExpr, Column column)
          Gets the SQLValueExpressionColumn corresponding to the given Column, in the given table
static ValueExpressionColumn getColumnExpressionForName(TableExpression tableExpr, java.lang.String columnName)
          Returns the ValueExpressionColumn from the given TableExpression, if the ValueExpressionColumn's name matches the given columnName.
static ValueExpressionColumn getColumnExpressionForName(TableReference tableRef, java.lang.String columnName)
          Returns the ValueExpressionColumn from the given TableReference matching the given columnName.
static ValueExpressionColumn getColumnExpressionForNameRecursively(TableExpression tableExpr, java.lang.String columnName)
          Returns the ValueExpressionColumn from the given TableExpression, if the ValueExpressionColumn's name matches the given columnName.
static Column getColumnForColumnExpression(TableExpression tableExpr, ValueExpressionColumn colExpr)
          Returns the Column matching the name of the SQLValueExpressionColumn from the given SQLTableExpression
static Column getColumnForName(TableExpression tableExpr, java.lang.String columnName)
          Deprecated. use getColumnForName(TableInDatabase, String)
static Column getColumnForName(TableInDatabase tableInDB, java.lang.String columnName)
          Returns the Column matching the columnName from the given TableInDatabase
static Column getColumnForName(TableReference tableRef, java.lang.String columnName)
          Returns the Column matching the columnName from the given TableReference
static Column getColumnForName(WithTableReference withTableRef, java.lang.String columnName)
          Returns the Column matching the columnName from the given WithTableReference.
static java.util.SortedSet getDistinctColumnExpressionList(TableExpression tableExpr)
          Deprecated. use TableExpression.getColumnList()it now reflects the exact order of exposed effective "result" columns of a TableExpression
static java.util.List getEffectiveResultColumns(TableReference tableRef)
          Returns a List of ValueExpressionColumns, with name, dataType and in ordering, so the given tableRef can be handled like a TableInDatabase.
static java.lang.String getExposedTableName(TableExpression tableExpr)
          Returns the name or the alias name of the given TableExpression tableExpr depending on, whether or not the tableExpr has a TableCorrelation.
static java.util.List getForeignKeyColumns(Table table)
          Returns the list of Columns that are part of the Foreign key constraint for the given table.
static java.lang.String getFullTableName(Table table)
          Returns fully qualified name for the given table.
static ValueExpressionColumn getOrCreateColumnExpression(java.lang.String columnName, TableExpression tableExpr)
          Returns the ValueExpressionColumn with the given columnName from the given tableExpression's columnList or, if the given tableExpression's columnList does not contain a ValueExpressionColumn with the given columnName, creates a new ValueExpressionColumn with the given columnName and returns it.
static java.util.List getPrimaryKeyColumns(Table table)
          Returns the list of Columns that are part of the primary key constraint for the given table.
static ResultColumn getResultColumnForAliasOrColumnName(QueryExpressionBody tableQuery, java.lang.String columnName)
          Returns the ResultColumn contained in the selectClause of the given QueryExpressionBody, whose name matches the given columnName or whose referenced ValueExpression is of type ValueExpressionColumn and has a name matching the given columnName.
static ResultColumn getResultColumnForName(QueryExpressionBody tableQuery, java.lang.String columnName)
          Returns the ResultColumn contained in the selectClause of the given QueryExpressionBody, whose name matches the given columnName.
static java.util.List getResultColumnsOfQueryExpression(QueryExpressionBody queryExpr)
          Returns the ResultColumns of the given QueryExpressionBody queryExpr.
static Schema getSchemaForTableInDatabase(TableInDatabase tableInDB)
           
static java.lang.String getSchemaNameForTableExpression(TableExpression tableExpr)
          Returns the name of the Schema that the given TableExpression is part of or null, if the given TableExpression has no reference to a Schema or the referenced Schema's name is null.
static TableExpression getTableExpressionForNamedColumn(java.lang.String aTableName, java.lang.String aColName, java.util.List aTableExprList)
          Gets the table object from the given list of table references that is associated with (contains) a column with the given table and column name.
static TableExpression getTableExpressionFromTableExprList(java.lang.String aTableName, java.util.List aTableExprList)
          Gets the TableExpression object from the given list of table references by name or correlation name ("AS"-alias).
static java.util.List getTableExpressionsInTableReference(TableReference tableRef)
          Retrieves a List of TableExpression s from the given TableReference.
static java.util.List getTableExpressionsInTableReferenceList(java.util.List tableReferenceList)
          Retrieves a List of TableExpression s from the given List of TableReferences.
static Table getTableForTableExpression(TableExpression tableExpr)
          Returns the Table from the given SQLTableExpression if there is one otherwise return null.
static java.util.List getTableInDatabaseInTableReferenceList(java.util.List tableReferenceList)
          Retrieves the TableInDatabase objects contained in the given List of TableReferences.
static boolean isForeignKey(Column column)
          Returns true if the given column is part of Foreign key constraint.
static boolean isForeignKey(ValueExpressionColumn colExpr)
          Returns true if the given ValueExpressionColumn is part of Foreign key constraint.
static boolean isPrimaryKey(Column column)
          Returns true if the given column is part of a primary key constraint.
static boolean isPrimaryKey(ValueExpressionColumn colExpr)
          Returns true if the given ValueExpressionColumn is part of a primary key constraint.
static boolean isTableReferencedByColumnWithName(TableExpression tableExpr, java.lang.String referencedByColumnName)
          Returns the true if the given tableExpr is referenced by another ValueExpressionColumn with the same name as the given referencedByColumnName
static void populateTableExpressionColumns(TableInDatabase tableInDB, Table databaseTable)
          Populates the list of ValueExpressionColumn in the given table expression using the columns in the given Table object
static void removeColumnExpressionFromTableIfDuplicate(ValueExpressionColumn columnExpr)
          Deprecated. odd method not of practical use anymore, use columnExpr.setTableExpr(null) since TableExpression.getColumnList() does reflect only the exposed columns of a TableExpression where as TableExpression.getValueExprColumns() is the list containing the arbitrary references to ValueExpressionColumns which are referencing to that TableExpression by ValueExpressionColumn.getTableExpr()()
static void removeColumnExpressionFromTableIfNotReferenced(ValueExpressionColumn col)
          Removes a columnExpression from its tableExpression if it has no other refernces to objects other than its tableExpression.
static void resolveColumnTableReferences(java.util.Collection unresolvedColumns, java.util.List aTableRefList)
          Link table references in column expressions to tables in the given list of tables (that is, the From clause), copies DataTypes as well.
static void resolveResultTableReferences(java.util.List resultTableList, java.util.List tableExprList)
          Resolves the TableReference s of the ResultTableAllColumns in the given resultTableList with the TableExpression s in the given tableExprList.
static void resolveTableReferencesInSearchCondition(SearchCondition searchCondition, java.util.List tableExpressionList)
          Deprecated. NO, but not implemented Associates the column refernces in the given search condition to the tables in the list of TableExpressions.
static void setTableAliasInTableExpression(TableExpression tableExpr, java.lang.String alias)
          Assigns the alias to the given TableExpression.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

copyright

public static final java.lang.String copyright
See Also:
Constant Field Values

DELIMITED_IDENTIFIER_QUOTE

public static final java.lang.String DELIMITED_IDENTIFIER_QUOTE
TODO: make that DELIMITED_IDENTIFIER_QUOTE String flexible with Database info String constant for the quote that are used for delimited identifiers like "Col1" where this delimited identifier should not be modified to or be compared equal to COL1 or col1, value: "\"", the character "

See Also:
Constant Field Values
Constructor Detail

TableHelper

public TableHelper()
Method Detail

getColumnExpressionForName

public static ValueExpressionColumn getColumnExpressionForName(TableReference tableRef,
                                                               java.lang.String columnName)
Returns the ValueExpressionColumn from the given TableReference matching the given columnName. If the given TableReference is of type QueryExpressionBody ResultColumns of the QuerySelect statement will be regarded too.

NOTE: If there is more than one ValueExpressionColumn with the same name (both representing one and the same real Column), the first one found will be returned.

Parameters:
tableRef - the TableReference seached for the matching column
columnName - the String name of the column to be searched
Returns:
the found ValueExpressionColumn or null

isTableReferencedByColumnWithName

public static boolean isTableReferencedByColumnWithName(TableExpression tableExpr,
                                                        java.lang.String referencedByColumnName)
Returns the true if the given tableExpr is referenced by another ValueExpressionColumn with the same name as the given referencedByColumnName

Parameters:
tableExpr - the TableReference seached for the matching column name reference
referencedByColumnName - the String name of the ValueExpressionColumn to be searched in the list of column references to the given tableExpr
Returns:
true if another column was found to reference the given tableExpr

getColumnExpressionForName

public static ValueExpressionColumn getColumnExpressionForName(TableExpression tableExpr,
                                                               java.lang.String columnName)
Returns the ValueExpressionColumn from the given TableExpression, if the ValueExpressionColumn's name matches the given columnName.

NOTE: If there is more than one ValueExpressionColumn with the same name (both representing one and the same real Column), the first one found will be returned.

Parameters:
tableExpr - the TableReference seached for the matching column name
columnName - the String name of the ValueExpressionColumn to be searched
Returns:
column the found ValueExpressionColumn or null

getColumnExpressionForNameRecursively

public static ValueExpressionColumn getColumnExpressionForNameRecursively(TableExpression tableExpr,
                                                                          java.lang.String columnName)
Returns the ValueExpressionColumn from the given TableExpression, if the ValueExpressionColumn's name matches the given columnName. If the given TableExpression is of type QueryExpressionBody, this method will recursively analyze its effective result columns, e.g. the ResultColumns of a nested QuerySelect statement will be considered, too.

NOTE: If there is more than one ValueExpressionColumn with the same name (both representing one and the same real Column), the first one found will be returned.

Parameters:
tableExpr - the TableReference seached for the matching column name
columnName - the String name of the ValueExpressionColumn to be searched
Returns:
column the found ValueExpressionColumn or null

getResultColumnForName

public static ResultColumn getResultColumnForName(QueryExpressionBody tableQuery,
                                                  java.lang.String columnName)
Returns the ResultColumn contained in the selectClause of the given QueryExpressionBody, whose name matches the given columnName.

Parameters:
tableQuery - the TableReference seached for the matching column name
columnName - the String name of the ValueExpressionColumn to be searched
Returns:
column the found ValueExpressionColumn or null

getResultColumnForAliasOrColumnName

public static ResultColumn getResultColumnForAliasOrColumnName(QueryExpressionBody tableQuery,
                                                               java.lang.String columnName)
Returns the ResultColumn contained in the selectClause of the given QueryExpressionBody, whose name matches the given columnName or whose referenced ValueExpression is of type ValueExpressionColumn and has a name matching the given columnName.

Parameters:
tableQuery - the TableReference seached for the matching column name
columnName - the String name of the ValueExpressionColumn to be searched
Returns:
column the found ResultColumn null

getResultColumnsOfQueryExpression

public static java.util.List getResultColumnsOfQueryExpression(QueryExpressionBody queryExpr)
Returns the ResultColumns of the given QueryExpressionBody queryExpr.

NOTE: If the given queryExpr's QueryResultSpecification is of type ResultTableAllColumns ('SELECT * FROM ...') an empty List will be returned.

Parameters:
queryExpr - the QueryExpressionBody which's ResultColumns will be returned
Returns:
List with the ResultColumns of the given queryExpr

getColumnForName

public static Column getColumnForName(TableExpression tableExpr,
                                      java.lang.String columnName)
Deprecated. use getColumnForName(TableInDatabase, String)

Returns the Column matching the columnName from the given TableExpression

Parameters:
tableExpr - the TableExpression seached for the matching column name
columnName - the String name of the column to be searched
Returns:
column

getColumnForName

public static Column getColumnForName(TableInDatabase tableInDB,
                                      java.lang.String columnName)
Returns the Column matching the columnName from the given TableInDatabase

Parameters:
tableInDB - the TableInDatabase seached for the matching column name
columnName - the String name of the column to be searched
Returns:
column

getColumnForName

public static Column getColumnForName(WithTableReference withTableRef,
                                      java.lang.String columnName)
Returns the Column matching the columnName from the given WithTableReference.

Parameters:
withTableRef - the WithTableReference seached in for the matching column name
columnName - the String name of the column to be searched
Returns:
column

getColumnForName

public static Column getColumnForName(TableReference tableRef,
                                      java.lang.String columnName)
Returns the Column matching the columnName from the given TableReference

Parameters:
tableRef - the TableReference seached for the matching column name
columnName - the String name of the column to be searched
Returns:
column

getColumnForColumnExpression

public static Column getColumnForColumnExpression(TableExpression tableExpr,
                                                  ValueExpressionColumn colExpr)
Returns the Column matching the name of the SQLValueExpressionColumn from the given SQLTableExpression

Parameters:
tableExpr - the SQLTableExpression seached for the matching SQLValueExpressionColumn
colExpr - the SQLValueExpressionColumn which needs to be searched
Returns:
column

createTableExpressionForTable

public static TableInDatabase createTableExpressionForTable(Table table)
Creates and Returns SQLRDBTable for the given Table and initializes its list of SQLValueExpressColumn corresponding to each column of the table.

Parameters:
table - the Table for which we need a SQLRDBTable
Returns:
the SQLRDBTable that is created

populateTableExpressionColumns

public static void populateTableExpressionColumns(TableInDatabase tableInDB,
                                                  Table databaseTable)
Populates the list of ValueExpressionColumn in the given table expression using the columns in the given Table object

Parameters:
tableInDB - the TableInDatabase to be populated
databaseTable - the Table object used in populating the tableExpression

isPrimaryKey

public static boolean isPrimaryKey(Column column)
Returns true if the given column is part of a primary key constraint.

Parameters:
column - the Column that needs to check for the primary key constraint
Returns:
the Boolean result

isPrimaryKey

public static boolean isPrimaryKey(ValueExpressionColumn colExpr)
Returns true if the given ValueExpressionColumn is part of a primary key constraint.

Parameters:
colExpr - the ValueExpressionColumn that needs to check for the primary key constraint
Returns:
the Boolean result

getColumnExpressionForColumn

public static ValueExpressionColumn getColumnExpressionForColumn(TableExpression tableExpr,
                                                                 Column column)
Gets the SQLValueExpressionColumn corresponding to the given Column, in the given table

Parameters:
tableExpr - the table to search upon
column - the column to be looked for
Returns:
the SQLValueExpressionColumn corresponding to the given Column , or null if there is no match

getPrimaryKeyColumns

public static java.util.List getPrimaryKeyColumns(Table table)
Returns the list of Columns that are part of the primary key constraint for the given table.

Parameters:
table - the Table for which list of primary key columns needed
Returns:
the list of columns

isForeignKey

public static boolean isForeignKey(Column column)
Returns true if the given column is part of Foreign key constraint.

Parameters:
column - the Column that needs to check for the Foreign key constraint
Returns:
the Boolean result

isForeignKey

public static boolean isForeignKey(ValueExpressionColumn colExpr)
Returns true if the given ValueExpressionColumn is part of Foreign key constraint.

Parameters:
colExpr - the ValueExpressionColumn that needs to check for the Foreign key constraint
Returns:
the Boolean result

getForeignKeyColumns

public static java.util.List getForeignKeyColumns(Table table)
Returns the list of Columns that are part of the Foreign key constraint for the given table.

Parameters:
table - the Table for which list of Foreign key columns needed
Returns:
the list of columns

getExposedTableName

public static java.lang.String getExposedTableName(TableExpression tableExpr)
Returns the name or the alias name of the given TableExpression tableExpr depending on, whether or not the tableExpr has a TableCorrelation.

Parameters:
tableExpr - the TableExpression for which the exposed name is needed
Returns:
the exposed table name

getFullTableName

public static java.lang.String getFullTableName(Table table)
Returns fully qualified name for the given table.

Parameters:
table - the Table for which the fully qualified name is needed
Returns:
the fully qualified table name

getTableForTableExpression

public static Table getTableForTableExpression(TableExpression tableExpr)
Returns the Table from the given SQLTableExpression if there is one otherwise return null.

Parameters:
tableExpr - the SQLTableExpression for which the table is needed
Returns:
the table

getTableExpressionForNamedColumn

public static TableExpression getTableExpressionForNamedColumn(java.lang.String aTableName,
                                                               java.lang.String aColName,
                                                               java.util.List aTableExprList)
Gets the table object from the given list of table references that is associated with (contains) a column with the given table and column name. If the table name is null or blank, look through all the tables for a match on the column name alone.

Parameters:
aTableName - a table name to use to search for a table reference
aColName - a column name to use to search for a table reference
aTableExprList - a list of table references to search
Returns:
TableExpression the table expression associated with the column. Null if not found

getTableExpressionFromTableExprList

public static TableExpression getTableExpressionFromTableExprList(java.lang.String aTableName,
                                                                  java.util.List aTableExprList)
Gets the TableExpression object from the given list of table references by name or correlation name ("AS"-alias).

Parameters:
aTableName - a table name or alias name to use to search for a table reference
aTableExprList - a list of table references to search
Returns:
TableExpression the table expression associated with the column. Null if not found

findColumnReferencesInGroupingExpression

public static java.util.Set findColumnReferencesInGroupingExpression(GroupingExpression groupingExpr)
Returns a Set containing all ValueExpressionColumn s found in the given GroupingExpression.


findColumnReferencesInQueryResultSpecificationList

public static java.util.Set findColumnReferencesInQueryResultSpecificationList(java.util.List queryResultSpecList)
Returns a Set containing all ValueExpressionColumn s found in the given QueryResultSpecification list.


findColumnReferencesInQueryResultSpecification

public static java.util.Set findColumnReferencesInQueryResultSpecification(QueryResultSpecification queryResult)
Returns a Set containing all ValueExpressionColumn s found in the given QueryResultSpecification.


findColumnReferencesInOrderBySpecificationList

public static java.util.Set findColumnReferencesInOrderBySpecificationList(java.util.List orderBySpecList)
Returns a Set containing all ValueExpressionColumn s found in the given List of OrderBySpecification.


findColumnReferencesInOrderBySpecification

public static java.util.Set findColumnReferencesInOrderBySpecification(OrderBySpecification orderBySpec)
Returns a Set containing all ValueExpressionColumn s found in the given OrderBySpecification.


findColumnReferencesInUpdateSourceExprList

public static java.util.Set findColumnReferencesInUpdateSourceExprList(UpdateSourceExprList updateSourceExprList)
Returns a Set containing all ValueExpressionColumn s found in the given UpdateSourceExprList.


findColumnReferencesInValuesRow

public static java.util.Set findColumnReferencesInValuesRow(ValuesRow valuesRow)
Returns a Set containing all ValueExpressionColumns found in the given ValuesRow.


findColumnReferencesInSearchCondition

public static java.util.Set findColumnReferencesInSearchCondition(QuerySearchCondition searchCond)
Returns a Set of not neccessarily distinct ValueExpressionColumns found in the given SearchCondition, means you have to expect duplicates regarding column names.

Parameters:
searchCond -
Returns:

findColumnReferencesInPredicate

public static java.util.Set findColumnReferencesInPredicate(Predicate predicate)
Returns a Set containing all ValueExpressionColumns found in the given Predicate.


findColumnReferencesInValueExpression

public static java.util.Set findColumnReferencesInValueExpression(QueryValueExpression valueExpr)
Returns a Set containing all ValueExpressionColumn s found in the given QueryValueExpression.

Parameters:
valueExpr -
Returns:
a Set of ValueExpressionColumns

findColumnReferencesInValueExpressionList

public static java.util.Set findColumnReferencesInValueExpressionList(java.util.List valueExprList)
Returns a Set containing all ValueExpressionColumn s found in the given ValueExpression list.


findColumnReferencesInGroupingSpecificationList

public static java.util.Set findColumnReferencesInGroupingSpecificationList(java.util.List groupingSpecList)
Returns a Set containing all ValueExpressionColumn s found in the given GroupingSpecification list.


findColumnReferencesInGroupingSpecification

public static java.util.Set findColumnReferencesInGroupingSpecification(GroupingSpecification groupingSpec)
Returns a Set containing all ValueExpressionColumn s found in the given GroupingSpecification.


findColumnReferencesInQueryExpressionBody

public static java.util.Set findColumnReferencesInQueryExpressionBody(QueryExpressionBody queryExprBody)
TODO: Developer Note: not completely implemented. Returns a Set containing all ValueExpressionColumns found in the given QueryExpressionBody.


findColumnReferencesInQueryExpressionRoot

public static java.util.Set findColumnReferencesInQueryExpressionRoot(QueryExpressionRoot queryExprRoot)
Returns a Set containing all ValueExpressionColumns found in the given QueryExpressionRoot.


findColumnReferencesInQuerySelectStatement

public static java.util.Set findColumnReferencesInQuerySelectStatement(QuerySelectStatement querySelect)
Returns a Set containing all ValueExpressionColumn s found in the given QuerySelectStatement.


findColumnReferencesInQueryUpdateStatement

public static java.util.Set findColumnReferencesInQueryUpdateStatement(QueryUpdateStatement updateStmt)
Returns a Set containing all ValueExpressionColumn s found in the given QueryUpdateStatement.


findColumnReferencesInUpdateAssignmentExprList

public static java.util.Set findColumnReferencesInUpdateAssignmentExprList(java.util.List updateAssignmentExprList)
Returns a Set containing all ValueExpressionColumn s found in the given List of UpdateAssignmentExpressions.

Parameters:
updateAssignmentExprList - the list of UpdateAssignmentExpression s to search in
Returns:
Set containing all ValueExpressionColumn s found

findColumnReferencesInUpdateAssignmentExpr

public static java.util.Set findColumnReferencesInUpdateAssignmentExpr(UpdateAssignmentExpression updateAssignmentExpr)
Returns a Set containing all ValueExpressionColumn s found in the given List of UpdateAssignmentExpression.

Parameters:
updateAssignmentExpr - the UpdateAssignmentExpression to search in
Returns:
Set containing all ValueExpressionColumn s found

resolveTableReferencesInSearchCondition

public static void resolveTableReferencesInSearchCondition(SearchCondition searchCondition,
                                                           java.util.List tableExpressionList)
                                                    throws org.eclipse.datatools.modelbase.sql.query.helper.TableHelper.ColumnInTwoTablesException
Deprecated. NO, but not implemented Associates the column refernces in the given search condition to the tables in the list of TableExpressions.

NOT IMPLEMENTED!

Parameters:
searchCondition - the SearchCondition that contains ValueExpressionColumn s with column refernces to TableExpression s
tableExpressionList - a List of TableExpressions, that ValueExpressionColumn s in the given SearchCondition should be associated with
Throws:
org.eclipse.datatools.modelbase.sql.query.helper.TableHelper.ColumnInTwoTablesException

createFromClauseForStatement

public static java.lang.String createFromClauseForStatement(QueryStatement stmt)
Creates the From Clause with the tables used in the given SQLStatement.

Parameters:
stmt - the QueryStatement from which is used to get list of tables
Returns:
the From Clause string

createFromClauseForStatement

public static java.lang.String createFromClauseForStatement(SQLQueryObject stmt)
Creates the From Clause with the tables used in the given SQLStatement.

Parameters:
stmt - the QueryStatement from which is used to get list of tables
Returns:
the From Clause string

findTableExpressionInTableExpressionList

public static TableExpression findTableExpressionInTableExpressionList(java.lang.String schemaName,
                                                                       java.lang.String tableName,
                                                                       java.util.List tableExprList)
Finds in the given List of TableExpression s the one TableExpression with a name that matches the given tableName and, if a schemaName is given, with a Schema whose name matches the schemaName. If no schemaName is given, the first TableExpression found without regard of its Schema, will be returned.

Parameters:
schemaName - optional the schema name of the table to find
tableName - the name of the table to find
tableExprList - the list of TableExpression s to search
Returns:
the matching TableExpression or null

findTableExpressionsByNameOrAlias

public static TableExpression findTableExpressionsByNameOrAlias(java.lang.String tableNameOrAlias,
                                                                java.util.List tableExprList,
                                                                java.lang.String defaultSchemaName)
Finds in the given List of TableExpression s the TableExpression with a name that matches the given tableNameOrAlias or a tableCorrelation with a name that matches tableNameOrAlias. If multiple tables are found, preference is given to the first. Note: if no table is found by alias name but more than one table is found by name, the table that is in the default Schema specified by defaultSchemaName will be returned, or, if no defaultSchemaName is given the table to be returned must have no Schema reference. If you are searching for a table with name and schema, use findTableExpressionInTableExpressionList(String, String, List) Note: If only one table is found with the given tableNameOrAlias, but it is Schema-qualified, it will be returned also. Example:
for tableNameOrAlias = "T1" and the given tableExprList contains:
tableExprList*return
T1
T2
T1
S1.T1
T1
T1
S1.T1 AS T1
S2.T1
S1.T1
S1.T1
S1.T2
S1.T1
S1.T2
S1.T3
null
S1.T1
S2.T1
null
* S1,S2 are Schema names; T1,T2,T3 are Table names

Parameters:
tableNameOrAlias - the name of the table to find or its correlation name
tableExprList - the list of TableExpression s to search
defaultSchemaName - optional, if given and no table is found by alias name but tables, that have no alias are found by name, the table to be returned has to be in the default Schema
Returns:
the matching TableExpression or null

getSchemaNameForTableExpression

public static java.lang.String getSchemaNameForTableExpression(TableExpression tableExpr)
Returns the name of the Schema that the given TableExpression is part of or null, if the given TableExpression has no reference to a Schema or the referenced Schema's name is null.

Parameters:
tableExpr -
Returns:
the Schema name or null

getTableExpressionsInTableReferenceList

public static java.util.List getTableExpressionsInTableReferenceList(java.util.List tableReferenceList)
Retrieves a List of TableExpression s from the given List of TableReferences.

Parameters:
tableReferenceList -
Returns:

getTableInDatabaseInTableReferenceList

public static java.util.List getTableInDatabaseInTableReferenceList(java.util.List tableReferenceList)
Retrieves the TableInDatabase objects contained in the given List of TableReferences. This method might be useful to find all the references to database tables in the FROM-clause of a QuerySelect.

Parameters:
tableReferenceList - List of TableReference s
Returns:
List of TableInDatabase s contained in the given tableReferenceList

getTableExpressionsInTableReference

public static java.util.List getTableExpressionsInTableReference(TableReference tableRef)
Retrieves a List of TableExpression s from the given TableReference.

Parameters:
tableRef -
Returns:

removeColumnExpressionFromTableIfNotReferenced

public static void removeColumnExpressionFromTableIfNotReferenced(ValueExpressionColumn col)
Removes a columnExpression from its tableExpression if it has no other refernces to objects other than its tableExpression.


removeColumnExpressionFromTableIfDuplicate

public static void removeColumnExpressionFromTableIfDuplicate(ValueExpressionColumn columnExpr)
Deprecated. odd method not of practical use anymore, use columnExpr.setTableExpr(null) since TableExpression.getColumnList() does reflect only the exposed columns of a TableExpression where as TableExpression.getValueExprColumns() is the list containing the arbitrary references to ValueExpressionColumns which are referencing to that TableExpression by ValueExpressionColumn.getTableExpr()()

Removes a columnExpression from its tableExpression if its tableExpr has another columnExpression with the same name. Note: only call this method if the columnExpr has no references to objects other than its tableExpression

Parameters:
columnExpr -

resolveColumnTableReferences

public static void resolveColumnTableReferences(java.util.Collection unresolvedColumns,
                                                java.util.List aTableRefList)
Link table references in column expressions to tables in the given list of tables (that is, the From clause), copies DataTypes as well.

Note: the given set of ValueExpressionColumns aColumnSet will be modified directly. The resolved columns will be removed from the set.

Note: TableExpressions directly contained in the given aTableRefList will be given preference before TableExpressions found contained indeirectly within TableNesteds or TableJoineds, when two TableReferences with the same name are found.

Parameters:
unresolvedColumns - will be modified, see NOTE
aTableRefList - a list of tables to use to resolve column references

getSchemaForTableInDatabase

public static Schema getSchemaForTableInDatabase(TableInDatabase tableInDB)
Parameters:
tableInDB -
Returns:

resolveResultTableReferences

public static void resolveResultTableReferences(java.util.List resultTableList,
                                                java.util.List tableExprList)
Resolves the TableReference s of the ResultTableAllColumns in the given resultTableList with the TableExpression s in the given tableExprList.

Parameters:
resultTableList - a List of ResultTableAllColumns
tableExprList - a List of TableExpressions

setTableAliasInTableExpression

public static void setTableAliasInTableExpression(TableExpression tableExpr,
                                                  java.lang.String alias)
Assigns the alias to the given TableExpression.

Parameters:
tableExpr - the TableExpression for which alias needs to be set
alias - the String value for the alias

exposeEffectiveResultColumns

public static java.util.List exposeEffectiveResultColumns(QueryExpressionBody nestedQuery)
Adds a ValueExpressionColumn to the given nestedQuery for each of its QuerySelect's ResultColumns that have either a name or reference a ValueExpressionColumn that has a name. That is useful in case the given QueryExpressionBody is used as a nested query - as a TableReference - within another QuerySelect, so that nested full-select can be treated like any other TableReference with its columnList.

Parameters:
nestedQuery -
Returns:
List of already or newly exposed ValueExpressionColumns

exposeEffectiveResultColumns

public static java.util.List exposeEffectiveResultColumns(TableExpression tableExpr)
Populates the given tableExpr's columnList with ValueExpressionColumns, with name, dataType and in ordering, so the given tableExpr can be handled like a TableInDatabase.

Parameters:
tableExpr -
Returns:
List of already or newly exposed ValueExpressionColumns

getEffectiveResultColumns

public static java.util.List getEffectiveResultColumns(TableReference tableRef)
Returns a List of ValueExpressionColumns, with name, dataType and in ordering, so the given tableRef can be handled like a TableInDatabase.

Parameters:
tableRef -
Returns:
List of exposed ValueExpressionColumns

exposeEffectiveResultColumns

public static java.util.List exposeEffectiveResultColumns(WithTableReference withTable)
Populates the given withTable's columnList with ValueExpressionColumns, with name, dataType and in ordering, so the given tableExpr can be handled like a TableInDatabase.

Parameters:
withTable -
Returns:
List of already or newly exposed ValueExpressionColumns

getOrCreateColumnExpression

public static ValueExpressionColumn getOrCreateColumnExpression(java.lang.String columnName,
                                                                TableExpression tableExpr)
Returns the ValueExpressionColumn with the given columnName from the given tableExpression's columnList or, if the given tableExpression's columnList does not contain a ValueExpressionColumn with the given columnName, creates a new ValueExpressionColumn with the given columnName and returns it.

Parameters:
columnName -
tableExpr - optional TableExpression, if provided the existing ValueExpressionColumn with the given columnName will be returned from the tableExpr's columnList
Returns:
a ValueExpressionColumn - already existing or newly created

getDistinctColumnExpressionList

public static java.util.SortedSet getDistinctColumnExpressionList(TableExpression tableExpr)
Deprecated. use TableExpression.getColumnList()it now reflects the exact order of exposed effective "result" columns of a TableExpression

Note: deprecated! use TableExpression.getColumnList()
Returns an distinct List of the given TableExpression's ValueExpressionColumn s ordered by name.

Note: out of two ValueExpressionColumn s with the same name, the first one found in the TableExpression's columnList will be part of the returned Set, regardles of the references to other objects that are not also refernced by the ValueExpressionColumn in the returned Set.

Returns:
SortedSet of ValueExpressionColumn s without duplicates regarding their name


Copyright © 2006 Actuate, IBM Corporation, Sybase, Inc. and others. All rights reserved.