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

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

public class TableHelper
extends java.lang.Object

Provides utility functions related to tables and columns.


Field Summary
static java.lang.String DELIMITED_IDENTIFIER_QUOTE
          This is the default quote character to use for delimited identifiers like "Col1".
 
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 a TableInDatabase object for the given Table object and initializes its list of SQLValueExpressColumn objects 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 ValueExpressionColumns found in the given GroupingExpression.
static java.util.Set findColumnReferencesInGroupingSpecification(GroupingSpecification groupingSpec)
          Returns a Set containing all ValueExpressionColumns found in the given GroupingSpecification.
static java.util.Set findColumnReferencesInGroupingSpecificationList(java.util.List groupingSpecList)
          Returns a Set containing all ValueExpressionColumns 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, not necessarily distinct, ValueExpressionColumns found in the given Predicate.
static java.util.Set findColumnReferencesInQueryExpressionBody(QueryExpressionBody queryExprBody)
          Returns a Set containing all ValueExpressionColumns found in the given QueryExpressionBody.
static java.util.Set findColumnReferencesInQueryExpressionRoot(QueryExpressionRoot queryExprRoot)
          Returns a Set containing all ValueExpressionColumns found in the given QueryExpressionRoot.
static java.util.Set findColumnReferencesInQueryMergeStatement(QueryMergeStatement mergeStmt)
          Returns a set containing all the column value expression objects in the given statement.
static java.util.Set findColumnReferencesInQueryResultSpecification(QueryResultSpecification queryResult)
          Returns a Set containing all ValueExpressionColumns found in the given QueryResultSpecification.
static java.util.Set findColumnReferencesInQueryResultSpecificationList(java.util.List queryResultSpecList)
          Returns a Set containing all ValueExpressionColumns found in the given QueryResultSpecification list.
static java.util.Set findColumnReferencesInQuerySelectStatement(QuerySelectStatement querySelect)
          Returns a Set containing all ValueExpressionColumns found in the given QuerySelectStatement.
static java.util.Set findColumnReferencesInQueryUpdateStatement(QueryUpdateStatement updateStmt)
          Returns a Set containing all ValueExpressionColumns 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 findColumnReferencesInTableReference(TableReference tableRef)
          Returns a Set containing all the ValueExpressionColumns found in the given TableReference.
static java.util.Set findColumnReferencesInTableReferenceList(java.util.List tableRefList)
          Returns a Set containing all the ValueExpressionColumns found in the given TableReference list.
static java.util.Set findColumnReferencesInUpdateAssignmentExpr(UpdateAssignmentExpression updateAssignmentExpr)
          Returns a Set containing all ValueExpressionColumns found in the given List of UpdateAssignmentExpression.
static java.util.Set findColumnReferencesInUpdateAssignmentExprList(java.util.List updateAssignmentExprList)
          Returns a Set containing all ValueExpressionColumns found in the given List of UpdateAssignmentExpressions.
static java.util.Set findColumnReferencesInUpdateSourceExprList(UpdateSourceExprList updateSourceExprList)
          Returns a Set containing all ValueExpressionColumns found in the given UpdateSourceExprList.
static java.util.Set findColumnReferencesInValueExpression(QueryValueExpression valueExpr)
          Returns a Set containing all ValueExpressionColumns found in the given QueryValueExpression.
static java.util.Set findColumnReferencesInValueExpressionList(java.util.List valueExprList)
          Returns a Set containing all ValueExpressionColumns 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 java.util.Set findColumnReferencesInWithTableSpecification(WithTableSpecification withTableSpec)
          Returns a Set containing all the ValueExpressionColumns found in the given WithTableSpecification.
static TableExpression findTableExpressionInTableExpressionList(java.lang.String schemaName, java.lang.String tableName, java.util.List tableExprList)
          Finds in the given List of TableExpressions 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 TableExpressions 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 column name.
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(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.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 TableExpressions 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 removeColumnExpressionFromTableIfNotReferenced(ValueExpressionColumn col)
          Removes a columnExpression from its tableExpression if it has no other references 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 TableReferences of the ResultTableAllColumns in the given resultTableList with the TableExpressions in the given tableExprList.
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

DELIMITED_IDENTIFIER_QUOTE

public static final java.lang.String DELIMITED_IDENTIFIER_QUOTE
This is the default quote character to use for delimited identifiers like "Col1". When comparing with a delimited identifier, the characters inside the delimiters must match exactly.

Note: this character can vary depending on the database type, so use of this constant is not recommended. Instead get the identifier quote character from the database configuration.

See Also:
Constant Field Values
Constructor Detail

TableHelper

public TableHelper()
Method Detail

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

createTableExpressionForTable

public static TableInDatabase createTableExpressionForTable(Table table)
Creates and returns a TableInDatabase object for the given Table object and initializes its list of SQLValueExpressColumn objects corresponding to each column of the table.

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

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 - the query whose columns should be exposed
Returns:
a 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 - the table expression whose columns should be expose
Returns:
a list of already or newly 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 - the WITH table whose columns should be exposed
Returns:
a list of already or newly exposed ValueExpressionColumns

findColumnReferencesInGroupingExpression

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


findColumnReferencesInGroupingSpecification

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


findColumnReferencesInGroupingSpecificationList

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


findColumnReferencesInOrderBySpecification

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


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.


findColumnReferencesInPredicate

public static java.util.Set findColumnReferencesInPredicate(Predicate predicate)
Returns a Set containing all, not necessarily distinct, ValueExpressionColumns found in the given Predicate. This means you have to expect duplicate ValueExpressionColumns regarding their column names.

Parameters:
predicate -
Returns:

findColumnReferencesInQueryExpressionBody

public static java.util.Set findColumnReferencesInQueryExpressionBody(QueryExpressionBody queryExprBody)
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.


findColumnReferencesInQueryMergeStatement

public static java.util.Set findColumnReferencesInQueryMergeStatement(QueryMergeStatement mergeStmt)
Returns a set containing all the column value expression objects in the given statement.

Parameters:
mergeStmt - the statement from which column expressions are wanted
Returns:
a set containing the column expressions in the statement

findColumnReferencesInQueryResultSpecification

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


findColumnReferencesInQueryResultSpecificationList

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


findColumnReferencesInQuerySelectStatement

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


findColumnReferencesInQueryUpdateStatement

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


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:

findColumnReferencesInTableReference

public static java.util.Set findColumnReferencesInTableReference(TableReference tableRef)
Returns a Set containing all the ValueExpressionColumns found in the given TableReference.


findColumnReferencesInTableReferenceList

public static java.util.Set findColumnReferencesInTableReferenceList(java.util.List tableRefList)
Returns a Set containing all the ValueExpressionColumns found in the given TableReference list.


findColumnReferencesInUpdateAssignmentExpr

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

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

findColumnReferencesInUpdateAssignmentExprList

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

Parameters:
updateAssignmentExprList - the list of UpdateAssignmentExpressions to search in
Returns:
Set containing all ValueExpressionColumns found

findColumnReferencesInUpdateSourceExprList

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


findColumnReferencesInValueExpression

public static java.util.Set findColumnReferencesInValueExpression(QueryValueExpression valueExpr)
Returns a Set containing all ValueExpressionColumns 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 ValueExpressionColumns found in the given ValueExpression list.


findColumnReferencesInValuesRow

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


findColumnReferencesInWithTableSpecification

public static java.util.Set findColumnReferencesInWithTableSpecification(WithTableSpecification withTableSpec)
Returns a Set containing all the ValueExpressionColumns found in the given WithTableSpecification.


findTableExpressionInTableExpressionList

public static TableExpression findTableExpressionInTableExpressionList(java.lang.String schemaName,
                                                                       java.lang.String tableName,
                                                                       java.util.List tableExprList)
Finds in the given List of TableExpressions 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 TableExpressions 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

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
column - the column to be looked for
Returns:
the SQLValueExpressionColumn corresponding to the given Column, or null if there is no match

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 column name.

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 to search for the matching column name
columnName - the name of the ValueExpressionColumn to search for
Returns:
the found ValueExpressionColumn or null

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 to search for the matching column
columnName - the name of the column to search for
Returns:
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 to search for the matching column name
columnName - the name of the ValueExpressionColumn search for
Returns:
column the found ValueExpressionColumn or null

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 to search for the matching SQLValueExpressionColumn
colExpr - the SQLValueExpressionColumn to search for
Returns:
the found column object or null if not found

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 to search for the matching column name
columnName - the name of the column to search for
Returns:
the column object or null if not found

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 to search for the matching column name
columnName - the String name of the column to search
Returns:
the found column object or null if not found

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 to search for the matching column name
columnName - the name of the column to search for
Returns:
the found column object or null if not found

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

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

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

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

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

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

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 to search for the matching column name
columnName - the name of the ValueExpressionColumn to search
Returns:
the found ResultColumn 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 to search for the matching column name
columnName - the name of the ValueExpressionColumn to search for
Returns:
the found ValueExpressionColumn or 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 for which the ResultColumns will be returned
Returns:
the ResultColumns of the given queryExpr

getSchemaForTableInDatabase

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

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

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

getTableExpressionsInTableReference

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

Parameters:
tableRef -
Returns:

getTableExpressionsInTableReferenceList

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

Parameters:
tableReferenceList -
Returns:

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

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

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

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

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 searched 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

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

removeColumnExpressionFromTableIfNotReferenced

public static void removeColumnExpressionFromTableIfNotReferenced(ValueExpressionColumn col)
Removes a columnExpression from its tableExpression if it has no other 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

resolveResultTableReferences

public static void resolveResultTableReferences(java.util.List resultTableList,
                                                java.util.List tableExprList)
Resolves the TableReferences of the ResultTableAllColumns in the given resultTableList with the TableExpressions 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