Class SelectNode
- java.lang.Object
-
- org.eclipse.persistence.internal.jpa.parsing.Node
-
- org.eclipse.persistence.internal.jpa.parsing.MajorNode
-
- org.eclipse.persistence.internal.jpa.parsing.QueryNode
-
- org.eclipse.persistence.internal.jpa.parsing.SelectNode
-
public class SelectNode extends QueryNode
INTERNAL:Purpose: Represent a SELECT
Responsibilities:
- Hold the distinct status
- Modify a query based on the contents
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
- Since:
- TopLink 5.0
- Author:
- Jon Driscoll
-
-
Field Summary
-
Fields inherited from class org.eclipse.persistence.internal.jpa.parsing.Node
alias, left, right, shouldGenerateExpression
-
-
Constructor Summary
Constructors Constructor Description SelectNode()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
applyToQuery(DatabaseQuery theQuery, GenerationContext context)
INTERNAL Apply this node to the passed queryDatabaseQuery
createDatabaseQuery(ParseTreeContext context)
Returns a DatabaseQuery instance representing the owning ParseTree.Expression
generateExpression(GenerationContext context)
Return a EclipseLink expression generated using the left node.List
getIdentifiers()
Class
getReferenceClass(GenerationContext context)
Compute the Reference class for this query.List
getSelectExpressions()
boolean
hasOneToOneSelected(GenerationContext context)
boolean
isSelected(String variableName)
Answer true if the variable name given as argument is SELECTed.boolean
isSelectNode()
boolean
isVariableInINClauseSelected(GenerationContext context)
Answer true if a variable in the IN clause is SELECTedboolean
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 pNode
qualifyAttributeAccess(ParseTreeContext context)
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.Class
resolveClass(GenerationContext context)
Answer the class associated with my left node.void
setDistinct(boolean distinct)
void
setIdentifiers(List identifiers)
void
setSelectExpressions(List exprs)
boolean
usesDistinct()
void
validate(ParseTreeContext context)
Validate node.void
verifySelectedAlias(GenerationContext context)
Verify that the selected alias is a valid alias.-
Methods inherited from class org.eclipse.persistence.internal.jpa.parsing.QueryNode
getParseTree, isDeleteNode, isUpdateNode, setParseTree
-
Methods inherited from class org.eclipse.persistence.internal.jpa.parsing.MajorNode
getContext, setContext
-
Methods inherited from class org.eclipse.persistence.internal.jpa.parsing.Node
addToExpression, appendExpression, applyToQuery, getAlias, getAsString, getColumn, getLeft, getLine, getRight, getType, hasLeft, hasRight, isAggregateNode, isAliasableNode, isAttributeNode, isConstructorNode, isCountNode, isDivideNode, isDotNode, isEscape, isLiteralNode, isMapKeyNode, isMinusNode, isMultiplyNode, isNotNode, isParameterNode, isPlusNode, isSubqueryNode, isVariableNode, resolveAttribute, resolveClass, resolveMapping, resolveMapping, setAlias, setColumn, setLeft, setLine, setRight, setType, toString, toString, toStringDisplayName, toStringIndent, validateParameter
-
-
-
-
Method Detail
-
getSelectExpressions
public List getSelectExpressions()
-
setSelectExpressions
public void setSelectExpressions(List exprs)
-
getIdentifiers
public List getIdentifiers()
-
setIdentifiers
public void setIdentifiers(List identifiers)
-
usesDistinct
public boolean usesDistinct()
-
setDistinct
public void setDistinct(boolean distinct)
-
createDatabaseQuery
public DatabaseQuery createDatabaseQuery(ParseTreeContext context)
Returns a DatabaseQuery instance representing the owning ParseTree. This implementation returns a ReadAllQuery for simple SELECT queries and a ReportQuery otherwise.- Specified by:
createDatabaseQuery
in classQueryNode
-
applyToQuery
public void applyToQuery(DatabaseQuery theQuery, GenerationContext context)
INTERNAL Apply this node to the passed query- Specified by:
applyToQuery
in classQueryNode
-
hasOneToOneSelected
public boolean hasOneToOneSelected(GenerationContext context)
-
verifySelectedAlias
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 ...
-
isSelected
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"
-
isSelectNode
public boolean isSelectNode()
- Overrides:
isSelectNode
in classQueryNode
-
qualifyAttributeAccess
public Node qualifyAttributeAccess(ParseTreeContext context)
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.- Overrides:
qualifyAttributeAccess
in classNode
-
validate
public void validate(ParseTreeContext context)
Validate node.
-
resolveClass
public Class resolveClass(GenerationContext context)
Answer the class associated with my left node.- Specified by:
resolveClass
in classQueryNode
-
generateExpression
public Expression generateExpression(GenerationContext context)
Return a EclipseLink expression generated using the left node.- Specified by:
generateExpression
in classQueryNode
-
getReferenceClass
public Class getReferenceClass(GenerationContext context)
Compute the Reference class for this query.- Overrides:
getReferenceClass
in classQueryNode
- Returns:
- the class this query is querying for
-
isVariableInINClauseSelected
public boolean isVariableInINClauseSelected(GenerationContext context)
Answer true if a variable in the IN clause is SELECTed
-
nodeRefersToObject
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
-
-