Class OrderByItemStateObject

  • All Implemented Interfaces:
    StateObject

    public class OrderByItemStateObject
    extends AbstractStateObject
    An ORDER BY item must be one of the following:
    1. A state_field_path_expression that evaluates to an orderable state field of an entity or embeddable class abstract schema type designated in the SELECT clause by one of the following:
      • A general_identification_variable
      • A single_valued_object_path_expression
    2. A state_field_path_expression that evaluates to the same state field of the same entity or embeddable abstract schema type as a state_field_path_expression in the SELECT clause
    3. A result_variable that refers to an orderable item in the SELECT clause for which the same result_variable has been specified. This may be the result of an aggregate_expression, a scalar_expression, or a state_field_path_expression in the SELECT clause.

    The keyword ASC specifies that ascending ordering be used for the associated ORDER BY item; the keyword DESC specifies that descending ordering be used. Ascending ordering is the default.

    JPA 1.0:

    BNF: orderby_item ::= state_field_path_expression [ ASC | DESC ]

    JPA 2.0

    BNF: orderby_item ::= state_field_path_expression | result_variable [ ASC | DESC ]

    Version:
    2.4
    See Also:
    OrderByItem
    Author:
    Pascal Filion
    Since:
    2.4
    • Field Detail

      • ORDERING_PROPERTY

        public static final java.lang.String ORDERING_PROPERTY
        Notifies the ordering property has changed.
        See Also:
        Constant Field Values
      • STATE_OBJECT_PROPERTY

        public static final java.lang.String STATE_OBJECT_PROPERTY
        Notifies the ordering property has changed.
        See Also:
        Constant Field Values
    • Constructor Detail

      • OrderByItemStateObject

        public OrderByItemStateObject​(OrderByClauseStateObject parent)
        Creates a new OrderByItemStateObject.
        Parameters:
        parent - The parent of this state object, which cannot be null
        Throws:
        java.lang.NullPointerException - The given parent cannot be null
      • OrderByItemStateObject

        public OrderByItemStateObject​(OrderByClauseStateObject parent,
                                      OrderByItem.Ordering ordering)
        Creates a new OrderByItemStateObject.
        Parameters:
        parent - The parent of this state object, which cannot be null
        Throws:
        java.lang.NullPointerException - The given parent cannot be null
      • OrderByItemStateObject

        public OrderByItemStateObject​(OrderByClauseStateObject parent,
                                      StateObject stateObject,
                                      OrderByItem.Ordering ordering)
        Creates a new OrderByItemStateObject.
        Parameters:
        parent - The parent of this state object, which cannot be null
        stateObject - The StateObject of the item
        ordering - One of the possible OrderByItem.Ordering choice
        Throws:
        java.lang.NullPointerException - The given parent cannot be null
      • OrderByItemStateObject

        public OrderByItemStateObject​(OrderByClauseStateObject parent,
                                      java.lang.String jpqlFragment,
                                      OrderByItem.Ordering ordering)
        Creates a new OrderByItemStateObject.
        Parameters:
        parent - The parent of this state object, which cannot be null
        jpqlFragment - The JPQL fragment representing the ordering item
        ordering - One of the possible OrderByItem.Ordering choice
        Throws:
        java.lang.NullPointerException - The given parent cannot be null
    • Method Detail

      • getExpression

        public OrderByItem getExpression()
        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)
      • getOrdering

        public OrderByItem.Ordering getOrdering()
        Returns the enum constant representing the ordering type.
        Returns:
        The constant representing the ordering, in the case the ordering was not parsed, then OrderByItem.Ordering.DEFAULT is returned
      • getStateObject

        public StateObject getStateObject()
        Returns the StateObject representing the value used for ordering.
        Returns:
        The StateObject representing the value used for ordering
      • hasStateObject

        public boolean hasStateObject()
        Determines whether the StateObject representing the value used for ordering has been defined.
        Returns:
        true if the ordering value is defined; false otherwise
      • isAscending

        public boolean isAscending()
        Determines whether the ordering was specified as being ascendant.
        Returns:
        true if ASC was parsed; false otherwise
      • isDefault

        public boolean isDefault()
        Determines whether the ordering was not specified.
        Returns:
        true if no ordering was parsed; false otherwise
      • isDescending

        public boolean isDescending()
        Determines whether the ordering was specified as being descendant.
        Returns:
        true if DESC was parsed; false otherwise
      • parse

        public void parse​(java.lang.String jpqlFragment)
        Parses the given JPQL fragment, which represents either a state-field pathe expression or a result variable, and creates the StateObject.
        Parameters:
        jpqlFragment - The portion of the query representing a state-field path expression or result variable
      • removeOrdering

        public void removeOrdering()
        Removes the ordering if it's specified, otherwise do nothing.
      • setExpression

        public void setExpression​(OrderByItem 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 an order by item
      • setOrdering

        public void setOrdering​(OrderByItem.Ordering ordering)
        Sets the enum constant representing the ordering type.
        Parameters:
        ordering - The constant representing the ordering, in the case the ordering was not parsed, then OrderByItem.Ordering.DEFAULT should be used
      • setStateObject

        public void setStateObject​(StateObject stateObject)
        Sets the StateObject representing the value used for ordering.
        Parameters:
        stateObject - The StateObject representing the value used for ordering
      • toTextInternal

        protected void toTextInternal​(java.lang.Appendable writer)
                               throws java.io.IOException
        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:
        java.io.IOException - This should never happens, it is only required because Appendable is used instead of any concrete class