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

public final Class CastExpression

extends AbstractSingleEncapsulatedExpression
Class Inheritance
Imports
java.util.List, org.eclipse.persistence.jpa.jpql.WordParser

The CAST function cast value to a different type. The database type is the second parameter, and can be any valid database type including size and scale.
BNF: expression ::= CAST(scalar_expression [AS] database_type)
Author
James Sutherland
Since
2.4
Version
2.5
See Also
DatabaseType

Field Summary

Modifier and TypeField and Description
private String
asIdentifier

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

private AbstractExpression
databaseType

The Expression representing the database type to cast to.

private boolean
hasSpaceAfterAs

Determines whether a space was parsed after the identifier AS.

private boolean
hasSpaceAfterExpression

Determines whether a space was parsed after the expression.

private boolean
parsingDatabaseType

Flag used to determine how to stop parsing based on what is being parsed.

private boolean
shouldParseWithFactoryFirst

This flag is used to prevent the parsing from using any ExpressionFactory before going through the fallback procedure.

Constructor Summary

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

Creates a new CastExpression.

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.
protected void
addOrderedEncapsulatedExpressionTo(List<Expression>
The list used to store the string representation of the encapsulated Expression
children
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.addOrderedEncapsulatedExpressionTo.

Adds the Expressions representing the encapsulated Expression.
public Expression

Returns:

The Expression representing the database type
getDatabaseType
()

Returns the database type to cast to.

public String
public JPQLQueryBNF
public boolean

Returns:

true if the identifier AS was parsed; false otherwise
hasAs
()

Determines whether the identifier AS was part of the query.

public boolean

Returns:

true if the database type was parsed; false otherwise
hasDatabaseType
()

Determines whether the database type was parsed or not.

public boolean
public boolean

Returns:

true the expression to be cast was parsed; false otherwise
hasScalarExpression
()

Determines whether something was parsed after the left parenthesis and before the AS identifier.

public boolean

Returns:

true if there was a whitespace parsed after AS; false otherwise
hasSpaceAfterAs
()

Determines whether a whitespace parsed after AS.

public boolean

Returns:

true if there was a whitespace parsed after the expression; false otherwise
hasSpaceAfterExpression
()

Determines whether a whitespace was parsed after the expression.

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.AbstractEncapsulatedExpression.isParsingComplete.

Determines whether the parsing is complete based on what is left in the given text.
protected void
parseEncapsulatedExpression(WordParser
The text to parse based on the current position of the cursor
wordParser
,
int
The number of whitespace characters that were parsed after '('
whitespaceCount
,
boolean
Determines whether the parsing system should be tolerant, meaning if it should try to parse invalid or incomplete queries
tolerant
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.parseEncapsulatedExpression.

Parses the encapsulated expression by starting at the current position, which is part of the given WordParser.
protected void
protected boolean
shouldParseWithFactoryFirst()

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

Determines whether the parsing of the query should be performed using the factories first or it should automatically fallback to the fallback factory.
protected void
toParsedTextEncapsulatedExpression(StringBuilder
The buffer used to append the encapsulated Expression's string representation
writer
,
boolean
Determines whether to include any characters that are considered virtual, i.e. that was parsed when the query is incomplete and is needed for functionality like content assist
actual
)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.toParsedTextEncapsulatedExpression.

Generates a string representation of the encapsulated Expression.
Inherited from org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression:
acceptChildrenaddChildrenTofindQueryBNFgetExpressionhasExpressionsetExpression

Field Detail

asIdentifierback to summary
private String asIdentifier

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

databaseTypeback to summary
private AbstractExpression databaseType

The Expression representing the database type to cast to.

hasSpaceAfterAsback to summary
private boolean hasSpaceAfterAs

Determines whether a space was parsed after the identifier AS.

hasSpaceAfterExpressionback to summary
private boolean hasSpaceAfterExpression

Determines whether a space was parsed after the expression.

parsingDatabaseTypeback to summary
private boolean parsingDatabaseType

Flag used to determine how to stop parsing based on what is being parsed.

shouldParseWithFactoryFirstback to summary
private boolean shouldParseWithFactoryFirst

This flag is used to prevent the parsing from using any ExpressionFactory before going through the fallback procedure. This is necessary because only a DatabaseType should be created, even if the database type is a JPQL identifier (eg: TIMESTAMP).

Constructor Detail

CastExpressionback to summary
public CastExpression(AbstractExpression parent)

Creates a new CastExpression.

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
addOrderedEncapsulatedExpressionToback to summary
protected void addOrderedEncapsulatedExpressionTo(List<Expression> children)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.addOrderedEncapsulatedExpressionTo.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractEncapsulatedExpression.addOrderedEncapsulatedExpressionTo.

Adds the Expressions representing the encapsulated Expression.

Parameters
children:List<Expression>

The list used to store the string representation of the encapsulated Expression

Annotations
@Override
getDatabaseTypeback to summary
public Expression getDatabaseType()

Returns the database type to cast to.

Returns:Expression

The Expression representing the database type

getEncapsulatedExpressionQueryBNFIdback to summary
public String getEncapsulatedExpressionQueryBNFId()

Implements abstract org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.getEncapsulatedExpressionQueryBNFId.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.getEncapsulatedExpressionQueryBNFId.

Returns the BNF used to parse the encapsulated expression.

Returns:String

The BNF used to parse the encapsulated expression

Annotations
@Override
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
hasAsback to summary
public boolean hasAs()

Determines whether the identifier AS was part of the query.

Returns:boolean

true if the identifier AS was parsed; false otherwise

hasDatabaseTypeback to summary
public boolean hasDatabaseType()

Determines whether the database type was parsed or not.

Returns:boolean

true if the database type was parsed; false otherwise

hasEncapsulatedExpressionback to summary
public boolean hasEncapsulatedExpression()

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.hasEncapsulatedExpression.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractEncapsulatedExpression.hasEncapsulatedExpression.

Determines whether something was parsed after the left parenthesis.

Returns:boolean

true if something was parsed; false otherwise

Annotations
@Override
hasScalarExpressionback to summary
public boolean hasScalarExpression()

Determines whether something was parsed after the left parenthesis and before the AS identifier.

Returns:boolean

true the expression to be cast was parsed; false otherwise

Since
2.5
hasSpaceAfterAsback to summary
public boolean hasSpaceAfterAs()

Determines whether a whitespace parsed after AS.

Returns:boolean

true if there was a whitespace parsed after AS; false otherwise

hasSpaceAfterExpressionback to summary
public boolean hasSpaceAfterExpression()

Determines whether a whitespace was parsed after the expression.

Returns:boolean

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

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

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractEncapsulatedExpression.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
parseEncapsulatedExpressionback to summary
protected void parseEncapsulatedExpression(WordParser wordParser, int whitespaceCount, boolean tolerant)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.parseEncapsulatedExpression.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractEncapsulatedExpression.parseEncapsulatedExpression.

Parses the encapsulated expression 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

whitespaceCount:int

The number of whitespace characters that were parsed after '('

tolerant:boolean

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

Annotations
@Override
removeEncapsulatedExpressionback to summary
protected void removeEncapsulatedExpression()

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.removeEncapsulatedExpression.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractEncapsulatedExpression.removeEncapsulatedExpression.

Removes the encapsulated Expression that was parsed, it should not be part of this one. This happens when the parsed information does not have both '(' and ')'.

Annotations
@Override
shouldParseWithFactoryFirstback to summary
protected boolean shouldParseWithFactoryFirst()

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

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

Determines whether the parsing of the query should be performed using the factories first or it should automatically fallback to the fallback factory.

Returns:boolean

true is returned by default so the factories are used before falling back

Annotations
@Override
toParsedTextEncapsulatedExpressionback to summary
protected void toParsedTextEncapsulatedExpression(StringBuilder writer, boolean actual)

Overrides org.eclipse.persistence.jpa.jpql.parser.AbstractSingleEncapsulatedExpression.toParsedTextEncapsulatedExpression.

Doc from org.eclipse.persistence.jpa.jpql.parser.AbstractEncapsulatedExpression.toParsedTextEncapsulatedExpression.

Generates a string representation of the encapsulated Expression.

Parameters
writer:StringBuilder

The buffer used to append the encapsulated Expression's string representation

actual:boolean

Determines whether to include any characters that are considered virtual, i.e. that was parsed when the query is incomplete and is needed for functionality like content assist

Annotations
@Override