org.eclipse.datatools.sqltools.sqlbuilder.model
Class ExpressionHelper

java.lang.Object
  extended by org.eclipse.datatools.sqltools.sqlbuilder.model.ExpressionHelper

public class ExpressionHelper
extends java.lang.Object

Helper class for manipulating QueryValueExpression


Constructor Summary
ExpressionHelper()
           
 
Method Summary
static void addExpression(QueryValueExpression prevExpr, QueryValueExpression newExpr, ValueExpressionCombinedOperator operator)
          Adds an expression to the expression tree
 java.lang.String appendQuotes(DataType columnType, java.lang.String value)
          Adds quotes to the string value passed which has given DataType.
 java.lang.String appendQuotes(int columnType, java.lang.String value)
          Adds quotes to the string value passed
 java.lang.String appendQuotes(java.lang.String columnType, java.lang.String value)
          Adds quotes to the string value passed.
 boolean containsParameterName(java.lang.String source)
          Determines whether or not the given SQL string contains a parameter name.
 ValueExpressionCast createCast(QueryValueExpression expr, java.lang.String dataType)
          Creates a cast expression
static ValueExpressionColumn createColumnExpression(TableExpression table, Column col)
          Creates a SQLColumnExpression for the given table and column.
static ValueExpressionCombinedOperator createCombinedOperator(java.lang.String opType)
           
static QueryValueExpression createExpression()
           
static QueryValueExpression createExpression(java.lang.Object item)
          Build a QueryValueExpression object from the input
static ValueExpressionFunction createFunction(java.lang.String functionName)
          Create a ValueExpressionFunction , given a function name, An example of using this call will be to create function such as CURRENT DATE, CURRENT TIME
static ValueExpressionFunction createFunction(java.lang.String functionName, java.util.List parmList)
          Create a ValueExpressionFunction given a function name and a parameter list.
static ValueExpressionNested createNestedExpression(QueryValueExpression expr)
           
 PredicateBasic createPredicate(java.lang.Object left, java.lang.Object right, java.lang.String comparisonKind)
          Create a SQLPredicate object given a left, right and comparsionKind If the comparisonKind requires no right side, set the right side to ""
 ValueExpressionScalarSelect createScalarSelect(QueryStatement stmt)
          Creates a subquery statement expression
static ValueExpressionColumn createValueExpressionColumn(java.lang.String name, TableExpression tblExpr)
          Builds a ValueExpressionColumn object and sets the given name and TableExpression.
static ValueExpressionColumn createValueExpressionColumn(ValueExpressionColumn oldValExpr)
          Builds a ValueExpressionColumn object from the given ValueExpressionColumn.
static QueryValueExpression createValueExpressionDefaultValue()
           
static QueryValueExpression createValueExpressionNullValue()
           
 boolean firstParameterChar(java.lang.String source)
          Determines whether or not the given SQL string starts with a parameter character name.
static java.lang.String getDefaultValueForColumn(Column aColumn)
          Gets an acceptable default value (as a string) for the given database column, based on its datatype.
static java.lang.String getDisplayString(java.lang.String opString)
           
static QueryValueExpression getLowestLeftChild(QueryValueExpression expr)
           
 java.lang.String getQuotesContext()
          Get the Context of the variable which needs quotes.
static QueryValueExpression getRoot(QueryValueExpression node)
          Returns the root node of the tree in which the given node is a left side child.
static TableExpression getTableExprForValueExpressionColumn(ValueExpressionColumn colValExp)
          Returns the TableExpression for the given ValueExpressionColumn.
static boolean isComplete(QueryValueExpression expr)
           
static void removeExpression(QueryValueExpression expr)
          Removes the given expression from a tree of expressions The expression tree for the expression A + B - C is as follows - + C A B
static void replaceExpression(QueryValueExpression oldExpr, QueryValueExpression newExpr)
          Replaces an expression in an expression tree with a new expression.
static void replaceOperator(QueryValueExpression expression, ValueExpressionCombinedOperator newOperator)
          Replaces the operator on a ValueExpressionCombined node in the expression tree The expression tree for the expression A + B - C is as follows - + C A B
 void resolveColumnReferencesInTemporaryStatement(QuerySelect select, java.util.List tableExprList)
          Unhooks all the ValueExpressionColumn s in the given temporary QuerySelect and hooks them into the corresponding TableExpression s in the given tableExprList, regardless of duplicate column names - identical logical column references.
 void setQuotesContext(java.lang.String quotesContext)
          Set the Context of the variable which needs quotes.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExpressionHelper

public ExpressionHelper()
Method Detail

containsParameterName

public boolean containsParameterName(java.lang.String source)
Determines whether or not the given SQL string contains a parameter name.

Parameters:
source - the SQL source to check
Returns:
true when the source contains a parameter name, otherwise false

firstParameterChar

public boolean firstParameterChar(java.lang.String source)
Determines whether or not the given SQL string starts with a parameter character name.

Parameters:
source - the SQL source to check
Returns:
true when the source starts with parameter character, otherwise false

createValueExpressionColumn

public static ValueExpressionColumn createValueExpressionColumn(java.lang.String name,
                                                                TableExpression tblExpr)
Builds a ValueExpressionColumn object and sets the given name and TableExpression.

Parameters:
name - the String name for the new ValueExpressionColumn
tblExpr - the TableExpression that needs to be set for the new ValueExpressionColumn
Returns:
the newly created QueryValueExpression

createValueExpressionColumn

public static ValueExpressionColumn createValueExpressionColumn(ValueExpressionColumn oldValExpr)
Builds a ValueExpressionColumn object from the given ValueExpressionColumn.

Parameters:
oldValExpr - the ValueExpressionColumn that needs to be set for the new ValueExpressionColumn
Returns:
the newly created QueryValueExpression

createValueExpressionNullValue

public static QueryValueExpression createValueExpressionNullValue()

createValueExpressionDefaultValue

public static QueryValueExpression createValueExpressionDefaultValue()

createExpression

public static QueryValueExpression createExpression()

createExpression

public static QueryValueExpression createExpression(java.lang.Object item)
Build a QueryValueExpression object from the input


createColumnExpression

public static ValueExpressionColumn createColumnExpression(TableExpression table,
                                                           Column col)
Creates a SQLColumnExpression for the given table and column.

Parameters:
table - the table containing the column
col - the column for which a column expression object is wanted
Returns:
the new column expression object

createPredicate

public PredicateBasic createPredicate(java.lang.Object left,
                                      java.lang.Object right,
                                      java.lang.String comparisonKind)
Create a SQLPredicate object given a left, right and comparsionKind If the comparisonKind requires no right side, set the right side to ""


createFunction

public static ValueExpressionFunction createFunction(java.lang.String functionName)
Create a ValueExpressionFunction , given a function name, An example of using this call will be to create function such as CURRENT DATE, CURRENT TIME

Parameters:
functionName - - the name of the function

createFunction

public static ValueExpressionFunction createFunction(java.lang.String functionName,
                                                     java.util.List parmList)
Create a ValueExpressionFunction given a function name and a parameter list. Examples of using this call be: - MAX(Salary) - CORRELATION(Salary, Bonus) - CHAR(Staring + Duration, USA)

Parameters:
functionName - - the name of the function
parmList - - the parm list See createList, and createExpressionGroup for more information

createScalarSelect

public ValueExpressionScalarSelect createScalarSelect(QueryStatement stmt)
Creates a subquery statement expression


createCast

public ValueExpressionCast createCast(QueryValueExpression expr,
                                      java.lang.String dataType)
Creates a cast expression


getQuotesContext

public java.lang.String getQuotesContext()
Get the Context of the variable which needs quotes. depending upon the context "NULL" and "Default" is ignored from being quoted

Returns:
Returns the quotesContext.

setQuotesContext

public void setQuotesContext(java.lang.String quotesContext)
Set the Context of the variable which needs quotes. depending upon the context "NULL" and "Default" is ignored from being quoted

Parameters:
quotesContext - The quotesContext to set.

appendQuotes

public java.lang.String appendQuotes(DataType columnType,
                                     java.lang.String value)
Adds quotes to the string value passed which has given DataType.

Parameters:
the - DataType of the value passed
value - the String value that needs quotes
Returns:
quoted value

appendQuotes

public java.lang.String appendQuotes(java.lang.String columnType,
                                     java.lang.String value)
Adds quotes to the string value passed.

Parameters:
columntype - the name of the datatype
value - the String value that needs quotes
Returns:
quoted value

appendQuotes

public java.lang.String appendQuotes(int columnType,
                                     java.lang.String value)
Adds quotes to the string value passed

Parameters:
columntype - - SQLDefinedType datatype
value - - string value needs quotes
Returns:
- string quoted value

resolveColumnReferencesInTemporaryStatement

public void resolveColumnReferencesInTemporaryStatement(QuerySelect select,
                                                        java.util.List tableExprList)
Unhooks all the ValueExpressionColumn s in the given temporary QuerySelect and hooks them into the corresponding TableExpression s in the given tableExprList, regardless of duplicate column names - identical logical column references. All the ValueExpressionColumn s in the given temporary QuerySelect must reference to one TableReference in the given temporary QuerySelect'sfromClause, in order to be detached from their temporary TableReference and attached to a corresponding TableReference in the given tableExprList.

Note: All TableReference in the given QuerySelect's fromClause and the given tableExprList, that belong to the default Schema, must all either be not qualified with their Schema name or must all be qualified with their Schema name.

Parameters:
select - a temporary valid QuerySelect with fromClause
tableExpressionList - a List of TableExpression s

createNestedExpression

public static ValueExpressionNested createNestedExpression(QueryValueExpression expr)

isComplete

public static boolean isComplete(QueryValueExpression expr)

replaceExpression

public static void replaceExpression(QueryValueExpression oldExpr,
                                     QueryValueExpression newExpr)
Replaces an expression in an expression tree with a new expression. If the expression is to be replaced is not a node in a tree of expressions, nothing is changed The expression tree for the expression A + B - C is as follows - + C A B

Parameters:
oldExpr - the QueryValueExpression to be replaced
newExpr - the new QueryValueExpression

replaceOperator

public static void replaceOperator(QueryValueExpression expression,
                                   ValueExpressionCombinedOperator newOperator)
Replaces the operator on a ValueExpressionCombined node in the expression tree The expression tree for the expression A + B - C is as follows - + C A B

Parameters:
expression - the expression in the same row as that of the operator being replaced, int the expressionbuilder UI
newOperator - the new operator to be set in the tree

addExpression

public static void addExpression(QueryValueExpression prevExpr,
                                 QueryValueExpression newExpr,
                                 ValueExpressionCombinedOperator operator)
Adds an expression to the expression tree

Parameters:
prevExpr - the expression the row above this expression is to be added in the expression builder UI
newExpr - the new expression to be added to the tree
operator - the new operator

removeExpression

public static void removeExpression(QueryValueExpression expr)
Removes the given expression from a tree of expressions The expression tree for the expression A + B - C is as follows - + C A B

Parameters:
expr - the expression to be removed

getDisplayString

public static java.lang.String getDisplayString(java.lang.String opString)

createCombinedOperator

public static ValueExpressionCombinedOperator createCombinedOperator(java.lang.String opType)

getRoot

public static QueryValueExpression getRoot(QueryValueExpression node)
Returns the root node of the tree in which the given node is a left side child. Traverses up the tree recursively, finding in each recursion, the parent node of which the given node is a left side child.Recursion does not proceed if the given node is a right child of any parent node

Parameters:
node - a node in the tree
Returns:

getLowestLeftChild

public static QueryValueExpression getLowestLeftChild(QueryValueExpression expr)

getTableExprForValueExpressionColumn

public static TableExpression getTableExprForValueExpressionColumn(ValueExpressionColumn colValExp)
Returns the TableExpression for the given ValueExpressionColumn.

Parameters:
colValExp - the given ValueExpressionColumn for which TableExpression is needed
Returns:
the TableExpression

getDefaultValueForColumn

public static java.lang.String getDefaultValueForColumn(Column aColumn)
Gets an acceptable default value (as a string) for the given database column, based on its datatype. This can be used for INSERT and UPDATE statements. String and date, time, and timestamp values are surrounded by single quotes.

Parameters:
aColumn - a column for which the default value is needed
Returns:
the default value string