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>
ACASEpredicate is used to calculate a condition and when it'strue, itsTHENexpression will be executed.BNF:orgeneral_case_expression ::= CASE when_clause {when_clause}* ELSE scalar_expression ENDBNF: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.StringCASE_OPERAND_STATE_OBJECT_PROPERTYNotify theStateObjectrepresenting the case operand that follows theCASEidentifier has changed.static java.lang.StringELSE_STATE_OBJECT_PROPERTYNotify theStateObjectrepresenting the else expression that follows theELSEidentifier has changed.static java.lang.StringWHEN_CLAUSE_STATE_OBJECT_LISTNotify the list ofStateObjectsrepresenting the when clauses that follow theWHENhas 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 voidaccept(StateObjectVisitor visitor)Visits thisStateObjectby the givenvisitor.protected voidaddChildren(java.util.List<StateObject> children)Adds the children of thisStateObjectto the given list.protected voidaddProblems(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.WhenClauseStateObjectaddWhenClause()Adds a newWHENclause.WhenClauseStateObjectaddWhenClause(java.lang.String whenJpqlFragment, java.lang.String thenJpqlFragment)Adds the given twoStateObjectsas theWHENexpression and theTHENexpression of the newWHENclause.WhenClauseStateObjectaddWhenClause(StateObject whenStateObject, StateObject thenStateObject)Adds the given twoStateObjectsas theWHENexpression and theTHENexpression of the newWHENclause.StateObjectgetCaseOperand()Returns theStateObjectrepresenting the case operand.StateObjectgetElse()Returns theStateObjectrepresenting theELSEscalar expression.CaseExpressiongetExpression()Returns the actual parsed object if thisStateObjectrepresentation of the JPQL query was created by parsing an existing JPQL query.booleanhasCaseOperand()Determines whether theStateObjectrepresenting the case operand is present.booleanhasElse()Determines whether theStateObjectrepresenting theELSEscalar expression is present.booleanisEquivalent(StateObject stateObject)Determines whether the givenStateObjectis equivalent to this one, i.e. the information of bothStateObjectis the same.protected java.lang.StringlistName()Returns the name that is uniquely identifying the list.voidparseCaseOperand(java.lang.String jpqlFragment)Parses the given JPQL fragment, which will represent the case operand.voidparseElse(java.lang.String jpqlFragment)Parses the given JPQL fragment, which will represent theELSEexpression.voidremoveCaseOperand()Removes the case operand.voidsetCaseOperand(StateObject caseOperand)Sets the case operand to be the givenStateObject.voidsetElse(StateObject elseStateObject)Sets theELSEscalar expression to be the givenStateObject.voidsetExpression(CaseExpression expression)Keeps a reference of theparsed objectobject, which should only be done when this object is instantiated during the conversion of a parsed JPQL query intoStateObjects.voidtoTextInternal(java.lang.Appendable writer)Prints out a string representation of thisStateObject, which should not be used to define atruestring 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 theStateObjectrepresenting the case operand that follows theCASEidentifier has changed.- See Also:
- Constant Field Values
-
ELSE_STATE_OBJECT_PROPERTY
public static final java.lang.String ELSE_STATE_OBJECT_PROPERTY
Notify theStateObjectrepresenting the else expression that follows theELSEidentifier 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 ofStateObjectsrepresenting the when clauses that follow theWHENhas 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 benullwhenClauseStateObjects- The list ofWhenClauseStateObjectsthat are representing theWHENclauseselseStateObject- TheStateObjectrepresenting the scalar expression that is following theELSEidentifier- 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 benullcaseOperandStateObject- TheStateObjectrepresenting the case operand that is following theCASEidentifier ornullif none is declaredwhenClauseStateObjects- The list ofWhenClauseStateObjectsthat are representing theWHENclauseselseStateObject- TheStateObjectrepresenting the scalar expression that is following theELSEidentifier- Throws:
java.lang.NullPointerException- The given parent cannot benull
-
-
Method Detail
-
accept
public void accept(StateObjectVisitor visitor)
Visits thisStateObjectby the givenvisitor.- Parameters:
visitor- Thevisitorto visit this object
-
addChildren
protected void addChildren(java.util.List<StateObject> children)
Adds the children of thisStateObjectto the given list.- Overrides:
addChildrenin 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:
addProblemsin classAbstractStateObject- Parameters:
problems- The list to which the problems are added
-
addWhenClause
public WhenClauseStateObject addWhenClause()
Adds a newWHENclause.- Returns:
- The newly created
WhenClauseStateObject
-
addWhenClause
public WhenClauseStateObject addWhenClause(StateObject whenStateObject, StateObject thenStateObject)
Adds the given twoStateObjectsas theWHENexpression and theTHENexpression of the newWHENclause.- Parameters:
whenStateObject- TheStateObjectrepresenting theWHENexpressionthenStateObject- TheStateObjectrepresenting theTHENexpression- Returns:
- The newly created
WhenClauseStateObject
-
addWhenClause
public WhenClauseStateObject addWhenClause(java.lang.String whenJpqlFragment, java.lang.String thenJpqlFragment)
Adds the given twoStateObjectsas theWHENexpression and theTHENexpression of the newWHENclause.- Parameters:
whenJpqlFragment- The string representation of theWHENto parse and to convert into aStateObjectrepresentationthenJpqlFragment- The string representation of theTHENto parse and to convert into aStateObjectrepresentation- Returns:
- The newly created
WhenClauseStateObject
-
getCaseOperand
public StateObject getCaseOperand()
Returns theStateObjectrepresenting the case operand.- Returns:
- The
StateObjectrepresenting the case operand ornullif it is not present
-
getElse
public StateObject getElse()
Returns theStateObjectrepresenting theELSEscalar expression.- Returns:
- The
StateObjectrepresenting theELSEscalar expression ornullif it is not present
-
getExpression
public CaseExpression getExpression()
Returns the actual parsed object if thisStateObjectrepresentation of the JPQL query was created by parsing an existing JPQL query.- Specified by:
getExpressionin interfaceStateObject- Overrides:
getExpressionin classAbstractStateObject- Returns:
- The parsed object when a JPQL query is parsed and converted into a
StateObjectornullwhen the JPQL query is manually created (i.e. not from a string)
-
hasCaseOperand
public boolean hasCaseOperand()
Determines whether theStateObjectrepresenting the case operand is present.- Returns:
truethe case operand exists; otherwisefalse
-
hasElse
public boolean hasElse()
Determines whether theStateObjectrepresenting theELSEscalar expression is present.- Returns:
truetheELSEscalar expression exists; otherwisefalse
-
isEquivalent
public boolean isEquivalent(StateObject stateObject)
Determines whether the givenStateObjectis equivalent to this one, i.e. the information of bothStateObjectis the same.- Specified by:
isEquivalentin interfaceStateObject- Overrides:
isEquivalentin classAbstractStateObject- Parameters:
stateObject- TheStateObjectto compare its content to this one- Returns:
trueif both object are equivalent;falseotherwise
-
listName
protected java.lang.String listName()
Returns the name that is uniquely identifying the list.- Specified by:
listNamein 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 aStateObjectrepresentation
-
parseElse
public void parseElse(java.lang.String jpqlFragment)
Parses the given JPQL fragment, which will represent theELSEexpression. The JPQL fragment should not start with the identifier.- Parameters:
jpqlFragment- The string representation of theELSEto parse and to convert into aStateObjectrepresentation
-
removeCaseOperand
public void removeCaseOperand()
Removes the case operand.
-
setCaseOperand
public void setCaseOperand(StateObject caseOperand)
Sets the case operand to be the givenStateObject.- Parameters:
caseOperand- TheStateObjectrepresenting the case operand ornullto remove it
-
setElse
public void setElse(StateObject elseStateObject)
Sets theELSEscalar expression to be the givenStateObject.- Parameters:
elseStateObject- TheStateObjectrepresenting theELSEscalar expression ornullto remove it
-
setExpression
public void setExpression(CaseExpression expression)
Keeps a reference of theparsed objectobject, which should only be done when this object is instantiated during the conversion of a parsed JPQL query intoStateObjects.- Parameters:
expression- Theparsed objectrepresenting aCASEexpression
-
toTextInternal
public void toTextInternal(java.lang.Appendable writer) throws java.io.IOExceptionPrints out a string representation of thisStateObject, which should not be used to define atruestring representation of a JPQL query but should be used for debugging purposes.- Specified by:
toTextInternalin classAbstractStateObject- Parameters:
writer- The writer used to print out the string representation- Throws:
java.io.IOException- This should never happens, it is only required becauseAppendableis used instead of any concrete class
-
-