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

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

public class StatementHelper
extends java.lang.Object


Field Summary
static char DELIMITED_IDENTIFIER_QUOTE
          TODO: make that DELIMITED_IDENTIFIER_QUOTE char 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 "
static int STATEMENT_TYPE_DELETE
           
static int STATEMENT_TYPE_FULLSELECT
           
static int STATEMENT_TYPE_INSERT
           
static int STATEMENT_TYPE_SELECT
           
static int STATEMENT_TYPE_UPDATE
           
static int STATEMENT_TYPE_WITH
           
 
Constructor Summary
StatementHelper()
           
StatementHelper(Database database)
           
 
Method Summary
 void addNewName(Table selectedTable)
          Provide the name that will be generated next this is for populating alias text field with a default
static int compareSQL(java.lang.String sql1, java.lang.String sql2)
          Compares the SQL source of the given SQL fragments according to their syntax.
static int compareSQL(java.lang.String sql1, java.lang.String sql2, char identifierDelimiterQt)
          Compares the SQL source of the given SQL fragments according to their syntax.
static java.lang.String convertCatalogIdentifierToSQLFormat(java.lang.String catalogIdentifier, char idDelimiterQuote)
          Converts an identifier from catalog format to SQL format.
static java.lang.String convertSQLIdentifierToCatalogFormat(java.lang.String sqlIdentifier, char idDelimiterQuote)
          Converts an identifier from SQL format to catalog format.
static ValueExpressionColumn createColumnExpression(java.lang.String name)
          Create a new ValueExpressionColumn with the given name.
static ColumnName createColumnName(java.lang.String name)
          Creates the new ColumnName object and sets the given name.
static QueryDeleteStatement createDeleteStatement(java.lang.String name)
           
static QueryInsertStatement createInsertStatement(java.lang.String name)
          return false if we cannot find the input name
 QueryInsertStatement createInsertStatement(java.lang.String name, boolean addToDb)
          Deprecated.  
static QueryCombined createQueryCombined()
          Creates a QueryCombined
static QuerySelectStatement createQueryCombinedStatement(java.lang.String name)
          Creates a QuerySelectStatement statement, with a QueryCombined in it
static QueryExpressionRoot createQueryExpressionRoot()
          Creates a QueryExpressionRoot
static QueryExpressionRoot createQueryExpressionRoot(QuerySelectStatement aParent)
          Creates a QueryExpressionRoot and attaches it to QuerySelectStatement
static QuerySelect createQuerySelect()
          Creates a QuerySelect Object
static QuerySelect createQuerySelect(QueryExpressionRoot anExpRoot)
          Creates a QuerySelect Object and hook it to a QueryExpressionRoot
static QuerySelect createQuerySelect(QuerySelectStatement aStatement)
          Creates a QuerySelect Object and hook it to a QuerySelectStatement
static QuerySelectStatement createQuerySelectStatement(java.lang.String aName)
          Creates a QuerySelectStatement
static QueryStatement createQueryStatement(int stmtType, java.lang.String stmtName)
          Creates a statement of the given type with the given name.
 QuerySelectStatement createSelectStatement(java.lang.String name)
           
static QueryUpdateStatement createUpdateStatement(java.lang.String name)
           
 QueryUpdateStatement createUpdateStatement(java.lang.String name, boolean addToDb)
          Deprecated.  
static QuerySelectStatement createWithStatement(java.lang.String name)
          Creates a WITH query statement.
static WithTableReference createWithTableReferenceForWithTable(WithTableSpecification withTableSpec)
          Creates a new WithTableReference for the given withTableSpec and creates ValueExpressionColumn objects for each of the given WithTableSpecification's declared columns (WithTableSpecification.getColumnNameList()) or, if columns are not declared, for each of the WithTableSpecification's query's result columns.
static boolean equalSQLIdentifiers(java.lang.String sqlIdent1, java.lang.String sqlIdent2, char identDelimiterQuote)
          Compares two SQL identifier in SQL format, regarding delimited identifiers using the given identDelimiterQuote as delimiter.
static ResultColumn findResultColumnForColumnExpression(QuerySelect select, ValueExpressionColumn columnExpr)
          Returns null or the ResultColumn of the given QuerySelect whose ValueExpression is of type ValueExpressionColumn which in name and tableExpr equals the given columnExpr.
static ResultColumn findResultColumnForColumnNameOrAlias(QuerySelect select, java.lang.String columnNameOrAlias)
          Returns null or the ResultColumn of the given QuerySelect whose name matches the given columnNameOrAlias or whose ValueExpression is of type ValueExpressionColumn which has a name matching the given columnNameOrAlias.
static java.util.List getAllVariablesInQueryStatement(QueryStatement queryStmt)
          Returns all ValueExpressionVariables contained in the given QueryStatement.
static Database getDatabase(QueryStatement stmt)
          Returns the Database for which SQL Statement is associated with.
static TableInDatabase getDerivedDatabaseTable(ValueExpressionColumn columnExpr)
          Returns the TableInDatabase that the given columnExpr was derived from, if the given column is not the result of an expression in the selectClause of a QuerySelect or the result column of a QueryValues.
static java.util.List getDerivedDatabaseTables(java.util.List columnExprList)
          Returns the TableInDatabases, that the given columnExprs were derived from, if the given columns are not the result of an expression in the selectClause of a QuerySelect or the result column of a QueryValues.
static java.util.Set getDirectReferences(EObject eObject, java.lang.Class typeFilter)
          Returns all directly referenced Objects of the given eObject that are of type or a subtype of the given typeFilter.
static SQLQueryObject getEContainerRecursively(EObject eObject, java.lang.Class containerType)
          Returns the EObject#eContainer()for the given eObject that is assignable to the given type containerType.
static java.util.List getEffectiveResultColumns(QuerySelectStatement selectStmt)
          This method compiles a list of ValueExpressionColumns that reflects the columns, in order and with datatype, which are the result of the given QuerySelectStatement.
static QuerySearchCondition getHavingCondition(QueryStatement stmt)
          Returns "Having" clause for the given statement.
static QuerySearchCondition getHavingCondition(SQLQueryObject stmt)
           
 java.lang.String getNewName(QueryInsertStatement insert)
           
static Predicate getPredicateOfVariable(ValueExpressionVariable variable)
          Returns the Predicate of the given variable or null, if the variable has no reference to a Predicate.
static QuerySelect getQuerySelectForTableReference(TableExpression tableExpr)
          Returns the QuerySelect that contains the given tableExpr in its fromClause.
static QueryStatement getQueryStatementForTableReference(TableReference tableRef)
          Returns the QueryStatement associated with the given tableRef.
static java.util.Set getReferencesRecursively(EObject eObject, java.lang.Class typeFilter)
          Returns all Objects recursively referenced by the given eObject, that are of type or a subtype of the given typeFilter.
static java.util.Set getReferencesViaSpecificReferencePaths(EObject eObject, java.lang.Class typeFilter, java.lang.Class[] referencePathTypes)
          Returns Objects recursively referenced by the given eObject, that are of type or a subtype of the given typeFilter.
static java.util.List getResultTableAllColumnsInQueryResultSpecificationList(java.util.List queryResultSpecList)
          Returns a List containing only the QueryResultSpecifications in the given queryResultSpecList that are of type ResultTableAllColumns.
static QuerySearchCondition getSearchCondition(QueryStatement stmt)
          Returns QuerySearchCondition for the given statement.
static QuerySearchCondition getSearchCondition(SQLQueryObject stmt)
           
static java.lang.String getSQLForExecution(SQLQueryObject queryObject)
          Generates SQL source for the given queryObject without any comments and with the current schema qualified tables.
static java.lang.String getSQLQualified(SQLQueryObject queryObject, int qualificationSpec)
          Returns the SQL source text of the given SQLQueryObject with all identifiers (table and column references) qualified according to the given qualificationSpec.
static java.lang.String getSQLSchemaQualified(SQLQueryObject queryObject)
          Returns the SQL source text of the given SQLQueryObject with all identifiers (table and column references) qualified with their schema name.
static java.lang.String getSQLSourceUnformatted(SQLQueryObject queryObject)
          Returnes the generated SQL source for the given queryObject without any formatting and without comments in a single line.
static java.lang.String getSQLSourceUnformatted(java.lang.String queryStmt)
          Returnes the given SQL source String in a single line without any formatting.
static java.lang.String getSQLTableQualified(SQLQueryObject queryObject)
          Returns the SQL source text of the given SQLQueryObject with all column references qualified with table names, but all table names unqualified (without schema name).
static java.lang.String getSQLUnqualified(SQLQueryObject queryObject)
          Returns the SQL source text of the given SQLQueryObject with all identifiers unqualified (column references without table names, and all table references without schema names).
static java.lang.String getSQLWithComments(SQLQueryObject queryObject)
          Returnes the generated SQL source for the given queryObject with all comments.
static java.lang.String getSQLWithoutComments(SQLQueryObject queryObject)
          Returnes the generated SQL source for the given queryObject without any comments.
static int getStatementType(QueryStatement statement)
          Returns the integer constant defined in this class, that represents the given QueryStatement
static TableExpression getTableExpressionForTable(Table table, QuerySelect qSelect)
          Returns the TableExpression representing the given Table object,in the given QuerySelect
static TableExpression getTableExpressionForTable(Table table, QuerySelectStatement selectStmt)
          Returns the TableExpression representing the given Table object,in the given QuerySelectStatement
static java.util.List getTableExpressionsInQueryExpressionBody(QueryExpressionBody query)
           
static java.util.List getTableExpressionsInQuerySelect(QuerySelect querySelect)
           
static java.util.List getTableExpressionsVisibleInQuerySelect(QuerySelect querySelect)
          Returns the TableExpression s in the given QuerySelect's fromClause plus all the TableExpression s that are visible in the scope of the given QuerySelect, if the QuerySelect given is a nested query or subquery, all the TableExpression s of the super query are appende to the returned list of TableExpressions.
static java.util.List getTablesForStatement(QueryStatement stmt)
          Returns List of tables (TableExpression) referenced in the statement.
static java.util.List getTablesForStatement(SQLQueryObject stmt)
           
static java.lang.String getTemplateSQL(int statementType)
          Returns the default SQL template for a statement
static boolean isColumnNameAmbiguous(ValueExpressionColumn columnExpr)
          Returns true only if the given columnExpr name is equal to another ValueExpressionColumn's name in a different table and therefore needs to be qualified.
static boolean isOrderByClauseContainsValidOrderBySpecification(java.util.List orderByClause)
          Returns true, if at least one OrderBySpecification contained in the given orderByClause list is valid.
static boolean isOrderBySpecificationValid(OrderBySpecification orderBySpec)
           
static boolean isTableNameAmbiguous(TableExpression tableExpr)
          Returns true if the given tableExpr's name is not unique within the fromClause of its containing QuerySelect and the other TableExpression s in the fromClause as well as the given TableExpression have no TableCorrelation to distinguish between them.
static boolean isTemplateSQL(java.lang.String sql)
          Checks to see if the given string is same as the template for any of the DML statements
static void logDebug(java.lang.String debugMsg)
           
static void logError(java.lang.String errorMsg)
           
static boolean omitSchema(TableInDatabase tableInDB)
          Returns true if the given tableInDB does not have to be qualified with its Schema name.
static java.lang.String removeCommentsInSQL(java.lang.String statement, char delimitedIdentifierQt)
          Walks through the given SQL and strips out the comments that are identified by two dashes in line "--" and that are not part of a delimited character string (single quotes), or SQL delimited object name (double quotes).
static void removeTableExpressionFromQueryStatement(TableExpression tableExpr, SQLQueryObject queryObj)
          Removes the given TableExpression from the given SQLQueryObject.
static void removeValueExpression(QueryValueExpression valExpr)
          Removes the given ValueExpression object from the object that contains it.
static java.util.Set resolveOrderByColumns(QueryExpressionBody queryExpr, java.util.List orderByList)
           
static java.util.Set resolveOrderByColumns(QuerySelect select, java.util.List orderByList)
          Every given OrderBySpecifications contained in the given orderByList, that is of type OrderByValueExpression and its owned ValueExpression is of type ValueExpressionColumn, will be removed from the given QuerySelect and substituted by a new OrderByResultColumn that will then be given the reference to the ValueExpressionColumn formerly associated to the removed OrderByValueExpression, if the given QuerySelect has a ResultColumn that refers by its name to the same ValueExpressionColumn.
static void resolveQueryResultSpecification(QuerySelect querySelect)
          Resolves columnExpressions and tableReferences in given querySelect's QueryResultSpecification ResultColumn or ResultTableAllColumns with the columnExpressions and tableExpressions in the given querySelect's fromClause.
static void resolveResultTableAllColumns(QuerySelect querySelect)
          Resolves tableReferences in given querySelect's QueryResultSpecifications of type ResultTableAllColumns with the tableExpressions in the given querySelect's fromClause.
static WithTableReference resolveWithTableSpecificationReference(TableExpression potentialWithTableRef)
          Substitutes the given TableReference with the WithTableSpecification that is refered by the given potentialTableWithRef's name, if a TableWithSpecification is found in the QueryExpressionRoot that contains the given TableReference.
static void setHavingClauseForStatement(QuerySearchCondition newSearchCon, QueryStatement statement)
          Sets the having clause in the given sql statement.
static void setHavingClauseForStatement(QuerySearchCondition newSearchCon, SQLQueryObject statement)
          Sets the having clause in the given SQLQueryObject.
static void setWhereClauseForStatement(QuerySearchCondition newSearchCon, QueryStatement statement)
          Sets the where clause in the given sql statement.
static void setWhereClauseForStatement(QuerySearchCondition newSearchCon, SQLQueryObject statement)
          Sets the where clause in the given sqlQueryObject.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DELIMITED_IDENTIFIER_QUOTE

public static final char DELIMITED_IDENTIFIER_QUOTE
TODO: make that DELIMITED_IDENTIFIER_QUOTE char 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

STATEMENT_TYPE_DELETE

public static final int STATEMENT_TYPE_DELETE
See Also:
Constant Field Values

STATEMENT_TYPE_FULLSELECT

public static final int STATEMENT_TYPE_FULLSELECT
See Also:
Constant Field Values

STATEMENT_TYPE_INSERT

public static final int STATEMENT_TYPE_INSERT
See Also:
Constant Field Values

STATEMENT_TYPE_SELECT

public static final int STATEMENT_TYPE_SELECT
See Also:
Constant Field Values

STATEMENT_TYPE_UPDATE

public static final int STATEMENT_TYPE_UPDATE
See Also:
Constant Field Values

STATEMENT_TYPE_WITH

public static final int STATEMENT_TYPE_WITH
See Also:
Constant Field Values
Constructor Detail

StatementHelper

public StatementHelper()

StatementHelper

public StatementHelper(Database database)
Method Detail

compareSQL

public static int compareSQL(java.lang.String sql1,
                             java.lang.String sql2)
Compares the SQL source of the given SQL fragments according to their syntax.

Parameters:
sql1 -
sql2 -
Returns:
0 if the given SQL fragments are syntactically equivalent

compareSQL

public static int compareSQL(java.lang.String sql1,
                             java.lang.String sql2,
                             char identifierDelimiterQt)
Compares the SQL source of the given SQL fragments according to their syntax.

Parameters:
sql1 -
sql2 -
identifierDelimiterQt -
Returns:
0 if the given SQL fragments are syntactically equivalent

convertCatalogIdentifierToSQLFormat

public static java.lang.String convertCatalogIdentifierToSQLFormat(java.lang.String catalogIdentifier,
                                                                   char idDelimiterQuote)
Converts an identifier from catalog format to SQL format. See following table for examples.
SQL format Catalog format
schema1
Schema1
SCHEMA1
"SCHEMA1"
SCHEMA1
"Schema1" Schema1
"Sch""ma1" Sch"ma1
"Table A" Table A
Table A Error
Sch"ma1 Error

Parameters:
catalogIdentifier - identifier in catalog format
idDelimiterQuote -
Returns:
identifier in SQL format

convertSQLIdentifierToCatalogFormat

public static java.lang.String convertSQLIdentifierToCatalogFormat(java.lang.String sqlIdentifier,
                                                                   char idDelimiterQuote)
Converts an identifier from SQL format to catalog format. See following table for examples.
SQL format Catalog format
schema1
Schema1
SCHEMA1
"SCHEMA1"
SCHEMA1
"Schema1" Schema1
"Sch""ma1" Sch"ma1
"Table A" Table A
Table A Error
Sch"ma1 Error

Parameters:
sqlIdentifier - identifier in SQL format
idDelimiterQuote -
Returns:
identifier in catalog format

createColumnExpression

public static ValueExpressionColumn createColumnExpression(java.lang.String name)
Create a new ValueExpressionColumn with the given name.

Parameters:
name - optional name of the result column
Returns:
new ValueExpressionColumn

createColumnName

public static ColumnName createColumnName(java.lang.String name)
Creates the new ColumnName object and sets the given name.

Parameters:
name - the String name of the ColumnName.
Returns:
the created ColumnName

createDeleteStatement

public static QueryDeleteStatement createDeleteStatement(java.lang.String name)

createInsertStatement

public static QueryInsertStatement createInsertStatement(java.lang.String name)
return false if we cannot find the input name


createQueryCombined

public static QueryCombined createQueryCombined()
Creates a QueryCombined

Returns:
the created QueryCombined

createQueryCombinedStatement

public static QuerySelectStatement createQueryCombinedStatement(java.lang.String name)
Creates a QuerySelectStatement statement, with a QueryCombined in it

Parameters:
name - the name of the statement.
Returns:
the created QuerySelectStatement statement

createQueryExpressionRoot

public static QueryExpressionRoot createQueryExpressionRoot()
Creates a QueryExpressionRoot

Returns:
the created QueryExpressionRoot Object

createQueryExpressionRoot

public static QueryExpressionRoot createQueryExpressionRoot(QuerySelectStatement aParent)
Creates a QueryExpressionRoot and attaches it to QuerySelectStatement

Parameters:
aParent - the parent QuerySelectStatement
Returns:
the QueryExpressionRoot Object or null is aParent is null

createQuerySelect

public static QuerySelect createQuerySelect()
Creates a QuerySelect Object

Returns:
the created QuerySelect Object

createQuerySelect

public static QuerySelect createQuerySelect(QueryExpressionRoot anExpRoot)
Creates a QuerySelect Object and hook it to a QueryExpressionRoot

Parameters:
anExpRoot - the QueryExpressionRoot
Returns:
the QuerySelect Object or null if anExpRoot is null

createQuerySelect

public static QuerySelect createQuerySelect(QuerySelectStatement aStatement)
Creates a QuerySelect Object and hook it to a QuerySelectStatement

Parameters:
aStatement - the QuerySelectStatement
Returns:
the QuerySelect Object or null if aStatement is null

createQuerySelectStatement

public static QuerySelectStatement createQuerySelectStatement(java.lang.String aName)
Creates a QuerySelectStatement

Parameters:
aName - the name of the statement
Returns:
the created QuerySelecteStatement

createQueryStatement

public static QueryStatement createQueryStatement(int stmtType,
                                                  java.lang.String stmtName)
Creates a statement of the given type with the given name. The valid statement types are defined as constants in this class.

Parameters:
stmtType - the requested statement type
stmtName - the name for the statement
Returns:
the new query statement object

createUpdateStatement

public static QueryUpdateStatement createUpdateStatement(java.lang.String name)

createWithStatement

public static QuerySelectStatement createWithStatement(java.lang.String name)
Creates a WITH query statement.

Parameters:
name - the String name of the statement.
Returns:
the created QuerySelecteStatement with TableWithSpecification.

createWithTableReferenceForWithTable

public static WithTableReference createWithTableReferenceForWithTable(WithTableSpecification withTableSpec)
Creates a new WithTableReference for the given withTableSpec and creates ValueExpressionColumn objects for each of the given WithTableSpecification's declared columns (WithTableSpecification.getColumnNameList()) or, if columns are not declared, for each of the WithTableSpecification's query's result columns.

Parameters:
withTableSpec -
Returns:

equalSQLIdentifiers

public static boolean equalSQLIdentifiers(java.lang.String sqlIdent1,
                                          java.lang.String sqlIdent2,
                                          char identDelimiterQuote)
Compares two SQL identifier in SQL format, regarding delimited identifiers using the given identDelimiterQuote as delimiter. If the given SQL identifiers start and end with the identDelimiterQuote they will be compared using String.compareTo(java.lang.String), otherwise they will be compared using String.compareToIgnoreCase(java.lang.String). If identDelimiterQuote is not given, DELIMITED_IDENTIFIER_QUOTE will be used. If both sqlIdent1 and sqlIdent2 are null the result of this method is false.

Parameters:
sqlIdent1 - one SQL identifier
sqlIdent2 - another SQL identifier to be compared to sqlIdent1
identDelimiterQuote - the char that, if present as a pre- and suffix in the given SQL identifiers forces the comparison to regard the case (upper/lower case), default is DELIMITED_IDENTIFIER_QUOTE
Returns:
true if both SQL identifiers are equal, or, even equal regardless of their case, if both identifiers are not delimited, false if both SQL identifiers are null

findResultColumnForColumnExpression

public static ResultColumn findResultColumnForColumnExpression(QuerySelect select,
                                                               ValueExpressionColumn columnExpr)
Returns null or the ResultColumn of the given QuerySelect whose ValueExpression is of type ValueExpressionColumn which in name and tableExpr equals the given columnExpr.

Parameters:
select -
columnExpr - a ValueExpressionColumn
Returns:

findResultColumnForColumnNameOrAlias

public static ResultColumn findResultColumnForColumnNameOrAlias(QuerySelect select,
                                                                java.lang.String columnNameOrAlias)
Returns null or the ResultColumn of the given QuerySelect whose name matches the given columnNameOrAlias or whose ValueExpression is of type ValueExpressionColumn which has a name matching the given columnNameOrAlias.

Parameters:
select -
columnNameOrAlias -
Returns:

getAllVariablesInQueryStatement

public static java.util.List getAllVariablesInQueryStatement(QueryStatement queryStmt)
Returns all ValueExpressionVariables contained in the given QueryStatement.

Parameters:
queryStmt -
Returns:
List of the ValueExpressionVariable

getDatabase

public static Database getDatabase(QueryStatement stmt)
Returns the Database for which SQL Statement is associated with.

Parameters:
stmt - the SQLQueryStatement for which Database is needed
Returns:
the database

getDerivedDatabaseTable

public static TableInDatabase getDerivedDatabaseTable(ValueExpressionColumn columnExpr)
Returns the TableInDatabase that the given columnExpr was derived from, if the given column is not the result of an expression in the selectClause of a QuerySelect or the result column of a QueryValues. The derived table of "c1" in "select t1.col1 as c1 from (select col1 from table1) as t1;" would be "table1".

Parameters:
columnExpr - a ValueExpressionColumn that is part of a TableExpression s columnList( TableExpression.getColumnList()) as the tables exposed ordered result columns (not the ResultColumn of a QuerySelect)
Returns:
the TableInDatabase the given column was derived from or null if the given column is not derived from a TableInDatabase

getDerivedDatabaseTables

public static java.util.List getDerivedDatabaseTables(java.util.List columnExprList)
Returns the TableInDatabases, that the given columnExprs were derived from, if the given columns are not the result of an expression in the selectClause of a QuerySelect or the result column of a QueryValues. The derived tables of "select t1.col1, t2.col1 from table1 t1, table2 t2" would be "table1" and "table2".

Parameters:
columnExprList - a List of ValueExpressionColumns that are part of a TableExpression s columnList( TableExpression.getColumnList()), the tables exposed ordered result columns (not the ResultColumn of a QuerySelect!)
Returns:
the List of TableInDatabases that the given columns were derived from, can be empty

getDirectReferences

public static java.util.Set getDirectReferences(EObject eObject,
                                                java.lang.Class typeFilter)
Returns all directly referenced Objects of the given eObject that are of type or a subtype of the given typeFilter.

Parameters:
eObject - the EObject we want to find refernces for
typeFilter - optional the type of the refernced Objects to be returned, may be null or Object.class to not filter the refernces
Returns:
the Set of referenced Objects

getEContainerRecursively

public static SQLQueryObject getEContainerRecursively(EObject eObject,
                                                      java.lang.Class containerType)
Returns the EObject#eContainer()for the given eObject that is assignable to the given type containerType.

For the ValueExpressionColumn "col1" in the QuerySelect that represents the query SELECT * FROM tbl1 WHERE col1 = 1, the eConatiner would be a PredicateBasic "col1 = 1", but the eConatiner of type QuerySelect would be the whole QuerySelect, that eContains the PredicateBasic.

Parameters:
eObject -
containerType -
Returns:
SQLQueryObject of type containerType that ultimately contains the given eObject

getEffectiveResultColumns

public static java.util.List getEffectiveResultColumns(QuerySelectStatement selectStmt)
This method compiles a list of ValueExpressionColumns that reflects the columns, in order and with datatype, which are the result of the given QuerySelectStatement.

Note: this method will not return the ResultColumn list of the given selectStmt's QuerySelect, because these don't necessarily reflect the effectiv result colomns of a star-query for example.

Note: the returned ValueExpressionColumn's name can be null, for example when the given QuerySelectStatement's query is of type QueryValues ("VALUES (1,2),(3,4)") or if the query is a QuerySelect with a unnamed ResultColumn like in "SELECT COL1 + 10 FROM TABLE1" where "COL1 + 1" has no alias name.

Parameters:
selectStmt -
Returns:
List of ValueExpressionColumns

getHavingCondition

public static QuerySearchCondition getHavingCondition(QueryStatement stmt)
Returns "Having" clause for the given statement.

Parameters:
stmt - the QueryStatement for which Having clause needs to be returned
Returns:
the having clause

getHavingCondition

public static QuerySearchCondition getHavingCondition(SQLQueryObject stmt)

getPredicateOfVariable

public static Predicate getPredicateOfVariable(ValueExpressionVariable variable)
Returns the Predicate of the given variable or null, if the variable has no reference to a Predicate.

Note: If more than one reference of type Predicate is found for the given variable, the first one found will be returned arbitrarily.

Parameters:
variable -
Returns:
the Predicate referencing the given ValueExpressionVariable

getQuerySelectForTableReference

public static QuerySelect getQuerySelectForTableReference(TableExpression tableExpr)
Returns the QuerySelect that contains the given tableExpr in its fromClause.

Parameters:
tableExpr -
Returns:
the containing QuerySelect

getQueryStatementForTableReference

public static QueryStatement getQueryStatementForTableReference(TableReference tableRef)
Returns the QueryStatement associated with the given tableRef.

Parameters:
tableRef -
Returns:

getReferencesRecursively

public static java.util.Set getReferencesRecursively(EObject eObject,
                                                     java.lang.Class typeFilter)
Returns all Objects recursively referenced by the given eObject, that are of type or a subtype of the given typeFilter.

Parameters:
eObject - the object we want to find refernces of
typeFilter - optional the type of the refernced Objects to be returned, may be null or Object.class to not filter the refernces
Returns:
Set of EObject s referenced recursively of type assignable to typeFilter

getReferencesViaSpecificReferencePaths

public static java.util.Set getReferencesViaSpecificReferencePaths(EObject eObject,
                                                                   java.lang.Class typeFilter,
                                                                   java.lang.Class[] referencePathTypes)
Returns Objects recursively referenced by the given eObject, that are of type or a subtype of the given typeFilter. Only such references will be traversed that are of one of the give types in referencePathTypes.

Parameters:
eObject - the object we want to find refernces of
typeFilter - optional the type of the refernced Objects to be returned, may be null or Object.class to not filter the refernces
referencePathTypes - the types of references that are traversed to reach Objects indirectly referenced by the given eObject
Returns:
Set of EObjects referenced recursively

getResultTableAllColumnsInQueryResultSpecificationList

public static java.util.List getResultTableAllColumnsInQueryResultSpecificationList(java.util.List queryResultSpecList)
Returns a List containing only the QueryResultSpecifications in the given queryResultSpecList that are of type ResultTableAllColumns.

Parameters:
queryResultSpecList - a List of QueryResultSpecification
Returns:
a List of ResultTableAllColumns

getSearchCondition

public static QuerySearchCondition getSearchCondition(QueryStatement stmt)
Returns QuerySearchCondition for the given statement.

Parameters:
stmt - the QueryStatement for which search condition needs to be returned
Returns:
the search condition

getSearchCondition

public static QuerySearchCondition getSearchCondition(SQLQueryObject stmt)

getSQLForExecution

public static java.lang.String getSQLForExecution(SQLQueryObject queryObject)
Generates SQL source for the given queryObject without any comments and with the current schema qualified tables.

Note: this method is not Thread -safe, concurrent calls to SQLQueryObject.getSQL() on the given queryObject might not return the expected result.

Parameters:
queryObject - a SQLQueryObject to get the SQL source for
Returns:
the SQL source String of the given queryObject without any comments and qualified tables

getSQLQualified

public static java.lang.String getSQLQualified(SQLQueryObject queryObject,
                                               int qualificationSpec)
Returns the SQL source text of the given SQLQueryObject with all identifiers (table and column references) qualified according to the given qualificationSpec.

Note: this method is not Thread -safe, concurrent calls to SQLQueryObject.getSQL() on the given queryObject might not return the expected or even a semantically invalid result.

Parameters:
queryObject -
qualificationSpec -
Returns:
SQL source of the given SQLQueryObject

getSQLSchemaQualified

public static java.lang.String getSQLSchemaQualified(SQLQueryObject queryObject)
Returns the SQL source text of the given SQLQueryObject with all identifiers (table and column references) qualified with their schema name.

Note: this method is not Thread -safe, concurrent calls to SQLQueryObject.getSQL() on the given queryObject might not return the expected result.

Parameters:
queryObject -
Returns:
SQL source of the given SQLQueryObject

getSQLSourceUnformatted

public static java.lang.String getSQLSourceUnformatted(SQLQueryObject queryObject)
Returnes the generated SQL source for the given queryObject without any formatting and without comments in a single line. The returned String will have no occurence of more than one blank " " or and no occurence of a line break "\n", so that for any given SQLQueryObject queryObject getSQLSourceUnformatted(queryObject).indexOf(" "+" ") < 0 is true and getSQLSourceUnformatted(queryObject).indexOf("\n") < 0 is true.

Parameters:
queryObject - a SQLQueryObject to get the SQL source for
Returns:
the SQL source String of the given queryObject without any formatting

getSQLSourceUnformatted

public static java.lang.String getSQLSourceUnformatted(java.lang.String queryStmt)
Returnes the given SQL source String in a single line without any formatting. The returned String will have no occurence of more than one blank " " or and no occurence of a line break "\n", so that for any given QueryStatement queryStmt getSQLSourceUnformatted(queryStmt).indexOf(" "+" ") < 0 is true and getSQLSourceUnformatted(queryStmt).indexOf("\n") < 0 is true.

Note: this method only works on SQL statements without single-line comments! Use #stripWhiteSpaceAndComments(String, char) for SQL that contains comments.

Parameters:
queryStmt - the SQL source String of a QueryStatement
Returns:
the given queryStmt SQL source without any formatting

getSQLTableQualified

public static java.lang.String getSQLTableQualified(SQLQueryObject queryObject)
Returns the SQL source text of the given SQLQueryObject with all column references qualified with table names, but all table names unqualified (without schema name).

Note: this method is not Thread -safe, concurrent calls to SQLQueryObject.getSQL() on the given queryObject might not return the expected or even a semantically invalid result.

Parameters:
queryObject -
Returns:
SQL source of the given SQLQueryObject

getSQLUnqualified

public static java.lang.String getSQLUnqualified(SQLQueryObject queryObject)
Returns the SQL source text of the given SQLQueryObject with all identifiers unqualified (column references without table names, and all table references without schema names).

Note: this method is not Thread -safe, concurrent calls to SQLQueryObject.getSQL() on the given queryObject might not return the expected or even a semantically invalid result.

Parameters:
queryObject -
Returns:
SQL source of the given SQLQueryObject

getSQLWithComments

public static java.lang.String getSQLWithComments(SQLQueryObject queryObject)
Returnes the generated SQL source for the given queryObject with all comments.

Parameters:
queryObject - a SQLQueryObject to get the SQL source for
Returns:
the SQL source String of the given queryObject with all comments

getSQLWithoutComments

public static java.lang.String getSQLWithoutComments(SQLQueryObject queryObject)
Returnes the generated SQL source for the given queryObject without any comments.

Parameters:
queryObject - a SQLQueryObject to get the SQL source for
Returns:
the SQL source String of the given queryObject without any comments

getStatementType

public static int getStatementType(QueryStatement statement)
Returns the integer constant defined in this class, that represents the given QueryStatement

Parameters:
statement - the QueryStatement
Returns:
the integer constatnt defined in this class, that represents the given QueryStatement or -1 if no matching is found

getTableExpressionForTable

public static TableExpression getTableExpressionForTable(Table table,
                                                         QuerySelect qSelect)
Returns the TableExpression representing the given Table object,in the given QuerySelect

Parameters:
table - the Table object
qSelect - the QuerySelect in which the TableExpression is searched for
Returns:
the TableExpression object, for the Table object,or null if none is found

getTableExpressionForTable

public static TableExpression getTableExpressionForTable(Table table,
                                                         QuerySelectStatement selectStmt)
Returns the TableExpression representing the given Table object,in the given QuerySelectStatement

Parameters:
table - the Table object
selectStmt - the QuerySelectStatement in which the TableExpression is searched for
Returns:
the TableExpression object, for the Table object,or null if none is found

getTableExpressionsInQueryExpressionBody

public static java.util.List getTableExpressionsInQueryExpressionBody(QueryExpressionBody query)
Parameters:
query -
Returns:

getTableExpressionsInQuerySelect

public static java.util.List getTableExpressionsInQuerySelect(QuerySelect querySelect)

getTableExpressionsVisibleInQuerySelect

public static java.util.List getTableExpressionsVisibleInQuerySelect(QuerySelect querySelect)
Returns the TableExpression s in the given QuerySelect's fromClause plus all the TableExpression s that are visible in the scope of the given QuerySelect, if the QuerySelect given is a nested query or subquery, all the TableExpression s of the super query are appende to the returned list of TableExpressions.

Parameters:
querySelect -
Returns:
List of visible TableExpressions

getTablesForStatement

public static java.util.List getTablesForStatement(QueryStatement stmt)
Returns List of tables (TableExpression) referenced in the statement. For Select statement it returns the source tables of the "From" clause. For Insert, Update and Delete returns the target table.

Parameters:
stmt - the SQLQueryStatement from which the table are wanted
Returns:
the List of table

getTablesForStatement

public static java.util.List getTablesForStatement(SQLQueryObject stmt)

getTemplateSQL

public static java.lang.String getTemplateSQL(int statementType)
Returns the default SQL template for a statement

Parameters:
statementType - the type of the statement
Returns:
the SQL template

isColumnNameAmbiguous

public static boolean isColumnNameAmbiguous(ValueExpressionColumn columnExpr)
Returns true only if the given columnExpr name is equal to another ValueExpressionColumn's name in a different table and therefore needs to be qualified.

Parameters:
columnExpr -
Returns:
true if the given column's name has to be qualified with it's table name/alias

isOrderByClauseContainsValidOrderBySpecification

public static boolean isOrderByClauseContainsValidOrderBySpecification(java.util.List orderByClause)
Returns true, if at least one OrderBySpecification contained in the given orderByClause list is valid.

Returns:

isOrderBySpecificationValid

public static boolean isOrderBySpecificationValid(OrderBySpecification orderBySpec)
Parameters:
orderBySpec -
Returns:

isTableNameAmbiguous

public static boolean isTableNameAmbiguous(TableExpression tableExpr)
Returns true if the given tableExpr's name is not unique within the fromClause of its containing QuerySelect and the other TableExpression s in the fromClause as well as the given TableExpression have no TableCorrelation to distinguish between them. That is important for column references to that table, which will have to get qualified with the table's Schema name.

Parameters:
tableExpr -
Returns:
true if the given tableExpr's name is not unique within the fromClause of its containing QuerySelect and the other TableExpression s in the fromClause as well as the given TableExpression have no TableCorrelation to distinguish between them

isTemplateSQL

public static boolean isTemplateSQL(java.lang.String sql)
Checks to see if the given string is same as the template for any of the DML statements

Parameters:
sql - the string to check if it is the template statement
Returns:
true of if sql is same as a tmplate , false otherwise

logDebug

public static void logDebug(java.lang.String debugMsg)

logError

public static void logError(java.lang.String errorMsg)

omitSchema

public static boolean omitSchema(TableInDatabase tableInDB)
Returns true if the given tableInDB does not have to be qualified with its Schema name.

Note: Assumptions:

Parameters:
tableInDB -
Returns:
true if table name does not have to be qualified

removeCommentsInSQL

public static java.lang.String removeCommentsInSQL(java.lang.String statement,
                                                   char delimitedIdentifierQt)
Walks through the given SQL and strips out the comments that are identified by two dashes in line "--" and that are not part of a delimited character string (single quotes), or SQL delimited object name (double quotes).
NOTE: The given SQL statement string must contain the line-break characters to delimit the "--" comments, otherwise all of the SQL-Statement that comes after the first occurence of a "--" comment be treated as part of the comment and rather be ignored, moreover the resulting statement is likely to fail!

SELECT EMP_NUM FROM DEPARTEMENT -- pre-accumulated number of employees
WHERE LOCATION = 'C-Tower--01' OR LOCATION = 'C-Tower-02'

In this statement the first occurence of "--" would indicate a comment that would be stripped of and the second occurence would be retained, as it is part of a String delimited by the enclosing single quotes.

Parameters:
statement - A SQL statement
delimitedIdentifierQt - the quote char used to prefix and suffix non-standard identifiers or identifiers that are case sensitive
Returns:
The a SQL statement without "--" comments.

removeTableExpressionFromQueryStatement

public static void removeTableExpressionFromQueryStatement(TableExpression tableExpr,
                                                           SQLQueryObject queryObj)
Removes the given TableExpression from the given SQLQueryObject. The SQLQueryObject should be either a QueryStatement or a QuerySelect. All references to columns of the TableExpression are removed as well.

Parameters:
tableExpr - the table expression to remove
queryObj - the query object from which the table expression should be removed

removeValueExpression

public static void removeValueExpression(QueryValueExpression valExpr)
Removes the given ValueExpression object from the object that contains it. If the containing object would then be invalid, remove the containing object as well.

Parameters:
valExpr - the object to remove

resolveOrderByColumns

public static java.util.Set resolveOrderByColumns(QueryExpressionBody queryExpr,
                                                  java.util.List orderByList)
See Also:
resolveOrderByColumns(QuerySelect, List)

resolveOrderByColumns

public static java.util.Set resolveOrderByColumns(QuerySelect select,
                                                  java.util.List orderByList)
Every given OrderBySpecifications contained in the given orderByList, that is of type OrderByValueExpression and its owned ValueExpression is of type ValueExpressionColumn, will be removed from the given QuerySelect and substituted by a new OrderByResultColumn that will then be given the reference to the ValueExpressionColumn formerly associated to the removed OrderByValueExpression, if the given QuerySelect has a ResultColumn that refers by its name to the same ValueExpressionColumn. In other words, the type of a OrderByValueExpression, that references a ValueExpressionColumn also referred to by one ResultColumn of the given select, will be changed to OrderByResultColumn.

Note: Returns the Set of ValueExpressionColumns that have been removed from their OrderByValueExpression.

Parameters:
select -
orderByList - List of OrderBySpecifications referring to the given QuerySelect
Returns:
Set of ValueExpressionColumns that have been removed from their OrderByValueExpression

resolveQueryResultSpecification

public static void resolveQueryResultSpecification(QuerySelect querySelect)
Resolves columnExpressions and tableReferences in given querySelect's QueryResultSpecification ResultColumn or ResultTableAllColumns with the columnExpressions and tableExpressions in the given querySelect's fromClause.

Parameters:
querySelect -

resolveResultTableAllColumns

public static void resolveResultTableAllColumns(QuerySelect querySelect)
Resolves tableReferences in given querySelect's QueryResultSpecifications of type ResultTableAllColumns with the tableExpressions in the given querySelect's fromClause.

Parameters:
querySelect -

resolveWithTableSpecificationReference

public static WithTableReference resolveWithTableSpecificationReference(TableExpression potentialWithTableRef)
Substitutes the given TableReference with the WithTableSpecification that is refered by the given potentialTableWithRef's name, if a TableWithSpecification is found in the QueryExpressionRoot that contains the given TableReference.

Returns:
the substitute TableWithSpecification found

setHavingClauseForStatement

public static void setHavingClauseForStatement(QuerySearchCondition newSearchCon,
                                               QueryStatement statement)
Sets the having clause in the given sql statement.

Parameters:
newSearchCon - new QuerySearchCondition that needs to be set.
statement - the SQL Statement on which new having clause needs to set.

setHavingClauseForStatement

public static void setHavingClauseForStatement(QuerySearchCondition newSearchCon,
                                               SQLQueryObject statement)
Sets the having clause in the given SQLQueryObject.

Parameters:
newSearchCon - new QuerySearchCondition that needs to be set.
statement - the SQLQueryObject on which new having clause needs to set.

setWhereClauseForStatement

public static void setWhereClauseForStatement(QuerySearchCondition newSearchCon,
                                              QueryStatement statement)
Sets the where clause in the given sql statement.

Parameters:
newSearchCon - new QuerySearchCondition that needs to set.
statement - the SQL Statement on which new where clause needs to set.

setWhereClauseForStatement

public static void setWhereClauseForStatement(QuerySearchCondition newSearchCon,
                                              SQLQueryObject statement)
Sets the where clause in the given sqlQueryObject.

Parameters:
newSearchCon - new QuerySearchCondition that needs to set.
statement - the SQLObject on which new where clause needs to set.

addNewName

public void addNewName(Table selectedTable)
Provide the name that will be generated next this is for populating alias text field with a default


createInsertStatement

public QueryInsertStatement createInsertStatement(java.lang.String name,
                                                  boolean addToDb)
Deprecated.  

Parameters:
name -
addToDb -
Returns:

createSelectStatement

public QuerySelectStatement createSelectStatement(java.lang.String name)

createUpdateStatement

public QueryUpdateStatement createUpdateStatement(java.lang.String name,
                                                  boolean addToDb)
Deprecated.  

Parameters:
name -
addToDb -
Returns:

getNewName

public java.lang.String getNewName(QueryInsertStatement insert)


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