All Implemented Interfaces:
ListHolderStateObject<WhenClauseStateObject>, StateObject

public class CaseExpressionStateObject extends AbstractListHolderStateObject<WhenClauseStateObject>
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

Since:
2.4
Version:
2.4
See Also:
  • Field Details

    • CASE_OPERAND_STATE_OBJECT_PROPERTY

      public static final String CASE_OPERAND_STATE_OBJECT_PROPERTY
      Notify the StateObject representing the case operand that follows the CASE identifier has changed.
      See Also:
    • ELSE_STATE_OBJECT_PROPERTY

      public static final String ELSE_STATE_OBJECT_PROPERTY
      Notify the StateObject representing the else expression that follows the ELSE identifier has changed.
      See Also:
    • WHEN_CLAUSE_STATE_OBJECT_LIST

      public static final String WHEN_CLAUSE_STATE_OBJECT_LIST
      Notify the list of StateObjects representing the when clauses that follow the WHEN has changed.
      See Also:
  • Constructor Details

    • CaseExpressionStateObject

      public CaseExpressionStateObject(StateObject parent)
      Creates a new CaseExpressionStateObject.
      Parameters:
      parent - The parent of this state object, which cannot be null
      Throws:
      NullPointerException - The given parent cannot be null
    • CaseExpressionStateObject

      public CaseExpressionStateObject(StateObject parent, List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject)
      Creates a new CaseExpressionStateObject.
      Parameters:
      parent - The parent of this state object, which cannot be null
      whenClauseStateObjects - The list of WhenClauseStateObjects that are representing the WHEN clauses
      elseStateObject - The StateObject representing the scalar expression that is following the ELSE identifier
      Throws:
      NullPointerException - The given parent cannot be null
    • CaseExpressionStateObject

      public CaseExpressionStateObject(StateObject parent, StateObject caseOperandStateObject, List<WhenClauseStateObject> whenClauseStateObjects, StateObject elseStateObject)
      Creates a new CaseExpressionStateObject.
      Parameters:
      parent - The parent of this state object, which cannot be null
      caseOperandStateObject - The StateObject representing the case operand that is following the CASE identifier or null if none is declared
      whenClauseStateObjects - The list of WhenClauseStateObjects that are representing the WHEN clauses
      elseStateObject - The StateObject representing the scalar expression that is following the ELSE identifier
      Throws:
      NullPointerException - The given parent cannot be null
  • Method Details

    • accept

      public void accept(StateObjectVisitor visitor)
      Description copied from interface: StateObject
      Visits this StateObject by the given visitor.
      Parameters:
      visitor - The visitor to visit this object
    • addChildren

      protected void addChildren(List<StateObject> children)
      Description copied from class: AbstractStateObject
      Adds the children of this StateObject to the given list.
      Overrides:
      addChildren in class AbstractListHolderStateObject<WhenClauseStateObject>
      Parameters:
      children - The list used to store the children
    • addProblems

      protected void addProblems(List<Problem> problems)
      Description copied from class: AbstractStateObject
      Adds to the given list the problems that were found with the current state of this StateObject, which means there are validation issues.
      Overrides:
      addProblems in class AbstractStateObject
      Parameters:
      problems - The list to which the problems are added
    • addWhenClause

      public WhenClauseStateObject addWhenClause()
      Adds a new WHEN clause.
      Returns:
      The newly created WhenClauseStateObject
    • addWhenClause

      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 - The StateObject representing the WHEN expression
      thenStateObject - The StateObject representing the THEN expression
      Returns:
      The newly created WhenClauseStateObject
    • addWhenClause

      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 - The string representation of the WHEN to parse and to convert into a StateObject representation
      thenJpqlFragment - The string representation of the THEN to parse and to convert into a StateObject representation
      Returns:
      The newly created WhenClauseStateObject
    • getCaseOperand

      public StateObject getCaseOperand()
      Returns the StateObject representing the case operand.
      Returns:
      The StateObject representing the case operand or null if it is not present
    • getElse

      public StateObject getElse()
      Returns the StateObject representing the ELSE scalar expression.
      Returns:
      The StateObject representing the ELSE scalar expression or null if it is not present
    • getExpression

      public CaseExpression getExpression()
      Description copied from interface: StateObject
      Returns the actual parsed object if this StateObject representation of the JPQL query was created by parsing an existing JPQL query.
      Specified by:
      getExpression in interface StateObject
      Overrides:
      getExpression in class AbstractStateObject
      Returns:
      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)
    • hasCaseOperand

      public boolean hasCaseOperand()
      Determines whether the StateObject representing the case operand is present.
      Returns:
      true the case operand exists; otherwise false
    • hasElse

      public boolean hasElse()
      Determines whether the StateObject representing the ELSE scalar expression is present.
      Returns:
      true the ELSE scalar expression exists; otherwise false
    • isEquivalent

      public boolean isEquivalent(StateObject stateObject)
      Description copied from interface: StateObject
      Determines whether the given StateObject is equivalent to this one, i.e. the information of both StateObject is the same.
      Specified by:
      isEquivalent in interface StateObject
      Overrides:
      isEquivalent in class AbstractStateObject
      Parameters:
      stateObject - The StateObject to compare its content to this one
      Returns:
      true if both object are equivalent; false otherwise
    • listName

      protected String listName()
      Description copied from class: AbstractListHolderStateObject
      Returns the name that is uniquely identifying the list.
      Specified by:
      listName in class AbstractListHolderStateObject<WhenClauseStateObject>
      Returns:
      The unique name identifying the list
    • parseCaseOperand

      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 - The string representation of the case operand to parse and to convert into a StateObject representation
    • parseElse

      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 - The string representation of the ELSE to parse and to convert into a StateObject representation
    • removeCaseOperand

      public void removeCaseOperand()
      Removes the case operand.
    • setCaseOperand

      public void setCaseOperand(StateObject caseOperand)
      Sets the case operand to be the given StateObject.
      Parameters:
      caseOperand - The StateObject representing the case operand or null to remove it
    • setElse

      public void setElse(StateObject elseStateObject)
      Sets the ELSE scalar expression to be the given StateObject.
      Parameters:
      elseStateObject - The StateObject representing the ELSE scalar expression or null to remove it
    • setExpression

      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 - The parsed object representing a CASE expression
    • toTextInternal

      public void toTextInternal(Appendable writer) throws IOException
      Description copied from class: AbstractStateObject
      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.
      Specified by:
      toTextInternal in class AbstractStateObject
      Parameters:
      writer - The writer used to print out the string representation
      Throws:
      IOException - This should never happens, it is only required because Appendable is used instead of any concrete class