|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.datatools.modelbase.sql.query.helper.StatementHelper
public class StatementHelper
Nested Class Summary | |
---|---|
static class |
StatementHelper.ValueExpressionComparator
Comparator for sorting ValueExpressionVariables. |
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 |
concatName(java.lang.String name,
int count)
Return a new name concatonating the int (inside delimiters if need be) Assumes that the name is well formed, ending with a delimiter if it begins with one. |
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 QueryNested |
createQueryNested()
Creates a QueryNested object. |
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 ident1,
java.lang.String ident2)
Determines whether two SQL identifiers are equal, respecting delimited identifiers using the default delimited identifier quote character. |
static boolean |
equalSQLIdentifiers(java.lang.String ident1,
java.lang.String ident2,
char delimiterChar)
Determines whether two SQL identifiers are equal, respecting delimited identifiers using the given quote character 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 |
getAllParameterMarkersInQueryStatement(QueryStatement queryStmt)
Gets all the parameter marker-type ("?") variables in the given query statement. |
static java.util.List |
getAllVariablesInQueryStatement(QueryStatement queryStmt)
Returns all ValueExpressionVariables contained in the
given QueryStatement . |
static java.util.List |
getAllVariablesInQueryStatement(QueryStatement queryStmt,
boolean nameParameterMarkers)
Returns all ValueExpressionVariables contained in the
given QueryStatement . |
static java.util.List |
getAllVariablesInQueryStatement(QueryStatement queryStmt,
boolean nameParameterMarkers,
java.lang.String varStem)
Returns all ValueExpressionVariables contained in the
given QueryStatement . |
static java.util.List |
getAllVariablesInQueryStatement(QueryStatement queryStmt,
java.lang.String varStem)
Returns all ValueExpressionVariables contained in the
given QueryStatement . |
static Database |
getDatabase(QueryStatement stmt)
Returns the Database for which SQL Statement is associated with. |
static char |
getDELIMITED_IDENTIFIER_QUOTE()
Gets the DELIMITED_IDENTIFIER_QUOTE char. |
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 TableInDatabase s, that the given
columnExpr s 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 ValueExpressionColumn s
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 QueryResultSpecification s
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
TableExpression s. |
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 java.lang.String |
getUniqueVarName(java.util.Vector varNames,
java.lang.String name)
Return a unique name for adding an attribute by appending a count to the passed string and also checking for the existence of the name in the vector. |
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 |
isNameUnique(java.util.Vector names,
java.lang.String uniqueName)
Checks the passed uniqueName is in the passed array names and returns false if found, true otherwise. |
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 OrderBySpecification s 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
QueryResultSpecification s 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 |
setDELIMITED_IDENTIFIER_QUOTE(char delimited_identifier_quote)
Sets the DELIMITED_IDENTIFIER_QUOTE char to make this class 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 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. |
static java.lang.String |
stripWhiteSpace(java.lang.String sql,
char delimitedIdentifierQt)
Strips of the optional whitespace from the given sql and
replaces all new lines with single spaces. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static char DELIMITED_IDENTIFIER_QUOTE
public static final int STATEMENT_TYPE_DELETE
public static final int STATEMENT_TYPE_FULLSELECT
public static final int STATEMENT_TYPE_INSERT
public static final int STATEMENT_TYPE_SELECT
public static final int STATEMENT_TYPE_UPDATE
public static final int STATEMENT_TYPE_WITH
Constructor Detail |
---|
public StatementHelper()
public StatementHelper(Database database)
Method Detail |
---|
public static char getDELIMITED_IDENTIFIER_QUOTE()
public static void setDELIMITED_IDENTIFIER_QUOTE(char delimited_identifier_quote)
public static int compareSQL(java.lang.String sql1, java.lang.String sql2)
sql1
- sql2
-
0
if the given SQL fragments are syntactically
equivalentpublic static int compareSQL(java.lang.String sql1, java.lang.String sql2, char identifierDelimiterQt)
sql1
- sql2
- identifierDelimiterQt
-
0
if the given SQL fragments are syntactically
equivalentpublic static java.lang.String convertCatalogIdentifierToSQLFormat(java.lang.String catalogIdentifier, char idDelimiterQuote)
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 |
catalogIdentifier
- identifier in catalog formatidDelimiterQuote
-
public static java.lang.String convertSQLIdentifierToCatalogFormat(java.lang.String sqlIdentifier, char idDelimiterQuote)
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 |
sqlIdentifier
- identifier in SQL formatidDelimiterQuote
-
public static ValueExpressionColumn createColumnExpression(java.lang.String name)
ValueExpressionColumn
with the given name.
name
- optional name of the result column
public static ColumnName createColumnName(java.lang.String name)
name
- the String name of the ColumnName.
public static QueryDeleteStatement createDeleteStatement(java.lang.String name)
public static QueryInsertStatement createInsertStatement(java.lang.String name)
public static QueryCombined createQueryCombined()
public static QuerySelectStatement createQueryCombinedStatement(java.lang.String name)
name
- the name of the statement.
public static QueryExpressionRoot createQueryExpressionRoot()
public static QueryExpressionRoot createQueryExpressionRoot(QuerySelectStatement aParent)
aParent
- the parent QuerySelectStatement
public static QueryNested createQueryNested()
public static QuerySelect createQuerySelect()
public static QuerySelect createQuerySelect(QueryExpressionRoot anExpRoot)
anExpRoot
- the QueryExpressionRoot
public static QuerySelect createQuerySelect(QuerySelectStatement aStatement)
aStatement
- the QuerySelectStatement
public static QuerySelectStatement createQuerySelectStatement(java.lang.String aName)
aName
- the name of the statement
public static QueryStatement createQueryStatement(int stmtType, java.lang.String stmtName)
stmtType
- the requested statement typestmtName
- the name for the statement
public static QueryUpdateStatement createUpdateStatement(java.lang.String name)
public static QuerySelectStatement createWithStatement(java.lang.String name)
name
- the String name of the statement.
public static WithTableReference createWithTableReferenceForWithTable(WithTableSpecification withTableSpec)
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.
withTableSpec
-
public static boolean equalSQLIdentifiers(java.lang.String ident1, java.lang.String ident2)
ident1
- a SQL identifierident2
- another SQL identifier
public static boolean equalSQLIdentifiers(java.lang.String ident1, java.lang.String ident2, char delimiterChar)
ident1
- a SQL identifierident2
- another SQL identifieridentDelimiterQuote
- the delimiter char
public static ResultColumn findResultColumnForColumnExpression(QuerySelect select, ValueExpressionColumn columnExpr)
null
or the ResultColumn
of the
given QuerySelect
whose ValueExpression
is
of type ValueExpressionColumn
which in name
and tableExpr
equals the given columnExpr
.
select
- columnExpr
- a ValueExpressionColumn
public static ResultColumn findResultColumnForColumnNameOrAlias(QuerySelect select, java.lang.String columnNameOrAlias)
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
.
select
- columnNameOrAlias
-
public static java.util.List getAllParameterMarkersInQueryStatement(QueryStatement queryStmt)
queryStmt
-
public static java.util.List getAllVariablesInQueryStatement(QueryStatement queryStmt)
ValueExpressionVariables
contained in the
given QueryStatement
. All parameter marker-type ("?")
variables will be modified to have names VAR0n where n is a sequence
number.
queryStmt
- the statement from which variables are wanted
ValueExpressionVariable
public static java.util.List getAllVariablesInQueryStatement(QueryStatement queryStmt, java.lang.String varStem)
ValueExpressionVariables
contained in the
given QueryStatement
.
queryStmt
- A SQL statement that might have host variables or parameter markersvarStem
- The stem for naming variables from parameter markers
ValueExpressionVariable
public static java.util.List getAllVariablesInQueryStatement(QueryStatement queryStmt, boolean nameParameterMarkers)
ValueExpressionVariables
contained in the
given QueryStatement
.
queryStmt
- A SQL statement that might have host variables or parameter markersnameParameterMarkers
- True if you wish to generate names for parameter markers
ValueExpressionVariable
public static java.util.List getAllVariablesInQueryStatement(QueryStatement queryStmt, boolean nameParameterMarkers, java.lang.String varStem)
ValueExpressionVariables
contained in the
given QueryStatement
.
queryStmt
- A SQL statement that might have host variables or parameter markersnameParameterMarkers
- True if you wish to generate names for parameter markersvarStem
- The stem for naming variables from parameter markers
ValueExpressionVariable
public static java.lang.String getUniqueVarName(java.util.Vector varNames, java.lang.String name)
attrNames
- All attribute names in the type including the
inherited attribute names.name
- Name that we append count to.
public static boolean isNameUnique(java.util.Vector names, java.lang.String uniqueName)
names
- Array of namesuniqueName
- The name to be checked.
public static java.lang.String concatName(java.lang.String name, int count)
public static Database getDatabase(QueryStatement stmt)
stmt
- the SQLQueryStatement for which Database is needed
public static TableInDatabase getDerivedDatabaseTable(ValueExpressionColumn columnExpr)
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".
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
)
TableInDatabase
the given column was derived
from or null
if the given column is not derived
from a TableInDatabase
public static java.util.List getDerivedDatabaseTables(java.util.List columnExprList)
TableInDatabase
s, that the given
columnExpr
s 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".
columnExprList
- a List of ValueExpressionColumn
s
that are part of a TableExpression
s
columnList
(
TableExpression.getColumnList()
), the tables exposed
ordered result columns (not the ResultColumn
of a
QuerySelect
!)
TableInDatabase
s that the given
columns were derived from, can be emptypublic static java.util.Set getDirectReferences(EObject eObject, java.lang.Class typeFilter)
eObject
that are of type or a subtype of the given typeFilter
.
eObject
- the EObject we want to find refernces fortypeFilter
- optional the type of the refernced Objects to be
returned, may be null
or Object.class
to not filter the refernces
public static SQLQueryObject getEContainerRecursively(EObject eObject, java.lang.Class containerType)
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
.
eObject
- containerType
-
SQLQueryObject
of type containerType
that ultimately contains the given eObject
public static java.util.List getEffectiveResultColumns(QuerySelectStatement selectStmt)
ValueExpressionColumn
s
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.
selectStmt
-
ValueExpressionColumn
spublic static QuerySearchCondition getHavingCondition(QueryStatement stmt)
stmt
- the QueryStatement for which Having clause needs to be
returned
public static QuerySearchCondition getHavingCondition(SQLQueryObject stmt)
public static Predicate getPredicateOfVariable(ValueExpressionVariable variable)
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.
variable
-
Predicate
referencing the given
ValueExpressionVariable
public static QuerySelect getQuerySelectForTableReference(TableExpression tableExpr)
QuerySelect
that contains the given
tableExpr
in its fromClause
.
tableExpr
-
QuerySelect
public static QueryStatement getQueryStatementForTableReference(TableReference tableRef)
QueryStatement
associated with the given
tableRef
.
tableRef
-
public static java.util.Set getReferencesRecursively(EObject eObject, java.lang.Class typeFilter)
eObject
, that are of type or a subtype of the given
typeFilter
.
eObject
- the object we want to find refernces oftypeFilter
- optional the type of the refernced Objects to be
returned, may be null
or Object.class
to not filter the refernces
EObject
s referenced recursively of type
assignable to typeFilter
public static java.util.Set getReferencesViaSpecificReferencePaths(EObject eObject, java.lang.Class typeFilter, java.lang.Class[] referencePathTypes)
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
.
eObject
- the object we want to find refernces oftypeFilter
- optional the type of the refernced Objects to be
returned, may be null
or Object.class
to not filter the referncesreferencePathTypes
- the types of references that are traversed to
reach Objects indirectly referenced by the given
eObject
EObject
s referenced recursivelypublic static java.util.List getResultTableAllColumnsInQueryResultSpecificationList(java.util.List queryResultSpecList)
QueryResultSpecification
s
in the given queryResultSpecList
that are of type
ResultTableAllColumns
.
queryResultSpecList
- a List of QueryResultSpecification
ResultTableAllColumns
public static QuerySearchCondition getSearchCondition(QueryStatement stmt)
stmt
- the QueryStatement for which search condition needs to be
returned
public static QuerySearchCondition getSearchCondition(SQLQueryObject stmt)
public static java.lang.String getSQLForExecution(SQLQueryObject queryObject)
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.
queryObject
- a SQLQueryObject
to get the SQL source
for
queryObject
without any comments and qualified tablespublic static java.lang.String getSQLQualified(SQLQueryObject queryObject, int qualificationSpec)
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.
queryObject
- qualificationSpec
- SQLQuerySourceFormat.QUALIFY_IDENTIFIERS_WITH_SCHEMA_NAMES
SQLQuerySourceFormat.QUALIFY_IDENTIFIERS_WITH_TABLE_NAMES
SQLQuerySourceFormat.QUALIFY_IDENTIFIERS_NEVER
SQLQuerySourceFormat.QUALIFY_IDENTIFIERS_IN_CONTEXT
SQLQueryObject
public static java.lang.String getSQLSchemaQualified(SQLQueryObject queryObject)
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.
queryObject
-
SQLQueryObject
public static java.lang.String getSQLSourceUnformatted(SQLQueryObject queryObject)
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
.
queryObject
- a SQLQueryObject
to get the SQL source
for
queryObject
without any formattingpublic static java.lang.String getSQLSourceUnformatted(java.lang.String queryStmt)
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.
queryStmt
- the SQL source String of a QueryStatement
queryStmt
SQL source without any
formattingpublic static java.lang.String getSQLTableQualified(SQLQueryObject queryObject)
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.
queryObject
-
SQLQueryObject
public static java.lang.String getSQLUnqualified(SQLQueryObject queryObject)
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.
queryObject
-
SQLQueryObject
public static java.lang.String getSQLWithComments(SQLQueryObject queryObject)
queryObject
with all comments.
queryObject
- a SQLQueryObject
to get the SQL source
for
queryObject
with all commentspublic static java.lang.String getSQLWithoutComments(SQLQueryObject queryObject)
queryObject
without any comments.
queryObject
- a SQLQueryObject
to get the SQL source
for
queryObject
without any commentspublic static int getStatementType(QueryStatement statement)
statement
- the QueryStatement
public static TableExpression getTableExpressionForTable(Table table, QuerySelect qSelect)
table
- the Table objectqSelect
- the QuerySelect in which the TableExpression is searched
for
public static TableExpression getTableExpressionForTable(Table table, QuerySelectStatement selectStmt)
table
- the Table objectselectStmt
- the QuerySelectStatement in which the TableExpression
is searched for
public static java.util.List getTableExpressionsInQueryExpressionBody(QueryExpressionBody query)
query
-
public static java.util.List getTableExpressionsInQuerySelect(QuerySelect querySelect)
public static java.util.List getTableExpressionsVisibleInQuerySelect(QuerySelect querySelect)
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
TableExpression
s.
querySelect
-
TableExpression
spublic static java.util.List getTablesForStatement(QueryStatement stmt)
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.
stmt
- the SQLQueryStatement from which the table are wanted
public static java.util.List getTablesForStatement(SQLQueryObject stmt)
public static java.lang.String getTemplateSQL(int statementType)
statementType
- the type of the statement
public static boolean isColumnNameAmbiguous(ValueExpressionColumn columnExpr)
true
only if the given columnExpr
name is equal to another ValueExpressionColumn
's name in
a different table and therefore needs to be qualified.
columnExpr
-
public static boolean isOrderByClauseContainsValidOrderBySpecification(java.util.List orderByClause)
true
, if at least one
OrderBySpecification
contained in the given
orderByClause
list is valid.
public static boolean isOrderBySpecificationValid(OrderBySpecification orderBySpec)
orderBySpec
-
public static boolean isTableNameAmbiguous(TableExpression tableExpr)
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.
tableExpr
-
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 thempublic static boolean isTemplateSQL(java.lang.String sql)
sql
- the string to check if it is the template statement
public static void logDebug(java.lang.String debugMsg)
public static void logError(java.lang.String errorMsg)
public static boolean omitSchema(TableInDatabase tableInDB)
true
if the given tableInDB
does
not have to be qualified with its Schema
name.
Note: Assumptions:
tableInDB
is not null
tableInDB
has (indirect) reference to its
QueryStatement
QueryStatement
has reference to its
SQLQuerySourceInfo
and that way indirectly a reference to
a SQLQuerySourceFormat
(com.ibm.db.models.sql.query.util.SQLQuerySourceFormat#getOmitSchema()
)
tableInDB
-
true
if table name does not have to be qualifiedpublic static java.lang.String removeCommentsInSQL(java.lang.String statement, char delimitedIdentifierQt)
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.
statement
- A SQL statementdelimitedIdentifierQt
- the quote char used to prefix and suffix
non-standard identifiers or identifiers that are case sensitive
public static void removeTableExpressionFromQueryStatement(TableExpression tableExpr, SQLQueryObject queryObj)
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.
tableExpr
- the table expression to removequeryObj
- the query object from which the table expression should
be removedpublic static void removeValueExpression(QueryValueExpression valExpr)
valExpr
- the object to removepublic static java.util.Set resolveOrderByColumns(QueryExpressionBody queryExpr, java.util.List orderByList)
resolveOrderByColumns(QuerySelect, List)
public static java.util.Set resolveOrderByColumns(QuerySelect select, java.util.List orderByList)
OrderBySpecification
s 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 ValueExpressionColumn
s
that have been removed from their OrderByValueExpression
.
select
- orderByList
- List of OrderBySpecification
s
referring to the given QuerySelect
ValueExpressionColumn
s that have been
removed from their OrderByValueExpression
public static void resolveQueryResultSpecification(QuerySelect querySelect)
querySelect
's QueryResultSpecification
ResultColumn
or ResultTableAllColumns
with the columnExpressions and
tableExpressions in the given querySelect
's
fromClause
.
querySelect
- public static void resolveResultTableAllColumns(QuerySelect querySelect)
querySelect
's
QueryResultSpecification
s of type
ResultTableAllColumns
with the tableExpressions in the
given querySelect
's fromClause
.
querySelect
- public static WithTableReference resolveWithTableSpecificationReference(TableExpression potentialWithTableRef)
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
.
potentialTableWithRef
-
TableWithSpecification
foundpublic static void setHavingClauseForStatement(QuerySearchCondition newSearchCon, QueryStatement statement)
newSearchCon
- new QuerySearchCondition that needs to be set.statement
- the SQL Statement on which new having clause needs to
set.public static void setHavingClauseForStatement(QuerySearchCondition newSearchCon, SQLQueryObject statement)
newSearchCon
- new QuerySearchCondition that needs to be set.statement
- the SQLQueryObject on which new having clause needs to
set.public static void setWhereClauseForStatement(QuerySearchCondition newSearchCon, QueryStatement statement)
newSearchCon
- new QuerySearchCondition that needs to set.statement
- the SQL Statement on which new where clause needs to
set.public static void setWhereClauseForStatement(QuerySearchCondition newSearchCon, SQLQueryObject statement)
newSearchCon
- new QuerySearchCondition that needs to set.statement
- the SQLObject on which new where clause needs to set.public static java.lang.String stripWhiteSpace(java.lang.String sql, char delimitedIdentifierQt)
sql
and
replaces all new lines with single spaces.
Note: this method does not strip comments from the given
sql
and consequently makes any given SQL that contains
comments invalid, unless the comment is on the last line and no valid SQL
succeeds the comment.
Note performance: this method invokes
String.replaceAll(java.lang.String, java.lang.String)
11 times
after walking through the SQL source two times to remove all comments and
transforming the given sql
into upper case format
(respecting delimited identifiers).
sql
- the SQL source stringdelimitedIdentifierQt
- the String that is used to pre- and suffix
delimited identifiers, commonly it is the double-quote char '"'
sql
in upper case, without comments and
with minimal whitespacepublic void addNewName(Table selectedTable)
public QueryInsertStatement createInsertStatement(java.lang.String name, boolean addToDb)
name
- addToDb
-
public QuerySelectStatement createSelectStatement(java.lang.String name)
public QueryUpdateStatement createUpdateStatement(java.lang.String name, boolean addToDb)
name
- addToDb
-
public java.lang.String getNewName(QueryInsertStatement insert)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |