Class CaseExpressionStateObject
java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractListHolderStateObject<WhenClauseStateObject>
org.eclipse.persistence.jpa.jpql.tools.model.query.CaseExpressionStateObject
- All Implemented Interfaces:
ListHolderStateObject<WhenClauseStateObject>
,StateObject
A
CASE
predicate is used to calculate a condition and when it's true
,
its THEN
expression will be executed.
BNF:
or
general_case_expression ::= CASE when_clause {when_clause}* ELSE scalar_expression END
BNF: simple_case_expression ::= CASE case_operand simple_when_clause {simple_when_clause}* ELSE scalar_expression END
- Since:
- 2.4
- Version:
- 2.4
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Notify theStateObject
representing the case operand that follows theCASE
identifier has changed.static final String
Notify theStateObject
representing the else expression that follows theELSE
identifier has changed.static final String
Notify the list ofStateObjects
representing the when clauses that follow theWHEN
has changed. -
Constructor Summary
ConstructorDescriptionCaseExpressionStateObject
(StateObject parent) Creates a newCaseExpressionStateObject
.CaseExpressionStateObject
(StateObject parent, List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject) Creates a newCaseExpressionStateObject
.CaseExpressionStateObject
(StateObject parent, StateObject caseOperandStateObject, List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject) Creates a newCaseExpressionStateObject
. -
Method Summary
Modifier and TypeMethodDescriptionvoid
accept
(StateObjectVisitor visitor) Visits thisStateObject
by the givenvisitor
.protected void
addChildren
(List<StateObject> children) Adds the children of thisStateObject
to the given list.protected void
addProblems
(List<Problem> problems) Adds to the given list the problems that were found with the current state of thisStateObject
, which means there are validation issues.Adds a newWHEN
clause.addWhenClause
(String whenJpqlFragment, String thenJpqlFragment) Adds the given twoStateObjects
as theWHEN
expression and theTHEN
expression of the newWHEN
clause.addWhenClause
(StateObject whenStateObject, StateObject thenStateObject) Adds the given twoStateObjects
as theWHEN
expression and theTHEN
expression of the newWHEN
clause.Returns theStateObject
representing the case operand.getElse()
Returns theStateObject
representing theELSE
scalar expression.Returns the actual parsed object if thisStateObject
representation of the JPQL query was created by parsing an existing JPQL query.boolean
Determines whether theStateObject
representing the case operand is present.boolean
hasElse()
Determines whether theStateObject
representing theELSE
scalar expression is present.boolean
isEquivalent
(StateObject stateObject) Determines whether the givenStateObject
is equivalent to this one, i.e.protected String
listName()
Returns the name that is uniquely identifying the list.void
parseCaseOperand
(String jpqlFragment) Parses the given JPQL fragment, which will represent the case operand.void
Parses the given JPQL fragment, which will represent theELSE
expression.void
Removes the case operand.void
setCaseOperand
(StateObject caseOperand) Sets the case operand to be the givenStateObject
.void
setElse
(StateObject elseStateObject) Sets theELSE
scalar expression to be the givenStateObject
.void
setExpression
(CaseExpression 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
toTextInternal
(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.AbstractListHolderStateObject
addItem, addItems, addListChangeListener, areChildrenEquivalent, canMoveDown, canMoveUp, getItem, hasItems, initialize, items, itemsSize, moveDown, moveUp, removeItem, removeItems, removeListChangeListener, toStringItems
Methods inherited from class org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
acceptUnknownVisitor, acceptUnknownVisitor, addPropertyChangeListener, areEquivalent, buildProblem, buildProblem, buildStateObject, buildStateObjects, checkParent, children, decorate, equals, findIdentificationVariable, firePropertyChanged, getChangeSupport, getDeclaration, getDecorator, getGrammar, getManagedTypeProvider, getParent, 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, getParent, getQueryBuilder, getRoot, isDecorated, removePropertyChangeListener, setParent, toString, toText
-
Field Details
-
CASE_OPERAND_STATE_OBJECT_PROPERTY
Notify theStateObject
representing the case operand that follows theCASE
identifier has changed.- See Also:
-
ELSE_STATE_OBJECT_PROPERTY
Notify theStateObject
representing the else expression that follows theELSE
identifier has changed.- See Also:
-
WHEN_CLAUSE_STATE_OBJECT_LIST
Notify the list ofStateObjects
representing the when clauses that follow theWHEN
has changed.- See Also:
-
-
Constructor Details
-
CaseExpressionStateObject
Creates a newCaseExpressionStateObject
.- Parameters:
parent
- The parent of this state object, which cannot benull
- Throws:
NullPointerException
- The given parent cannot benull
-
CaseExpressionStateObject
public CaseExpressionStateObject(StateObject parent, List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject) Creates a newCaseExpressionStateObject
.- Parameters:
parent
- The parent of this state object, which cannot benull
whenClauseStateObjects
- The list ofWhenClauseStateObjects
that are representing theWHEN
clauseselseStateObject
- TheStateObject
representing the scalar expression that is following theELSE
identifier- Throws:
NullPointerException
- The given parent cannot benull
-
CaseExpressionStateObject
public CaseExpressionStateObject(StateObject parent, StateObject caseOperandStateObject, List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject) Creates a newCaseExpressionStateObject
.- Parameters:
parent
- The parent of this state object, which cannot benull
caseOperandStateObject
- TheStateObject
representing the case operand that is following theCASE
identifier ornull
if none is declaredwhenClauseStateObjects
- The list ofWhenClauseStateObjects
that are representing theWHEN
clauseselseStateObject
- TheStateObject
representing the scalar expression that is following theELSE
identifier- Throws:
NullPointerException
- The given parent cannot benull
-
-
Method Details
-
accept
Description copied from interface:StateObject
Visits thisStateObject
by the givenvisitor
.- Parameters:
visitor
- Thevisitor
to visit this object
-
addChildren
Description copied from class:AbstractStateObject
Adds the children of thisStateObject
to the given list.- Overrides:
addChildren
in classAbstractListHolderStateObject<WhenClauseStateObject>
- Parameters:
children
- The list used to store the children
-
addProblems
Description copied from class:AbstractStateObject
Adds to the given list the problems that were found with the current state of thisStateObject
, which means there are validation issues.- Overrides:
addProblems
in classAbstractStateObject
- Parameters:
problems
- The list to which the problems are added
-
addWhenClause
Adds a newWHEN
clause.- Returns:
- The newly created
WhenClauseStateObject
-
addWhenClause
public WhenClauseStateObject addWhenClause(StateObject whenStateObject, StateObject thenStateObject) Adds the given twoStateObjects
as theWHEN
expression and theTHEN
expression of the newWHEN
clause.- Parameters:
whenStateObject
- TheStateObject
representing theWHEN
expressionthenStateObject
- TheStateObject
representing theTHEN
expression- Returns:
- The newly created
WhenClauseStateObject
-
addWhenClause
Adds the given twoStateObjects
as theWHEN
expression and theTHEN
expression of the newWHEN
clause.- Parameters:
whenJpqlFragment
- The string representation of theWHEN
to parse and to convert into aStateObject
representationthenJpqlFragment
- The string representation of theTHEN
to parse and to convert into aStateObject
representation- Returns:
- The newly created
WhenClauseStateObject
-
getCaseOperand
Returns theStateObject
representing the case operand.- Returns:
- The
StateObject
representing the case operand ornull
if it is not present
-
getElse
Returns theStateObject
representing theELSE
scalar expression.- Returns:
- The
StateObject
representing theELSE
scalar expression ornull
if it is not present
-
getExpression
Description copied from interface:StateObject
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 classAbstractStateObject
- 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)
-
hasCaseOperand
public boolean hasCaseOperand()Determines whether theStateObject
representing the case operand is present.- Returns:
true
the case operand exists; otherwisefalse
-
hasElse
public boolean hasElse()Determines whether theStateObject
representing theELSE
scalar expression is present.- Returns:
true
theELSE
scalar expression exists; otherwisefalse
-
isEquivalent
Description copied from interface: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 classAbstractStateObject
- Parameters:
stateObject
- TheStateObject
to compare its content to this one- Returns:
true
if both object are equivalent;false
otherwise
-
listName
Description copied from class:AbstractListHolderStateObject
Returns the name that is uniquely identifying the list.- Specified by:
listName
in classAbstractListHolderStateObject<WhenClauseStateObject>
- Returns:
- The unique name identifying the list
-
parseCaseOperand
Parses the given JPQL fragment, which will represent the case operand. The JPQL fragment should not start with the identifier.- Parameters:
jpqlFragment
- The string representation of the case operand to parse and to convert into aStateObject
representation
-
parseElse
Parses the given JPQL fragment, which will represent theELSE
expression. The JPQL fragment should not start with the identifier.- Parameters:
jpqlFragment
- The string representation of theELSE
to parse and to convert into aStateObject
representation
-
removeCaseOperand
public void removeCaseOperand()Removes the case operand. -
setCaseOperand
Sets the case operand to be the givenStateObject
.- Parameters:
caseOperand
- TheStateObject
representing the case operand ornull
to remove it
-
setElse
Sets theELSE
scalar expression to be the givenStateObject
.- Parameters:
elseStateObject
- TheStateObject
representing theELSE
scalar expression ornull
to remove it
-
setExpression
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 aCASE
expression
-
toTextInternal
Description copied from class:AbstractStateObject
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:
IOException
- This should never happens, it is only required becauseAppendable
is used instead of any concrete class
-