Top Description Fields Constructors Methods
org.eclipse.persistence.internal.jpa.parsing

public Class SelectNode

extends QueryNode
Class Inheritance
Imports
java.util.ArrayList, .Iterator, .List, org.eclipse.persistence.descriptors.ClassDescriptor, org.eclipse.persistence.expressions.Expression, org.eclipse.persistence.queries.DatabaseQuery, .ObjectLevelReadQuery, .ReadAllQuery, .ReportQuery

INTERNAL:

Purpose: Represent a SELECT

Responsibilities:

The SELECT statement determines the return type of an EJBQL query. The SELECT may also determine the distinct state of a query A SELECT can be one of the following:

 1. SELECT OBJECT(someObject)... This query will return a collection of objects
 2. SELECT anObject.anAttribute ... This will return a collection of anAttribute
 3. SELECT <aggregateFunction> ... This will return a single value
     The allowable aggregateFunctions are: AVG, COUNT, MAX, MIN, SUM
         SELECT AVG(emp.salary)... Returns the average of all the employees salaries
         SELECT COUNT(emp)... Returns a count of the employees
         SELECT COUNT(emp.firstName)... Returns a count of the employee's firstNames
         SELECT MAX(emp.salary)... Returns the maximum employee salary
         SELECT MIN(emp.salary)... Returns the minimum employee salary
         SELECT SUM(emp.salary)... Returns the sum of all the employees salaries
Author
Jon Driscoll
Since
TopLink 5.0

Field Summary

Modifier and TypeField and Description
private boolean
private List<String>
private List<Node>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
applyToQuery(DatabaseQuery theQuery, GenerationContext context)

Implements abstract org.eclipse.persistence.internal.jpa.parsing.QueryNode.applyToQuery.

INTERNAL Apply this node to the passed query
public DatabaseQuery
createDatabaseQuery(ParseTreeContext context)

Implements abstract org.eclipse.persistence.internal.jpa.parsing.QueryNode.createDatabaseQuery.

Returns a DatabaseQuery instance representing the owning ParseTree.
public Expression
generateExpression(GenerationContext context)

Implements abstract org.eclipse.persistence.internal.jpa.parsing.QueryNode.generateExpression.

Return a EclipseLink expression generated using the left node.
private Class<?>
private Node
getFirstSelectExpressionNode()

Returns the first select expression node.

public List<String>
public Class<?>

Returns:

the class this query is querying for
getReferenceClass
(GenerationContext context)

Overrides org.eclipse.persistence.internal.jpa.parsing.QueryNode.getReferenceClass.

Compute the Reference class for this query.
public List<Node>
public boolean
private boolean
hasOneToOneSelected(Node node, GenerationContext context)

Answer true if there is a one-to-one relationship selected.

private boolean
isReadAllQuery(ParseTreeContext context)

Returns true if the SELECT clause consists of a single expression returning the base identification variable of the query and if the base variable is defined as a range variable w/o FETCH JOINs.

public boolean
isSelected(String variableName)

Answer true if the variable name given as argument is SELECTed.

public boolean
private boolean
public boolean
isVariableInINClauseSelected(GenerationContext context)

Answer true if a variable in the IN clause is SELECTed

public boolean
nodeRefersToObject(Node node, GenerationContext context)

Answer true if this node refers to an object described later in the EJBQL True: SELECT p FROM Project p False: SELECT p.id FROM Project p

public Node
qualifyAttributeAccess(ParseTreeContext context)

Overrides org.eclipse.persistence.internal.jpa.parsing.Node.qualifyAttributeAccess.

Check the select expression nodes for a path expression starting with a unqualified field access and if so, replace it by a qualified field access.
public Class<?>
resolveClass(GenerationContext context)

Implements abstract org.eclipse.persistence.internal.jpa.parsing.QueryNode.resolveClass.

Answer the class associated with my left node.
private boolean
selectingDirectToField(Node node, GenerationContext context)

Answer true if the SELECT ends in a direct-to-field.

private boolean
public void
setDistinct(boolean distinct)

public void
setIdentifiers(List<String> identifiers)

public void
public boolean
public void
public void
verifySelectedAlias(GenerationContext context)

Verify that the selected alias is a valid alias.

Inherited from org.eclipse.persistence.internal.jpa.parsing.QueryNode:
getParseTreeisDeleteNodeisUpdateNodesetParseTree

Field Detail

distinctback to summary
private boolean distinct
identifiersback to summary
private List<String> identifiers
selectExpressionsback to summary
private List<Node> selectExpressions

Constructor Detail

SelectNodeback to summary
public SelectNode()

Method Detail

applyToQueryback to summary
public void applyToQuery(DatabaseQuery theQuery, GenerationContext context)

Implements abstract org.eclipse.persistence.internal.jpa.parsing.QueryNode.applyToQuery.

INTERNAL Apply this node to the passed query

Annotations
@Override
createDatabaseQueryback to summary
public DatabaseQuery createDatabaseQuery(ParseTreeContext context)

Implements abstract org.eclipse.persistence.internal.jpa.parsing.QueryNode.createDatabaseQuery.

Returns a DatabaseQuery instance representing the owning ParseTree. This implementation returns a ReadAllQuery for simple SELECT queries and a ReportQuery otherwise.

Annotations
@Override
generateExpressionback to summary
public Expression generateExpression(GenerationContext context)

Implements abstract org.eclipse.persistence.internal.jpa.parsing.QueryNode.generateExpression.

Return a EclipseLink expression generated using the left node.

Annotations
@Override
getClassOfFirstVariableback to summary
private Class<?> getClassOfFirstVariable(GenerationContext context)
getFirstSelectExpressionNodeback to summary
private Node getFirstSelectExpressionNode()

Returns the first select expression node.

getIdentifiersback to summary
public List<String> getIdentifiers()
getReferenceClassback to summary
public Class<?> getReferenceClass(GenerationContext context)

Overrides org.eclipse.persistence.internal.jpa.parsing.QueryNode.getReferenceClass.

Compute the Reference class for this query.

Returns:Class<?>

the class this query is querying for

Annotations
@Override
getSelectExpressionsback to summary
public List<Node> getSelectExpressions()
hasOneToOneSelectedback to summary
public boolean hasOneToOneSelected(GenerationContext context)
hasOneToOneSelectedback to summary
private boolean hasOneToOneSelected(Node node, GenerationContext context)

Answer true if there is a one-to-one relationship selected. This includes a chain of relationships. True: SELECT employee.address FROM ..... //Simple 1:1 True: SELECT a.b.c.d FROM ..... //where a->b, b->c and c->d are all 1:1. False: SELECT OBJECT(employee) FROM ..... //simple SELECT False: SELECT phoneNumber.areaCode FROM ..... //direct-to-field

isReadAllQueryback to summary
private boolean isReadAllQuery(ParseTreeContext context)

Returns true if the SELECT clause consists of a single expression returning the base identification variable of the query and if the base variable is defined as a range variable w/o FETCH JOINs.

isSelectedback to summary
public boolean isSelected(String variableName)

Answer true if the variable name given as argument is SELECTed. True: "SELECT OBJECT(emp) ...." & variableName = "emp" False: "SELECT OBJECT(somethingElse) ..." & variableName = "emp"

isSelectNodeback to summary
public boolean isSelectNode()

Overrides org.eclipse.persistence.internal.jpa.parsing.QueryNode.isSelectNode.

Annotations
@Override
isSingleSelectExpressionback to summary
private boolean isSingleSelectExpression()
isVariableInINClauseSelectedback to summary
public boolean isVariableInINClauseSelected(GenerationContext context)

Answer true if a variable in the IN clause is SELECTed

nodeRefersToObjectback to summary
public boolean nodeRefersToObject(Node node, GenerationContext context)

Answer true if this node refers to an object described later in the EJBQL True: SELECT p FROM Project p False: SELECT p.id FROM Project p

qualifyAttributeAccessback to summary
public Node qualifyAttributeAccess(ParseTreeContext context)

Overrides org.eclipse.persistence.internal.jpa.parsing.Node.qualifyAttributeAccess.

Check the select expression nodes for a path expression starting with a unqualified field access and if so, replace it by a qualified field access.

Annotations
@Override
resolveClassback to summary
public Class<?> resolveClass(GenerationContext context)

Implements abstract org.eclipse.persistence.internal.jpa.parsing.QueryNode.resolveClass.

Answer the class associated with my left node.

Annotations
@Override
selectingDirectToFieldback to summary
private boolean selectingDirectToField(Node node, GenerationContext context)

Answer true if the SELECT ends in a direct-to-field. true: SELECT phone.areaCode false: SELECT employee.address

selectingRelationshipFieldback to summary
private boolean selectingRelationshipField(Node node, GenerationContext context)
setDistinctback to summary
public void setDistinct(boolean distinct)
setIdentifiersback to summary
public void setIdentifiers(List<String> identifiers)
setSelectExpressionsback to summary
public void setSelectExpressions(List<Node> exprs)
usesDistinctback to summary
public boolean usesDistinct()
validateback to summary
public void validate(ParseTreeContext context)

Overrides org.eclipse.persistence.internal.jpa.parsing.Node.validate.

Validate node.

Annotations
@Override
verifySelectedAliasback to summary
public void verifySelectedAlias(GenerationContext context)

Verify that the selected alias is a valid alias. If it's not valid, an Exception will be thrown, likely JPQLException.aliasResolutionException. Valid: SELECT OBJECT(emp) FROM Employee emp WHERE ... Invalid: SELECT OBJECT(badAlias) FROM Employee emp WHERE ...