Top Description Fields Constructors Methods
org.eclipse.persistence.jpa.jpql.tools.model.query

public Class CaseExpressionStateObject

extends AbstractListHolderStateObject<WhenClauseStateObject>
Class Inheritance
Annotations
@SuppressWarnings:nls, unused
Imports
java.io.IOException, java.util.List, org.eclipse.persistence.jpa.jpql.parser.CaseExpression, .CaseOperandBNF, .ElseExpressionBNF, org.eclipse.persistence.jpa.jpql.tools.model.Problem

A CASE predicate is used to calculate a condition and when it's true, its THEN expression will be executed.
BNF: general_case_expression ::= CASE when_clause {when_clause}* ELSE scalar_expression END
or

BNF: simple_case_expression ::= CASE case_operand simple_when_clause {simple_when_clause}* ELSE scalar_expression END

Author
Pascal Filion
Since
2.4
Version
2.4
See Also
WhenClauseStateObject, CaseExpression

Field Summary

Modifier and TypeField and Description
public static final String
CASE_OPERAND_STATE_OBJECT_PROPERTY

Notify the StateObject representing the case operand that follows the CASE identifier has changed.

private StateObject
caseOperandStateObject

The StateObject representing the case operand that is following the CASE identifier.

public static final String
ELSE_STATE_OBJECT_PROPERTY

Notify the StateObject representing the else expression that follows the ELSE identifier has changed.

private StateObject
elseStateObject

The StateObject representing the scalar expression that is following the ELSE identifier.

public static final String
WHEN_CLAUSE_STATE_OBJECT_LIST

Notify the list of StateObjects representing the when clauses that follow the WHEN has changed.

Constructor Summary

AccessConstructor and Description
public
CaseExpressionStateObject(StateObject
The parent of this state object, which cannot be null
parent
)

Creates a new CaseExpressionStateObject.

public
CaseExpressionStateObject(StateObject
The parent of this state object, which cannot be null
parent
,
List<WhenClauseStateObject>
The list of WhenClauseStateObjects that are representing the WHEN clauses
whenClauseStateObjects
,
StateObject
The StateObject representing the scalar expression that is following the ELSE identifier
elseStateObject
)

Creates a new CaseExpressionStateObject.

public
CaseExpressionStateObject(StateObject
The parent of this state object, which cannot be null
parent
,
StateObject
The StateObject representing the case operand that is following the CASE identifier or null if none is declared
caseOperandStateObject
,
List<WhenClauseStateObject>
The list of WhenClauseStateObjects that are representing the WHEN clauses
whenClauseStateObjects
,
StateObject
The StateObject representing the scalar expression that is following the ELSE identifier
elseStateObject
)

Creates a new CaseExpressionStateObject.

Method Summary

Modifier and TypeMethod and Description
public void
protected void
addChildren(List<StateObject>
The list used to store the children
children
)

Overrides org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractListHolderStateObject.addChildren.

Adds the children of this StateObject to the given list.
protected void
addProblems(List<Problem>
The list to which the problems are added
problems
)

Overrides org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.addProblems.

Adds to the given list the problems that were found with the current state of this StateObject, which means there are validation issues.
public WhenClauseStateObject

Returns:

The newly created WhenClauseStateObject
addWhenClause
()

Adds a new WHEN clause.

public WhenClauseStateObject

Returns:

The newly created WhenClauseStateObject
addWhenClause
(StateObject
The StateObject representing the WHEN expression
whenStateObject
,
StateObject
The StateObject representing the THEN expression
thenStateObject
)

Adds the given two StateObjects as the WHEN expression and the THEN expression of the new WHEN clause.

public WhenClauseStateObject

Returns:

The newly created WhenClauseStateObject
addWhenClause
(String
The string representation of the WHEN to parse and to convert into a StateObject representation
whenJpqlFragment
,
String
The string representation of the THEN to parse and to convert into a StateObject representation
thenJpqlFragment
)

Adds the given two StateObjects as the WHEN expression and the THEN expression of the new WHEN clause.

public StateObject

Returns:

The StateObject representing the case operand or null if it is not present
getCaseOperand
()

Returns the StateObject representing the case operand.

public StateObject

Returns:

The StateObject representing the ELSE scalar expression or null if it is not present
getElse
()

Returns the StateObject representing the ELSE scalar expression.

public CaseExpression
getExpression()

Overrides org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.getExpression.

Implements org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject.getExpression.

Returns the actual parsed object if this StateObject representation of the JPQL query was created by parsing an existing JPQL query.
public boolean

Returns:

true the case operand exists; otherwise false
hasCaseOperand
()

Determines whether the StateObject representing the case operand is present.

public boolean

Returns:

true the ELSE scalar expression exists; otherwise false
hasElse
()

Determines whether the StateObject representing the ELSE scalar expression is present.

public boolean
isEquivalent(StateObject
The StateObject to compare its content to this one
stateObject
)

Overrides org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.isEquivalent.

Implements org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject.isEquivalent.

Determines whether the given StateObject is equivalent to this one, i.e. the information of both StateObject is the same.
protected String
listName()

Implements abstract org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractListHolderStateObject.listName.

Returns the name that is uniquely identifying the list.
public void
parseCaseOperand(String
The string representation of the case operand to parse and to convert into a StateObject representation
jpqlFragment
)

Parses the given JPQL fragment, which will represent the case operand.

public void
parseElse(String
The string representation of the ELSE to parse and to convert into a StateObject representation
jpqlFragment
)

Parses the given JPQL fragment, which will represent the ELSE expression.

public void
removeCaseOperand()

Removes the case operand.

public void
setCaseOperand(StateObject
The StateObject representing the case operand or null to remove it
caseOperand
)

Sets the case operand to be the given StateObject.

public void
setElse(StateObject
The StateObject representing the ELSE scalar expression or null to remove it
elseStateObject
)

Sets the ELSE scalar expression to be the given StateObject.

public void
setExpression(CaseExpression
The parsed object representing a CASE expression
expression
)

Keeps a reference of the parsed object object, which should only be done when this object is instantiated during the conversion of a parsed JPQL query into StateObjects.

public void
toTextInternal(Appendable
The writer used to print out the string representation
writer
)

Implements abstract org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.toTextInternal.

Prints out a string representation of this StateObject, which should not be used to define a true string representation of a JPQL query but should be used for debugging purposes.
Inherited from org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractListHolderStateObject:
addItemaddItemsaddListChangeListenerareChildrenEquivalentcanMoveDowncanMoveUpgetItemhasItemsinitializeitemsitemsSizemoveDownmoveUpremoveItemremoveItemsremoveListChangeListenertoStringItems

Field Detail

CASE_OPERAND_STATE_OBJECT_PROPERTYback to summary
public static final String CASE_OPERAND_STATE_OBJECT_PROPERTY

Notify the StateObject representing the case operand that follows the CASE identifier has changed.

caseOperandStateObjectback to summary
private StateObject caseOperandStateObject

The StateObject representing the case operand that is following the CASE identifier.

ELSE_STATE_OBJECT_PROPERTYback to summary
public static final String ELSE_STATE_OBJECT_PROPERTY

Notify the StateObject representing the else expression that follows the ELSE identifier has changed.

elseStateObjectback to summary
private StateObject elseStateObject

The StateObject representing the scalar expression that is following the ELSE identifier.

WHEN_CLAUSE_STATE_OBJECT_LISTback to summary
public static final String WHEN_CLAUSE_STATE_OBJECT_LIST

Notify the list of StateObjects representing the when clauses that follow the WHEN has changed.

Constructor Detail

CaseExpressionStateObjectback to summary
public CaseExpressionStateObject(StateObject parent)

Creates a new CaseExpressionStateObject.

Parameters
parent:StateObject

The parent of this state object, which cannot be null

Exceptions
NullPointerException:
The given parent cannot be null
CaseExpressionStateObjectback to summary
public CaseExpressionStateObject(StateObject parent, List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject)

Creates a new CaseExpressionStateObject.

Parameters
parent:StateObject

The parent of this state object, which cannot be null

whenClauseStateObjects:List<WhenClauseStateObject>

The list of WhenClauseStateObjects that are representing the WHEN clauses

elseStateObject:StateObject

The StateObject representing the scalar expression that is following the ELSE identifier

Exceptions
NullPointerException:
The given parent cannot be null
CaseExpressionStateObjectback to summary
public CaseExpressionStateObject(StateObject parent, StateObject caseOperandStateObject, List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject)

Creates a new CaseExpressionStateObject.

Parameters
parent:StateObject

The parent of this state object, which cannot be null

caseOperandStateObject:StateObject

The StateObject representing the case operand that is following the CASE identifier or null if none is declared

whenClauseStateObjects:List<WhenClauseStateObject>

The list of WhenClauseStateObjects that are representing the WHEN clauses

elseStateObject:StateObject

The StateObject representing the scalar expression that is following the ELSE identifier

Exceptions
NullPointerException:
The given parent cannot be null

Method Detail

acceptback to summary
public void accept(StateObjectVisitor visitor)

Implements org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject.accept.

Doc from org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject.accept.

Visits this StateObject by the given visitor.

Parameters
visitor:StateObjectVisitor

The visitor to visit this object

Annotations
@Override
addChildrenback to summary
protected void addChildren(List<StateObject> children)

Overrides org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractListHolderStateObject.addChildren.

Doc from org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.addChildren.

Adds the children of this StateObject to the given list.

Parameters
children:List<StateObject>

The list used to store the children

Annotations
@Override
addProblemsback to summary
protected void addProblems(List<Problem> problems)

Overrides org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.addProblems.

Doc from org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.addProblems.

Adds to the given list the problems that were found with the current state of this StateObject, which means there are validation issues.

Parameters
problems:List<Problem>

The list to which the problems are added

Annotations
@Override
addWhenClauseback to summary
public WhenClauseStateObject addWhenClause()

Adds a new WHEN clause.

Returns:WhenClauseStateObject

The newly created WhenClauseStateObject

addWhenClauseback to summary
public WhenClauseStateObject addWhenClause(StateObject whenStateObject, StateObject thenStateObject)

Adds the given two StateObjects as the WHEN expression and the THEN expression of the new WHEN clause.

Parameters
whenStateObject:StateObject

The StateObject representing the WHEN expression

thenStateObject:StateObject

The StateObject representing the THEN expression

Returns:WhenClauseStateObject

The newly created WhenClauseStateObject

addWhenClauseback to summary
public WhenClauseStateObject addWhenClause(String whenJpqlFragment, String thenJpqlFragment)

Adds the given two StateObjects as the WHEN expression and the THEN expression of the new WHEN clause.

Parameters
whenJpqlFragment:String

The string representation of the WHEN to parse and to convert into a StateObject representation

thenJpqlFragment:String

The string representation of the THEN to parse and to convert into a StateObject representation

Returns:WhenClauseStateObject

The newly created WhenClauseStateObject

getCaseOperandback to summary
public StateObject getCaseOperand()

Returns the StateObject representing the case operand.

Returns:StateObject

The StateObject representing the case operand or null if it is not present

getElseback to summary
public StateObject getElse()

Returns the StateObject representing the ELSE scalar expression.

Returns:StateObject

The StateObject representing the ELSE scalar expression or null if it is not present

getExpressionback to summary
public CaseExpression getExpression()

Overrides org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.getExpression.

Implements org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject.getExpression.

Doc from org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject.getExpression.

Returns the actual parsed object if this StateObject representation of the JPQL query was created by parsing an existing JPQL query.

Returns:CaseExpression

The parsed object when a JPQL query is parsed and converted into a StateObject or null when the JPQL query is manually created (i.e. not from a string)

Annotations
@Override
hasCaseOperandback to summary
public boolean hasCaseOperand()

Determines whether the StateObject representing the case operand is present.

Returns:boolean

true the case operand exists; otherwise false

hasElseback to summary
public boolean hasElse()

Determines whether the StateObject representing the ELSE scalar expression is present.

Returns:boolean

true the ELSE scalar expression exists; otherwise false

isEquivalentback to summary
public boolean isEquivalent(StateObject stateObject)

Overrides org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.isEquivalent.

Implements org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject.isEquivalent.

Doc from org.eclipse.persistence.jpa.jpql.tools.model.query.StateObject.isEquivalent.

Determines whether the given StateObject is equivalent to this one, i.e. the information of both StateObject is the same.

Parameters
stateObject:StateObject

The StateObject to compare its content to this one

Returns:boolean

true if both object are equivalent; false otherwise

Annotations
@Override
listNameback to summary
protected String listName()

Implements abstract org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractListHolderStateObject.listName.

Doc from org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractListHolderStateObject.listName.

Returns the name that is uniquely identifying the list.

Returns:String

The unique name identifying the list

Annotations
@Override
parseCaseOperandback to summary
public void parseCaseOperand(String jpqlFragment)

Parses the given JPQL fragment, which will represent the case operand. The JPQL fragment should not start with the identifier.

Parameters
jpqlFragment:String

The string representation of the case operand to parse and to convert into a StateObject representation

parseElseback to summary
public void parseElse(String jpqlFragment)

Parses the given JPQL fragment, which will represent the ELSE expression. The JPQL fragment should not start with the identifier.

Parameters
jpqlFragment:String

The string representation of the ELSE to parse and to convert into a StateObject representation

removeCaseOperandback to summary
public void removeCaseOperand()

Removes the case operand.

setCaseOperandback to summary
public void setCaseOperand(StateObject caseOperand)

Sets the case operand to be the given StateObject.

Parameters
caseOperand:StateObject

The StateObject representing the case operand or null to remove it

setElseback to summary
public void setElse(StateObject elseStateObject)

Sets the ELSE scalar expression to be the given StateObject.

Parameters
elseStateObject:StateObject

The StateObject representing the ELSE scalar expression or null to remove it

setExpressionback to summary
public void setExpression(CaseExpression expression)

Keeps a reference of the parsed object object, which should only be done when this object is instantiated during the conversion of a parsed JPQL query into StateObjects.

Parameters
expression:CaseExpression

The parsed object representing a CASE expression

toTextInternalback to summary
public void toTextInternal(Appendable writer) throws IOException

Implements abstract org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.toTextInternal.

Doc from org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject.toTextInternal.

Prints out a string representation of this StateObject, which should not be used to define a true string representation of a JPQL query but should be used for debugging purposes.

Parameters
writer:Appendable

The writer used to print out the string representation

Annotations
@Override
Exceptions
IOException:
This should never happens, it is only required because Appendable is used instead of any concrete class