Class SelectClauseStateObject
- java.lang.Object
-
- org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
-
- org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractSelectClauseStateObject
-
- org.eclipse.persistence.jpa.jpql.tools.model.query.SelectClauseStateObject
-
- All Implemented Interfaces:
ListHolderStateObject<StateObject>
,StateObject
public class SelectClauseStateObject extends AbstractSelectClauseStateObject implements ListHolderStateObject<StateObject>
TheSELECT
statement queries data from entities, which determines the type of the objects or values to be selected.BNF: select_clause ::= SELECT [DISTINCT] select_expression {, select_expression}* select_expression ::= single_valued_path_expression | aggregate_expression | identification_variable | OBJECT(identification_variable) | constructor_expression
- Version:
- 2.4
- See Also:
SelectStatementStateObject
,SelectClause
- Author:
- Pascal Filion
- Since:
- 2.4
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
SELECT_ITEMS_LIST
A constant used to notify the list of select expressions has changed.-
Fields inherited from class org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractSelectClauseStateObject
DISTINCT_PROPERTY
-
-
Constructor Summary
Constructors Constructor Description SelectClauseStateObject(SelectStatementStateObject parent)
Creates a newSelectClauseStateObject
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(StateObjectVisitor visitor)
Visits thisStateObject
by the givenvisitor
.protected void
addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObject
to the given list.StateObject
addItem(java.lang.String jpqlFragment)
Adds the given path as a select item, which can either be an identification variable or a state-field path expression.ResultVariableStateObject
addItem(java.lang.String jpqlFragment, java.lang.String resultVariable)
Adds the given expression as a select item.ResultVariableStateObject
addItem(StateObject stateObject, java.lang.String resultVariable)
Adds the givenStateObject
as a select item.<S extends StateObject>
SaddItem(S item)
Adds the givenStateObject
as a child of this one.ResultVariableStateObject
addItemAs(java.lang.String jpqlFragment, java.lang.String resultVariable)
Adds the given JPQL fragment as a select item.ResultVariableStateObject
addItemAs(StateObject stateObject, java.lang.String resultVariable)
Adds the givenStateObject
as a select item.void
addItems(java.util.List<? extends StateObject> items)
Adds the given list ofStateObjects
as children of this one.void
addListChangeListener(java.lang.String listName, IListChangeListener<StateObject> listener)
Registers the givenIListChangeListener
for the specified list.protected boolean
areChildrenEquivalent(SelectClauseStateObject stateObject)
Determines whether the children of thisStateObject
are equivalent to the children of the given one, i.e. the information of theStateObjects
is the same.boolean
canMoveDown(StateObject item)
Determines whether the givenStateObject
can be moved down by one position in the list owned by its parent.boolean
canMoveUp(StateObject item)
Determines whether the givenStateObject
can be moved up by one position in the list owned by its parent.ISelectExpressionStateObjectBuilder
getBuilder()
Creates and returns a newISelectExpressionStateObjectBuilder
that can be used to programmatically create a single select expression and once the expression is complete,ISelectExpressionStateObjectBuilder.commit()
will push theStateObject
representation of that expression as this clause's select expression.SelectClause
getExpression()
Returns the actual parsed object if thisStateObject
representation of the JPQL query was created by parsing an existing JPQL query.FromClauseStateObject
getFromClause()
Returns theAbstractFromClauseStateObject
representing the FROM clause.StateObject
getItem(int index)
Returns theStateObject
at the given positions from the listSelectStatementStateObject
getParent()
Returns the parent of thisStateObject
.boolean
hasItems()
Determines whether thisStateObject
has any children.boolean
hasSelectItem()
Determines whether thisSELECT
clause has a select item defined (only one can be set for a subquery'sSELECT
clause and many for a top-level query).protected void
initialize()
Initializes this state object.boolean
isEquivalent(StateObject stateObject)
Determines whether the givenStateObject
is equivalent to this one, i.e. the information of bothStateObject
is the same.ListIterable<StateObject>
items()
Returns anListIterable
over the children.int
itemsSize()
Returns the number of children this list holder has.StateObject
moveDown(StateObject item)
Moves the givenStateObject
down by one position in the list owned by its parent.StateObject
moveUp(StateObject item)
Moves the givenStateObject
up by one position in the list owned by its parent.void
parse(java.lang.String jpqlFragment)
Parses the given JPQL fragment and create the select item.void
removeItem(StateObject stateObject)
Removes the givenStateObject
from the list of children.void
removeItems(java.util.Collection<StateObject> items)
Removes the givenStateObject
from the list of children.void
removeListChangeListener(java.lang.String listName, IListChangeListener<StateObject> listener)
Unregisters the givenIListChangeListener
that was registered for the specified list.void
setExpression(SelectClause expression)
Keeps a reference of theparsed object
object, which should only be done when this object is instantiated during the conversion of a parsed JPQL query intoStateObjects
.void
setItems(java.util.List<StateObject> stateObjects)
Sets the select expression to be those contained on the given collection.protected void
toTextInternal(java.lang.Appendable writer)
Prints out a string representation of thisStateObject
, which should not be used to define atrue
string representation of a JPQL query but should be used for debugging purposes.-
Methods inherited from class org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractSelectClauseStateObject
hasDistinct, setDistinct, toggleDistinct
-
Methods inherited from class org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
acceptUnknownVisitor, acceptUnknownVisitor, addProblems, addPropertyChangeListener, areEquivalent, buildProblem, buildProblem, buildStateObject, buildStateObjects, checkParent, children, decorate, equals, findIdentificationVariable, firePropertyChanged, getChangeSupport, getDeclaration, getDecorator, getGrammar, getManagedTypeProvider, getQueryBuilder, getRoot, getType, getType, getTypeHelper, getTypeRepository, hashCode, isDecorated, parent, parent, parent, removePropertyChangeListener, setExpression, setParent, toString, toString, toStringInternal, toStringItems, toText
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject
addPropertyChangeListener, children, decorate, findIdentificationVariable, getDeclaration, getDecorator, getGrammar, getManagedTypeProvider, getQueryBuilder, getRoot, isDecorated, removePropertyChangeListener, setParent, toString, toText
-
-
-
-
Field Detail
-
SELECT_ITEMS_LIST
public static final java.lang.String SELECT_ITEMS_LIST
A constant used to notify the list of select expressions has changed.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
SelectClauseStateObject
public SelectClauseStateObject(SelectStatementStateObject parent)
Creates a newSelectClauseStateObject
.- Parameters:
parent
- The parent of this state object, which cannot benull
- Throws:
java.lang.NullPointerException
- The given parent cannot benull
-
-
Method Detail
-
accept
public void accept(StateObjectVisitor visitor)
Visits thisStateObject
by the givenvisitor
.- Specified by:
accept
in interfaceStateObject
- Parameters:
visitor
- Thevisitor
to visit this object
-
addChildren
protected void addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObject
to the given list.- Overrides:
addChildren
in classAbstractStateObject
- Parameters:
children
- The list used to store the children
-
addItem
public ResultVariableStateObject addItem(StateObject stateObject, java.lang.String resultVariable)
Adds the givenStateObject
as a select item.- Parameters:
stateObject
- TheStateObject
representing the select expressionresultVariable
- The result variable identifying the select expression- Returns:
- The newly created
ResultVariableStateObject
-
addItem
public StateObject addItem(java.lang.String jpqlFragment)
Adds the given path as a select item, which can either be an identification variable or a state-field path expression.- Parameters:
jpqlFragment
- The select expression to parse as a select item- Returns:
- The
StateObject
encapsulating the given path
-
addItem
public ResultVariableStateObject addItem(java.lang.String jpqlFragment, java.lang.String resultVariable)
Adds the given expression as a select item.- Parameters:
jpqlFragment
- The select expression to parse as a select itemresultVariable
- The result variable identifying the select expression- Returns:
- The newly created
ResultVariableStateObject
-
addItem
public <S extends StateObject> S addItem(S item)
Adds the givenStateObject
as a child of this one.- Specified by:
addItem
in interfaceListHolderStateObject<StateObject>
- Parameters:
item
- The childStateObject
to become a child of this one return The given item
-
addItemAs
public ResultVariableStateObject addItemAs(StateObject stateObject, java.lang.String resultVariable)
Adds the givenStateObject
as a select item.- Parameters:
stateObject
- TheStateObject
representing the select expressionresultVariable
- The result variable identifying the select expression- Returns:
- The newly created
ResultVariableStateObject
-
addItemAs
public ResultVariableStateObject addItemAs(java.lang.String jpqlFragment, java.lang.String resultVariable)
Adds the given JPQL fragment as a select item.- Parameters:
jpqlFragment
- The portion of a JPQL query that represents a select expressionresultVariable
- The result variable identifying the select expression- Returns:
- The newly created
ResultVariableStateObject
-
addItems
public void addItems(java.util.List<? extends StateObject> items)
Adds the given list ofStateObjects
as children of this one.- Specified by:
addItems
in interfaceListHolderStateObject<StateObject>
- Parameters:
items
- TheStateObjects
to become children of this one
-
addListChangeListener
public void addListChangeListener(java.lang.String listName, IListChangeListener<StateObject> listener)
Registers the givenIListChangeListener
for the specified list. The listener will be notified only when items are added, removed, moved from the list.- Specified by:
addListChangeListener
in interfaceListHolderStateObject<StateObject>
- Parameters:
listName
- The name of the list for which the listener will be notified when the content of the list has changedlistener
- The listener to be notified upon changes
-
areChildrenEquivalent
protected boolean areChildrenEquivalent(SelectClauseStateObject stateObject)
Determines whether the children of thisStateObject
are equivalent to the children of the given one, i.e. the information of theStateObjects
is the same.- Parameters:
stateObject
- TheStateObject
to compare its children to this one's children- Returns:
true
if both have equivalent children;false
otherwise
-
canMoveDown
public boolean canMoveDown(StateObject item)
Determines whether the givenStateObject
can be moved down by one position in the list owned by its parent.- Specified by:
canMoveDown
in interfaceListHolderStateObject<StateObject>
- Parameters:
item
- TheStateObject
that could potentially be moved down- Returns:
true
if the object can be moved down by one unit;false
otherwise
-
canMoveUp
public boolean canMoveUp(StateObject item)
Determines whether the givenStateObject
can be moved up by one position in the list owned by its parent.- Specified by:
canMoveUp
in interfaceListHolderStateObject<StateObject>
- Parameters:
item
- TheStateObject
that could potentially be moved up- Returns:
true
if the object can be moved up by one unit;false
otherwise
-
getBuilder
public ISelectExpressionStateObjectBuilder getBuilder()
Creates and returns a newISelectExpressionStateObjectBuilder
that can be used to programmatically create a single select expression and once the expression is complete,ISelectExpressionStateObjectBuilder.commit()
will push theStateObject
representation of that expression as this clause's select expression.- Returns:
- A new builder that can be used to quickly create a select expression
-
getExpression
public SelectClause getExpression()
Returns the actual parsed object if thisStateObject
representation of the JPQL query was created by parsing an existing JPQL query.- Specified by:
getExpression
in interfaceStateObject
- Overrides:
getExpression
in classAbstractSelectClauseStateObject
- Returns:
- The parsed object when a JPQL query is parsed and converted into a
StateObject
ornull
when the JPQL query is manually created (i.e. not from a string)
-
getFromClause
public FromClauseStateObject getFromClause()
Returns theAbstractFromClauseStateObject
representing the FROM clause.- Overrides:
getFromClause
in classAbstractSelectClauseStateObject
- Returns:
- The state object representing the FROM clause
-
getItem
public StateObject getItem(int index)
Returns theStateObject
at the given positions from the list- Specified by:
getItem
in interfaceListHolderStateObject<StateObject>
- Parameters:
index
- The position of theStateObject
to retrieve- Returns:
- The
StateObject
at the given position
-
getParent
public SelectStatementStateObject getParent()
Returns the parent of thisStateObject
.- Specified by:
getParent
in interfaceStateObject
- Overrides:
getParent
in classAbstractSelectClauseStateObject
- Returns:
- Returns the parent of this
StateObject
, which isnull
only when this is the root of the hierarchy
-
hasItems
public boolean hasItems()
Determines whether thisStateObject
has any children.- Specified by:
hasItems
in interfaceListHolderStateObject<StateObject>
- Returns:
true
if thisStateObject
has children;false
otherwise
-
hasSelectItem
public boolean hasSelectItem()
Determines whether thisSELECT
clause has a select item defined (only one can be set for a subquery'sSELECT
clause and many for a top-level query).- Specified by:
hasSelectItem
in classAbstractSelectClauseStateObject
- Returns:
true
if this state object has children;false
otherwise
-
initialize
protected void initialize()
Initializes this state object.- Overrides:
initialize
in classAbstractStateObject
-
isEquivalent
public boolean isEquivalent(StateObject stateObject)
Determines whether the givenStateObject
is equivalent to this one, i.e. the information of bothStateObject
is the same.- Specified by:
isEquivalent
in interfaceStateObject
- Overrides:
isEquivalent
in classAbstractSelectClauseStateObject
- Parameters:
stateObject
- TheStateObject
to compare its content to this one- Returns:
true
if both object are equivalent;false
otherwise
-
items
public ListIterable<StateObject> items()
Returns anListIterable
over the children.- Specified by:
items
in interfaceListHolderStateObject<StateObject>
- Returns:
- An
ListIterable
that is iterating over the children
-
itemsSize
public int itemsSize()
Returns the number of children this list holder has.- Specified by:
itemsSize
in interfaceListHolderStateObject<StateObject>
- Returns:
- The count of
StateObjects
that are children of this one
-
moveDown
public StateObject moveDown(StateObject item)
Moves the givenStateObject
down by one position in the list owned by its parent.- Specified by:
moveDown
in interfaceListHolderStateObject<StateObject>
- Parameters:
item
- TheStateObject
to move down in the list- Returns:
- The given item
-
moveUp
public StateObject moveUp(StateObject item)
Moves the givenStateObject
up by one position in the list owned by its parent.- Specified by:
moveUp
in interfaceListHolderStateObject<StateObject>
- Parameters:
item
- TheStateObject
to move up in the list- Returns:
- The given item
-
parse
public void parse(java.lang.String jpqlFragment)
Parses the given JPQL fragment and create the select item. For the top-level query, the fragment can contain several select items but for a subquery, it can represent only one.- Specified by:
parse
in classAbstractSelectClauseStateObject
- Parameters:
jpqlFragment
- The portion of the query representing one or several select items
-
removeItem
public void removeItem(StateObject stateObject)
Removes the givenStateObject
from the list of children.- Specified by:
removeItem
in interfaceListHolderStateObject<StateObject>
- Parameters:
stateObject
- The childStateObject
to not longer be a child
-
removeItems
public void removeItems(java.util.Collection<StateObject> items)
Removes the givenStateObject
from the list of children.- Specified by:
removeItems
in interfaceListHolderStateObject<StateObject>
- Parameters:
items
- TheStateObjects
to remove from this one
-
removeListChangeListener
public void removeListChangeListener(java.lang.String listName, IListChangeListener<StateObject> listener)
Unregisters the givenIListChangeListener
that was registered for the specified list. The listener will no longer be notified only when items are added, removed, moved from the list.- Specified by:
removeListChangeListener
in interfaceListHolderStateObject<StateObject>
- Parameters:
listName
- The name of the list for which the listener was registeredlistener
- The listener to unregister
-
setExpression
public void setExpression(SelectClause expression)
Keeps a reference of theparsed object
object, which should only be done when this object is instantiated during the conversion of a parsed JPQL query intoStateObjects
.- Parameters:
expression
- Theparsed object
representing aSELECT
clause
-
setItems
public void setItems(java.util.List<StateObject> stateObjects)
Sets the select expression to be those contained on the given collection. If any select items were already set, they will be removed.- Parameters:
stateObjects
- The new select expressions
-
toTextInternal
protected void toTextInternal(java.lang.Appendable writer) throws java.io.IOException
Prints out a string representation of thisStateObject
, which should not be used to define atrue
string representation of a JPQL query but should be used for debugging purposes.- Specified by:
toTextInternal
in classAbstractStateObject
- Parameters:
writer
- The writer used to print out the string representation- Throws:
java.io.IOException
- This should never happens, it is only required becauseAppendable
is used instead of any concrete class
-
-