Class MetadataCriteriaProjectionBuilder
java.lang.Object
nl.datasteel.crudcraft.projection.impl.jpa.MetadataCriteriaProjectionBuilder
- All Implemented Interfaces:
CriteriaProjectionBuilder
CriteriaProjectionBuilder
that relies on pre-generated
ProjectionMetadata
instead of reflection.-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a MetadataCriteriaProjectionBuilder with the given registry.MetadataCriteriaProjectionBuilder
(ProjectionMetadataRegistry registry, ProjectionMapper mapper) Constructs a MetadataCriteriaProjectionBuilder with the given registry and mapper. -
Method Summary
Modifier and TypeMethodDescription<T,
D> jakarta.persistence.criteria.CriteriaQuery <D> build
(jakarta.persistence.criteria.CriteriaBuilder cb, Class<T> entityType, Class<D> dtoType, ProjectionQuery<T> query) Builds a JPA Criteria query that projects entity data into a DTO.<D> jakarta.persistence.criteria.Selection
<D> construct
(jakarta.persistence.criteria.CriteriaBuilder cb, jakarta.persistence.criteria.From<?, ?> from, Class<D> dtoType) Constructs a JPA Criteria selection for the given DTO type.
-
Constructor Details
-
MetadataCriteriaProjectionBuilder
Constructs a MetadataCriteriaProjectionBuilder with the given registry. This constructor uses a default ProjectionMapper for constructing selections when metadata is not available.- Parameters:
registry
- the ProjectionMetadataRegistry to use for accessing compile-time generated metadata
-
MetadataCriteriaProjectionBuilder
public MetadataCriteriaProjectionBuilder(ProjectionMetadataRegistry registry, ProjectionMapper mapper) Constructs a MetadataCriteriaProjectionBuilder with the given registry and mapper. This allows for custom mapping logic if needed.- Parameters:
registry
- the ProjectionMetadataRegistry to use for accessing compile-time generated metadatamapper
- the ProjectionMapper to use for constructing selections when metadata is not available
-
-
Method Details
-
build
public <T,D> jakarta.persistence.criteria.CriteriaQuery<D> build(jakarta.persistence.criteria.CriteriaBuilder cb, Class<T> entityType, Class<D> dtoType, ProjectionQuery<T> query) Builds a JPA Criteria query that projects entity data into a DTO. This method constructs the query using the provided CriteriaBuilder, entity type, DTO type, and ProjectionQuery.- Specified by:
build
in interfaceCriteriaProjectionBuilder
- Type Parameters:
T
- the type of the entityD
- the type of the DTO- Parameters:
cb
- the CriteriaBuilder to use for constructing the queryentityType
- the type of the entity to project fromdtoType
- the type of the DTO to project intoquery
- the ProjectionQuery containing additional query parameters- Returns:
- a CriteriaQuery that projects entity data into a DTO
-
construct
public <D> jakarta.persistence.criteria.Selection<D> construct(jakarta.persistence.criteria.CriteriaBuilder cb, jakarta.persistence.criteria.From<?, ?> from, Class<D> dtoType) Constructs a JPA Criteria selection for the given DTO type. If the metadata is available, it uses that to construct the selection; otherwise, it falls back to using the ProjectionMapper.- Specified by:
construct
in interfaceCriteriaProjectionBuilder
- Type Parameters:
D
- the type of the DTO- Parameters:
cb
- the CriteriaBuilder to use for constructing selectionsfrom
- the From object representing the root entitydtoType
- the type of the DTO to project into- Returns:
- a Selection that constructs the DTO from the entity paths
-