Interface AggregatePath

All Superinterfaces:
Comparable<AggregatePath>, Iterable<AggregatePath>

public interface AggregatePath extends Iterable<AggregatePath>, Comparable<AggregatePath>
Represents a path within an aggregate starting from the aggregate root. The path can be iterated from the leaf to its root.

It implements Comparable so that collections of AggregatePath instances can be sorted in a consistent way.

Since:
3.2
Author:
Jens Schauder, Mark Paluch
  • Method Details

    • getParentPath

      AggregatePath getParentPath()
      Returns the path that has the same beginning but is one segment shorter than this path.
      Returns:
      the parent path. Guaranteed to be not null.
      Throws:
      IllegalStateException - when called on an empty path.
    • append

      Creates a new path by extending the current path by the property passed as an argument.
      Parameters:
      property - must not be null.
      Returns:
      Guaranteed to be not null.
    • append

      Creates a new path by extending the current path by the path passed as an argument.
      Parameters:
      path - must not be null.
      Returns:
      Guaranteed to be not null.
      Since:
      4.0
    • isRoot

      boolean isRoot()
      Returns:
      true if this is a root path for the underlying type.
    • getLength

      default int getLength()
      Returns the path length for the aggregate path.
      Returns:
      the path length for the aggregate path
    • isWritable

      boolean isWritable()
    • isEntity

      boolean isEntity()
      Returns:
      true when this is an empty path or the path references an entity.
    • isEmbedded

      boolean isEmbedded()
      Returns true exactly when the path is non-empty and the leaf property an embedded one.
      Returns:
      if the leaf property is embedded.
    • isMultiValued

      boolean isMultiValued()
      Returns true if there are multiple values for this path, i.e. if the path contains at least one element that is a collection and array or a map. // TODO: why does this return true if the parent entity is a collection? This seems to mix some concepts that belong to somewhere else. // TODO: Multi-valued could be understood for embeddables with more than one column (i.e. composite primary keys)
      Returns:
      true if the path contains a multivalued element.
    • isQualified

      boolean isQualified()
      Returns:
      true when this is references a List or Map.
    • isMap

      boolean isMap()
      Returns:
      true if the leaf property of this path is a Map.
      See Also:
    • isCollectionLike

      boolean isCollectionLike()
      Returns:
      true when this is references a Collection or an array.
    • isOrdered

      boolean isOrdered()
      Returns:
      whether the leaf end of the path is ordered, i.e. the data to populate must be ordered.
      See Also:
    • hasIdProperty

      boolean hasIdProperty()
      Returns:
      true if this path represents an entity which has an identifier attribute.
    • getRequiredIdProperty

      RelationalPersistentProperty getRequiredIdProperty()
    • getRequiredPersistentPropertyPath

      PersistentPropertyPath<RelationalPersistentProperty> getRequiredPersistentPropertyPath()
      Returns:
      the persistent property path if the path is not a root path.
      Throws:
      IllegalStateException - if the current path is a root path.
      See Also:
    • getRequiredBaseProperty

      default RelationalPersistentProperty getRequiredBaseProperty()
      Returns:
      the base property.
      Throws:
      IllegalStateException - if the current path is a root path.
      See Also:
    • getRequiredLeafProperty

      default RelationalPersistentProperty getRequiredLeafProperty()
      Returns:
      the leaf property.
      Throws:
      IllegalStateException - if the current path is a root path.
      See Also:
    • getLeafEntity

      @Nullable RelationalPersistentEntity<?> getLeafEntity()
      The RelationalPersistentEntity associated with the leaf of this path.
      Returns:
      Might return null when called on a path that does not represent an entity.
    • getRequiredLeafEntity

      default RelationalPersistentEntity<?> getRequiredLeafEntity()
      The RelationalPersistentEntity associated with the leaf of this path or throw IllegalStateException if the leaf cannot be resolved.
      Returns:
      the required RelationalPersistentEntity associated with the leaf of this path.
      Throws:
      IllegalStateException - if the persistent entity cannot be resolved.
    • toDotPath

      String toDotPath()
      Returns the dot based path notation using PersistentProperty.getName().
      Returns:
      will never be null.
    • getTableInfo

      default AggregatePath.TableInfo getTableInfo()
    • getColumnInfo

      default AggregatePath.ColumnInfo getColumnInfo()
    • filter

      default @Nullable AggregatePath filter(Predicate<? super AggregatePath> predicate)
      Filter the AggregatePath returning the first item matching the given Predicate.
      Parameters:
      predicate - must not be null.
      Returns:
      the first matching element or null.
    • stream

      default Stream<AggregatePath> stream()
      Creates a non-parallel Stream of the underlying Iterable.
      Returns:
      will never be null.
    • getIdDefiningParentPath

      AggregatePath getIdDefiningParentPath()
      Returns the longest ancestor path that has an Id property.
      Returns:
      a path that starts just as this path but is shorter. Guaranteed to be not null.
      Throws:
      IllegalStateException - if the current path is not a root path or if there is no identifier associated.
    • getTail

      @Nullable AggregatePath getTail()
      The path resulting from removing the first element of the AggregatePath.
      Returns:
      null for any AggregatePath having less than two elements.
      Since:
      4.0
    • getRequiredTail

      default AggregatePath getRequiredTail()
      The required path resulting from removing the first element of the AggregatePath or throwing IllegalStateException for any AggregatePath having less than two elements.
      Throws:
      IllegalStateException - for any AggregatePath having less than two elements.
      Since:
      4.0
    • subtract

      @Nullable AggregatePath subtract(@Nullable AggregatePath basePath)
      Subtract the basePath from this AggregatePath by removing the basePath from the beginning of this.
      Parameters:
      basePath - the path to be removed.
      Returns:
      an AggregatePath that ends like the original AggregatePath but has basePath removed from the beginning.
      Since:
      4.0
    • compareTo

      default int compareTo(AggregatePath other)
      Compares this AggregatePath to another AggregatePath based on their dot path notation.

      This is used to get AggregatePath instances sorted in a consistent way. Since this order affects generated SQL this also affects query caches and similar.

      Specified by:
      compareTo in interface Comparable<AggregatePath>
      Parameters:
      other - the AggregatePath to compare to. Must not be null.
      Returns:
      a negative integer, zero, or a positive integer as this object's path is less than, equal to, or greater than the specified object's path.
      Since:
      4.0
    • getSubPathBasedOn

      AggregatePath getSubPathBasedOn(Class<?> baseType)