Top Description Fields Constructors Methods
org.eclipse.persistence.jpa.jpql.parser

public final Class ConstructorExpression

extends AbstractExpression
Class Inheritance
Imports
java.util.ArrayList, .Collection, .List, org.eclipse.persistence.jpa.jpql.ExpressionTools, .WordParser

In the SELECT clause a constructor may be used in the SELECT list to return one or more Java instances. The specified class is not required to be an entity or to be mapped to the database. The constructor name must be fully qualified.
BNF: constructor_expression ::= NEW constructor_name(constructor_item {, constructor_item}*)
Author
Pascal Filion
Since
2.3
Version
2.5

Field Summary

Modifier and TypeField and Description
private String
className

The fully qualified class name of this expression.

private AbstractExpression
constructorItems

The list of constructor items.

private boolean
hasLeftParenthesis

Flag used to determine if the closing parenthesis is present in the query.

private boolean
hasRightParenthesis

Flag used to determine if the opening parenthesis is present in the query.

private boolean
hasSpaceAfterConstructorName

When the expression is not valid and the left parenthesis is missing, then a space might have been parsed.

private boolean
hasSpaceAfterNew

Determines whether there is a whitespace after the identifier NEW.

private String
identifier

The actual NEW identifier found in the string representation of the JPQL query.

Inherited from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression:
COMMADOTDOUBLE_QUOTELEFT_CURLY_BRACKETLEFT_PARENTHESISNOT_DEFINEDRIGHT_CURLY_BRACKETRIGHT_PARENTHESISSINGLE_QUOTESPACEUNDERSCORE

Constructor Summary

AccessConstructor and Description
public
ConstructorExpression(AbstractExpression
The parent of this expression
parent
)

Creates a new ConstructorExpression.

Method Summary

Modifier and TypeMethod and Description
public void
accept(ExpressionVisitor
The ExpressionVisitor to visit this object
visitor
)

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.accept.

Visits this Expression by the given visitor.
public void
acceptChildren(ExpressionVisitor
The visitor to visit the children of this object.
visitor
)

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.acceptChildren.

Visits the children of this Expression.
protected void
addChildrenTo(Collection<Expression>
The collection used to store the children
children
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addChildrenTo.

Adds the children of this AbstractExpression to the given collection.
protected void
addOrderedChildrenTo(List<Expression>
The list used to store the string representation of this AbstractExpression
children
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addOrderedChildrenTo.

Adds the children of this AbstractExpression to the given list.
public CollectionExpression

Returns:

The single constructor item represented by a temporary collection
buildCollectionExpression
()

Creates a new CollectionExpression that will wrap the single constructor item.

public JPQLQueryBNF
findQueryBNF(Expression
The Expression that is a descendant of this one
expression
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.findQueryBNF.

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.findQueryBNF.

Retrieves the JPQLQueryBNF that represents the fragment of this Expression that was used when parsing the given Expression.
public String

Returns:

The NEW identifier that was actually parsed
getActualIdentifier
()

Returns the actual NEW identifier found in the string representation of the JPQL query, which has the actual case that was used.

public String

Returns:

The fully qualified class name or an empty string if it is not defined
getClassName
()

Returns the fully qualified class name that will be used to retrieve the constructor.

public Expression

Returns:

The constructor item or items or an invalid or "null" expression
getConstructorItems
()

Returns the constructor items aggregated into a single expression and separated by commas or a single expression.

public JPQLQueryBNF
public boolean

Returns:

true if the query had at least one constructor item; false otherwise
hasConstructorItems
()

Determines whether the constructor items were parsed.

public boolean

Returns:

true if the open parenthesis was present in the string version of the query; false otherwise
hasLeftParenthesis
()

Determines whether the open parenthesis was parsed or not.

public boolean

Returns:

true if the close parenthesis was present in the string version of the query; false otherwise
hasRightParenthesis
()

Determines whether the close parenthesis was parsed or not.

public boolean

Returns:

true if there was a whitespace after NEW; false otherwise
hasSpaceAfterNew
()

Determines whether a whitespace was parsed after NEW.

protected boolean
isParsingComplete(WordParser
The text to parse based on the current position of the cursor
wordParser
,
String
The word that was retrieved from the given text, which is the first word in the text
word
,
Expression
The Expression that has already been parsed
expression
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.isParsingComplete.

Determines whether the parsing is complete based on what is left in the given text.
protected void
parse(WordParser
The text to parse based on the current position of the cursor
wordParser
,
boolean
Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
tolerant
)

Implements abstract org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.parse.

Parses the query by starting at the current position, which is part of the given WordParser.
protected boolean
shouldSkipLiteral(AbstractExpression
The Expression that has just been parsed or null
expression
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.shouldSkipLiteral.

When parsing an invalid or incomplete query, it is possible two literals would be parsed but in some cases, a CollectionExpression should not be created and the parsing should actually stop here.
protected void
toParsedText(StringBuilder
The buffer used to append this Expression's string representation
writer
,
boolean
Determines whether the string representation should represent what was parsed, i.e. include any "virtual" whitespace (such as ending whitespace) and the actual case of the JPQL identifiers
actual
)

Implements abstract org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.toParsedText.

Generates a string representation of this Expression, including its children, if it has any.
Inherited from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression:
acceptUnknownVisitoracceptUnknownVisitorbuildExpressionFromFallingBackbuildNullExpressionbuildStringExpressionbuildStringExpressionbuildUnknownExpressioncalculatePositionchildrenfindFallBackExpressionFactorygetExpressionFactorygetExpressionRegistrygetGrammargetIdentifierVersiongetJPAVersiongetLengthgetOffsetgetParentgetQueryBNFgetRootgetTexthandleAggregatehandleCollectionisAncestorisIdentifierisNullisTolerantisUnknownisVirtualorderedChildrenparseparseUsingExpressionFactorypopulatePositionrebuildActualTextrebuildParsedTextsetParentsetTextshouldParseWithFactoryFirsttoActualTexttoParsedTexttoString

Field Detail

classNameback to summary
private String className

The fully qualified class name of this expression.

constructorItemsback to summary
private AbstractExpression constructorItems

The list of constructor items.

hasLeftParenthesisback to summary
private boolean hasLeftParenthesis

Flag used to determine if the closing parenthesis is present in the query.

hasRightParenthesisback to summary
private boolean hasRightParenthesis

Flag used to determine if the opening parenthesis is present in the query.

hasSpaceAfterConstructorNameback to summary
private boolean hasSpaceAfterConstructorName

When the expression is not valid and the left parenthesis is missing, then a space might have been parsed.

hasSpaceAfterNewback to summary
private boolean hasSpaceAfterNew

Determines whether there is a whitespace after the identifier NEW.

identifierback to summary
private String identifier

The actual NEW identifier found in the string representation of the JPQL query.

Constructor Detail

ConstructorExpressionback to summary
public ConstructorExpression(AbstractExpression parent)

Creates a new ConstructorExpression.

Parameters
parent:AbstractExpression

The parent of this expression

Method Detail

acceptback to summary
public void accept(ExpressionVisitor visitor)

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.accept.

Doc from org.eclipse.persistence.jpa.jpql.parser.Expression.accept.

Visits this Expression by the given visitor.

Parameters
visitor:ExpressionVisitor

The ExpressionVisitor to visit this object

Annotations
@Override
acceptChildrenback to summary
public void acceptChildren(ExpressionVisitor visitor)

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.acceptChildren.

Doc from org.eclipse.persistence.jpa.jpql.parser.Expression.acceptChildren.

Visits the children of this Expression. This method can be used to optimize traversing the children since a new list is not created every time children() is called.

This does not traverse the Expression sub-hierarchy, use a subclass of AbstractTraverseChildrenVisitor in order to traverse the entire sub-hierarchy.

Parameters
visitor:ExpressionVisitor

The visitor to visit the children of this object.

Annotations
@Override
addChildrenToback to summary
protected void addChildrenTo(Collection<Expression> children)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addChildrenTo.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addChildrenTo.

Adds the children of this AbstractExpression to the given collection.

Parameters
children:Collection<Expression>

The collection used to store the children

Annotations
@Override
addOrderedChildrenToback to summary
protected void addOrderedChildrenTo(List<Expression> children)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addOrderedChildrenTo.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.addOrderedChildrenTo.

Adds the children of this AbstractExpression to the given list.

Parameters
children:List<Expression>

The list used to store the string representation of this AbstractExpression

Annotations
@Override
buildCollectionExpressionback to summary
public CollectionExpression buildCollectionExpression()

Creates a new CollectionExpression that will wrap the single constructor item.

Returns:CollectionExpression

The single constructor item represented by a temporary collection

findQueryBNFback to summary
public JPQLQueryBNF findQueryBNF(Expression expression)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.findQueryBNF.

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.findQueryBNF.

Doc from org.eclipse.persistence.jpa.jpql.parser.Expression.findQueryBNF.

Retrieves the JPQLQueryBNF that represents the fragment of this Expression that was used when parsing the given Expression.

Parameters
expression:Expression

The Expression that is a descendant of this one

Returns:JPQLQueryBNF

The JPQLQueryBNF that was used to parse the given expression

Annotations
@Override
getActualIdentifierback to summary
public String getActualIdentifier()

Returns the actual NEW identifier found in the string representation of the JPQL query, which has the actual case that was used.

Returns:String

The NEW identifier that was actually parsed

getClassNameback to summary
public String getClassName()

Returns the fully qualified class name that will be used to retrieve the constructor.

Returns:String

The fully qualified class name or an empty string if it is not defined

getConstructorItemsback to summary
public Expression getConstructorItems()

Returns the constructor items aggregated into a single expression and separated by commas or a single expression.

Returns:Expression

The constructor item or items or an invalid or "null" expression

getQueryBNFback to summary
public JPQLQueryBNF getQueryBNF()

Implements org.eclipse.persistence.jpa.jpql.parser.Expression.getQueryBNF.

Doc from org.eclipse.persistence.jpa.jpql.parser.Expression.getQueryBNF.

Returns the BNF of this Expression.

Returns:JPQLQueryBNF

The JPQLQueryBNF, which represents the grammar of this Expression

Annotations
@Override
hasConstructorItemsback to summary
public boolean hasConstructorItems()

Determines whether the constructor items were parsed.

Returns:boolean

true if the query had at least one constructor item; false otherwise

hasLeftParenthesisback to summary
public boolean hasLeftParenthesis()

Determines whether the open parenthesis was parsed or not.

Returns:boolean

true if the open parenthesis was present in the string version of the query; false otherwise

hasRightParenthesisback to summary
public boolean hasRightParenthesis()

Determines whether the close parenthesis was parsed or not.

Returns:boolean

true if the close parenthesis was present in the string version of the query; false otherwise

hasSpaceAfterNewback to summary
public boolean hasSpaceAfterNew()

Determines whether a whitespace was parsed after NEW.

Returns:boolean

true if there was a whitespace after NEW; false otherwise

isParsingCompleteback to summary
protected boolean isParsingComplete(WordParser wordParser, String word, Expression expression)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.isParsingComplete.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.isParsingComplete.

Determines whether the parsing is complete based on what is left in the given text. The text is never empty.

Parameters
wordParser:WordParser

The text to parse based on the current position of the cursor

word:String

The word that was retrieved from the given text, which is the first word in the text

expression:Expression

The Expression that has already been parsed

Returns:boolean

true if the text no longer can't be parsed by the current expression; false if more can be parsed

Annotations
@Override
parseback to summary
protected void parse(WordParser wordParser, boolean tolerant)

Implements abstract org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.parse.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.parse.

Parses the query by starting at the current position, which is part of the given WordParser.

Parameters
wordParser:WordParser

The text to parse based on the current position of the cursor

tolerant:boolean

Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries

Annotations
@Override
shouldSkipLiteralback to summary
protected boolean shouldSkipLiteral(AbstractExpression expression)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.shouldSkipLiteral.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.shouldSkipLiteral.

When parsing an invalid or incomplete query, it is possible two literals would be parsed but in some cases, a CollectionExpression should not be created and the parsing should actually stop here. Example: BETWEEN 10 20, when parsing 20, it should not be parsed as part of the lower bound expression.

Parameters
expression:AbstractExpression

The Expression that has just been parsed or null

Returns:boolean

true

Annotations
@Override
toParsedTextback to summary
protected void toParsedText(StringBuilder writer, boolean actual)

Implements abstract org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.toParsedText.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractExpression.toParsedText.

Generates a string representation of this Expression, including its children, if it has any.

Parameters
writer:StringBuilder

The buffer used to append this Expression's string representation

actual:boolean

Determines whether the string representation should represent what was parsed, i.e. include any "virtual" whitespace (such as ending whitespace) and the actual case of the JPQL identifiers

Annotations
@Override