java.lang.Object
org.eclipse.persistence.jpa.jpql.tools.model.query.AbstractStateObject
All Implemented Interfaces:
StateObject
Direct Known Subclasses:
AbstractConditionalClauseStateObject, AbstractEncapsulatedExpressionStateObject, AbstractListHolderStateObject, AbstractModifyClauseStateObject, AbstractModifyStatementStateObject, AbstractPathExpressionStateObject, AbstractRangeVariableDeclarationStateObject, AbstractSelectClauseStateObject, AbstractSelectStatementStateObject, ArithmeticFactorStateObject, BetweenExpressionStateObject, CollectionExpressionStateObject, CollectionMemberDeclarationStateObject, CollectionMemberExpressionStateObject, CompoundExpressionStateObject, EmptyCollectionComparisonExpressionStateObject, FunctionExpressionStateObject, JoinStateObject, JPQLQueryStateObject, LikeExpressionStateObject, NotExpressionStateObject, NullComparisonExpressionStateObject, OrderByItemStateObject, ResultVariableStateObject, SimpleStateObject, TreatExpressionStateObject, UpdateItemStateObject

public abstract class AbstractStateObject extends Object implements StateObject
The abstract definition of a StateObject.
Since:
2.4
Version:
2.5
  • Constructor Details

    • AbstractStateObject

      protected AbstractStateObject(StateObject parent)
      Creates a new AbstractStateObject.
      Parameters:
      parent - The parent of this state object, which cannot be null
      Throws:
      NullPointerException - The given parent cannot be null, unless changeSupport is overridden and does not throw the exception
  • Method Details

    • acceptUnknownVisitor

      protected boolean acceptUnknownVisitor(StateObjectVisitor visitor)
      The given StateObjectVisitor needs to visit this class but it is defined by a third-party provider. This method will programmatically invoke the visit method defined on the given visitor which signature should be.
      {public|protected|private} void visit(ThirdPartyStateObject stateObject)

      or

      {public|protected|private} void visit(StateObject stateObject)

      Parameters:
      visitor - The StateObjectVisitor to visit this StateObject programmatically
      Returns:
      true if the call was successfully executed; false otherwise
      Since:
      2.4
    • acceptUnknownVisitor

      protected void acceptUnknownVisitor(StateObjectVisitor visitor, Class<?> type, Class<?> parameterType) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException
      The given StateObjectVisitor needs to visit this class but it is defined by a third-party provider. This method will programmatically invoke the visit method defined on the given visitor which signature should be.

      {public|protected|private} void visit(ThirdPartyStateObject stateObject)

      or

      {public|protected|private} void visit(StateObject stateObject)

      Parameters:
      visitor - The StateObjectVisitor to visit this StateObject programmatically
      type - The type found in the hierarchy of the given StateObjectVisitor that will be used to retrieve the visit method
      parameterType - The parameter type of the visit method
      Throws:
      NoSuchMethodException
      IllegalAccessException
      InvocationTargetException
      Since:
      2.4
      See Also:
    • addChildren

      protected void addChildren(List<StateObject> children)
      Adds the children of this StateObject to the given list.
      Parameters:
      children - The list used to store the children
    • addProblems

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

      public final void addPropertyChangeListener(String propertyName, IPropertyChangeListener<?> listener)
      Description copied from interface: StateObject
      Registers the given IPropertyChangeListener for the specified property. The listener will be notified only for changes to the specified property.
      Specified by:
      addPropertyChangeListener in interface StateObject
      Parameters:
      propertyName - The name of the property for which the listener was registered
      listener - The listener to be notified upon changes
    • areEquivalent

      protected final boolean areEquivalent(StateObject stateObject1, StateObject stateObject2)
      Determines whether the given two StateObject are equivalent, i.e. the information of both StateObject is the same.
      Parameters:
      stateObject1 - The first StateObject to compare its content with the other one
      stateObject2 - The second StateObject to compare its content with the other one
      Returns:
      true if both objects are equivalent; false otherwise
    • buildProblem

      protected final Problem buildProblem(String messageKey)
      Creates a new Problem describing a single issue found with the information contained in this StateObject.
      Parameters:
      messageKey - The key used to retrieve the localized message describing the problem found with the current state of this StateObject
      Returns:
      The new Problem
    • buildProblem

      protected final Problem buildProblem(String messageKey, String... arguments)
      Creates a new Problem describing a single issue found with the information contained in this StateObject.
      Parameters:
      messageKey - The key used to retrieve the localized message describing the problem found with the current state of this StateObject
      arguments - A list of arguments that can be used to complete the message or an empty list if no additional information is necessary
      Returns:
      The new Problem
    • buildStateObject

      protected <T extends StateObject> T buildStateObject(CharSequence jpqlFragment, String queryBNFId)
      Parses the given JPQL fragment using the given JPQL query BNF.
      Parameters:
      jpqlFragment - A portion of a JPQL query that will be parsed and converted into a StateObject
      queryBNFId - The unique identifier of the BNF that determines how to parse the fragment
      Returns:
      A StateObject representation of the given JPQL fragment
    • buildStateObjects

      protected <T extends StateObject> List<T> buildStateObjects(CharSequence jpqlFragment, String queryBNFId)
      Parses the given JPQL fragment using the given JPQL query BNF.
      Parameters:
      jpqlFragment - A portion of a JPQL query that will be parsed and converted into either a single StateObject or a list of StateObject, which happens when the fragment contains a collection of items separated by either a comma or a space
      queryBNFId - The unique identifier of the BNF that will be used to parse the fragment
      Returns:
      A list of StateObjects representing the given JPQL fragment, which means the list may contain a single StateObject or a multiple StateObjects if the fragment contains more than one expression of the same type. Example: "JOIN e.employees e LEFT JOIN e.address a", this would be parsed in two state objects
    • checkParent

      protected StateObject checkParent(StateObject parent)
      Checks whether the given parent is null or not. If it's null then throw a NullPointerException.
      Parameters:
      parent - The parent of this state object
      Returns:
      The given object
    • children

      public final Iterable<StateObject> children()
      Description copied from interface: StateObject
      Returns the ordered children of this StateObject.
      Specified by:
      children in interface StateObject
      Returns:
      The children of this StateObject or an empty iterable this state object does not have children
    • decorate

      public void decorate(StateObject decorator)
      Description copied from interface: StateObject
      Decorates this StateObject with the given decorator. It means the behavior of this StateObject is modified by the given one. By default, this StateObject becomes the parent of the given one.
      Specified by:
      decorate in interface StateObject
      Parameters:
      decorator - The StateObject decorating this one
    • equals

      public final boolean equals(Object object)
      Overrides:
      equals in class Object
    • findIdentificationVariable

      public IdentificationVariableStateObject findIdentificationVariable(String identificationVariable)
      Description copied from interface: StateObject
      Returns the IdentificationVariableStateObject representing the given identification variable.
      Specified by:
      findIdentificationVariable in interface StateObject
      Parameters:
      identificationVariable - The name of the identification variable to retrieve its state object
      Returns:
      The IdentificationVariableStateObject defining the given identification variable
    • firePropertyChanged

      protected final void firePropertyChanged(String propertyName, Object oldValue, Object newValue)
      Notifies the IPropertyChangeListeners that have been registered with the given property name that the property has changed.
      Parameters:
      propertyName - The name of the property associated with the property change
      oldValue - The old value of the property that changed
      newValue - The new value of the property that changed
    • getChangeSupport

      protected final ChangeSupport getChangeSupport()
      Returns the object responsible to actually register the listeners and to notify them upon changes made to this StateObject.
      Returns:
      The manager of listeners and notification
    • getDeclaration

      public DeclarationStateObject getDeclaration()
      Description copied from interface: StateObject
      Returns the declaration clause which defines the domain of the query by declaring identification variables.
      Specified by:
      getDeclaration in interface StateObject
      Returns:
      The declaration clause of which this StateObject is a child; i.e. either the top-level declaration if this is part of the top query or the sub-level declaration if this is part of a subquery
    • getDecorator

      public StateObject getDecorator()
      Description copied from interface: StateObject
      Returns the StateObject decorating this one if one has been set, which means the behavior of this StateObject is modified by the decorator.
      Specified by:
      getDecorator in interface StateObject
      Returns:
      The StateObject decorating this one
    • getExpression

      public Expression 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
      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)
    • getGrammar

      public JPQLGrammar getGrammar()
      Description copied from interface: StateObject
      Returns the grammar that defines how to parse a JPQL query.
      Specified by:
      getGrammar in interface StateObject
      Returns:
      The grammar that was used to parse the JPQL query
    • getManagedTypeProvider

      public IManagedTypeProvider getManagedTypeProvider()
      Description copied from interface: StateObject
      Returns the provider of managed types.
      Specified by:
      getManagedTypeProvider in interface StateObject
      Returns:
      The provider that gives access to the managed types
    • getParent

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

      public IJPQLQueryBuilder getQueryBuilder()
      Description copied from interface: StateObject
      Returns the IJPQLQueryBuilder that is responsible to create various part of the StateObject hierarchy.
      Specified by:
      getQueryBuilder in interface StateObject
      Returns:
      The builder that created this StateObject from a JPQL query or that gives access to various sub-builders
    • getRoot

      public JPQLQueryStateObject getRoot()
      Description copied from interface: StateObject
      Returns the root of the StateObject hierarchy.
      Specified by:
      getRoot in interface StateObject
      Returns:
      The root of the state model representing the JPQL query
    • getType

      public IType getType(Class<?> type)
      Retrieves the external type for the given Java type.
      Parameters:
      type - The Java type to wrap with an external form
      Returns:
      The external form of the given type
    • getType

      public IType getType(String typeName)
      Retrieves the external class for the given fully qualified class name.
      Parameters:
      typeName - The fully qualified class name of the class to retrieve
      Returns:
      The external form of the class to retrieve
    • getTypeHelper

      public TypeHelper getTypeHelper()
      Returns a helper that gives access to the most common types.
      Returns:
      A helper containing a collection of methods related to IType
    • getTypeRepository

      public ITypeRepository getTypeRepository()
      Returns the type repository for the application.
      Returns:
      The repository of ITypes
    • hashCode

      public final int hashCode()
      Overrides:
      hashCode in class Object
    • initialize

      protected void initialize()
      Initializes this state object.
    • isDecorated

      public boolean isDecorated()
      Description copied from interface: StateObject
      Determines whether this StateObject is being decorated by another StateObject, which means the behavior is modified by the given one. return true if this StateObject is being decorated; false otherwise
      Specified by:
      isDecorated in interface StateObject
    • 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
      Parameters:
      stateObject - The StateObject to compare its content to this one
      Returns:
      true if both object are equivalent; false otherwise
    • parent

      protected <T extends StateObject> List<T> parent(List<T> stateObjects)
      Makes sure the given list of StateObject has this one as its parent.
      Parameters:
      stateObjects - The list of StateObject to have this one as its parent
      Returns:
      The given list of StateObject
    • parent

      @SafeVarargs protected final <T extends StateObject> T[] parent(T... stateObjects)
      Makes sure the given list of StateObject has this one as its parent.
      Parameters:
      stateObjects - The list of StateObject to have this one as its parent
      Returns:
      The given list of StateObject
    • parent

      protected <T extends StateObject> T parent(T stateObject)
      Makes sure the given StateObject has this one as its parent.
      Parameters:
      stateObject - The StateObject to have this one as its parent
      Returns:
      The given StateObject
    • removePropertyChangeListener

      public final void removePropertyChangeListener(String propertyName, IPropertyChangeListener<?> listener)
      Description copied from interface: StateObject
      Unregisters the given IPropertyChangeListener that was registered for the specified property. The listener will no longer be notified when the property changes.
      Specified by:
      removePropertyChangeListener in interface StateObject
      Parameters:
      propertyName - The name of the property for which the listener was registered
      listener - The listener to unregister
    • setExpression

      public void setExpression(Expression expression)
      Sets the actual parsed object if this StateObject representation of the JPQL query is created by converting the parsed representation of the JPQL query.
      Parameters:
      expression - The parsed object when a JPQL query is parsed
    • setParent

      public final void setParent(StateObject parent)
      Description copied from interface: StateObject
      Sets the given StateObject to become the parent of this one.
      Specified by:
      setParent in interface StateObject
      Parameters:
      parent - The new parent StateObject of this one, which cannot be null
    • toString

      public final String toString()
      Overrides:
      toString in class Object
    • toString

      public final void toString(Appendable writer)
      Description copied from interface: StateObject
      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.

      Important: If this StateObject is decorated by another one, then StateObject.toText(Appendable) from that decorator is invoked, otherwise the information contained in this one will be printed out.

      Specified by:
      toString in interface StateObject
      Parameters:
      writer - The writer used to print out the string representation
      See Also:
    • toStringInternal

      protected final void toStringInternal(Appendable writer) throws IOException
      Prints out a string representation of this StateObject.

      Important: If this StateObject is decorated by another one, then toString(Appendable) from that decorator is invoked, otherwise toTextInternal(Appendable) from this one is invoked.

      Parameters:
      writer - The writer used to print out the string representation
      Throws:
      IOException - This should never happens, it is only required because Appendable.append(CharSequence) throws an IOException
    • toStringItems

      protected void toStringItems(Appendable writer, List<? extends StateObject> items, boolean useComma) throws IOException
      Throws:
      IOException
    • toText

      public final void toText(Appendable writer)
      Description copied from interface: StateObject
      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.

      Important: Even if this StateObject is decorated by another one, the decorator will not be used to print out a string representation of this one.

      Specified by:
      toText in interface StateObject
      Parameters:
      writer - The writer used to print out the string representation
      See Also:
    • toTextInternal

      protected abstract void toTextInternal(Appendable writer) throws 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.
      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