java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
org.eclipse.persistence.jpa.jpql.tools.model.query.TreatExpressionStateObject
All Implemented Interfaces:
StateObject

public class TreatExpressionStateObject extends AbstractStateObject
Returns an expression that allows to treat its base as if it were a subclass of the class returned by the base.

Note: EclipseLinkStateObjectVisitor needs to be used to traverse this state object.

BNF: join_treat ::= TREAT(collection_valued_path_expression [AS] entity_type_literal)

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

    • AS_PROPERTY

      public static final String AS_PROPERTY
      Notifies the visibility of the AS identifier has changed.
      See Also:
    • ENTITY_TYPE_NAME_PROPERTY

      public static final String ENTITY_TYPE_NAME_PROPERTY
      Notifies the entity type name property has changed.
      See Also:
  • Constructor Details

    • TreatExpressionStateObject

      public TreatExpressionStateObject(JoinStateObject parent)
      Creates a new TreatExpressionStateObject.
      Parameters:
      parent - The parent of this state object, which is temporary since this state object will be parented with the state object representing the join's association path expression
    • TreatExpressionStateObject

      public TreatExpressionStateObject(JoinStateObject parent, boolean as, String entityTypeName)
      Creates a new TreatExpressionStateObject.
      Parameters:
      parent - The parent of this state object, which is temporary since this state object will be parented with the state object representing the join's association path expression
      as - Determines whether the AS identifier is used or not
      entityTypeName - The entity type name used to cast the base expression
    • TreatExpressionStateObject

      public TreatExpressionStateObject(JoinStateObject parent, String entityTypeName)
      Creates a new TreatExpressionStateObject.
      Parameters:
      parent - The parent of this state object, which is temporary since this state object will be parented with the state object representing the join's association path expression
      entityTypeName - The entity type name used to cast the base expression
  • 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
    • addAs

      Makes sure the AS identifier is specified.
      Returns:
      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 AbstractStateObject
      Parameters:
      children - The list used to store the children
    • appendToEntityTypeName

      public void appendToEntityTypeName(String text)
      Appends the given text to the existing entity type name property.
      Parameters:
      text - The text to append to the entity type name property or nothing is done if the given value is null
    • getEntity

      public IEntity getEntity()
      Resolves the entity type name to the external form of the actual IEntity.
      Returns:
      Either the IEntity with the same entity type name or null if the managed type provider does not have an entity with that name
    • getEntityTypeName

      public String getEntityTypeName()
      Returns the name of the entity that is used to downcast the join association path.
      Returns:
      The name of the entity used for down casting
    • getExpression

      public TreatExpression 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)
    • getJoin

      public JoinStateObject getJoin()
      Returns the reference of the JoinStateObject.
      Returns:
      The "owning" of this object
    • getJoinAssociationIdentificationVariable

      public StateObject getJoinAssociationIdentificationVariable()
      Returns the StateObject representing the identification variable that starts the path expression, which can be a sample identification variable, a map value, map key or map entry expression.
      Returns:
      The root of the path expression
    • getJoinAssociationPathStateObject

      public CollectionValuedPathExpressionStateObject getJoinAssociationPathStateObject()
      Returns the CollectionValuedPathExpressionStateObject representing the join association path.
      Returns:
      The state object representing the join association path
    • hasAs

      public boolean hasAs()
      Determines whether the AS identifier is used.
      Returns:
      true if the AS identifier is used; false otherwise
    • hasEntityTypeName

      public boolean hasEntityTypeName()
      Determines whether the.
      Returns:
      true if the entity type name has been defined; false otherwise
    • initialize

      protected void initialize()
      Description copied from class: AbstractStateObject
      Initializes this state object.
      Overrides:
      initialize in class AbstractStateObject
    • 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
    • removeAs

      public void removeAs()
      Makes sure the AS identifier is not specified.
    • setAs

      public void setAs(boolean as)
      Sets whether the AS identifier should be used.
      Parameters:
      as - true if the AS identifier should be used part; false otherwise
    • setEntityTypeName

      public void setEntityTypeName(Class<?> entityType)
      Sets the name of the entity that is used to downcast the join association path.
      Parameters:
      entityType - The Java class representing the entity type
    • setEntityTypeName

      public void setEntityTypeName(IEntity entityType)
      Sets the name of the entity that is used to downcast the join association path.
      Parameters:
      entityType - The external form of the entity type
    • setEntityTypeName

      public void setEntityTypeName(String entityTypeName)
      Sets the name of the entity that is used to downcast the join association path.
      Parameters:
      entityTypeName - The new name of the entity used for down casting
    • setExpression

      public void setExpression(TreatExpression 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 the TREAD expression
    • toggleAs

      public void toggleAs()
      Toggles the visibility of the AS identifier; either adds it if it's not present otherwise removes it if it's present.
    • toTextInternal

      protected 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