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
public class CaseExpressionStateObject extends AbstractListHolderStateObject<WhenClauseStateObject>
ACASE
predicate is used to calculate a condition and when it'strue
, itsTHEN
expression will be executed.BNF:orgeneral_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
- Version:
- 2.4
- See Also:
WhenClauseStateObject
,CaseExpression
- Author:
- Pascal Filion
- Since:
- 2.4
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
CASE_OPERAND_STATE_OBJECT_PROPERTY
Notify theStateObject
representing the case operand that follows theCASE
identifier has changed.static java.lang.String
ELSE_STATE_OBJECT_PROPERTY
Notify theStateObject
representing the else expression that follows theELSE
identifier has changed.static java.lang.String
WHEN_CLAUSE_STATE_OBJECT_LIST
Notify the list ofStateObjects
representing the when clauses that follow theWHEN
has changed.
-
Constructor Summary
Constructors Constructor Description CaseExpressionStateObject(StateObject parent)
Creates a newCaseExpressionStateObject
.CaseExpressionStateObject(StateObject parent, java.util.List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject)
Creates a newCaseExpressionStateObject
.CaseExpressionStateObject(StateObject parent, StateObject caseOperandStateObject, java.util.List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject)
Creates a newCaseExpressionStateObject
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
accept(StateObjectVisitor visitor)
Visits thisStateObject
by the givenvisitor
.protected void
addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObject
to the given list.protected void
addProblems(java.util.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.WhenClauseStateObject
addWhenClause()
Adds a newWHEN
clause.WhenClauseStateObject
addWhenClause(java.lang.String whenJpqlFragment, java.lang.String thenJpqlFragment)
Adds the given twoStateObjects
as theWHEN
expression and theTHEN
expression of the newWHEN
clause.WhenClauseStateObject
addWhenClause(StateObject whenStateObject, StateObject thenStateObject)
Adds the given twoStateObjects
as theWHEN
expression and theTHEN
expression of the newWHEN
clause.StateObject
getCaseOperand()
Returns theStateObject
representing the case operand.StateObject
getElse()
Returns theStateObject
representing theELSE
scalar expression.CaseExpression
getExpression()
Returns the actual parsed object if thisStateObject
representation of the JPQL query was created by parsing an existing JPQL query.boolean
hasCaseOperand()
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. the information of bothStateObject
is the same.protected java.lang.String
listName()
Returns the name that is uniquely identifying the list.void
parseCaseOperand(java.lang.String jpqlFragment)
Parses the given JPQL fragment, which will represent the case operand.void
parseElse(java.lang.String jpqlFragment)
Parses the given JPQL fragment, which will represent theELSE
expression.void
removeCaseOperand()
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(java.lang.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 Detail
-
CASE_OPERAND_STATE_OBJECT_PROPERTY
public static final java.lang.String CASE_OPERAND_STATE_OBJECT_PROPERTY
Notify theStateObject
representing the case operand that follows theCASE
identifier has changed.- See Also:
- Constant Field Values
-
ELSE_STATE_OBJECT_PROPERTY
public static final java.lang.String ELSE_STATE_OBJECT_PROPERTY
Notify theStateObject
representing the else expression that follows theELSE
identifier has changed.- See Also:
- Constant Field Values
-
WHEN_CLAUSE_STATE_OBJECT_LIST
public static final java.lang.String WHEN_CLAUSE_STATE_OBJECT_LIST
Notify the list ofStateObjects
representing the when clauses that follow theWHEN
has changed.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CaseExpressionStateObject
public CaseExpressionStateObject(StateObject parent)
Creates a newCaseExpressionStateObject
.- Parameters:
parent
- The parent of this state object, which cannot benull
- Throws:
java.lang.NullPointerException
- The given parent cannot benull
-
CaseExpressionStateObject
public CaseExpressionStateObject(StateObject parent, java.util.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:
java.lang.NullPointerException
- The given parent cannot benull
-
CaseExpressionStateObject
public CaseExpressionStateObject(StateObject parent, StateObject caseOperandStateObject, java.util.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:
java.lang.NullPointerException
- The given parent cannot benull
-
-
Method Detail
-
accept
public void accept(StateObjectVisitor visitor)
Visits thisStateObject
by the givenvisitor
.- Parameters:
visitor
- Thevisitor
to visit this object
-
addChildren
protected void addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObject
to the given list.- Overrides:
addChildren
in classAbstractListHolderStateObject<WhenClauseStateObject>
- Parameters:
children
- The list used to store the children
-
addProblems
protected void addProblems(java.util.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.- Overrides:
addProblems
in classAbstractStateObject
- Parameters:
problems
- The list to which the problems are added
-
addWhenClause
public WhenClauseStateObject 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
public WhenClauseStateObject addWhenClause(java.lang.String whenJpqlFragment, java.lang.String thenJpqlFragment)
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
public StateObject getCaseOperand()
Returns theStateObject
representing the case operand.- Returns:
- The
StateObject
representing the case operand ornull
if it is not present
-
getElse
public StateObject getElse()
Returns theStateObject
representing theELSE
scalar expression.- Returns:
- The
StateObject
representing theELSE
scalar expression ornull
if it is not present
-
getExpression
public CaseExpression getExpression()
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
public boolean isEquivalent(StateObject 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
protected java.lang.String listName()
Returns the name that is uniquely identifying the list.- Specified by:
listName
in classAbstractListHolderStateObject<WhenClauseStateObject>
- Returns:
- The unique name identifying the list
-
parseCaseOperand
public void parseCaseOperand(java.lang.String jpqlFragment)
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
public void parseElse(java.lang.String jpqlFragment)
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
public void setCaseOperand(StateObject caseOperand)
Sets the case operand to be the givenStateObject
.- Parameters:
caseOperand
- TheStateObject
representing the case operand ornull
to remove it
-
setElse
public void setElse(StateObject elseStateObject)
Sets theELSE
scalar expression to be the givenStateObject
.- Parameters:
elseStateObject
- TheStateObject
representing theELSE
scalar expression ornull
to remove it
-
setExpression
public 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
.- Parameters:
expression
- Theparsed object
representing aCASE
expression
-
toTextInternal
public void toTextInternal(java.lang.Appendable writer) throws java.io.IOException
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:
java.io.IOException
- This should never happens, it is only required becauseAppendable
is used instead of any concrete class
-
-