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

public final Class WhenClause

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

A WHEN predicate is used to calculate a condition and when it's true, its THEN will be executed.
BNF: when_clause ::= WHEN conditional_expression THEN scalar_expression
or
BNF: simple_when_clause ::= WHEN scalar_expression THEN scalar_expression
Author
Pascal Filion
Since
2.3
Version
2.5

Field Summary

Modifier and TypeField and Description
private boolean
hasSpaceAfterThen

Determines whether a whitespace was parsed after the identifier THEN.

private boolean
hasSpaceAfterWhen

Determines whether a whitespace was parsed after the identifier WHEN.

private boolean
hasSpaceAfterWhenExpression

Determines whether a whitespace was parsed after the conditional expression.

private AbstractExpression
thenExpression

The Expression representing the expression following the identifier THEN.

private String
thenIdentifier

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

private AbstractExpression
whenExpression

The Expression representing the conditional predicate of the clause.

private String
whenIdentifier

The actual WHEN 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
WhenClause(AbstractExpression
The parent of this expression
parent
)

Creates a new WhenClause.

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 WHEN expression represented by a temporary collection
buildWhenCollectionExpression
()

Creates a new CollectionExpression that will wrap the single WHEN expression.

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 THEN identifier that was actually parsed, or an empty string if it was not parsed
getActualThenIdentifier
()

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

public String

Returns:

The WHEN identifier that was actually parsed
getActualWhenIdentifier
()

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

public JPQLQueryBNF
public AbstractExpression

Returns:

The expression representing the expression executed if the predicate is true
getThenExpression
()

Returns the Expression representing the expression following the identifier THEN.

public AbstractExpression

Returns:

The expression following the WHEN identifier
getWhenExpression
()

Returns the Expression representing the conditional predicate of the clause.

public boolean

Returns:

true if there was a whitespace after THEN; false otherwise
hasSpaceAfterThen
()

Determines whether a whitespace was parsed after THEN.

public boolean

Returns:

true if there was a whitespace after WHEN; false otherwise
hasSpaceAfterWhen
()

Determines whether a whitespace was parsed after WHEN.

public boolean

Returns:

true if there was a whitespace after the conditional expression; false otherwise
hasSpaceAfterWhenExpression
()

Determines whether a whitespace was parsed after the conditional expression.

public boolean

Returns:

true if the identifier THEN was parsed; false otherwise
hasThen
()

Determines whether the identifier THEN was part of the query.

public boolean

Returns:

true the THEN expression was parsed; false if nothing was parsed
hasThenExpression
()

Determines whether the THEN expression of the query was parsed.

public boolean

Returns:

true the conditional expression was parsed; false if nothing was parsed
hasWhenExpression
()

Determines whether the conditional expression of the query was parsed.

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 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:
acceptUnknownVisitoracceptUnknownVisitorbuildExpressionFromFallingBackbuildNullExpressionbuildStringExpressionbuildStringExpressionbuildUnknownExpressioncalculatePositionchildrenfindFallBackExpressionFactorygetExpressionFactorygetExpressionRegistrygetGrammargetIdentifierVersiongetJPAVersiongetLengthgetOffsetgetParentgetQueryBNFgetRootgetTexthandleAggregatehandleCollectionisAncestorisIdentifierisNullisTolerantisUnknownisVirtualorderedChildrenparseparseUsingExpressionFactorypopulatePositionrebuildActualTextrebuildParsedTextsetParentsetTextshouldParseWithFactoryFirstshouldSkipLiteraltoActualTexttoParsedTexttoString

Field Detail

hasSpaceAfterThenback to summary
private boolean hasSpaceAfterThen

Determines whether a whitespace was parsed after the identifier THEN.

hasSpaceAfterWhenback to summary
private boolean hasSpaceAfterWhen

Determines whether a whitespace was parsed after the identifier WHEN.

hasSpaceAfterWhenExpressionback to summary
private boolean hasSpaceAfterWhenExpression

Determines whether a whitespace was parsed after the conditional expression.

thenExpressionback to summary
private AbstractExpression thenExpression

The Expression representing the expression following the identifier THEN.

thenIdentifierback to summary
private String thenIdentifier

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

whenExpressionback to summary
private AbstractExpression whenExpression

The Expression representing the conditional predicate of the clause.

whenIdentifierback to summary
private String whenIdentifier

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

Constructor Detail

WhenClauseback to summary
public WhenClause(AbstractExpression parent)

Creates a new WhenClause.

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
buildWhenCollectionExpressionback to summary
public CollectionExpression buildWhenCollectionExpression()

Creates a new CollectionExpression that will wrap the single WHEN expression.

Returns:CollectionExpression

The single WHEN expression 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
getActualThenIdentifierback to summary
public String getActualThenIdentifier()

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

Returns:String

The THEN identifier that was actually parsed, or an empty string if it was not parsed

getActualWhenIdentifierback to summary
public String getActualWhenIdentifier()

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

Returns:String

The WHEN identifier that was actually parsed

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
getThenExpressionback to summary
public AbstractExpression getThenExpression()

Returns the Expression representing the expression following the identifier THEN.

Returns:AbstractExpression

The expression representing the expression executed if the predicate is true

getWhenExpressionback to summary
public AbstractExpression getWhenExpression()

Returns the Expression representing the conditional predicate of the clause.

Returns:AbstractExpression

The expression following the WHEN identifier

hasSpaceAfterThenback to summary
public boolean hasSpaceAfterThen()

Determines whether a whitespace was parsed after THEN.

Returns:boolean

true if there was a whitespace after THEN; false otherwise

hasSpaceAfterWhenback to summary
public boolean hasSpaceAfterWhen()

Determines whether a whitespace was parsed after WHEN.

Returns:boolean

true if there was a whitespace after WHEN; false otherwise

hasSpaceAfterWhenExpressionback to summary
public boolean hasSpaceAfterWhenExpression()

Determines whether a whitespace was parsed after the conditional expression.

Returns:boolean

true if there was a whitespace after the conditional expression; false otherwise

hasThenback to summary
public boolean hasThen()

Determines whether the identifier THEN was part of the query.

Returns:boolean

true if the identifier THEN was parsed; false otherwise

hasThenExpressionback to summary
public boolean hasThenExpression()

Determines whether the THEN expression of the query was parsed.

Returns:boolean

true the THEN expression was parsed; false if nothing was parsed

hasWhenExpressionback to summary
public boolean hasWhenExpression()

Determines whether the conditional expression of the query was parsed.

Returns:boolean

true the conditional expression was parsed; false if nothing was parsed

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
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