Class EntityProjection<M,D>

java.lang.Object
org.springframework.data.projection.EntityProjection<M,D>
Type Parameters:
M - the mapped type acting as view onto the domain type.
D - the domain type.
All Implemented Interfaces:
Iterable<EntityProjection.PropertyProjection<?,?>>, Supplier<Stream<EntityProjection.PropertyProjection<?,?>>>, Streamable<EntityProjection.PropertyProjection<?,?>>
Direct Known Subclasses:
EntityProjection.PropertyProjection

public class EntityProjection<M,D> extends Object implements Streamable<EntityProjection.PropertyProjection<?,?>>
Descriptor for a top-level mapped type representing a view onto a domain type structure. The view may exactly match the domain type or be a DTO/interface projection.
Since:
2.7
Author:
Mark Paluch, Christoph Strobl
  • Method Details

    • projecting

      public static <M, D> EntityProjection<M,D> projecting(TypeInformation<M> mappedType, TypeInformation<D> domainType, List<EntityProjection.PropertyProjection<?,?>> properties, EntityProjection.ProjectionType projectionType)
      Create a projecting variant of a mapped type.
      Parameters:
      mappedType - the target projection type. Must not be null.
      domainType - the source domain type. Must not be null.
      properties - properties to include.
      projectionType - must not be null.
      Returns:
      new instance of EntityProjection.
    • nonProjecting

      public static <M, D> EntityProjection<M,D> nonProjecting(TypeInformation<M> mappedType, TypeInformation<D> domainType, List<EntityProjection.PropertyProjection<?,?>> properties)
      Create a non-projecting variant of a mapped type.
      Parameters:
      mappedType - the target projection type. Must not be null.
      domainType - the source domain type. Must not be null.
      properties - properties to include.
      Returns:
      new instance of EntityProjection.
    • nonProjecting

      public static <T> EntityProjection<T,T> nonProjecting(Class<T> type)
      Create a non-projecting variant of a type.
      Parameters:
      type - must not be null.
      Returns:
      new instance of EntityProjection.
    • forEachRecursive

      public void forEachRecursive(Consumer<? super EntityProjection.PropertyProjection<?,?>> action)
      Performs the given action for each element of the Streamable recursively until all elements of the graph have been processed or the action throws an Exception. Unless otherwise specified by the implementing class, actions are performed in the order of iteration (if an iteration order is specified). Exceptions thrown by the action are relayed to the caller.
      Parameters:
      action - must not be null.
    • iterator

      Specified by:
      iterator in interface Iterable<M>
    • getMappedType

      public TypeInformation<M> getMappedType()
      Returns:
      the mapped type used by this type view.
    • getActualMappedType

      public TypeInformation<?> getActualMappedType()
      Returns:
      the actual mapped type used by this type view. Should be used for collection-like and map-like properties to determine the actual view type.
      Throws:
      IllegalStateException - if the actual type cannot be resolved.
    • getDomainType

      public TypeInformation<D> getDomainType()
      Returns:
      the domain type represented by this type view.
    • getActualDomainType

      public TypeInformation<?> getActualDomainType()
      Returns:
      the actual domain type represented by this type view. Should be used for collection-like and map-like properties to determine the actual domain type.
      Throws:
      IllegalStateException - if the actual type cannot be resolved.
    • isProjection

      public boolean isProjection()
      Returns:
      true if the getMappedType() is a projection.
    • isClosedProjection

      public boolean isClosedProjection()
      Returns:
      true if the getMappedType() is a closed projection.
    • findProperty

      @Nullable public EntityProjection<?,?> findProperty(String name)
      Return a EntityProjection for a property identified by name.
      Parameters:
      name - the property name.
      Returns:
      the type view, if the property is known; null otherwise.
    • toString

      public String toString()
      Overrides:
      toString in class Object