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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Descriptor for a property-level type along its potential projection that is held within aCollection
-like orMap
-like container.static enum
Projection type.static class
Descriptor for a property-level type along its potential projection. -
Method Summary
Modifier and TypeMethodDescriptionEntityProjection<?,
?> findProperty
(String name) Return aEntityProjection
for a property identified byname
.void
forEachRecursive
(Consumer<? super EntityProjection.PropertyProjection<?, ?>> action) Performs the given action for each element of theStreamable
recursively until all elements of the graph have been processed or the action throws anException
.boolean
boolean
iterator()
static <T> EntityProjection<T,
T> nonProjecting
(Class<T> type) Create a non-projecting variant of atype
.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.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.toString()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
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
Create a non-projecting variant of atype
.- Parameters:
type
- must not be null.- Returns:
- new instance of
EntityProjection
.
-
forEachRecursive
Performs the given action for each element of theStreamable
recursively until all elements of the graph have been processed or the action throws anException
. 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
-
getMappedType
- Returns:
- the mapped type used by this type view.
-
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
- Returns:
- the domain type represented by this type view.
-
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 thegetMappedType()
is a projection.
-
isClosedProjection
public boolean isClosedProjection()- Returns:
true
if thegetMappedType()
is a closed projection.
-
findProperty
Return aEntityProjection
for a property identified byname
.- Parameters:
name
- the property name.- Returns:
- the type view, if the property is known;
null
otherwise.
-
toString
-