org.eobjects.metamodel.query
Class SelectItem

java.lang.Object
  extended by org.eobjects.metamodel.util.BaseObject
      extended by org.eobjects.metamodel.query.SelectItem
All Implemented Interfaces:
Serializable, Cloneable, QueryItem

public class SelectItem
extends BaseObject
implements QueryItem, Cloneable

Represents a SELECT item. SelectItems can take different forms:

See Also:
SelectClause, Serialized Form

Constructor Summary
SelectItem(Column column)
          Creates a simple SelectItem that selects from a column
SelectItem(Column column, FromItem fromItem)
          Creates a SelectItem that references a column from a particular FromItem, for example a.price or p.age
SelectItem(FunctionType function, Column column)
          Creates a SelectItem that uses a function on a column, for example SUM(price) or MAX(age)
SelectItem(FunctionType function, Column column, FromItem fromItem)
          Creates a SelectItem that uses a function on a column from a particular FromItem, for example SUM(a.price) or MAX(p.age)
SelectItem(FunctionType function, String expression, String alias)
          Creates a SelectItem based on a function and an expression.
SelectItem(SelectItem subQuerySelectItem, FromItem subQueryFromItem)
          Creates a SelectItem that references another select item in a subquery
SelectItem(String expression, String alias)
          Creates a SelectItem based on an expression.
 
Method Summary
protected  SelectItem clone()
           
protected  void decorateIdentity(List<Object> identifiers)
          Subclasses should implement this method and add all fields to the list that are to be included in equals(...) and hashCode() evaluation
 boolean equalsIgnoreAlias(SelectItem that)
           
 boolean equalsIgnoreAlias(SelectItem that, boolean exactColumnCompare)
           
 String getAlias()
           
 Column getColumn()
           
static SelectItem getCountAllItem()
          Generates a COUNT(*) select item
 ColumnType getExpectedColumnType()
          Tries to infer the ColumnType of this SelectItem.
 String getExpression()
           
 FromItem getFromItem()
           
 FunctionType getFunction()
           
 Query getQuery()
           
 String getSameQueryAlias()
           
 String getSameQueryAlias(boolean includeSchemaInColumnPath)
           
 FromItem getSubQueryFromItem()
          Deprecated. use getFromItem() instead
 SelectItem getSubQuerySelectItem()
           
 String getSuperQueryAlias()
           
 String getSuperQueryAlias(boolean includeQuotes)
           
static boolean isCountAllItem(SelectItem item)
           
 boolean isFunctionApproximationAllowed()
           
 boolean isReferenced(Column column)
          Investigates whether or not this SelectItem references a particular column.
 SelectItem replaceFunction(FunctionType function)
          Creates a copy of the SelectItem, with a different FunctionType.
 SelectItem setAlias(String alias)
           
 void setFunctionApproximationAllowed(boolean functionApproximationAllowed)
           
 SelectItem setQuery(Query query)
           
 String toSql()
           
 String toSql(boolean includeSchemaInColumnPath)
           
 String toString()
           
 StringBuilder toStringNoAlias()
           
 StringBuilder toStringNoAlias(boolean includeSchemaInColumnPath)
           
 
Methods inherited from class org.eobjects.metamodel.util.BaseObject
classEquals, equals, hashCode
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SelectItem

public SelectItem(Column column)
Creates a simple SelectItem that selects from a column

Parameters:
column -

SelectItem

public SelectItem(FunctionType function,
                  Column column)
Creates a SelectItem that uses a function on a column, for example SUM(price) or MAX(age)

Parameters:
function -
column -

SelectItem

public SelectItem(Column column,
                  FromItem fromItem)
Creates a SelectItem that references a column from a particular FromItem, for example a.price or p.age

Parameters:
column -
fromItem -

SelectItem

public SelectItem(FunctionType function,
                  Column column,
                  FromItem fromItem)
Creates a SelectItem that uses a function on a column from a particular FromItem, for example SUM(a.price) or MAX(p.age)

Parameters:
function -
column -
fromItem -

SelectItem

public SelectItem(String expression,
                  String alias)
Creates a SelectItem based on an expression. All expression-based SelectItems must have aliases.

Parameters:
expression -
alias -

SelectItem

public SelectItem(FunctionType function,
                  String expression,
                  String alias)
Creates a SelectItem based on a function and an expression. All expression-based SelectItems must have aliases.

Parameters:
function -
expression -
alias -

SelectItem

public SelectItem(SelectItem subQuerySelectItem,
                  FromItem subQueryFromItem)
Creates a SelectItem that references another select item in a subquery

Parameters:
subQuerySelectItem -
subQueryFromItem - the FromItem that holds the sub-query
Method Detail

getCountAllItem

public static SelectItem getCountAllItem()
Generates a COUNT(*) select item


isCountAllItem

public static boolean isCountAllItem(SelectItem item)

getAlias

public String getAlias()

setAlias

public SelectItem setAlias(String alias)

getFunction

public FunctionType getFunction()

isFunctionApproximationAllowed

public boolean isFunctionApproximationAllowed()
Returns:
if this is a function based SelectItem where function calculation is allowed to be approximated (if the datastore type has an approximate calculation method). Approximated function results are as the name implies not exact, but might be valuable as an optimization in some cases.

setFunctionApproximationAllowed

public void setFunctionApproximationAllowed(boolean functionApproximationAllowed)

getColumn

public Column getColumn()

getExpectedColumnType

public ColumnType getExpectedColumnType()
Tries to infer the ColumnType of this SelectItem. For expression based select items, this is not possible, and the method will return null.

Returns:

getExpression

public String getExpression()

setQuery

public SelectItem setQuery(Query query)
Specified by:
setQuery in interface QueryItem

getQuery

public Query getQuery()
Specified by:
getQuery in interface QueryItem

getSubQuerySelectItem

public SelectItem getSubQuerySelectItem()

getSubQueryFromItem

@Deprecated
public FromItem getSubQueryFromItem()
Deprecated. use getFromItem() instead


getFromItem

public FromItem getFromItem()

getSuperQueryAlias

public String getSuperQueryAlias()
Returns:
the name that this SelectItem can be referenced with, if referenced from a super-query. This will usually be the alias, but if there is no alias, then the column name will be used.

getSuperQueryAlias

public String getSuperQueryAlias(boolean includeQuotes)
Parameters:
includeQuotes - indicates whether or not the output should include quotes, if the select item's column has quotes associated (typically true, but false if used for presentation)
Returns:
the name that this SelectItem can be referenced with, if referenced from a super-query. This will usually be the alias, but if there is no alias, then the column name will be used.

getSameQueryAlias

public String getSameQueryAlias()

getSameQueryAlias

public String getSameQueryAlias(boolean includeSchemaInColumnPath)
Returns:
an alias that can be used in WHERE, GROUP BY and ORDER BY clauses in the same query

toSql

public String toSql()
Specified by:
toSql in interface QueryItem

toSql

public String toSql(boolean includeSchemaInColumnPath)
Specified by:
toSql in interface QueryItem

toStringNoAlias

public StringBuilder toStringNoAlias()

toStringNoAlias

public StringBuilder toStringNoAlias(boolean includeSchemaInColumnPath)

equalsIgnoreAlias

public boolean equalsIgnoreAlias(SelectItem that)

equalsIgnoreAlias

public boolean equalsIgnoreAlias(SelectItem that,
                                 boolean exactColumnCompare)

decorateIdentity

protected void decorateIdentity(List<Object> identifiers)
Description copied from class: BaseObject
Subclasses should implement this method and add all fields to the list that are to be included in equals(...) and hashCode() evaluation

Specified by:
decorateIdentity in class BaseObject

clone

protected SelectItem clone()
Overrides:
clone in class Object

replaceFunction

public SelectItem replaceFunction(FunctionType function)
Creates a copy of the SelectItem, with a different FunctionType.

Parameters:
function -
Returns:

isReferenced

public boolean isReferenced(Column column)
Investigates whether or not this SelectItem references a particular column. This will search for direct references and indirect references via subqueries.

Parameters:
column -
Returns:
a boolean that is true if the specified column is referenced by this SelectItem and false otherwise.

toString

public String toString()
Specified by:
toString in interface QueryItem
Overrides:
toString in class BaseObject


Copyright © 2007-2013. All Rights Reserved.