All Implemented Interfaces:
StateObject

public class WhenClauseStateObject extends AbstractConditionalClauseStateObject
A WHEN predicate is used to calculate a condition and when it's true, its THEN will be executed.

BNF: when_clause ::= WHEN conditional_expression THEN scalar_expression

or

BNF: simple_when_clause ::= WHEN scalar_expression THEN scalar_expression

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

    • THEN_STATE_OBJECT_PROPERTY

      public static final String THEN_STATE_OBJECT_PROPERTY
      Notify the StateObject representing the scalar expression that follows the THEN identifier has changed.
      See Also:
  • Constructor Details

    • WhenClauseStateObject

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

      public WhenClauseStateObject(CaseExpressionStateObject parent, StateObject whenStateObject, StateObject thenStateObject)
      Creates a new WhenClauseStateObject.
      Parameters:
      parent - The parent of this state object
      whenStateObject - The StateObject representing the conditional expression that is following the WHEN identifier
      thenStateObject - The StateObject representing the scalar expression that is following the THEN identifier
      Throws:
      NullPointerException - The given parent cannot be null
    • WhenClauseStateObject

      public WhenClauseStateObject(CaseExpressionStateObject parent, String whenJpqlFragment, String thenJpqlFragment)
      Creates a new WhenClauseStateObject.
      Parameters:
      parent - The parent of this state object
      whenJpqlFragment - The string representation of the WHEN clause to parse and to convert into a StateObject
      thenJpqlFragment - The string representation of the THEN expression to parse and to convert into a StateObject
      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 AbstractConditionalClauseStateObject
      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
    • getExpression

      public WhenClause 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)
    • getIdentifier

      public String getIdentifier()
      Description copied from class: AbstractConditionalClauseStateObject
      Returns the JPQL identifier of this clause.
      Specified by:
      getIdentifier in class AbstractConditionalClauseStateObject
      Returns:
      The JPQL identifier of this conditional clause
    • getParent

      public CaseExpressionStateObject getParent()
      Description copied from interface: StateObject
      Returns the parent of this StateObject.
      Specified by:
      getParent in interface StateObject
      Overrides:
      getParent in class AbstractStateObject
      Returns:
      Returns the parent of this StateObject, which is null only when this is the root of the hierarchy
    • getThen

      public StateObject getThen()
      Returns the StateObject representing the scalar expression that is following the THEN identifier.
      Returns:
      Either the StateObject representing the THEN expression or null if it's not defined
    • hasThen

      public boolean hasThen()
      Determines whether the StateObject representing the scalar expression is present.
      Returns:
      true the 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 AbstractConditionalClauseStateObject
      Parameters:
      stateObject - The StateObject to compare its content to this one
      Returns:
      true if both object are equivalent; false otherwise
    • parseThen

      public void parseThen(String jpqlFragment)
      Parses the given JPQL fragment, which will represent the THEN expression. The JPQL fragment should not start with the identifier.
      Parameters:
      jpqlFragment - The string representation of the THEN expression to parse and to convert into a StateObject
    • parseWhen

      public void parseWhen(String jpqlFragment)
      Parses the given JPQL fragment, which will represent the WHEN clause. The JPQL fragment should not start with the identifier.
      Parameters:
      jpqlFragment - The string representation of the WHEN clause to parse and to convert into a StateObject
    • setExpression

      public void setExpression(WhenClause 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 WHEN clause
    • setThen

      public void setThen(StateObject thenStateObject)
      Sets the scalar expression to be the given StateObject.
      Parameters:
      thenStateObject - The StateObject representing the scalar 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.
      Overrides:
      toTextInternal in class AbstractConditionalClauseStateObject
      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