Class MetadataCriteriaProjectionBuilder

java.lang.Object
nl.datasteel.crudcraft.projection.impl.jpa.MetadataCriteriaProjectionBuilder
All Implemented Interfaces:
CriteriaProjectionBuilder

public class MetadataCriteriaProjectionBuilder extends Object implements CriteriaProjectionBuilder
CriteriaProjectionBuilder that relies on pre-generated ProjectionMetadata instead of reflection.
  • Constructor Details

    • MetadataCriteriaProjectionBuilder

      public MetadataCriteriaProjectionBuilder(ProjectionMetadataRegistry registry)
      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 metadata
      mapper - 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 interface CriteriaProjectionBuilder
      Type Parameters:
      T - the type of the entity
      D - the type of the DTO
      Parameters:
      cb - the CriteriaBuilder to use for constructing the query
      entityType - the type of the entity to project from
      dtoType - the type of the DTO to project into
      query - 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 interface CriteriaProjectionBuilder
      Type Parameters:
      D - the type of the DTO
      Parameters:
      cb - the CriteriaBuilder to use for constructing selections
      from - the From object representing the root entity
      dtoType - the type of the DTO to project into
      Returns:
      a Selection that constructs the DTO from the entity paths